Skip to content

Commit dc79eb3

Browse files
Auto merge of #144385 - xizheyin:macro-hygiene, r=<try>
Optimize performance by inline in macro hygiene system
2 parents fc5af18 + 60d6980 commit dc79eb3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

compiler/rustc_span/src/hygiene.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ impl ExpnId {
322322

323323
/// `expn_id.outer_expn_is_descendant_of(ctxt)` is equivalent to but faster than
324324
/// `expn_id.is_descendant_of(ctxt.outer_expn())`.
325+
#[inline]
325326
pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool {
326327
HygieneData::with(|data| data.is_descendant_of(self, data.outer_expn(ctxt)))
327328
}
@@ -394,6 +395,7 @@ impl HygieneData {
394395
}
395396
}
396397

398+
#[inline]
397399
fn with<R>(f: impl FnOnce(&mut HygieneData) -> R) -> R {
398400
with_session_globals(|session_globals| f(&mut session_globals.hygiene_data.borrow_mut()))
399401
}
@@ -406,6 +408,7 @@ impl HygieneData {
406408
}
407409
}
408410

411+
#[inline]
409412
fn local_expn_data(&self, expn_id: LocalExpnId) -> &ExpnData {
410413
self.local_expn_data[expn_id].as_ref().expect("no expansion data for an expansion ID")
411414
}
@@ -437,23 +440,28 @@ impl HygieneData {
437440
}
438441
}
439442

443+
#[inline]
440444
fn normalize_to_macros_2_0(&self, ctxt: SyntaxContext) -> SyntaxContext {
441445
self.syntax_context_data[ctxt.0 as usize].opaque
442446
}
443447

448+
#[inline]
444449
fn normalize_to_macro_rules(&self, ctxt: SyntaxContext) -> SyntaxContext {
445450
self.syntax_context_data[ctxt.0 as usize].opaque_and_semiopaque
446451
}
447452

453+
#[inline]
448454
fn outer_expn(&self, ctxt: SyntaxContext) -> ExpnId {
449455
self.syntax_context_data[ctxt.0 as usize].outer_expn
450456
}
451457

458+
#[inline]
452459
fn outer_mark(&self, ctxt: SyntaxContext) -> (ExpnId, Transparency) {
453460
let data = &self.syntax_context_data[ctxt.0 as usize];
454461
(data.outer_expn, data.outer_transparency)
455462
}
456463

464+
#[inline]
457465
fn parent_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext {
458466
self.syntax_context_data[ctxt.0 as usize].parent
459467
}
@@ -718,11 +726,13 @@ impl SyntaxContext {
718726
SyntaxContext(raw as u32)
719727
}
720728

729+
#[inline]
721730
fn from_usize(raw: usize) -> SyntaxContext {
722731
SyntaxContext(u32::try_from(raw).unwrap())
723732
}
724733

725734
/// Extend a syntax context with a given expansion and transparency.
735+
#[inline]
726736
pub fn apply_mark(self, expn_id: ExpnId, transparency: Transparency) -> SyntaxContext {
727737
HygieneData::with(|data| data.apply_mark(self, expn_id, transparency))
728738
}
@@ -743,10 +753,12 @@ impl SyntaxContext {
743753
/// of g (call it g1), calling remove_mark will result in the SyntaxContext for the
744754
/// invocation of f that created g1.
745755
/// Returns the mark that was removed.
756+
#[inline]
746757
pub fn remove_mark(&mut self) -> ExpnId {
747758
HygieneData::with(|data| data.remove_mark(self).0)
748759
}
749760

761+
#[inline]
750762
pub fn marks(self) -> Vec<(ExpnId, Transparency)> {
751763
HygieneData::with(|data| data.marks(self))
752764
}
@@ -776,11 +788,13 @@ impl SyntaxContext {
776788
/// ```
777789
/// This returns the expansion whose definition scope we use to privacy check the resolution,
778790
/// or `None` if we privacy check as usual (i.e., not w.r.t. a macro definition scope).
791+
#[inline]
779792
pub fn adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
780793
HygieneData::with(|data| data.adjust(self, expn_id))
781794
}
782795

783796
/// Like `SyntaxContext::adjust`, but also normalizes `self` to macros 2.0.
797+
#[inline]
784798
pub(crate) fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
785799
HygieneData::with(|data| {
786800
*self = data.normalize_to_macros_2_0(*self);
@@ -901,10 +915,12 @@ impl SyntaxContext {
901915
HygieneData::with(|data| data.outer_mark(self))
902916
}
903917

918+
#[inline]
904919
pub(crate) fn dollar_crate_name(self) -> Symbol {
905920
HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name)
906921
}
907922

923+
#[inline]
908924
pub fn edition(self) -> Edition {
909925
HygieneData::with(|data| data.expn_data(data.outer_expn(self)).edition)
910926
}

compiler/rustc_span/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ where
167167
}
168168
}
169169

170+
#[inline]
170171
pub fn with_session_globals<R, F>(f: F) -> R
171172
where
172173
F: FnOnce(&SessionGlobals) -> R,

0 commit comments

Comments
 (0)