diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs index be4a72896d761..f467a7bcc18fe 100644 --- a/compiler/rustc_span/src/span_encoding.rs +++ b/compiler/rustc_span/src/span_encoding.rs @@ -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); @@ -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); @@ -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(), @@ -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 { @@ -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(); @@ -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 { match self.fmt() { Fmt::InlineCtxt(InlineCtxt { ctxt, .. })