Skip to content

Commit f7a53c3

Browse files
committed
Do not call source_span when not tracking dependencies.
1 parent 3cabe7d commit f7a53c3

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
@@ -17,11 +17,19 @@ use rustc_query_system::dep_graph::{DepContext, DepKind, DepNode};
1717
use std::fmt;
1818

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

0 commit comments

Comments
 (0)