Skip to content

Commit

Permalink
Auto merge of rust-lang#119662 - matthiaskrgr:rollup-ehofh5n, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#118194 (rustdoc: search for tuples and unit by type with `()`)
 - rust-lang#118781 (merge core_panic feature into panic_internals)
 - rust-lang#119486 (pass allow-{dirty,staged} to clippy)
 - rust-lang#119591 (rustc_mir_transform: Make DestinationPropagation stable for queries)
 - rust-lang#119595 (Fixed ambiguity in hint.rs)
 - rust-lang#119624 (rustc_span: More consistent span combination operations)
 - rust-lang#119653 (compiler: update Fuchsia sanitizer support.)
 - rust-lang#119655 (Remove ignore-stage1 that was added when changing error count msg)
 - rust-lang#119661 (Strip lld-wrapper binaries)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 6, 2024
2 parents 9212108 + 5f0f028 commit b6a8c76
Show file tree
Hide file tree
Showing 66 changed files with 909 additions and 235 deletions.
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ gimli.debug = 0
miniz_oxide.debug = 0
object.debug = 0

# These are very thin wrappers around executing lld with the right binary name.
# Basically nothing within them can go wrong without having been explicitly logged anyway.
# We ship these in every rustc tarball and even after compression they add up
# to around 0.6MB of data every user needs to download (and 15MB on disk).
[profile.release.package.lld-wrapper]
debug = 0
strip = true

[patch.crates-io]
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
# here
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/fx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;
pub type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
pub type IndexOccupiedEntry<'a, K, V> = indexmap::map::OccupiedEntry<'a, K, V>;

#[macro_export]
macro_rules! define_id_collections {
Expand Down
30 changes: 14 additions & 16 deletions compiler/rustc_mir_transform/src/dest_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@
//! [attempt 2]: https://github.com/rust-lang/rust/pull/71003
//! [attempt 3]: https://github.com/rust-lang/rust/pull/72632

use std::collections::hash_map::{Entry, OccupiedEntry};

use crate::MirPass;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxIndexMap, IndexEntry, IndexOccupiedEntry};
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
use rustc_middle::mir::HasLocalDecls;
Expand Down Expand Up @@ -211,7 +209,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
let mut merged_locals: BitSet<Local> = BitSet::new_empty(body.local_decls.len());

// This is the set of merges we will apply this round. It is a subset of the candidates.
let mut merges = FxHashMap::default();
let mut merges = FxIndexMap::default();

for (src, candidates) in candidates.c.iter() {
if merged_locals.contains(*src) {
Expand Down Expand Up @@ -250,8 +248,8 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
/// frequently. Everything with a `&'alloc` lifetime points into here.
#[derive(Default)]
struct Allocations {
candidates: FxHashMap<Local, Vec<Local>>,
candidates_reverse: FxHashMap<Local, Vec<Local>>,
candidates: FxIndexMap<Local, Vec<Local>>,
candidates_reverse: FxIndexMap<Local, Vec<Local>>,
write_info: WriteInfo,
// PERF: Do this for `MaybeLiveLocals` allocations too.
}
Expand All @@ -272,11 +270,11 @@ struct Candidates<'alloc> {
///
/// We will still report that we would like to merge `_1` and `_2` in an attempt to allow us to
/// remove that assignment.
c: &'alloc mut FxHashMap<Local, Vec<Local>>,
c: &'alloc mut FxIndexMap<Local, Vec<Local>>,
/// A reverse index of the `c` set; if the `c` set contains `a => Place { local: b, proj }`,
/// then this contains `b => a`.
// PERF: Possibly these should be `SmallVec`s?
reverse: &'alloc mut FxHashMap<Local, Vec<Local>>,
reverse: &'alloc mut FxIndexMap<Local, Vec<Local>>,
}

//////////////////////////////////////////////////////////
Expand All @@ -287,7 +285,7 @@ struct Candidates<'alloc> {
fn apply_merges<'tcx>(
body: &mut Body<'tcx>,
tcx: TyCtxt<'tcx>,
merges: &FxHashMap<Local, Local>,
merges: &FxIndexMap<Local, Local>,
merged_locals: &BitSet<Local>,
) {
let mut merger = Merger { tcx, merges, merged_locals };
Expand All @@ -296,7 +294,7 @@ fn apply_merges<'tcx>(

struct Merger<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
merges: &'a FxHashMap<Local, Local>,
merges: &'a FxIndexMap<Local, Local>,
merged_locals: &'a BitSet<Local>,
}

Expand Down Expand Up @@ -379,7 +377,7 @@ impl<'alloc> Candidates<'alloc> {

/// `vec_filter_candidates` but for an `Entry`
fn entry_filter_candidates(
mut entry: OccupiedEntry<'_, Local, Vec<Local>>,
mut entry: IndexOccupiedEntry<'_, Local, Vec<Local>>,
p: Local,
f: impl FnMut(Local) -> CandidateFilter,
at: Location,
Expand All @@ -399,7 +397,7 @@ impl<'alloc> Candidates<'alloc> {
at: Location,
) {
// Cover the cases where `p` appears as a `src`
if let Entry::Occupied(entry) = self.c.entry(p) {
if let IndexEntry::Occupied(entry) = self.c.entry(p) {
Self::entry_filter_candidates(entry, p, &mut f, at);
}
// And the cases where `p` appears as a `dest`
Expand All @@ -412,7 +410,7 @@ impl<'alloc> Candidates<'alloc> {
if f(*src) == CandidateFilter::Keep {
return true;
}
let Entry::Occupied(entry) = self.c.entry(*src) else {
let IndexEntry::Occupied(entry) = self.c.entry(*src) else {
return false;
};
Self::entry_filter_candidates(
Expand Down Expand Up @@ -721,8 +719,8 @@ fn places_to_candidate_pair<'tcx>(
fn find_candidates<'alloc, 'tcx>(
body: &Body<'tcx>,
borrowed: &BitSet<Local>,
candidates: &'alloc mut FxHashMap<Local, Vec<Local>>,
candidates_reverse: &'alloc mut FxHashMap<Local, Vec<Local>>,
candidates: &'alloc mut FxIndexMap<Local, Vec<Local>>,
candidates_reverse: &'alloc mut FxIndexMap<Local, Vec<Local>>,
) -> Candidates<'alloc> {
candidates.clear();
candidates_reverse.clear();
Expand All @@ -744,7 +742,7 @@ fn find_candidates<'alloc, 'tcx>(

struct FindAssignments<'a, 'alloc, 'tcx> {
body: &'a Body<'tcx>,
candidates: &'alloc mut FxHashMap<Local, Vec<Local>>,
candidates: &'alloc mut FxIndexMap<Local, Vec<Local>>,
borrowed: &'a BitSet<Local>,
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,7 @@ impl<'a> Parser<'a> {
}
ExprKind::Block(_, None) => {
this.dcx().emit_err(errors::IfExpressionMissingCondition {
if_span: lo.shrink_to_hi(),
if_span: lo.with_neighbor(cond.span).shrink_to_hi(),
block_span: self.sess.source_map().start_point(cond_span),
});
std::mem::replace(&mut cond, this.mk_expr_err(cond_span.shrink_to_hi()))
Expand Down Expand Up @@ -3735,7 +3735,7 @@ impl<'a> Parser<'a> {
}

pub(crate) fn mk_expr(&self, span: Span, kind: ExprKind) -> P<Expr> {
P(Expr { kind, span, attrs: AttrVec::new(), id: DUMMY_NODE_ID, tokens: None })
self.mk_expr_with_attrs(span, kind, AttrVec::new())
}

pub(super) fn mk_expr_err(&self, span: Span) -> P<Expr> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ impl<'a> Parser<'a> {
Applicability::MaybeIncorrect,
);
err.span_suggestion(
span.shrink_to_hi(),
span.with_neighbor(self.token.span).shrink_to_hi(),
"add a semicolon",
';',
Applicability::MaybeIncorrect,
Expand Down Expand Up @@ -2632,7 +2632,7 @@ impl<'a> Parser<'a> {

let is_name_required = match this.token.kind {
token::DotDotDot => false,
_ => req_name(this.token.span.edition()),
_ => req_name(this.token.span.with_neighbor(this.prev_token.span).edition()),
};
let (pat, ty) = if is_name_required || this.is_named_param() {
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);
Expand Down
17 changes: 1 addition & 16 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,21 +852,6 @@ impl fmt::Debug for SyntaxContext {
}

impl Span {
/// Creates a fresh expansion with given properties.
/// Expansions are normally created by macros, but in some cases expansions are created for
/// other compiler-generated code to set per-span properties like allowed unstable features.
/// The returned span belongs to the created expansion and has the new properties,
/// but its location is inherited from the current span.
pub fn fresh_expansion(self, expn_id: LocalExpnId) -> Span {
HygieneData::with(|data| {
self.with_ctxt(data.apply_mark(
self.ctxt(),
expn_id.to_expn_id(),
Transparency::Transparent,
))
})
}

/// Reuses the span but adds information like the kind of the desugaring and features that are
/// allowed inside this span.
pub fn mark_with_reason(
Expand All @@ -881,7 +866,7 @@ impl Span {
..ExpnData::default(ExpnKind::Desugaring(reason), self, edition, None, None)
};
let expn_id = LocalExpnId::fresh(expn_data, ctx);
self.fresh_expansion(expn_id)
self.apply_mark(expn_id.to_expn_id(), Transparency::Transparent)
}
}

Expand Down
96 changes: 47 additions & 49 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,39 @@ impl Span {
)
}

/// Prepare two spans to a combine operation like `to` or `between`.
/// FIXME: consider using declarative macro metavariable spans for the given spans if they are
/// better suitable for combining (#119412).
fn prepare_to_combine(
a_orig: Span,
b_orig: Span,
) -> Result<(SpanData, SpanData, Option<LocalDefId>), Span> {
let (a, b) = (a_orig.data(), b_orig.data());

if a.ctxt != b.ctxt {
// Context mismatches usually happen when procedural macros combine spans copied from
// the macro input with spans produced by the macro (`Span::*_site`).
// In that case we consider the combined span to be produced by the macro and return
// the original macro-produced span as the result.
// Otherwise we just fall back to returning the first span.
// Combining locations typically doesn't make sense in case of context mismatches.
// `is_root` here is a fast path optimization.
let a_is_callsite = a.ctxt.is_root() || a.ctxt == b.span().source_callsite().ctxt();
return Err(if a_is_callsite { b_orig } else { a_orig });
}

let parent = if a.parent == b.parent { a.parent } else { None };
Ok((a, b, parent))
}

/// This span, but in a larger context, may switch to the metavariable span if suitable.
pub fn with_neighbor(self, neighbor: Span) -> Span {
match Span::prepare_to_combine(self, neighbor) {
Ok((this, ..)) => Span::new(this.lo, this.hi, this.ctxt, this.parent),
Err(_) => self,
}
}

/// Returns a `Span` that would enclose both `self` and `end`.
///
/// Note that this can also be used to extend the span "backwards":
Expand All @@ -836,26 +869,12 @@ impl Span {
/// ^^^^^^^^^^^^^^^^^^^^
/// ```
pub fn to(self, end: Span) -> Span {
let span_data = self.data();
let end_data = end.data();
// FIXME(jseyfried): `self.ctxt` should always equal `end.ctxt` here (cf. issue #23480).
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
// have an incomplete span than a completely nonsensical one.
if span_data.ctxt != end_data.ctxt {
if span_data.ctxt.is_root() {
return end;
} else if end_data.ctxt.is_root() {
return self;
match Span::prepare_to_combine(self, end) {
Ok((from, to, parent)) => {
Span::new(cmp::min(from.lo, to.lo), cmp::max(from.hi, to.hi), from.ctxt, parent)
}
// Both spans fall within a macro.
// FIXME(estebank): check if it is the *same* macro.
Err(fallback) => fallback,
}
Span::new(
cmp::min(span_data.lo, end_data.lo),
cmp::max(span_data.hi, end_data.hi),
if span_data.ctxt.is_root() { end_data.ctxt } else { span_data.ctxt },
if span_data.parent == end_data.parent { span_data.parent } else { None },
)
}

/// Returns a `Span` between the end of `self` to the beginning of `end`.
Expand All @@ -866,14 +885,12 @@ impl Span {
/// ^^^^^^^^^^^^^
/// ```
pub fn between(self, end: Span) -> Span {
let span = self.data();
let end = end.data();
Span::new(
span.hi,
end.lo,
if end.ctxt.is_root() { end.ctxt } else { span.ctxt },
if span.parent == end.parent { span.parent } else { None },
)
match Span::prepare_to_combine(self, end) {
Ok((from, to, parent)) => {
Span::new(cmp::min(from.hi, to.hi), cmp::max(from.lo, to.lo), from.ctxt, parent)
}
Err(fallback) => fallback,
}
}

/// Returns a `Span` from the beginning of `self` until the beginning of `end`.
Expand All @@ -884,31 +901,12 @@ impl Span {
/// ^^^^^^^^^^^^^^^^^
/// ```
pub fn until(self, end: Span) -> Span {
// Most of this function's body is copied from `to`.
// We can't just do `self.to(end.shrink_to_lo())`,
// because to also does some magic where it uses min/max so
// it can handle overlapping spans. Some advanced mis-use of
// `until` with different ctxts makes this visible.
let span_data = self.data();
let end_data = end.data();
// FIXME(jseyfried): `self.ctxt` should always equal `end.ctxt` here (cf. issue #23480).
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
// have an incomplete span than a completely nonsensical one.
if span_data.ctxt != end_data.ctxt {
if span_data.ctxt.is_root() {
return end;
} else if end_data.ctxt.is_root() {
return self;
match Span::prepare_to_combine(self, end) {
Ok((from, to, parent)) => {
Span::new(cmp::min(from.lo, to.lo), cmp::max(from.lo, to.lo), from.ctxt, parent)
}
// Both spans fall within a macro.
// FIXME(estebank): check if it is the *same* macro.
Err(fallback) => fallback,
}
Span::new(
span_data.lo,
end_data.lo,
if end_data.ctxt.is_root() { end_data.ctxt } else { span_data.ctxt },
if span_data.parent == end_data.parent { span_data.parent } else { None },
)
}

pub fn from_inner(self, inner: InnerSpan) -> Span {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub fn target() -> Target {
base.plt_by_default = false;
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI;
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::LEAK;
base.supports_xray = true;

Target {
llvm_target: "x86_64-unknown-fuchsia".into(),
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
#![feature(const_size_of_val)]
#![feature(const_waker)]
#![feature(core_intrinsics)]
#![feature(core_panic)]
#![feature(deprecated_suggestion)]
#![feature(dispatch_from_dyn)]
#![feature(error_generic_member_access)]
Expand All @@ -139,6 +138,7 @@
#![feature(maybe_uninit_slice)]
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_uninit_array_transpose)]
#![feature(panic_internals)]
#![feature(pattern)]
#![feature(ptr_internals)]
#![feature(ptr_metadata)]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub fn spin_loop() {
///
/// The compiler could theoretically make optimizations like the following:
///
/// - `needle` and `haystack` are always the same, move the call to `contains` outside the loop and
/// - The `needle` and `haystack` do not change, move the call to `contains` outside the loop and
/// delete the loop
/// - Inline `contains`
/// - `needle` and `haystack` have values known at compile time, `contains` is always true. Remove
Expand Down
1 change: 1 addition & 0 deletions library/core/src/intrinsics/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
//! ```rust
//! #![feature(core_intrinsics, custom_mir)]
//! #![allow(internal_features)]
//! #![allow(unused_assignments)]
//!
//! use core::intrinsics::mir::*;
//!
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@
#![feature(const_unicode_case_lookup)]
#![feature(const_unsafecell_get_mut)]
#![feature(const_waker)]
#![feature(core_panic)]
#![feature(coverage_attribute)]
#![feature(duration_consts_float)]
#![feature(internal_impls_macro)]
Expand All @@ -179,6 +178,7 @@
#![feature(non_null_convenience)]
#![feature(offset_of)]
#![feature(offset_of_enum)]
#![feature(panic_internals)]
#![feature(ptr_alignment_type)]
#![feature(ptr_metadata)]
#![feature(set_ptr_value)]
Expand Down

0 comments on commit b6a8c76

Please sign in to comment.