From 6d42636456cc140739b13f787cab5ce550785d94 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 25 Oct 2022 20:52:34 +0000 Subject: [PATCH 1/8] Encode span parent in the inlined representation. --- compiler/rustc_span/src/span_encoding.rs | 86 ++++++++++++++++++------ 1 file changed, 64 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs index f0e91e5a6a917..d48c4f7e5a811 100644 --- a/compiler/rustc_span/src/span_encoding.rs +++ b/compiler/rustc_span/src/span_encoding.rs @@ -4,7 +4,7 @@ // The encoding format for inline spans were obtained by optimizing over crates in rustc/libstd. // See https://internals.rust-lang.org/t/rfc-compiler-refactoring-spans/1357/28 -use crate::def_id::LocalDefId; +use crate::def_id::{DefIndex, LocalDefId}; use crate::hygiene::SyntaxContext; use crate::SPAN_TRACK; use crate::{BytePos, SpanData}; @@ -13,8 +13,8 @@ use rustc_data_structures::fx::FxIndexSet; /// A compressed span. /// -/// Whereas [`SpanData`] is 12 bytes, which is a bit too big to stick everywhere, `Span` -/// is a form that only takes up 8 bytes, with less space for the length and +/// Whereas [`SpanData`] is 16 bytes, which is a bit too big to stick everywhere, `Span` +/// is a form that only takes up 8 bytes, with less space for the length, parent and /// context. The vast majority (99.9%+) of `SpanData` instances will fit within /// those 8 bytes; any `SpanData` whose fields don't fit into a `Span` are /// stored in a separate interner table, and the `Span` will index into that @@ -25,7 +25,7 @@ use rustc_data_structures::fx::FxIndexSet; /// slower because only 80--90% of spans could be stored inline (even less in /// very large crates) and so the interner was used a lot more. /// -/// Inline (compressed) format: +/// Inline (compressed) format with no parent: /// - `span.base_or_index == span_data.lo` /// - `span.len_or_tag == len == span_data.hi - span_data.lo` (must be `<= MAX_LEN`) /// - `span.ctxt_or_tag == span_data.ctxt` (must be `<= MAX_CTXT`) @@ -35,6 +35,12 @@ use rustc_data_structures::fx::FxIndexSet; /// - `span.len_or_tag == LEN_TAG` (high bit set, all other bits are zero) /// - `span.ctxt_or_tag == span_data.ctxt` (must be `<= MAX_CTXT`) /// +/// Inline (compressed) format with root context: +/// - `span.base_or_index == span_data.lo` +/// - `span.len_or_tag == len == span_data.hi - span_data.lo` (must be `<= MAX_LEN`) +/// - `span.len_or_tag` has top bit (`PARENT_MASK`) set +/// - `span.ctxt == span_data.parent` (must be `<= MAX_CTXT`) +/// /// Interned format: /// - `span.base_or_index == index` (indexes into the interner table) /// - `span.len_or_tag == LEN_TAG` (high bit set, all other bits are zero) @@ -73,7 +79,8 @@ pub struct Span { ctxt_or_tag: u16, } -const LEN_TAG: u16 = 0b1000_0000_0000_0000; +const LEN_TAG: u16 = 0b1111_1111_1111_1111; +const PARENT_MASK: u16 = 0b1000_0000_0000_0000; const MAX_LEN: u32 = 0b0111_1111_1111_1111; const CTXT_TAG: u32 = 0b1111_1111_1111_1111; const MAX_CTXT: u32 = CTXT_TAG - 1; @@ -95,16 +102,32 @@ impl Span { let (base, len, ctxt2) = (lo.0, hi.0 - lo.0, ctxt.as_u32()); - if len <= MAX_LEN && ctxt2 <= MAX_CTXT && parent.is_none() { - // Inline format. - Span { base_or_index: base, len_or_tag: len as u16, ctxt_or_tag: ctxt2 as u16 } - } else { - // Interned format. - let index = - with_span_interner(|interner| interner.intern(&SpanData { lo, hi, ctxt, parent })); - let ctxt_or_tag = if ctxt2 <= MAX_CTXT { ctxt2 } else { CTXT_TAG } as u16; - Span { base_or_index: index, len_or_tag: LEN_TAG, ctxt_or_tag } + if len <= MAX_LEN && ctxt2 <= MAX_CTXT { + let len_or_tag = len as u16; + debug_assert_eq!(len_or_tag & PARENT_MASK, 0); + + if let Some(parent) = parent { + // Inline format with parent. + let len_or_tag = len_or_tag | PARENT_MASK; + let parent2 = parent.local_def_index.as_u32(); + if ctxt2 == SyntaxContext::root().as_u32() && parent2 <= MAX_CTXT { + return Span { base_or_index: base, len_or_tag, ctxt_or_tag: parent2 as u16 }; + } + } else { + // Inline format with ctxt. + return Span { + base_or_index: base, + len_or_tag: len as u16, + ctxt_or_tag: ctxt2 as u16, + }; + } } + + // Interned format. + let index = + with_span_interner(|interner| interner.intern(&SpanData { lo, hi, ctxt, parent })); + let ctxt_or_tag = if ctxt2 <= MAX_CTXT { ctxt2 } else { CTXT_TAG } as u16; + Span { base_or_index: index, len_or_tag: LEN_TAG, ctxt_or_tag } } #[inline] @@ -122,12 +145,25 @@ impl Span { pub fn data_untracked(self) -> SpanData { if self.len_or_tag != LEN_TAG { // Inline format. - debug_assert!(self.len_or_tag as u32 <= MAX_LEN); - SpanData { - lo: BytePos(self.base_or_index), - hi: BytePos(self.base_or_index + self.len_or_tag as u32), - ctxt: SyntaxContext::from_u32(self.ctxt_or_tag as u32), - parent: None, + if self.len_or_tag & PARENT_MASK == 0 { + debug_assert!(self.len_or_tag as u32 <= MAX_LEN); + SpanData { + lo: BytePos(self.base_or_index), + hi: BytePos(self.base_or_index + self.len_or_tag as u32), + ctxt: SyntaxContext::from_u32(self.ctxt_or_tag as u32), + parent: None, + } + } else { + let len = self.len_or_tag & !PARENT_MASK; + debug_assert!(len as u32 <= MAX_LEN); + let parent = + LocalDefId { local_def_index: DefIndex::from_u32(self.ctxt_or_tag as u32) }; + SpanData { + lo: BytePos(self.base_or_index), + hi: BytePos(self.base_or_index + len as u32), + ctxt: SyntaxContext::root(), + parent: Some(parent), + } } } else { // Interned format. @@ -141,8 +177,14 @@ impl Span { pub fn ctxt(self) -> SyntaxContext { let ctxt_or_tag = self.ctxt_or_tag as u32; if ctxt_or_tag <= MAX_CTXT { - // Inline format or interned format with inline ctxt. - SyntaxContext::from_u32(ctxt_or_tag) + if self.len_or_tag == LEN_TAG || self.len_or_tag & PARENT_MASK == 0 { + // Inline format or interned format with inline ctxt. + SyntaxContext::from_u32(ctxt_or_tag) + } else { + // Inline format or interned format with inline parent. + // We know that the SyntaxContext is root. + SyntaxContext::root() + } } else { // Interned format. let index = self.base_or_index; From 44972b2ce7bff10ca9277212eedf23b15bbe0eb2 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 31 Oct 2022 16:39:45 +0000 Subject: [PATCH 2/8] Mark incremental-ignore-spans as TRACKED. Using that options basically changes all stable hashes we may compute. Adding/removing as UNTRACKED it makes everything ICE (unstable fingerprint everywhere). As TRACKED, it can still do its job without ICEing. --- compiler/rustc_interface/src/tests.rs | 2 +- compiler/rustc_session/src/options.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index ff2196d58577c..eb3baba999b9c 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -652,7 +652,6 @@ fn test_unstable_options_tracking_hash() { untracked!(future_incompat_test, true); untracked!(hir_stats, true); untracked!(identify_regions, true); - untracked!(incremental_ignore_spans, true); untracked!(incremental_info, true); untracked!(incremental_verify_ich, true); untracked!(input_stats, true); @@ -737,6 +736,7 @@ fn test_unstable_options_tracking_hash() { tracked!(fuel, Some(("abc".to_string(), 99))); tracked!(function_sections, Some(false)); tracked!(human_readable_cgu_names, true); + tracked!(incremental_ignore_spans, true); tracked!(inline_in_all_cgus, Some(true)); tracked!(inline_mir, Some(true)); tracked!(inline_mir_hint_threshold, Some(123)); diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 40bc669707aa0..19dde0a977502 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1333,7 +1333,7 @@ options! { "generate human-readable, predictable names for codegen units (default: no)"), identify_regions: bool = (false, parse_bool, [UNTRACKED], "display unnamed regions as `'`, using a non-ident unique id (default: no)"), - incremental_ignore_spans: bool = (false, parse_bool, [UNTRACKED], + incremental_ignore_spans: bool = (false, parse_bool, [TRACKED], "ignore spans during ICH computation -- used for testing (default: no)"), incremental_info: bool = (false, parse_bool, [UNTRACKED], "print high-level information about incremental reuse (or the lack thereof) \ From 66e0316414072908e23d65edb8ae3f8bcdcf5bac Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 30 Apr 2021 23:57:02 +0200 Subject: [PATCH 3/8] Use absolute spans when trying to steal an AST diagnostic. --- compiler/rustc_errors/src/lib.rs | 8 +++++--- compiler/rustc_hir_typeck/src/expr.rs | 2 +- compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 2 +- compiler/rustc_hir_typeck/src/method/suggest.rs | 4 +++- compiler/rustc_hir_typeck/src/op.rs | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 518b5ec10f890..292ea64ee7ba3 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -653,17 +653,19 @@ impl Handler { /// Retrieve a stashed diagnostic with `steal_diagnostic`. pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) { let mut inner = self.inner.borrow_mut(); - inner.stash((span, key), diag); + inner.stash((span.with_parent(None), key), diag); } /// Steal a previously stashed diagnostic with the given `Span` and [`StashKey`] as the key. pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option> { let mut inner = self.inner.borrow_mut(); - inner.steal((span, key)).map(|diag| DiagnosticBuilder::new_diagnostic(self, diag)) + inner + .steal((span.with_parent(None), key)) + .map(|diag| DiagnosticBuilder::new_diagnostic(self, diag)) } pub fn has_stashed_diagnostic(&self, span: Span, key: StashKey) -> bool { - self.inner.borrow().stashed_diagnostics.get(&(span, key)).is_some() + self.inner.borrow().stashed_diagnostics.get(&(span.with_parent(None), key)).is_some() } /// Emit all stashed diagnostics. diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index ae641b26eeedb..b8b4e87366310 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -395,7 +395,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { E0614, "type `{oprnd_t}` cannot be dereferenced", ); - let sp = tcx.sess.source_map().start_point(expr.span); + let sp = tcx.sess.source_map().start_point(expr.span).with_parent(None); if let Some(sp) = tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 9a7d753e66b8e..fd0c302ff6842 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -973,7 +973,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err: &mut Diagnostic, expr: &hir::Expr<'_>, ) -> bool { - let sp = self.tcx.sess.source_map().start_point(expr.span); + let sp = self.tcx.sess.source_map().start_point(expr.span).with_parent(None); if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) { // `{ 42 } &&x` (#61475) or `{ 42 } && if x { 1 } else { 0 }` err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp)); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 7c5a9a333feba..0eda0258ab975 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -339,7 +339,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &mut err, item_name, rcvr_ty, cal, span, ); } - if let Some(span) = tcx.resolutions(()).confused_type_with_std_module.get(&span) { + if let Some(span) = + tcx.resolutions(()).confused_type_with_std_module.get(&span.with_parent(None)) + { err.span_suggestion( span.shrink_to_lo(), "you are looking for the module in `std`, not the primitive type", diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 9f0d175c4c669..a642fe30506c6 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -660,7 +660,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - let sp = self.tcx.sess.source_map().start_point(ex.span); + let sp = self.tcx.sess.source_map().start_point(ex.span).with_parent(None); if let Some(sp) = self.tcx.sess.parse_sess.ambiguous_block_expr_parse.borrow().get(&sp) { From 65f342daeaaab5b546e2e76d04140d1c788780b9 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 10 Jun 2021 20:34:42 +0200 Subject: [PATCH 4/8] Enable relative span hashing. --- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_expand/src/expand.rs | 2 +- compiler/rustc_middle/src/hir/map/mod.rs | 2 +- compiler/rustc_session/src/options.rs | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index db2527a200c32..bff48a6d0a1b3 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -776,7 +776,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// Intercept all spans entering HIR. /// Mark a span as relative to the current owning item. fn lower_span(&self, span: Span) -> Span { - if self.tcx.sess.opts.unstable_opts.incremental_relative_spans { + if self.tcx.sess.opts.incremental.is_some() { span.with_parent(Some(self.current_hir_id_owner.def_id)) } else { // Do not make spans relative when not using incremental compilation. diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index e26c16dcd7ee7..32dbe579fb47b 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -587,7 +587,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { .resolver .visit_ast_fragment_with_placeholders(self.cx.current_expansion.id, &fragment); - if self.cx.sess.opts.unstable_opts.incremental_relative_spans { + if self.cx.sess.opts.incremental.is_some() { for (invoc, _) in invocations.iter_mut() { let expn_id = invoc.expansion_data.id; let parent_def = self.cx.resolver.invocation_parent(expn_id); diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index fe640f185b647..ec5f7f7917b6a 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -1162,7 +1162,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { hir_body_hash.hash_stable(&mut hcx, &mut stable_hasher); upstream_crates.hash_stable(&mut hcx, &mut stable_hasher); source_file_names.hash_stable(&mut hcx, &mut stable_hasher); - if tcx.sess.opts.unstable_opts.incremental_relative_spans { + if tcx.sess.opts.incremental.is_some() { let definitions = tcx.definitions_untracked(); let mut owner_spans: Vec<_> = krate .owners diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 19dde0a977502..cd2c9f4d0eaa4 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1338,8 +1338,6 @@ options! { incremental_info: bool = (false, parse_bool, [UNTRACKED], "print high-level information about incremental reuse (or the lack thereof) \ (default: no)"), - incremental_relative_spans: bool = (false, parse_bool, [TRACKED], - "hash spans relative to their parent item for incr. comp. (default: no)"), incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED], "verify incr. comp. hashes of green query instances (default: no)"), inline_in_all_cgus: Option = (None, parse_opt_bool, [TRACKED], From 40c8165395cef78f5f8bfadd8802cbda41a4cb00 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 9 Dec 2022 16:36:28 +0000 Subject: [PATCH 5/8] Only enable relative span hashing on nightly. --- compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_expand/src/expand.rs | 2 +- compiler/rustc_middle/src/hir/map/mod.rs | 2 +- compiler/rustc_session/src/config.rs | 6 ++++++ compiler/rustc_session/src/options.rs | 3 +++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index bff48a6d0a1b3..bb087326cb145 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -776,7 +776,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// Intercept all spans entering HIR. /// Mark a span as relative to the current owning item. fn lower_span(&self, span: Span) -> Span { - if self.tcx.sess.opts.incremental.is_some() { + if self.tcx.sess.opts.incremental_relative_spans() { span.with_parent(Some(self.current_hir_id_owner.def_id)) } else { // Do not make spans relative when not using incremental compilation. diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 32dbe579fb47b..5d47c1ed363fb 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -587,7 +587,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { .resolver .visit_ast_fragment_with_placeholders(self.cx.current_expansion.id, &fragment); - if self.cx.sess.opts.incremental.is_some() { + if self.cx.sess.opts.incremental_relative_spans() { for (invoc, _) in invocations.iter_mut() { let expn_id = invoc.expansion_data.id; let parent_def = self.cx.resolver.invocation_parent(expn_id); diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index ec5f7f7917b6a..c35681b4b355f 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -1162,7 +1162,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { hir_body_hash.hash_stable(&mut hcx, &mut stable_hasher); upstream_crates.hash_stable(&mut hcx, &mut stable_hasher); source_file_names.hash_stable(&mut hcx, &mut stable_hasher); - if tcx.sess.opts.incremental.is_some() { + if tcx.sess.opts.incremental_relative_spans() { let definitions = tcx.definitions_untracked(); let mut owner_spans: Vec<_> = krate .owners diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 3bafd3730bd79..02e3992a6a940 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -787,6 +787,12 @@ impl Options { pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion { self.cg.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy) } + + #[allow(rustc::bad_opt_access)] + pub fn incremental_relative_spans(&self) -> bool { + self.unstable_opts.incremental_relative_spans + || (self.unstable_features.is_nightly_build() && self.incremental.is_some()) + } } impl UnstableOptions { diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index cd2c9f4d0eaa4..83a3fd752651f 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1338,6 +1338,9 @@ options! { incremental_info: bool = (false, parse_bool, [UNTRACKED], "print high-level information about incremental reuse (or the lack thereof) \ (default: no)"), + #[rustc_lint_opt_deny_field_access("use `Session::incremental_relative_spans` instead of this field")] + incremental_relative_spans: bool = (false, parse_bool, [TRACKED], + "hash spans relative to their parent item for incr. comp. (default: no)"), incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED], "verify incr. comp. hashes of green query instances (default: no)"), inline_in_all_cgus: Option = (None, parse_opt_bool, [TRACKED], From 4719cb30367496c90827f05b52f9fb3306aeae11 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 30 Apr 2021 19:38:06 +0200 Subject: [PATCH 6/8] Ignore span references from diagnostics. The diagnostics are replayed at the correct place anyway. --- compiler/rustc_errors/src/lib.rs | 98 ++++++++++--------- compiler/rustc_interface/src/callbacks.rs | 13 ++- .../rustc_query_system/src/dep_graph/graph.rs | 6 +- 3 files changed, 66 insertions(+), 51 deletions(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index 292ea64ee7ba3..4b9073d470b66 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -473,10 +473,12 @@ pub enum StashKey { CallAssocMethod, } -fn default_track_diagnostic(_: &Diagnostic) {} +fn default_track_diagnostic(d: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) { + (*f)(d) +} -pub static TRACK_DIAGNOSTICS: AtomicRef = - AtomicRef::new(&(default_track_diagnostic as fn(&_))); +pub static TRACK_DIAGNOSTICS: AtomicRef = + AtomicRef::new(&(default_track_diagnostic as _)); #[derive(Copy, Clone, Default)] pub struct HandlerFlags { @@ -1290,67 +1292,69 @@ impl HandlerInner { && !diagnostic.is_force_warn() { if diagnostic.has_future_breakage() { - (*TRACK_DIAGNOSTICS)(diagnostic); + (*TRACK_DIAGNOSTICS)(diagnostic, &mut |_| {}); } return None; } - (*TRACK_DIAGNOSTICS)(diagnostic); - if matches!(diagnostic.level, Level::Expect(_) | Level::Allow) { + (*TRACK_DIAGNOSTICS)(diagnostic, &mut |_| {}); return None; } - if let Some(ref code) = diagnostic.code { - self.emitted_diagnostic_codes.insert(code.clone()); - } - - let already_emitted = |this: &mut Self| { - let mut hasher = StableHasher::new(); - diagnostic.hash(&mut hasher); - let diagnostic_hash = hasher.finish(); - !this.emitted_diagnostics.insert(diagnostic_hash) - }; + let mut guaranteed = None; + (*TRACK_DIAGNOSTICS)(diagnostic, &mut |diagnostic| { + if let Some(ref code) = diagnostic.code { + self.emitted_diagnostic_codes.insert(code.clone()); + } - // Only emit the diagnostic if we've been asked to deduplicate or - // haven't already emitted an equivalent diagnostic. - if !(self.flags.deduplicate_diagnostics && already_emitted(self)) { - debug!(?diagnostic); - debug!(?self.emitted_diagnostics); - let already_emitted_sub = |sub: &mut SubDiagnostic| { - debug!(?sub); - if sub.level != Level::OnceNote { - return false; - } + let already_emitted = |this: &mut Self| { let mut hasher = StableHasher::new(); - sub.hash(&mut hasher); + diagnostic.hash(&mut hasher); let diagnostic_hash = hasher.finish(); - debug!(?diagnostic_hash); - !self.emitted_diagnostics.insert(diagnostic_hash) + !this.emitted_diagnostics.insert(diagnostic_hash) }; - diagnostic.children.drain_filter(already_emitted_sub).for_each(|_| {}); - - self.emitter.emit_diagnostic(diagnostic); - if diagnostic.is_error() { - self.deduplicated_err_count += 1; - } else if let Warning(_) = diagnostic.level { - self.deduplicated_warn_count += 1; + // Only emit the diagnostic if we've been asked to deduplicate or + // haven't already emitted an equivalent diagnostic. + if !(self.flags.deduplicate_diagnostics && already_emitted(self)) { + debug!(?diagnostic); + debug!(?self.emitted_diagnostics); + let already_emitted_sub = |sub: &mut SubDiagnostic| { + debug!(?sub); + if sub.level != Level::OnceNote { + return false; + } + let mut hasher = StableHasher::new(); + sub.hash(&mut hasher); + let diagnostic_hash = hasher.finish(); + debug!(?diagnostic_hash); + !self.emitted_diagnostics.insert(diagnostic_hash) + }; + + diagnostic.children.drain_filter(already_emitted_sub).for_each(|_| {}); + + self.emitter.emit_diagnostic(diagnostic); + if diagnostic.is_error() { + self.deduplicated_err_count += 1; + } else if let Warning(_) = diagnostic.level { + self.deduplicated_warn_count += 1; + } } - } - if diagnostic.is_error() { - if matches!(diagnostic.level, Level::Error { lint: true }) { - self.bump_lint_err_count(); + if diagnostic.is_error() { + if matches!(diagnostic.level, Level::Error { lint: true }) { + self.bump_lint_err_count(); + } else { + self.bump_err_count(); + } + + guaranteed = Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()); } else { - self.bump_err_count(); + self.bump_warn_count(); } + }); - Some(ErrorGuaranteed::unchecked_claim_error_was_emitted()) - } else { - self.bump_warn_count(); - - None - } + guaranteed } fn emit_artifact_notification(&mut self, path: &Path, artifact_type: &str) { diff --git a/compiler/rustc_interface/src/callbacks.rs b/compiler/rustc_interface/src/callbacks.rs index 76442de69d351..ee0552d77ceee 100644 --- a/compiler/rustc_interface/src/callbacks.rs +++ b/compiler/rustc_interface/src/callbacks.rs @@ -10,6 +10,7 @@ //! origin crate when the `TyCtxt` is not present in TLS. use rustc_errors::{Diagnostic, TRACK_DIAGNOSTICS}; +use rustc_middle::dep_graph::TaskDepsRef; use rustc_middle::ty::tls; use std::fmt; @@ -26,14 +27,22 @@ fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) { /// This is a callback from `rustc_ast` as it cannot access the implicit state /// in `rustc_middle` otherwise. It is used when diagnostic messages are /// emitted and stores them in the current query, if there is one. -fn track_diagnostic(diagnostic: &Diagnostic) { +fn track_diagnostic(diagnostic: &mut Diagnostic, f: &mut dyn FnMut(&mut Diagnostic)) { tls::with_context_opt(|icx| { if let Some(icx) = icx { if let Some(diagnostics) = icx.diagnostics { let mut diagnostics = diagnostics.lock(); diagnostics.extend(Some(diagnostic.clone())); + std::mem::drop(diagnostics); } + + // Diagnostics are tracked, we can ignore the dependency. + let icx = tls::ImplicitCtxt { task_deps: TaskDepsRef::Ignore, ..icx.clone() }; + return tls::enter_context(&icx, move |_| (*f)(diagnostic)); } + + // In any other case, invoke diagnostics anyway. + (*f)(diagnostic); }) } @@ -55,5 +64,5 @@ fn def_id_debug(def_id: rustc_hir::def_id::DefId, f: &mut fmt::Formatter<'_>) -> pub fn setup_callbacks() { rustc_span::SPAN_TRACK.swap(&(track_span_parent as fn(_))); rustc_hir::def_id::DEF_ID_DEBUG.swap(&(def_id_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); - TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_))); + TRACK_DIAGNOSTICS.swap(&(track_diagnostic as _)); } diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 52957ee022238..0b1ff5d709fe9 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -634,7 +634,7 @@ impl DepGraph { if dep_node_debug.borrow().contains_key(&dep_node) { return; } - let debug_str = debug_str_gen(); + let debug_str = self.with_ignore(debug_str_gen); dep_node_debug.borrow_mut().insert(dep_node, debug_str); } @@ -829,7 +829,9 @@ impl DepGraph { ); if !side_effects.is_empty() { - self.emit_side_effects(qcx, data, dep_node_index, side_effects); + self.with_query_deserialization(|| { + self.emit_side_effects(qcx, data, dep_node_index, side_effects) + }); } // ... and finally storing a "Green" entry in the color map. From 5b9360bb1e0ca80831ef80d521aaf0815ea6e303 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 31 Oct 2022 16:43:37 +0000 Subject: [PATCH 7/8] Remove references to removed option from tests. --- .../change_symbol_export_status.rs | 2 -- .../incremental/hashes/call_expressions.rs | 3 --- .../incremental/hashes/closure_expressions.rs | 3 --- .../incremental/hashes/enum_constructors.rs | 3 --- src/test/incremental/hashes/enum_defs.rs | 3 --- .../incremental/hashes/exported_vs_not.rs | 3 --- src/test/incremental/hashes/extern_mods.rs | 3 --- src/test/incremental/hashes/for_loops.rs | 3 --- .../incremental/hashes/function_interfaces.rs | 3 --- src/test/incremental/hashes/if_expressions.rs | 3 --- .../hashes/indexing_expressions.rs | 3 --- src/test/incremental/hashes/inherent_impls.rs | 3 --- src/test/incremental/hashes/inline_asm.rs | 3 --- .../incremental/hashes/let_expressions.rs | 3 --- .../incremental/hashes/loop_expressions.rs | 3 --- .../incremental/hashes/match_expressions.rs | 3 --- src/test/incremental/hashes/statics.rs | 3 --- .../incremental/hashes/struct_constructors.rs | 3 --- src/test/incremental/hashes/struct_defs.rs | 3 --- src/test/incremental/hashes/trait_defs.rs | 3 --- src/test/incremental/hashes/trait_impls.rs | 3 --- .../hashes/unary_and_binary_exprs.rs | 3 --- .../incremental/hashes/while_let_loops.rs | 3 --- src/test/incremental/hashes/while_loops.rs | 3 --- .../spans_significant_w_debuginfo.rs | 12 +++------ .../incremental/spans_significant_w_panic.rs | 12 +++------ src/test/incremental/string_constant.rs | 13 +++------- .../thinlto/cgu_keeps_identical_fn.rs | 25 +------------------ 28 files changed, 13 insertions(+), 120 deletions(-) diff --git a/src/test/incremental/change_symbol_export_status.rs b/src/test/incremental/change_symbol_export_status.rs index dd3dce4e7209c..83737a0220091 100644 --- a/src/test/incremental/change_symbol_export_status.rs +++ b/src/test/incremental/change_symbol_export_status.rs @@ -2,8 +2,6 @@ // compile-flags: -Zquery-dep-graph // [rpass1]compile-flags: -Zincremental-ignore-spans // [rpass2]compile-flags: -Zincremental-ignore-spans -// [rpass3]compile-flags: -Zincremental-relative-spans -// [rpass4]compile-flags: -Zincremental-relative-spans #![feature(rustc_attrs)] #![rustc_partition_reused(module = "change_symbol_export_status-mod1", cfg = "rpass2")] diff --git a/src/test/incremental/hashes/call_expressions.rs b/src/test/incremental/hashes/call_expressions.rs index f3a7722cdcad0..65df2e8292a04 100644 --- a/src/test/incremental/hashes/call_expressions.rs +++ b/src/test/incremental/hashes/call_expressions.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] diff --git a/src/test/incremental/hashes/closure_expressions.rs b/src/test/incremental/hashes/closure_expressions.rs index c769246b29b2f..7bf99f6112ed9 100644 --- a/src/test/incremental/hashes/closure_expressions.rs +++ b/src/test/incremental/hashes/closure_expressions.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/enum_constructors.rs b/src/test/incremental/hashes/enum_constructors.rs index 70ef10645f19f..db367d07094d7 100644 --- a/src/test/incremental/hashes/enum_constructors.rs +++ b/src/test/incremental/hashes/enum_constructors.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/enum_defs.rs b/src/test/incremental/hashes/enum_defs.rs index 0f8898c389b7f..bc83723a908f2 100644 --- a/src/test/incremental/hashes/enum_defs.rs +++ b/src/test/incremental/hashes/enum_defs.rs @@ -16,9 +16,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/exported_vs_not.rs b/src/test/incremental/hashes/exported_vs_not.rs index 87fd21fd1b810..9ac9ae24f81bc 100644 --- a/src/test/incremental/hashes/exported_vs_not.rs +++ b/src/test/incremental/hashes/exported_vs_not.rs @@ -4,9 +4,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/extern_mods.rs b/src/test/incremental/hashes/extern_mods.rs index 3121abbea369b..1906843c7a247 100644 --- a/src/test/incremental/hashes/extern_mods.rs +++ b/src/test/incremental/hashes/extern_mods.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/for_loops.rs b/src/test/incremental/hashes/for_loops.rs index 16d6af01695f1..193e792c84330 100644 --- a/src/test/incremental/hashes/for_loops.rs +++ b/src/test/incremental/hashes/for_loops.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/function_interfaces.rs b/src/test/incremental/hashes/function_interfaces.rs index 3ff949fbb3f80..182ca7d926c6b 100644 --- a/src/test/incremental/hashes/function_interfaces.rs +++ b/src/test/incremental/hashes/function_interfaces.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(linkage)] diff --git a/src/test/incremental/hashes/if_expressions.rs b/src/test/incremental/hashes/if_expressions.rs index cff557dcb74b8..937fd3ac879a9 100644 --- a/src/test/incremental/hashes/if_expressions.rs +++ b/src/test/incremental/hashes/if_expressions.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/indexing_expressions.rs b/src/test/incremental/hashes/indexing_expressions.rs index 9ef4684724364..b1ac6f6fa6c2b 100644 --- a/src/test/incremental/hashes/indexing_expressions.rs +++ b/src/test/incremental/hashes/indexing_expressions.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/inherent_impls.rs b/src/test/incremental/hashes/inherent_impls.rs index 1abbff32c6f34..285f857c9cbcf 100644 --- a/src/test/incremental/hashes/inherent_impls.rs +++ b/src/test/incremental/hashes/inherent_impls.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] diff --git a/src/test/incremental/hashes/inline_asm.rs b/src/test/incremental/hashes/inline_asm.rs index dc878d6827cbf..3118aa1356452 100644 --- a/src/test/incremental/hashes/inline_asm.rs +++ b/src/test/incremental/hashes/inline_asm.rs @@ -12,9 +12,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/let_expressions.rs b/src/test/incremental/hashes/let_expressions.rs index 01320cd51f445..180bf6fec8772 100644 --- a/src/test/incremental/hashes/let_expressions.rs +++ b/src/test/incremental/hashes/let_expressions.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/loop_expressions.rs b/src/test/incremental/hashes/loop_expressions.rs index ada541e644a31..87b86479d07bd 100644 --- a/src/test/incremental/hashes/loop_expressions.rs +++ b/src/test/incremental/hashes/loop_expressions.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/match_expressions.rs b/src/test/incremental/hashes/match_expressions.rs index fa054c7decc57..4429df6833e48 100644 --- a/src/test/incremental/hashes/match_expressions.rs +++ b/src/test/incremental/hashes/match_expressions.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/statics.rs b/src/test/incremental/hashes/statics.rs index 67d87f5c4ed92..bb83f8300d06d 100644 --- a/src/test/incremental/hashes/statics.rs +++ b/src/test/incremental/hashes/statics.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/struct_constructors.rs b/src/test/incremental/hashes/struct_constructors.rs index fc9671cb41b47..e50e5674c661e 100644 --- a/src/test/incremental/hashes/struct_constructors.rs +++ b/src/test/incremental/hashes/struct_constructors.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/struct_defs.rs b/src/test/incremental/hashes/struct_defs.rs index 7a91722d70fda..4a2706b4f0100 100644 --- a/src/test/incremental/hashes/struct_defs.rs +++ b/src/test/incremental/hashes/struct_defs.rs @@ -16,9 +16,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/trait_defs.rs b/src/test/incremental/hashes/trait_defs.rs index c453eeceb77f5..b583bee2f2449 100644 --- a/src/test/incremental/hashes/trait_defs.rs +++ b/src/test/incremental/hashes/trait_defs.rs @@ -16,9 +16,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/trait_impls.rs b/src/test/incremental/hashes/trait_impls.rs index f555f555f9236..3b2e18d17a96b 100644 --- a/src/test/incremental/hashes/trait_impls.rs +++ b/src/test/incremental/hashes/trait_impls.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/unary_and_binary_exprs.rs b/src/test/incremental/hashes/unary_and_binary_exprs.rs index 18fb716353fa7..58af51eef077f 100644 --- a/src/test/incremental/hashes/unary_and_binary_exprs.rs +++ b/src/test/incremental/hashes/unary_and_binary_exprs.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/while_let_loops.rs b/src/test/incremental/hashes/while_let_loops.rs index 88fd4d89b2827..c81b0d0afb811 100644 --- a/src/test/incremental/hashes/while_let_loops.rs +++ b/src/test/incremental/hashes/while_let_loops.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/hashes/while_loops.rs b/src/test/incremental/hashes/while_loops.rs index 9b4d23757b871..c1cc0b62bc244 100644 --- a/src/test/incremental/hashes/while_loops.rs +++ b/src/test/incremental/hashes/while_loops.rs @@ -11,9 +11,6 @@ // [cfail1]compile-flags: -Zincremental-ignore-spans // [cfail2]compile-flags: -Zincremental-ignore-spans // [cfail3]compile-flags: -Zincremental-ignore-spans -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/incremental/spans_significant_w_debuginfo.rs b/src/test/incremental/spans_significant_w_debuginfo.rs index 639454cc97530..38ab28461911b 100644 --- a/src/test/incremental/spans_significant_w_debuginfo.rs +++ b/src/test/incremental/spans_significant_w_debuginfo.rs @@ -1,21 +1,17 @@ // This test makes sure that just changing a definition's location in the // source file also changes its incr. comp. hash, if debuginfo is enabled. -// revisions:rpass1 rpass2 rpass3 rpass4 +// revisions:rpass1 rpass2 // ignore-asmjs wasm2js does not support source maps yet // compile-flags: -g -Z query-dep-graph -// [rpass3]compile-flags: -Zincremental-relative-spans -// [rpass4]compile-flags: -Zincremental-relative-spans #![feature(rustc_attrs)] #![rustc_partition_codegened(module = "spans_significant_w_debuginfo", cfg = "rpass2")] -#![rustc_partition_codegened(module = "spans_significant_w_debuginfo", cfg = "rpass4")] -#[cfg(any(rpass1, rpass3))] +#[cfg(rpass1)] pub fn main() {} -#[cfg(any(rpass2, rpass4))] -#[rustc_clean(except = "hir_owner,hir_owner_nodes,optimized_mir", cfg = "rpass2")] -#[rustc_clean(cfg = "rpass4")] +#[cfg(rpass2)] +#[rustc_clean(cfg = "rpass2")] pub fn main() {} diff --git a/src/test/incremental/spans_significant_w_panic.rs b/src/test/incremental/spans_significant_w_panic.rs index 6f51c9729e370..085e4cd78ca1c 100644 --- a/src/test/incremental/spans_significant_w_panic.rs +++ b/src/test/incremental/spans_significant_w_panic.rs @@ -1,26 +1,22 @@ // This test makes sure that just changing a definition's location in the // source file also changes its incr. comp. hash, if debuginfo is enabled. -// revisions:rpass1 rpass2 rpass3 rpass4 -// [rpass3]compile-flags: -Zincremental-relative-spans -// [rpass4]compile-flags: -Zincremental-relative-spans +// revisions:rpass1 rpass2 // compile-flags: -C overflow-checks=on -Z query-dep-graph #![feature(rustc_attrs)] #![rustc_partition_codegened(module = "spans_significant_w_panic", cfg = "rpass2")] -#![rustc_partition_codegened(module = "spans_significant_w_panic", cfg = "rpass4")] -#[cfg(any(rpass1, rpass3))] +#[cfg(rpass1)] pub fn main() { if std::hint::black_box(false) { panic!() } } -#[cfg(any(rpass2, rpass4))] -#[rustc_clean(except = "hir_owner,hir_owner_nodes,optimized_mir", cfg = "rpass2")] -#[rustc_clean(cfg = "rpass4")] +#[cfg(rpass2)] +#[rustc_clean(cfg = "rpass2")] pub fn main() { if std::hint::black_box(false) { panic!() diff --git a/src/test/incremental/string_constant.rs b/src/test/incremental/string_constant.rs index cae7b4aab7565..e15a8d18f853d 100644 --- a/src/test/incremental/string_constant.rs +++ b/src/test/incremental/string_constant.rs @@ -1,7 +1,5 @@ -// revisions: cfail1 cfail2 cfail3 cfail4 +// revisions: cfail1 cfail2 // compile-flags: -Z query-dep-graph -// [cfail3]compile-flags: -Zincremental-relative-spans -// [cfail4]compile-flags: -Zincremental-relative-spans // build-pass (FIXME(62277): could be check-pass?) #![allow(warnings)] @@ -13,14 +11,13 @@ // needed even for callers of `x`. pub mod x { - #[cfg(any(cfail1, cfail3))] + #[cfg(cfail1)] pub fn x() { println!("{}", "1"); } - #[cfg(any(cfail2, cfail4))] - #[rustc_clean(except = "hir_owner,hir_owner_nodes,optimized_mir,promoted_mir", cfg = "cfail2")] - #[rustc_clean(except = "hir_owner_nodes,promoted_mir", cfg = "cfail4")] + #[cfg(cfail2)] + #[rustc_clean(except = "hir_owner_nodes,promoted_mir", cfg = "cfail2")] pub fn x() { println!("{}", "2"); } @@ -30,7 +27,6 @@ pub mod y { use x; #[rustc_clean(cfg = "cfail2")] - #[rustc_clean(cfg = "cfail4")] pub fn y() { x::x(); } @@ -40,7 +36,6 @@ pub mod z { use y; #[rustc_clean(cfg = "cfail2")] - #[rustc_clean(cfg = "cfail4")] pub fn z() { y::y(); } diff --git a/src/test/incremental/thinlto/cgu_keeps_identical_fn.rs b/src/test/incremental/thinlto/cgu_keeps_identical_fn.rs index 31f329a7f726b..368a726ea904d 100644 --- a/src/test/incremental/thinlto/cgu_keeps_identical_fn.rs +++ b/src/test/incremental/thinlto/cgu_keeps_identical_fn.rs @@ -3,10 +3,7 @@ // ends up with any spans in its LLVM bitecode, so LLVM is able to skip // re-building any modules which import 'inlined_fn' -// revisions: cfail1 cfail2 cfail3 cfail4 cfail5 cfail6 -// [cfail4]compile-flags: -Zincremental-relative-spans -// [cfail5]compile-flags: -Zincremental-relative-spans -// [cfail6]compile-flags: -Zincremental-relative-spans +// revisions: cfail1 cfail2 cfail3 // compile-flags: -Z query-dep-graph -O // build-pass (FIXME(62277): could be check-pass?) @@ -18,16 +15,6 @@ cfg = "cfail3", kind = "post-lto" )] -#![rustc_expected_cgu_reuse( - module = "cgu_keeps_identical_fn-foo", - cfg = "cfail5", - kind = "post-lto" -)] -#![rustc_expected_cgu_reuse( - module = "cgu_keeps_identical_fn-foo", - cfg = "cfail6", - kind = "post-lto" -)] #![rustc_expected_cgu_reuse( module = "cgu_keeps_identical_fn-bar", cfg = "cfail2", @@ -38,16 +25,6 @@ cfg = "cfail3", kind = "post-lto" )] -#![rustc_expected_cgu_reuse( - module = "cgu_keeps_identical_fn-bar", - cfg = "cfail5", - kind = "post-lto" -)] -#![rustc_expected_cgu_reuse( - module = "cgu_keeps_identical_fn-bar", - cfg = "cfail6", - kind = "post-lto" -)] mod foo { From 7b6ead2027d073613ff3f160f221f5d3a5941b0b Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 31 Oct 2022 16:48:23 +0000 Subject: [PATCH 8/8] Explain disabled span hashing. --- compiler/rustc_span/src/hygiene.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index c2d8287f2431d..8d81d44df5b36 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -104,6 +104,10 @@ fn assert_default_hashing_controls(ctx: &CTX, msg: &str) // `-Z incremental-ignore-spans` option. Normally, this option is disabled, // which will cause us to require that this method always be called with `Span` hashing // enabled. + // + // Span hashing can also be disabled without `-Z incremental-ignore-spans`. + // This is the case for instance when building a hash for name mangling. + // Such configuration must not be used for metadata. HashingControls { hash_spans } if hash_spans == !ctx.unstable_opts_incremental_ignore_spans() => {} other => panic!("Attempted hashing of {msg} with non-default HashingControls: {:?}", other),