Skip to content

Commit ad3f3c7

Browse files
committed
Skip locking span interner for some syntax context checks
1 parent 28e684b commit ad3f3c7

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

compiler/rustc_span/src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,6 @@ impl Span {
564564
!self.is_dummy() && sm.is_span_accessible(self)
565565
}
566566

567-
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
568-
#[inline]
569-
pub fn from_expansion(self) -> bool {
570-
!self.ctxt().is_root()
571-
}
572-
573567
/// Returns `true` if `span` originates in a derive-macro's expansion.
574568
pub fn in_derive_expansion(self) -> bool {
575569
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))

compiler/rustc_span/src/span_encoding.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,13 @@ impl Span {
305305
}
306306
}
307307

308+
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
309+
#[inline]
310+
pub fn from_expansion(self) -> bool {
311+
// If the span is fully inferred then ctxt > MAX_CTXT
312+
self.inline_ctxt().map_or(true, |ctxt| !ctxt.is_root())
313+
}
314+
308315
/// Returns `true` if this is a dummy span with any hygienic context.
309316
#[inline]
310317
pub fn is_dummy(self) -> bool {
@@ -372,9 +379,10 @@ impl Span {
372379
pub fn eq_ctxt(self, other: Span) -> bool {
373380
match (self.inline_ctxt(), other.inline_ctxt()) {
374381
(Ok(ctxt1), Ok(ctxt2)) => ctxt1 == ctxt2,
375-
(Ok(ctxt), Err(index)) | (Err(index), Ok(ctxt)) => {
376-
with_span_interner(|interner| ctxt == interner.spans[index].ctxt)
377-
}
382+
// If `inline_ctxt` returns `Ok` the context is <= MAX_CTXT.
383+
// If it returns `Err` the span is fully interned and the context is > MAX_CTXT.
384+
// As these do not overlap an `Ok` and `Err` result cannot have an equal context.
385+
(Ok(_), Err(_)) | (Err(_), Ok(_)) => false,
378386
(Err(index1), Err(index2)) => with_span_interner(|interner| {
379387
interner.spans[index1].ctxt == interner.spans[index2].ctxt
380388
}),

0 commit comments

Comments
 (0)