Skip to content

Commit

Permalink
Do not call source_span when not tracking dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jul 3, 2024
1 parent 3cabe7d commit f7a53c3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions compiler/rustc_interface/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ use rustc_query_system::dep_graph::{DepContext, DepKind, DepNode};
use std::fmt;

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);
}
}
})
}
Expand Down

0 comments on commit f7a53c3

Please sign in to comment.