This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit c87e2bb
committed
Auto merge of rust-lang#119689 - petrochenkov:markeager, r=<try>
macro_rules: Eagerly mark spans of produced tokens
When a declarative macro expands and produces tokens it marks their spans as coming from that specific macro expansion.
Marking is a relatively expensive operation - it needs to lock the global hygiene data.
Right now marking happens lazily, when a token is actually produced into the output.
But that means marking happens 100 times if `$($var)*` expands to a sequence of length 100 (span of `$var` is marked and outputted as a part of the resulting nonterminal token).
In this PR I'm trying to perform this marking eagerly and once.
- Pros (perf): tokens from sequences are marked once (1 time instead of N).
- Cons (perf): tokens that never end up in the output are still marked (1 time instead of 0).
- Cons (perf): cloning of the used macro arm's right hand side is required (`src` in `fn transcribe`).
- Cons (perf): metavariable tokens of the `tt` kind weren't previously marked but they are marked now (can't tell whether the variable is `tt` this early). However, for rust-lang#119673 we'll need `tt` metavars marked anyway.
- Pros (diagnostics): Some erroneous tokens are now correctly reported as coming from a macro expansion.File tree
9 files changed
+122
-38
lines changed- compiler/rustc_expand/src
- mbe
- tests/ui
- macros
- rfc-3086-metavar-expr
- parser/macro
9 files changed
+122
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
| 245 | + | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| |||
342 | 342 | | |
343 | 343 | | |
344 | 344 | | |
345 | | - | |
| 345 | + | |
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1378 | 1378 | | |
1379 | 1379 | | |
1380 | 1380 | | |
1381 | | - | |
| 1381 | + | |
1382 | 1382 | | |
1383 | 1383 | | |
1384 | 1384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
| 226 | + | |
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
| 249 | + | |
249 | 250 | | |
250 | 251 | | |
251 | 252 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
79 | 128 | | |
80 | 129 | | |
81 | 130 | | |
| |||
108 | 157 | | |
109 | 158 | | |
110 | 159 | | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
111 | 164 | | |
112 | 165 | | |
113 | 166 | | |
114 | 167 | | |
115 | | - | |
| 168 | + | |
116 | 169 | | |
117 | 170 | | |
118 | 171 | | |
| |||
132 | 185 | | |
133 | 186 | | |
134 | 187 | | |
135 | | - | |
136 | 188 | | |
137 | 189 | | |
138 | 190 | | |
| |||
245 | 297 | | |
246 | 298 | | |
247 | 299 | | |
248 | | - | |
| 300 | + | |
| 301 | + | |
249 | 302 | | |
250 | 303 | | |
251 | | - | |
| 304 | + | |
252 | 305 | | |
253 | 306 | | |
254 | 307 | | |
| |||
260 | 313 | | |
261 | 314 | | |
262 | 315 | | |
263 | | - | |
264 | 316 | | |
265 | 317 | | |
266 | 318 | | |
| |||
272 | 324 | | |
273 | 325 | | |
274 | 326 | | |
275 | | - | |
276 | | - | |
277 | 327 | | |
278 | 328 | | |
279 | | - | |
| 329 | + | |
280 | 330 | | |
281 | 331 | | |
282 | 332 | | |
283 | 333 | | |
284 | 334 | | |
285 | 335 | | |
286 | 336 | | |
287 | | - | |
| 337 | + | |
288 | 338 | | |
289 | 339 | | |
290 | 340 | | |
291 | 341 | | |
292 | 342 | | |
293 | 343 | | |
294 | 344 | | |
295 | | - | |
296 | | - | |
| 345 | + | |
297 | 346 | | |
298 | 347 | | |
299 | 348 | | |
300 | 349 | | |
301 | | - | |
| 350 | + | |
302 | 351 | | |
303 | 352 | | |
304 | 353 | | |
| |||
307 | 356 | | |
308 | 357 | | |
309 | 358 | | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
| 359 | + | |
314 | 360 | | |
315 | 361 | | |
316 | 362 | | |
| |||
475 | 521 | | |
476 | 522 | | |
477 | 523 | | |
478 | | - | |
| 524 | + | |
479 | 525 | | |
480 | 526 | | |
481 | 527 | | |
| |||
620 | 666 | | |
621 | 667 | | |
622 | 668 | | |
623 | | - | |
624 | 669 | | |
625 | 670 | | |
626 | 671 | | |
627 | 672 | | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | 673 | | |
634 | 674 | | |
635 | 675 | | |
636 | 676 | | |
637 | 677 | | |
638 | 678 | | |
639 | | - | |
| 679 | + | |
640 | 680 | | |
641 | 681 | | |
642 | 682 | | |
| |||
648 | 688 | | |
649 | 689 | | |
650 | 690 | | |
651 | | - | |
| 691 | + | |
652 | 692 | | |
653 | 693 | | |
654 | 694 | | |
| |||
657 | 697 | | |
658 | 698 | | |
659 | 699 | | |
660 | | - | |
| 700 | + | |
661 | 701 | | |
662 | 702 | | |
663 | 703 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
6 | 11 | | |
7 | 12 | | |
8 | 13 | | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
12 | 22 | | |
13 | 23 | | |
14 | 24 | | |
15 | 25 | | |
16 | 26 | | |
17 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
18 | 33 | | |
19 | 34 | | |
20 | 35 | | |
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
204 | 209 | | |
205 | 210 | | |
206 | 211 | | |
207 | 212 | | |
208 | 213 | | |
209 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
210 | 220 | | |
211 | 221 | | |
212 | 222 | | |
213 | 223 | | |
214 | 224 | | |
215 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
216 | 231 | | |
217 | 232 | | |
218 | 233 | | |
| |||
0 commit comments