Skip to content

Commit ae84552

Browse files
Auto merge of #142815 - tgross35:transcribe-perf, r=<try>
mbe: Inline functions in `transcribe` that are only called once [#142713] did some refactoring of macro expansion, which seems to have had an effect on performance. The only change was to split large functions into smaller ones, so mark some functions that are only called once `#[inline]` to make codegen more similar. [#142713]: https://www.github.com/rust-lang/rust/pull/142713
2 parents 15c701f + 3a76b79 commit ae84552

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ pub(super) fn transcribe<'a>(
289289
}
290290

291291
/// Turn `$(...)*` sequences into tokens.
292+
#[inline] // called once
292293
fn transcribe_sequence<'tx, 'itp>(
293294
tscx: &mut TranscrCtx<'tx, 'itp>,
294295
seq: &mbe::TokenTree,
@@ -357,6 +358,7 @@ fn transcribe_sequence<'tx, 'itp>(
357358
/// producing "xyz", which is bad because it effectively merges tokens.
358359
/// `Spacing::Alone` is the safer option. Fortunately, `space_between` will avoid
359360
/// some of the unnecessary whitespace.
361+
#[inline] // called once
360362
fn transcribe_metavar<'tx>(
361363
tscx: &mut TranscrCtx<'tx, '_>,
362364
mut sp: Span,
@@ -492,6 +494,7 @@ fn transcribe_metavar<'tx>(
492494
}
493495

494496
/// Turn `${expr(...)}` metavariable expressionss into tokens.
497+
#[inline] // called once
495498
fn transcribe_metavar_expr<'tx>(
496499
tscx: &mut TranscrCtx<'tx, '_>,
497500
dspan: DelimSpan,
@@ -537,6 +540,7 @@ fn transcribe_metavar_expr<'tx>(
537540
}
538541

539542
/// Handle the `${concat(...)}` metavariable expression.
543+
#[inline] // called once
540544
fn metavar_expr_concat<'tx>(
541545
tscx: &mut TranscrCtx<'tx, '_>,
542546
dspan: DelimSpan,
@@ -617,6 +621,7 @@ fn metavar_expr_concat<'tx>(
617621
/// These are typically used for passing larger amounts of code, and tokens in that code usually
618622
/// combine with each other and not with tokens outside of the sequence.
619623
/// - The metavariable span comes from a different crate, then we prefer the more local span.
624+
#[inline] // called once
620625
fn maybe_use_metavar_location(
621626
psess: &ParseSess,
622627
stack: &[Frame<'_>],
@@ -808,6 +813,7 @@ fn lockstep_iter_size(
808813
/// * `[ $( ${count(foo, 0)} ),* ]` will be the same as `[ $( ${count(foo)} ),* ]`
809814
/// * `[ $( ${count(foo, 1)} ),* ]` will return an error because `${count(foo, 1)}` is
810815
/// declared inside a single repetition and the index `1` implies two nested repetitions.
816+
#[inline] // called once
811817
fn count_repetitions<'dx>(
812818
dcx: DiagCtxtHandle<'dx>,
813819
depth_user: usize,

0 commit comments

Comments
 (0)