Skip to content

Commit

Permalink
rustc_span: Inline new hot functions
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jun 1, 2024
1 parent 8c62dc1 commit 00c399e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions compiler/rustc_span/src/span_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ enum Fmt<'a> {
}

impl InlineCtxt {
#[inline]
fn data(self) -> SpanData {
let len = self.len as u32;
debug_assert!(len <= MAX_LEN);
Expand All @@ -134,12 +135,14 @@ impl InlineCtxt {
parent: None,
}
}
#[inline]
fn to_span(self) -> Span {
unsafe { transmute(self) }
}
}

impl InlineParent {
#[inline]
fn data(self) -> SpanData {
let len = (self.len_with_tag & !PARENT_TAG) as u32;
debug_assert!(len <= MAX_LEN);
Expand All @@ -150,33 +153,39 @@ impl InlineParent {
parent: Some(LocalDefId { local_def_index: DefIndex::from_u32(self.parent as u32) }),
}
}
#[inline]
fn to_span(self) -> Span {
unsafe { transmute(self) }
}
}

impl PartiallyInterned {
#[inline]
fn data(self) -> SpanData {
SpanData {
ctxt: SyntaxContext::from_u32(self.ctxt as u32),
..with_span_interner(|interner| interner.spans[self.index as usize])
}
}
#[inline]
fn to_span(self) -> Span {
unsafe { transmute(self) }
}
}

impl Interned {
#[inline]
fn data(self) -> SpanData {
with_span_interner(|interner| interner.spans[self.index as usize])
}
#[inline]
fn to_span(self) -> Span {
unsafe { transmute(self) }
}
}

impl Fmt<'_> {
#[inline]
fn data(self) -> SpanData {
match self {
Fmt::InlineCtxt(span) => span.data(),
Expand Down Expand Up @@ -241,6 +250,7 @@ impl Span {
}
}

#[inline]
fn fmt(&mut self) -> Fmt<'_> {
if self.len_with_tag_or_marker != BASE_LEN_INTERNED_MARKER {
if self.len_with_tag_or_marker & PARENT_TAG == 0 {
Expand Down Expand Up @@ -291,6 +301,7 @@ impl Span {
// For optimization we are interested in cases in which the context is inline and the context
// update doesn't change format. All non-inline or format changing scenarios require accessing
// interner and can fall back to `Span::new`.
#[inline]
pub fn update_ctxt(&mut self, update: impl FnOnce(SyntaxContext) -> SyntaxContext) {
// FIXME(#125017): Update ctxt inline without touching interner when possible.
let data = self.data();
Expand All @@ -299,6 +310,7 @@ impl Span {

// Returns either syntactic context, if it can be retrieved without taking the interner lock,
// or an index into the interner if it cannot.
#[inline]
fn inline_ctxt(mut self) -> Result<SyntaxContext, usize> {
match self.fmt() {
Fmt::InlineCtxt(InlineCtxt { ctxt, .. })
Expand Down

0 comments on commit 00c399e

Please sign in to comment.