rustc_span: Optimize syntax context comparisons

Including comparisons with root context
This commit is contained in:
Vadim Petrochenkov
2024-01-02 23:32:40 +03:00
parent b8c207435c
commit 90d11d6448
13 changed files with 76 additions and 52 deletions

View File

@@ -295,11 +295,13 @@ impl ExpnId {
pub fn expansion_cause(mut self) -> Option<Span> {
let mut last_macro = None;
loop {
// Fast path to avoid locking.
if self == ExpnId::root() {
break;
}
let expn_data = self.expn_data();
// Stop going up the backtrace once include! is encountered
if expn_data.is_root()
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
{
if expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include) {
break;
}
self = expn_data.call_site.ctxt().outer_expn();
@@ -433,7 +435,7 @@ impl HygieneData {
fn marks(&self, mut ctxt: SyntaxContext) -> Vec<(ExpnId, Transparency)> {
let mut marks = Vec::new();
while ctxt != SyntaxContext::root() {
while !ctxt.is_root() {
debug!("marks: getting parent of {:?}", ctxt);
marks.push(self.outer_mark(ctxt));
ctxt = self.parent_ctxt(ctxt);