Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #89572

Merged
merged 26 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
734209e
Normalize assoc types when checking ret ty of main
ThePuzzlemaker Sep 6, 2021
33a2825
Clean up the fix a bit
ThePuzzlemaker Sep 7, 2021
f1c8acc
Use `libc::sigaction()` instead of `sys::signal()` to prevent a deadlock
FabianWolff Sep 10, 2021
2bff77d
Fix suggestion for nested struct patterns
FabianWolff Sep 12, 2021
e3e5ae9
Clean up unneeded explicit pointer cast
dtolnay Sep 29, 2021
65ef265
Call `libc::sigaction()` only on Android
FabianWolff Oct 1, 2021
e3996ff
Fix Lower/UpperExp formatting for integers and precision zero
FabianWolff Oct 3, 2021
199b33f
Use a test value that doesn't depend on the handling of even/odd roun…
joshtriplett Oct 4, 2021
9cb30f4
Move generic error message to separate branches
JulianKnodt Sep 28, 2021
32a5abc
Make `proc_macro_derive_resolution_fallback` a future-breakage lint
Aaron1011 Oct 4, 2021
40fe064
Add a check for duplicated doc aliases in unused lint
GuillaumeGomez Oct 1, 2021
013aa37
Add test for duplicated doc aliases
GuillaumeGomez Oct 1, 2021
02c2a35
Discuss field-sensitivity and enums in context of `MaybeLiveLocals`
ecstatic-morse Oct 4, 2021
9f9f7f6
Ensure that `MaybeLiveLocals` works with simple sum-type assignments
ecstatic-morse Oct 4, 2021
c35a700
Make an initial guess for metadata size to reduce buffer resizes
joshtriplett Oct 5, 2021
4ec0377
for signed overflowing remainder, delay comparing lhs with MIN
tspiteri Oct 5, 2021
960e49e
Rollup merge of #88706 - ThePuzzlemaker:issue-88609, r=jackh726
Manishearth Oct 5, 2021
eb86098
Rollup merge of #88828 - FabianWolff:issue-88585, r=dtolnay
Manishearth Oct 5, 2021
60b9c5d
Rollup merge of #88871 - FabianWolff:issue-88403, r=jackh726
Manishearth Oct 5, 2021
0352a28
Rollup merge of #89317 - JulianKnodt:precise_errors, r=BoxyUwU
Manishearth Oct 5, 2021
e745e09
Rollup merge of #89351 - tspiteri:wrapping_rem, r=dtolnay
Manishearth Oct 5, 2021
80f1f0d
Rollup merge of #89442 - GuillaumeGomez:duplicated-doc-alias, r=estebank
Manishearth Oct 5, 2021
4e8c853
Rollup merge of #89502 - FabianWolff:issue-89493, r=joshtriplett
Manishearth Oct 5, 2021
048b0fd
Rollup merge of #89523 - Aaron1011:derive-future-compat, r=wesleywiser
Manishearth Oct 5, 2021
f71b3e2
Rollup merge of #89532 - ecstatic-morse:maybe-live-locals-enum, r=oli…
Manishearth Oct 5, 2021
5f8b161
Rollup merge of #89546 - joshtriplett:grow-metadata-faster, r=petroch…
Manishearth Oct 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,7 @@ declare_lint! {
"detects proc macro derives using inaccessible names from parent modules",
@future_incompatible = FutureIncompatibleInfo {
reference: "issue #83583 <https://github.com/rust-lang/rust/issues/83583>",
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
};
}

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,9 @@ fn get_metadata_section(
// Header is okay -> inflate the actual metadata
let compressed_bytes = &buf[header_len..];
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
let mut inflated = Vec::new();
// Assume the decompressed data will be at least the size of the compressed data, so we
// don't have to grow the buffer as much.
let mut inflated = Vec::with_capacity(compressed_bytes.len());
match FrameDecoder::new(compressed_bytes).read_to_end(&mut inflated) {
Ok(_) => rustc_erase_owner!(OwningRef::new(inflated).map_owner_box()),
Err(_) => {
Expand Down
31 changes: 31 additions & 0 deletions compiler/rustc_mir_dataflow/src/impls/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ use crate::{AnalysisDomain, Backward, GenKill, GenKillAnalysis};
/// exist. See [this `mir-dataflow` test][flow-test] for an example. You almost never want to use
/// this analysis without also looking at the results of [`MaybeBorrowedLocals`].
///
/// ## Field-(in)sensitivity
///
/// As the name suggests, this analysis is field insensitive. If a projection of a variable `x` is
/// assigned to (e.g. `x.0 = 42`), it does not "define" `x` as far as liveness is concerned. In fact,
/// such an assignment is currently marked as a "use" of `x` in an attempt to be maximally
/// conservative.
///
/// ## Enums and `SetDiscriminant`
///
/// Assigning a literal value to an `enum` (e.g. `Option<i32>`), does not result in a simple
/// assignment of the form `_1 = /*...*/` in the MIR. For example, the following assignment to `x`:
///
/// ```
/// x = Some(4);
/// ```
///
/// compiles to this MIR
///
/// ```
/// ((_1 as Some).0: i32) = const 4_i32;
/// discriminant(_1) = 1;
/// ```
///
/// However, `MaybeLiveLocals` **does** mark `x` (`_1`) as "killed" after a statement like this.
/// That's because it treats the `SetDiscriminant` operation as a definition of `x`, even though
/// the writes that actually initialized the locals happened earlier.
///
/// This makes `MaybeLiveLocals` unsuitable for certain classes of optimization normally associated
/// with a live variables analysis, notably dead-store elimination. It's a dirty hack, but it works
/// okay for the generator state transform (currently the main consumuer of this analysis).
///
/// [`MaybeBorrowedLocals`]: super::MaybeBorrowedLocals
/// [flow-test]: https://github.com/rust-lang/rust/blob/a08c47310c7d49cbdc5d7afb38408ba519967ecd/src/test/ui/mir-dataflow/liveness-ptr.rs
/// [liveness]: https://en.wikipedia.org/wiki/Live_variable_analysis
Expand Down
42 changes: 36 additions & 6 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_middle::ty::query::Providers;
use rustc_middle::ty::TyCtxt;

use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, NestedMetaItem};
use rustc_data_structures::stable_set::FxHashSet;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{pluralize, struct_span_err, Applicability};
use rustc_feature::{AttributeType, BUILTIN_ATTRIBUTE_MAP};
use rustc_hir as hir;
Expand Down Expand Up @@ -66,6 +66,7 @@ impl CheckAttrVisitor<'tcx> {
target: Target,
item: Option<ItemLike<'_>>,
) {
let mut doc_aliases = FxHashMap::default();
let mut is_valid = true;
let mut specified_inline = None;
let mut seen = FxHashSet::default();
Expand All @@ -79,7 +80,13 @@ impl CheckAttrVisitor<'tcx> {
sym::track_caller => {
self.check_track_caller(hir_id, &attr.span, attrs, span, target)
}
sym::doc => self.check_doc_attrs(attr, hir_id, target, &mut specified_inline),
sym::doc => self.check_doc_attrs(
attr,
hir_id,
target,
&mut specified_inline,
&mut doc_aliases,
),
sym::no_link => self.check_no_link(hir_id, &attr, span, target),
sym::export_name => self.check_export_name(hir_id, &attr, span, target),
sym::rustc_layout_scalar_valid_range_start
Expand Down Expand Up @@ -512,6 +519,7 @@ impl CheckAttrVisitor<'tcx> {
hir_id: HirId,
target: Target,
is_list: bool,
aliases: &mut FxHashMap<String, Span>,
) -> bool {
let tcx = self.tcx;
let err_fn = move |span: Span, msg: &str| {
Expand Down Expand Up @@ -582,17 +590,38 @@ impl CheckAttrVisitor<'tcx> {
if &*item_name.as_str() == doc_alias {
return err_fn(meta.span(), "is the same as the item's name");
}
let span = meta.span();
if let Err(entry) = aliases.try_insert(doc_alias.to_owned(), span) {
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, span, |lint| {
lint.build("doc alias is duplicated")
.span_label(*entry.entry.get(), "first defined here")
.emit();
});
}
true
}

fn check_doc_alias(&self, meta: &NestedMetaItem, hir_id: HirId, target: Target) -> bool {
fn check_doc_alias(
&self,
meta: &NestedMetaItem,
hir_id: HirId,
target: Target,
aliases: &mut FxHashMap<String, Span>,
) -> bool {
if let Some(values) = meta.meta_item_list() {
let mut errors = 0;
for v in values {
match v.literal() {
Some(l) => match l.kind {
LitKind::Str(s, _) => {
if !self.check_doc_alias_value(v, &s.as_str(), hir_id, target, true) {
if !self.check_doc_alias_value(
v,
&s.as_str(),
hir_id,
target,
true,
aliases,
) {
errors += 1;
}
}
Expand Down Expand Up @@ -621,7 +650,7 @@ impl CheckAttrVisitor<'tcx> {
}
errors == 0
} else if let Some(doc_alias) = meta.value_str().map(|s| s.to_string()) {
self.check_doc_alias_value(meta, &doc_alias, hir_id, target, false)
self.check_doc_alias_value(meta, &doc_alias, hir_id, target, false, aliases)
} else {
self.tcx
.sess
Expand Down Expand Up @@ -858,6 +887,7 @@ impl CheckAttrVisitor<'tcx> {
hir_id: HirId,
target: Target,
specified_inline: &mut Option<(bool, Span)>,
aliases: &mut FxHashMap<String, Span>,
) -> bool {
let mut is_valid = true;

Expand All @@ -867,7 +897,7 @@ impl CheckAttrVisitor<'tcx> {
match i_meta.name_or_empty() {
sym::alias
if !self.check_attr_not_crate_level(&meta, hir_id, "alias")
|| !self.check_doc_alias(&meta, hir_id, target) =>
|| !self.check_doc_alias(&meta, hir_id, target, aliases) =>
{
is_valid = false
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
#![feature(in_band_lifetimes)]
#![feature(format_args_capture)]
#![feature(iter_zip)]
#![feature(nll)]
#![feature(map_try_insert)]
#![feature(min_specialization)]
#![feature(nll)]
#![feature(try_blocks)]
#![recursion_limit = "256"]

Expand Down
23 changes: 15 additions & 8 deletions compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,24 @@ impl IrMaps<'tcx> {
self.capture_info_map.insert(hir_id, Rc::new(cs));
}

fn add_from_pat(&mut self, pat: &hir::Pat<'tcx>) {
fn collect_shorthand_field_ids(&self, pat: &hir::Pat<'tcx>) -> HirIdSet {
// For struct patterns, take note of which fields used shorthand
// (`x` rather than `x: x`).
let mut shorthand_field_ids = HirIdSet::default();
let mut pats = VecDeque::new();
pats.push_back(pat);

while let Some(pat) = pats.pop_front() {
use rustc_hir::PatKind::*;
match &pat.kind {
Binding(.., inner_pat) => {
pats.extend(inner_pat.iter());
}
Struct(_, fields, _) => {
let ids = fields.iter().filter(|f| f.is_shorthand).map(|f| f.pat.hir_id);
shorthand_field_ids.extend(ids);
let (short, not_short): (Vec<&_>, Vec<&_>) =
fields.iter().partition(|f| f.is_shorthand);
shorthand_field_ids.extend(short.iter().map(|f| f.pat.hir_id));
pats.extend(not_short.iter().map(|f| f.pat));
}
Ref(inner_pat, _) | Box(inner_pat) => {
pats.push_back(inner_pat);
Expand All @@ -296,6 +299,12 @@ impl IrMaps<'tcx> {
}
}

return shorthand_field_ids;
}

fn add_from_pat(&mut self, pat: &hir::Pat<'tcx>) {
let shorthand_field_ids = self.collect_shorthand_field_ids(pat);

pat.each_binding(|_, hir_id, _, ident| {
self.add_live_node_for_node(hir_id, VarDefNode(ident.span, hir_id));
self.add_variable(Local(LocalInfo {
Expand Down Expand Up @@ -373,15 +382,13 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
}

fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
let shorthand_field_ids = self.collect_shorthand_field_ids(param.pat);
param.pat.each_binding(|_bm, hir_id, _x, ident| {
let var = match param.pat.kind {
rustc_hir::PatKind::Struct(_, fields, _) => Local(LocalInfo {
rustc_hir::PatKind::Struct(..) => Local(LocalInfo {
id: hir_id,
name: ident.name,
is_shorthand: fields
.iter()
.find(|f| f.ident == ident)
.map_or(false, |f| f.is_shorthand),
is_shorthand: shorthand_field_ids.contains(&hir_id),
}),
_ => Param(hir_id, ident.name),
};
Expand Down
Loading