Skip to content

Commit 0fe71d9

Browse files
committed
remove span tracking during lowering
1 parent c4dc70e commit 0fe71d9

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ struct SpanLowerer {
226226
impl SpanLowerer {
227227
fn lower(&self, span: Span) -> Span {
228228
if self.is_incremental {
229-
span.with_parent(Some(self.def_id))
229+
span.with_parent_untracked(Some(self.def_id))
230230
} else {
231231
// Do not make spans relative when not using incremental compilation.
232232
span

compiler/rustc_span/src/span_encoding.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,36 @@ impl Span {
429429
data.with_parent(parent)
430430
}
431431

432+
#[inline]
433+
pub fn with_parent_untracked(self, parent: Option<LocalDefId>) -> Span {
434+
let data = match_span_kind! {
435+
self,
436+
InlineCtxt(span) => {
437+
// This format occurs 1-2 orders of magnitude more often than others (#126544),
438+
// so it makes sense to micro-optimize it to avoid `span.data()` and `Span::new()`.
439+
// Copypaste from `Span::new`, the small len & ctxt conditions are known to hold.
440+
match parent {
441+
None => return self,
442+
Some(parent) => {
443+
let parent32 = parent.local_def_index.as_u32();
444+
if span.ctxt == 0 && parent32 <= MAX_CTXT {
445+
return InlineParent::span(span.lo, span.len, parent32 as u16);
446+
}
447+
}
448+
}
449+
span.data()
450+
},
451+
InlineParent(span) => span.data(),
452+
PartiallyInterned(span) => span.data(),
453+
Interned(span) => span.data(),
454+
};
455+
456+
if let Some(old_parent) = data.parent {
457+
// (*SPAN_TRACK)(old_parent);
458+
}
459+
data.with_parent(parent)
460+
}
461+
432462
#[inline]
433463
pub fn parent(self) -> Option<LocalDefId> {
434464
let interned_parent =

0 commit comments

Comments
 (0)