-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macro_rules: Eagerly mark spans of produced tokens #119689
Conversation
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
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.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
macro_rules: Add an expansion-local cache to span marker Most tokens in a macro body typically have the same syntax context. So the cache should usually be hit. This change can either be combined with rust-lang#119689, or serve as its alternative, depending on perf results.
Finished benchmarking commit (52e9fd6): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 668.625s -> 666.421s (-0.33%) |
macro_rules: Add an expansion-local cache to span marker Most tokens in a macro body typically have the same syntax context. So the cache should usually be hit. This change can either be combined with rust-lang#119689, or serve as its alternative, depending on perf results.
ee50351
to
24f88f8
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
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.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (c87e2bb): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 667.831s -> 670.809s (0.45%) |
After #119693 it's still useful for huge sequences like in |
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.
src
infn transcribe
).tt
kind weren't previously marked but they are marked now (can't tell whether the variable istt
this early). However, for macro_rules: Preserve all metavariable spans in a global side table #119673 we'll needtt
metavars marked anyway.