Skip to content

Commit 396339e

Browse files
Auto merge of #146880 - azhogin:azhogin/source_span_hook, r=<try>
source_span hook in case of non-incremental build
2 parents 4056082 + 6123d0a commit 396339e

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,13 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
963963

964964
let incremental = dep_graph.is_fully_enabled();
965965

966+
// Optimization of source_span call for non-incremental build
967+
if incremental {
968+
providers.hooks.source_span = |tcx, def_id| tcx.source_span_q(def_id);
969+
} else {
970+
providers.hooks.source_span = providers.queries.source_span_q;
971+
}
972+
966973
let gcx_cell = OnceLock::new();
967974
let arena = WorkerLocal::new(|_| Arena::default());
968975
let hir_arena = WorkerLocal::new(|_| rustc_hir::Arena::default());

compiler/rustc_middle/src/hooks/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use rustc_hir::def_id::{DefId, DefPathHash};
77
use rustc_session::StableCrateId;
88
use rustc_span::def_id::{CrateNum, LocalDefId};
9-
use rustc_span::{ExpnHash, ExpnId};
9+
use rustc_span::{ExpnHash, ExpnId, Span};
1010

1111
use crate::mir;
1212
use crate::ty::{Ty, TyCtxt};
@@ -102,6 +102,15 @@ declare_hooks! {
102102
/// Ensure the given scalar is valid for the given type.
103103
/// This checks non-recursive runtime validity.
104104
hook validate_scalar_in_layout(scalar: crate::ty::ScalarInt, ty: Ty<'tcx>) -> bool;
105+
106+
/// Return the span for a definition.
107+
///
108+
/// Contrary to `def_span` below, this query returns the full absolute span of the definition.
109+
/// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
110+
/// of rustc_middle::hir::source_map.
111+
///
112+
/// Hook is initialized into simple function call (for optimization), if not incremental build
113+
hook source_span(key: LocalDefId) -> Span;
105114
}
106115

107116
#[cold]

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ rustc_queries! {
209209
/// Contrary to `def_span` below, this query returns the full absolute span of the definition.
210210
/// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
211211
/// of rustc_middle::hir::source_map.
212-
query source_span(key: LocalDefId) -> Span {
212+
query source_span_q(key: LocalDefId) -> Span {
213213
// Accesses untracked data
214214
eval_always
215215
desc { "getting the source span" }

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,8 @@ pub fn provide(providers: &mut Providers) {
35443544
// We want to check if the panic handler was defined in this crate
35453545
tcx.lang_items().panic_impl().is_some_and(|did| did.is_local())
35463546
};
3547-
providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP);
3547+
providers.source_span_q =
3548+
|tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP);
35483549
}
35493550

35503551
pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {

0 commit comments

Comments
 (0)