Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b315e9a
clippy fix: rely on autoderef
hkBst Jul 4, 2025
05154af
docs: update documentation of core::mem::copy to include const on the…
SunkenPotato Jul 15, 2025
a9fd8d0
bootstrap: Move musl-root fallback out of sanity check
Gelbpunkt Jul 22, 2025
3d186ea
Fix tests/assembly-llvm/dwarf-mixed-versions-lto.rs test failure on r…
Jul 23, 2025
2e49c52
Fix tests/codegen-llvm/const-vector.rs test failure on riscv64
Jul 23, 2025
23fda60
RustWrapper: Suppress getNextNonDebugInfoInstruction
heiher Jul 23, 2025
e7441fb
Clippy fixup
Gelbpunkt Jul 23, 2025
78fc7c3
Suggest unwrapping when private method name is available in inner type
estebank Jul 23, 2025
60d6980
Inline some methods in rustc_span hygiene
xizheyin Jul 23, 2025
94c0cf8
Rename tests/ui/SUMMARY.md and update rustc dev guide on error-pattern
Oneirical Jul 23, 2025
97676e6
Allow setting `release-blog-post` label with rustbot
BoxyUwU Jul 24, 2025
6020170
Rollup merge of #143424 - hkBst:auto-deref, r=jhpratt
Kobzol Jul 25, 2025
334b2e7
Rollup merge of #143970 - SunkenPotato:update_mem_copy_docs, r=scottmcm
Kobzol Jul 25, 2025
2514055
Rollup merge of #144316 - Gelbpunkt:musl-libdir-bootstrap, r=Kobzol
Kobzol Jul 25, 2025
bc9f44b
Rollup merge of #144339 - CaiWeiran:dwarf-mixed-versions-lto_test, r=…
Kobzol Jul 25, 2025
a3741f7
Rollup merge of #144340 - Oneirical:uncertain-illusion, r=jieyouxu
Kobzol Jul 25, 2025
38066ad
Rollup merge of #144341 - CaiWeiran:const-vector_test, r=wesleywiser
Kobzol Jul 25, 2025
77fffaa
Rollup merge of #144352 - heiher:llvm-22, r=dianqk
Kobzol Jul 25, 2025
eb3222d
Rollup merge of #144376 - estebank:issue-143795, r=lcnr
Kobzol Jul 25, 2025
582aa96
Rollup merge of #144385 - xizheyin:macro-hygiene, r=petrochenkov
Kobzol Jul 25, 2025
1a8dff4
Rollup merge of #144424 - BoxyUwU:release_blog_post_unauthorized_user…
Kobzol Jul 25, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inline some methods in rustc_span hygiene
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
  • Loading branch information
xizheyin committed Jul 24, 2025
commit 60d69804bacb47875bb691ffc97b25e92f0b98fd
16 changes: 16 additions & 0 deletions compiler/rustc_span/src/hygiene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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()))
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
}
Expand All @@ -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))
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ where
}
}

#[inline]
pub fn with_session_globals<R, F>(f: F) -> R
where
F: FnOnce(&SessionGlobals) -> R,
Expand Down
Loading