Skip to content

Refactor SyntaxContext::ctxt logic. #110497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions compiler/rustc_span/src/span_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,23 @@ impl Span {
#[inline]
pub fn ctxt(self) -> SyntaxContext {
let ctxt_or_tag = self.ctxt_or_tag as u32;
if ctxt_or_tag <= MAX_CTXT {
if self.len_or_tag == LEN_TAG || self.len_or_tag & PARENT_MASK == 0 {
// Inline format or interned format with inline ctxt.
SyntaxContext::from_u32(ctxt_or_tag)
// Check for interned format.
if self.len_or_tag == LEN_TAG {
if ctxt_or_tag == CTXT_TAG {
// Fully interned format.
let index = self.base_or_index;
with_span_interner(|interner| interner.spans[index as usize].ctxt)
} else {
// Inline format or interned format with inline parent.
// We know that the SyntaxContext is root.
SyntaxContext::root()
// Interned format with inline ctxt.
SyntaxContext::from_u32(ctxt_or_tag)
}
} else if self.len_or_tag & PARENT_MASK == 0 {
// Inline format with inline ctxt.
SyntaxContext::from_u32(ctxt_or_tag)
} else {
// Interned format.
let index = self.base_or_index;
with_span_interner(|interner| interner.spans[index as usize].ctxt)
// Inline format with inline parent.
// We know that the SyntaxContext is root.
SyntaxContext::root()
}
}
}
Expand Down