diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2024-07-03 07:01:50 +0000 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2024-08-24 16:40:40 +0000 |
| commit | bb17fda3845bda0da7bcdcf28cd17e4823e58c9d (patch) | |
| tree | 4b94cfce2457ad525bebb3c2c385fe9edc2adfa0 | |
| parent | eff09483c67e6fc96c8098ba46dce476162754c5 (diff) | |
| download | rust-bb17fda3845bda0da7bcdcf28cd17e4823e58c9d.tar.gz rust-bb17fda3845bda0da7bcdcf28cd17e4823e58c9d.zip | |
Do not call source_span when not tracking dependencies.
| -rw-r--r-- | compiler/rustc_interface/src/callbacks.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/compiler/rustc_interface/src/callbacks.rs b/compiler/rustc_interface/src/callbacks.rs index 786e2bb511f..f66b9eb3a28 100644 --- a/compiler/rustc_interface/src/callbacks.rs +++ b/compiler/rustc_interface/src/callbacks.rs @@ -18,11 +18,19 @@ use rustc_query_system::dep_graph::dep_node::default_dep_kind_debug; use rustc_query_system::dep_graph::{DepContext, DepKind, DepNode}; fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) { - tls::with_opt(|tcx| { - if let Some(tcx) = tcx { - let _span = tcx.source_span(def_id); - // Sanity check: relative span's parent must be an absolute span. - debug_assert_eq!(_span.data_untracked().parent, None); + tls::with_context_opt(|icx| { + if let Some(icx) = icx { + // `track_span_parent` gets called a lot from HIR lowering code. + // Skip doing anything if we aren't tracking dependencies. + let tracks_deps = match icx.task_deps { + TaskDepsRef::Allow(..) => true, + TaskDepsRef::EvalAlways | TaskDepsRef::Ignore | TaskDepsRef::Forbid => false, + }; + if tracks_deps { + let _span = icx.tcx.source_span(def_id); + // Sanity check: relative span's parent must be an absolute span. + debug_assert_eq!(_span.data_untracked().parent, None); + } } }) } |
