Inline some methods in rustc_span hygiene

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
xizheyin
2025-07-23 23:17:54 +08:00
parent 460259d14d
commit 60d69804ba
2 changed files with 17 additions and 0 deletions

View File

@@ -322,6 +322,7 @@ impl ExpnId {
/// `expn_id.outer_expn_is_descendant_of(ctxt)` is equivalent to but faster than
/// `expn_id.is_descendant_of(ctxt.outer_expn())`.
#[inline]
pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool {
HygieneData::with(|data| data.is_descendant_of(self, data.outer_expn(ctxt)))
}
@@ -394,6 +395,7 @@ impl HygieneData {
}
}
#[inline]
fn with<R>(f: impl FnOnce(&mut HygieneData) -> R) -> R {
with_session_globals(|session_globals| f(&mut session_globals.hygiene_data.borrow_mut()))
}
@@ -406,6 +408,7 @@ impl HygieneData {
}
}
#[inline]
fn local_expn_data(&self, expn_id: LocalExpnId) -> &ExpnData {
self.local_expn_data[expn_id].as_ref().expect("no expansion data for an expansion ID")
}
@@ -437,23 +440,28 @@ impl HygieneData {
}
}
#[inline]
fn normalize_to_macros_2_0(&self, ctxt: SyntaxContext) -> SyntaxContext {
self.syntax_context_data[ctxt.0 as usize].opaque
}
#[inline]
fn normalize_to_macro_rules(&self, ctxt: SyntaxContext) -> SyntaxContext {
self.syntax_context_data[ctxt.0 as usize].opaque_and_semiopaque
}
#[inline]
fn outer_expn(&self, ctxt: SyntaxContext) -> ExpnId {
self.syntax_context_data[ctxt.0 as usize].outer_expn
}
#[inline]
fn outer_mark(&self, ctxt: SyntaxContext) -> (ExpnId, Transparency) {
let data = &self.syntax_context_data[ctxt.0 as usize];
(data.outer_expn, data.outer_transparency)
}
#[inline]
fn parent_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext {
self.syntax_context_data[ctxt.0 as usize].parent
}
@@ -718,11 +726,13 @@ impl SyntaxContext {
SyntaxContext(raw as u32)
}
#[inline]
fn from_usize(raw: usize) -> SyntaxContext {
SyntaxContext(u32::try_from(raw).unwrap())
}
/// Extend a syntax context with a given expansion and transparency.
#[inline]
pub fn apply_mark(self, expn_id: ExpnId, transparency: Transparency) -> SyntaxContext {
HygieneData::with(|data| data.apply_mark(self, expn_id, transparency))
}
@@ -743,10 +753,12 @@ impl SyntaxContext {
/// of g (call it g1), calling remove_mark will result in the SyntaxContext for the
/// invocation of f that created g1.
/// Returns the mark that was removed.
#[inline]
pub fn remove_mark(&mut self) -> ExpnId {
HygieneData::with(|data| data.remove_mark(self).0)
}
#[inline]
pub fn marks(self) -> Vec<(ExpnId, Transparency)> {
HygieneData::with(|data| data.marks(self))
}
@@ -776,11 +788,13 @@ impl SyntaxContext {
/// ```
/// This returns the expansion whose definition scope we use to privacy check the resolution,
/// or `None` if we privacy check as usual (i.e., not w.r.t. a macro definition scope).
#[inline]
pub fn adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
HygieneData::with(|data| data.adjust(self, expn_id))
}
/// Like `SyntaxContext::adjust`, but also normalizes `self` to macros 2.0.
#[inline]
pub(crate) fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
HygieneData::with(|data| {
*self = data.normalize_to_macros_2_0(*self);
@@ -901,10 +915,12 @@ impl SyntaxContext {
HygieneData::with(|data| data.outer_mark(self))
}
#[inline]
pub(crate) fn dollar_crate_name(self) -> Symbol {
HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name)
}
#[inline]
pub fn edition(self) -> Edition {
HygieneData::with(|data| data.expn_data(data.outer_expn(self)).edition)
}

View File

@@ -167,6 +167,7 @@ where
}
}
#[inline]
pub fn with_session_globals<R, F>(f: F) -> R
where
F: FnOnce(&SessionGlobals) -> R,