Skip to content
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

rustc_span: Optimize more hygiene operations using Span::map_ctxt #126543

Merged
merged 1 commit into from
Jun 17, 2024
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
40 changes: 25 additions & 15 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,33 +1065,41 @@ impl Span {

#[inline]
pub fn remove_mark(&mut self) -> ExpnId {
let mut span = self.data();
let mark = span.ctxt.remove_mark();
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent);
let mut mark = ExpnId::root();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this one is intentionally different from the others (which start as None), may it be documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to document, these functions don't have their own logic and just forward to the underlying SyntaxContext methods, which may have different signatures and have their own documentation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh indeed, apologies, I didn't look at the the function signature

*self = self.map_ctxt(|mut ctxt| {
mark = ctxt.remove_mark();
ctxt
});
mark
}

#[inline]
pub fn adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
let mut span = self.data();
let mark = span.ctxt.adjust(expn_id);
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent);
let mut mark = None;
*self = self.map_ctxt(|mut ctxt| {
mark = ctxt.adjust(expn_id);
ctxt
});
mark
}

#[inline]
pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
let mut span = self.data();
let mark = span.ctxt.normalize_to_macros_2_0_and_adjust(expn_id);
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent);
let mut mark = None;
*self = self.map_ctxt(|mut ctxt| {
mark = ctxt.normalize_to_macros_2_0_and_adjust(expn_id);
ctxt
});
mark
}

#[inline]
pub fn glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> {
let mut span = self.data();
let mark = span.ctxt.glob_adjust(expn_id, glob_span);
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent);
let mut mark = None;
*self = self.map_ctxt(|mut ctxt| {
mark = ctxt.glob_adjust(expn_id, glob_span);
ctxt
});
mark
}

Expand All @@ -1101,9 +1109,11 @@ impl Span {
expn_id: ExpnId,
glob_span: Span,
) -> Option<Option<ExpnId>> {
let mut span = self.data();
let mark = span.ctxt.reverse_glob_adjust(expn_id, glob_span);
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent);
let mut mark = None;
*self = self.map_ctxt(|mut ctxt| {
mark = ctxt.reverse_glob_adjust(expn_id, glob_span);
ctxt
});
mark
}

Expand Down
Loading