This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit 52e9fd6
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
+121
-38
lines changed- compiler/rustc_expand/src
- mbe
- tests/ui
- macros
- rfc-3086-metavar-expr
- parser/macro
9 files changed
+121
-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 | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 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 | + | |
70 | 119 | | |
71 | 120 | | |
72 | 121 | | |
| |||
99 | 148 | | |
100 | 149 | | |
101 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
102 | 154 | | |
103 | 155 | | |
104 | 156 | | |
105 | 157 | | |
106 | | - | |
| 158 | + | |
107 | 159 | | |
108 | 160 | | |
109 | 161 | | |
| |||
123 | 175 | | |
124 | 176 | | |
125 | 177 | | |
126 | | - | |
127 | 178 | | |
128 | 179 | | |
129 | 180 | | |
| |||
236 | 287 | | |
237 | 288 | | |
238 | 289 | | |
239 | | - | |
| 290 | + | |
| 291 | + | |
240 | 292 | | |
241 | 293 | | |
242 | | - | |
| 294 | + | |
243 | 295 | | |
244 | 296 | | |
245 | 297 | | |
| |||
251 | 303 | | |
252 | 304 | | |
253 | 305 | | |
254 | | - | |
255 | 306 | | |
256 | 307 | | |
257 | 308 | | |
| |||
263 | 314 | | |
264 | 315 | | |
265 | 316 | | |
266 | | - | |
267 | | - | |
268 | 317 | | |
269 | 318 | | |
270 | | - | |
| 319 | + | |
271 | 320 | | |
272 | 321 | | |
273 | 322 | | |
274 | 323 | | |
275 | 324 | | |
276 | 325 | | |
277 | 326 | | |
278 | | - | |
| 327 | + | |
279 | 328 | | |
280 | 329 | | |
281 | 330 | | |
282 | 331 | | |
283 | 332 | | |
284 | 333 | | |
285 | 334 | | |
286 | | - | |
287 | | - | |
| 335 | + | |
288 | 336 | | |
289 | 337 | | |
290 | 338 | | |
291 | 339 | | |
292 | | - | |
| 340 | + | |
293 | 341 | | |
294 | 342 | | |
295 | 343 | | |
| |||
298 | 346 | | |
299 | 347 | | |
300 | 348 | | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
| 349 | + | |
305 | 350 | | |
306 | 351 | | |
307 | 352 | | |
| |||
466 | 511 | | |
467 | 512 | | |
468 | 513 | | |
469 | | - | |
| 514 | + | |
470 | 515 | | |
471 | 516 | | |
472 | 517 | | |
| |||
611 | 656 | | |
612 | 657 | | |
613 | 658 | | |
614 | | - | |
615 | 659 | | |
616 | 660 | | |
617 | 661 | | |
618 | 662 | | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | 663 | | |
625 | 664 | | |
626 | 665 | | |
627 | 666 | | |
628 | 667 | | |
629 | 668 | | |
630 | | - | |
| 669 | + | |
631 | 670 | | |
632 | 671 | | |
633 | 672 | | |
| |||
639 | 678 | | |
640 | 679 | | |
641 | 680 | | |
642 | | - | |
| 681 | + | |
643 | 682 | | |
644 | 683 | | |
645 | 684 | | |
| |||
648 | 687 | | |
649 | 688 | | |
650 | 689 | | |
651 | | - | |
| 690 | + | |
652 | 691 | | |
653 | 692 | | |
654 | 693 | | |
| |||
| 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