Skip to content

Commit 64b0ee6

Browse files
committed
Auto merge of #129513 - cjgillot:fast-source-span, r=petrochenkov
Do not call source_span when not tracking dependencies. Split from #127241
2 parents ae9f501 + bb17fda commit 64b0ee6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

compiler/rustc_interface/src/callbacks.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ use rustc_query_system::dep_graph::dep_node::default_dep_kind_debug;
1818
use rustc_query_system::dep_graph::{DepContext, DepKind, DepNode};
1919

2020
fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {
21-
tls::with_opt(|tcx| {
22-
if let Some(tcx) = tcx {
23-
let _span = tcx.source_span(def_id);
24-
// Sanity check: relative span's parent must be an absolute span.
25-
debug_assert_eq!(_span.data_untracked().parent, None);
21+
tls::with_context_opt(|icx| {
22+
if let Some(icx) = icx {
23+
// `track_span_parent` gets called a lot from HIR lowering code.
24+
// Skip doing anything if we aren't tracking dependencies.
25+
let tracks_deps = match icx.task_deps {
26+
TaskDepsRef::Allow(..) => true,
27+
TaskDepsRef::EvalAlways | TaskDepsRef::Ignore | TaskDepsRef::Forbid => false,
28+
};
29+
if tracks_deps {
30+
let _span = icx.tcx.source_span(def_id);
31+
// Sanity check: relative span's parent must be an absolute span.
32+
debug_assert_eq!(_span.data_untracked().parent, None);
33+
}
2634
}
2735
})
2836
}

0 commit comments

Comments
 (0)