Track span dependency using a callback.
This commit is contained in:
parent
e85ddeb474
commit
b19ae20aad
6 changed files with 40 additions and 5 deletions
|
@ -1947,6 +1947,7 @@ pub struct FileLines {
|
|||
|
||||
pub static SPAN_DEBUG: AtomicRef<fn(Span, &mut fmt::Formatter<'_>) -> fmt::Result> =
|
||||
AtomicRef::new(&(default_span_debug as fn(_, &mut fmt::Formatter<'_>) -> _));
|
||||
pub static SPAN_TRACK: AtomicRef<fn(LocalDefId)> = AtomicRef::new(&((|_| {}) as fn(_)));
|
||||
|
||||
// _____________________________________________________________________________
|
||||
// SpanLinesError, SpanSnippetError, DistinctSources, MalformedSourceMapPositions
|
||||
|
@ -2031,7 +2032,7 @@ where
|
|||
return;
|
||||
}
|
||||
|
||||
let span = self.data();
|
||||
let span = self.decode();
|
||||
span.ctxt.hash_stable(ctx, hasher);
|
||||
span.parent.hash_stable(ctx, hasher);
|
||||
|
||||
|
@ -2041,7 +2042,7 @@ where
|
|||
}
|
||||
|
||||
if let Some(parent) = span.parent {
|
||||
let def_span = ctx.def_span(parent).data();
|
||||
let def_span = ctx.def_span(parent).decode();
|
||||
if def_span.contains(span) {
|
||||
// This span is enclosed in a definition: only hash the relative position.
|
||||
Hash::hash(&TAG_RELATIVE_SPAN, hasher);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use crate::def_id::LocalDefId;
|
||||
use crate::hygiene::SyntaxContext;
|
||||
use crate::SPAN_TRACK;
|
||||
use crate::{BytePos, SpanData};
|
||||
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
|
@ -55,6 +56,10 @@ use rustc_data_structures::fx::FxIndexSet;
|
|||
/// the code. No crates in `rustc-perf` need more than 15 bits for `ctxt`,
|
||||
/// but larger crates might need more than 16 bits.
|
||||
///
|
||||
/// In order to reliably use parented spans in incremental compilation,
|
||||
/// the dependency to the parent definition's span. This is performed
|
||||
/// using the callback `SPAN_TRACK` to access the query engine.
|
||||
///
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
|
||||
pub struct Span {
|
||||
base_or_index: u32,
|
||||
|
@ -96,6 +101,17 @@ impl Span {
|
|||
|
||||
#[inline]
|
||||
pub fn data(self) -> SpanData {
|
||||
let data = self.decode();
|
||||
if let Some(parent) = data.parent {
|
||||
(*SPAN_TRACK)(parent);
|
||||
}
|
||||
data
|
||||
}
|
||||
|
||||
/// Internal function to translate between an encoded span and the expanded representation.
|
||||
/// This function must not be used outside the incremental engine.
|
||||
#[inline]
|
||||
pub fn decode(self) -> SpanData {
|
||||
if self.len_or_tag != LEN_TAG {
|
||||
// Inline format.
|
||||
debug_assert!(self.len_or_tag as u32 <= MAX_LEN);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue