@@ -27,14 +27,6 @@ use crate::mbe::{self, KleeneOp, MetaVarExpr};
27
27
28
28
/// Context needed to perform transcription of metavariable expressions.
29
29
struct TranscrCtx < ' psess , ' itp > {
30
- psess : & ' psess ParseSess ,
31
-
32
- /// Map from metavars to matched tokens
33
- interp : & ' itp FxHashMap < MacroRulesNormalizedIdent , NamedMatch > ,
34
-
35
- /// Allow marking spans.
36
- marker : Marker ,
37
-
38
30
/// The stack of things yet to be completely expanded.
39
31
///
40
32
/// We descend into the RHS (`src`), expanding things as we go. This stack contains the things
@@ -66,6 +58,14 @@ struct TranscrCtx<'psess, 'itp> {
66
58
/// The in-progress `result` lives at the top of this stack. Each entered `TokenTree` adds a
67
59
/// new entry.
68
60
result_stack : Vec < Vec < TokenTree > > ,
61
+
62
+ /// Allow marking spans.
63
+ marker : Marker ,
64
+
65
+ psess : & ' psess ParseSess ,
66
+
67
+ /// Map from metavars to matched tokens
68
+ interp : & ' itp FxHashMap < MacroRulesNormalizedIdent , NamedMatch > ,
69
69
}
70
70
71
71
impl < ' psess > TranscrCtx < ' psess , ' _ > {
@@ -174,17 +174,17 @@ pub(super) fn transcribe<'a>(
174
174
}
175
175
176
176
let mut tscx = TranscrCtx {
177
- psess,
178
- interp,
179
- marker : Marker { expand_id, transparency, cache : Default :: default ( ) } ,
180
- repeats : Vec :: new ( ) ,
181
177
stack : smallvec ! [ Frame :: new_delimited(
182
178
src,
183
179
src_span,
184
180
DelimSpacing :: new( Spacing :: Alone , Spacing :: Alone )
185
181
) ] ,
182
+ repeats : Vec :: new ( ) ,
186
183
result : Vec :: new ( ) ,
187
184
result_stack : Vec :: new ( ) ,
185
+ marker : Marker { expand_id, transparency, cache : Default :: default ( ) } ,
186
+ psess,
187
+ interp,
188
188
} ;
189
189
190
190
loop {
@@ -289,6 +289,7 @@ pub(super) fn transcribe<'a>(
289
289
}
290
290
291
291
/// Turn `$(...)*` sequences into tokens.
292
+ #[ inline( always) ] // called once
292
293
fn transcribe_sequence < ' tx , ' itp > (
293
294
tscx : & mut TranscrCtx < ' tx , ' itp > ,
294
295
seq : & mbe:: TokenTree ,
@@ -357,6 +358,7 @@ fn transcribe_sequence<'tx, 'itp>(
357
358
/// producing "xyz", which is bad because it effectively merges tokens.
358
359
/// `Spacing::Alone` is the safer option. Fortunately, `space_between` will avoid
359
360
/// some of the unnecessary whitespace.
361
+ #[ inline( always) ] // called once
360
362
fn transcribe_metavar < ' tx > (
361
363
tscx : & mut TranscrCtx < ' tx , ' _ > ,
362
364
mut sp : Span ,
@@ -492,6 +494,7 @@ fn transcribe_metavar<'tx>(
492
494
}
493
495
494
496
/// Turn `${expr(...)}` metavariable expressionss into tokens.
497
+ #[ inline( always) ] // called once
495
498
fn transcribe_metavar_expr < ' tx > (
496
499
tscx : & mut TranscrCtx < ' tx , ' _ > ,
497
500
dspan : DelimSpan ,
@@ -502,7 +505,7 @@ fn transcribe_metavar_expr<'tx>(
502
505
MetaVarExpr :: Concat ( ref elements) => metavar_expr_concat ( tscx, dspan, elements) ?,
503
506
MetaVarExpr :: Count ( original_ident, depth) => {
504
507
let matched = matched_from_ident ( dcx, original_ident, tscx. interp ) ?;
505
- let count = count_repetitions ( dcx, depth, matched, & tscx. repeats , & dspan) ?;
508
+ let count = count_repetitions ( dcx, depth, matched, & tscx. repeats , dspan) ?;
506
509
TokenTree :: token_alone (
507
510
TokenKind :: lit ( token:: Integer , sym:: integer ( count) , None ) ,
508
511
tscx. visited_dspan ( dspan) ,
@@ -537,6 +540,7 @@ fn transcribe_metavar_expr<'tx>(
537
540
}
538
541
539
542
/// Handle the `${concat(...)}` metavariable expression.
543
+ #[ inline( always) ] // called once
540
544
fn metavar_expr_concat < ' tx > (
541
545
tscx : & mut TranscrCtx < ' tx , ' _ > ,
542
546
dspan : DelimSpan ,
@@ -617,6 +621,7 @@ fn metavar_expr_concat<'tx>(
617
621
/// These are typically used for passing larger amounts of code, and tokens in that code usually
618
622
/// combine with each other and not with tokens outside of the sequence.
619
623
/// - The metavariable span comes from a different crate, then we prefer the more local span.
624
+ #[ inline( always) ] // called once
620
625
fn maybe_use_metavar_location (
621
626
psess : & ParseSess ,
622
627
stack : & [ Frame < ' _ > ] ,
@@ -808,12 +813,13 @@ fn lockstep_iter_size(
808
813
/// * `[ $( ${count(foo, 0)} ),* ]` will be the same as `[ $( ${count(foo)} ),* ]`
809
814
/// * `[ $( ${count(foo, 1)} ),* ]` will return an error because `${count(foo, 1)}` is
810
815
/// declared inside a single repetition and the index `1` implies two nested repetitions.
816
+ #[ inline( always) ] // called once
811
817
fn count_repetitions < ' dx > (
812
818
dcx : DiagCtxtHandle < ' dx > ,
813
819
depth_user : usize ,
814
820
mut matched : & NamedMatch ,
815
821
repeats : & [ ( usize , usize ) ] ,
816
- sp : & DelimSpan ,
822
+ sp : DelimSpan ,
817
823
) -> PResult < ' dx , usize > {
818
824
// Recursively count the number of matches in `matched` at given depth
819
825
// (or at the top-level of `matched` if no depth is given).
0 commit comments