Skip to content

Commit 62b2a43

Browse files
authored
Unrolled build for rust-lang#128197
Rollup merge of rust-lang#128197 - Alexendoo:span-ctxt, r=davidtwco Skip locking span interner for some syntax context checks - `from_expansion` now never needs to consult the interner - `eq_ctxt` now only needs the interner when both spans are fully interned
2 parents 90ab8ea + ad3f3c7 commit 62b2a43

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
@@ -559,12 +559,6 @@ impl Span {
559559
!self.is_dummy() && sm.is_span_accessible(self)
560560
}
561561

562-
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
563-
#[inline]
564-
pub fn from_expansion(self) -> bool {
565-
!self.ctxt().is_root()
566-
}
567-
568562
/// Returns `true` if `span` originates in a derive-macro's expansion.
569563
pub fn in_derive_expansion(self) -> bool {
570564
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
@@ -303,6 +303,13 @@ impl Span {
303303
}
304304
}
305305

306+
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
307+
#[inline]
308+
pub fn from_expansion(self) -> bool {
309+
// If the span is fully inferred then ctxt > MAX_CTXT
310+
self.inline_ctxt().map_or(true, |ctxt| !ctxt.is_root())
311+
}
312+
306313
/// Returns `true` if this is a dummy span with any hygienic context.
307314
#[inline]
308315
pub fn is_dummy(self) -> bool {
@@ -370,9 +377,10 @@ impl Span {
370377
pub fn eq_ctxt(self, other: Span) -> bool {
371378
match (self.inline_ctxt(), other.inline_ctxt()) {
372379
(Ok(ctxt1), Ok(ctxt2)) => ctxt1 == ctxt2,
373-
(Ok(ctxt), Err(index)) | (Err(index), Ok(ctxt)) => {
374-
with_span_interner(|interner| ctxt == interner.spans[index].ctxt)
375-
}
380+
// If `inline_ctxt` returns `Ok` the context is <= MAX_CTXT.
381+
// If it returns `Err` the span is fully interned and the context is > MAX_CTXT.
382+
// As these do not overlap an `Ok` and `Err` result cannot have an equal context.
383+
(Ok(_), Err(_)) | (Err(_), Ok(_)) => false,
376384
(Err(index1), Err(index2)) => with_span_interner(|interner| {
377385
interner.spans[index1].ctxt == interner.spans[index2].ctxt
378386
}),

0 commit comments

Comments
 (0)