Remove some AST tokens fields#158942
Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Remove some AST `tokens` fields
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (3f39560): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.3%, secondary -0.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.4%, secondary -9.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.0%, secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 487.812s -> 487.974s (0.03%) |
d3bb72f to
dbcb5a4
Compare
|
Good icount results on a few benchmarks, even better cycles results. |
|
cc @rust-lang/rustfmt Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer
cc @rust-lang/clippy The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 |
| span: self.span, | ||
| tokens: self.tokens.clone(), | ||
| }) | ||
| ensure_sufficient_stack(|| Self { id: self.id, kind: self.kind.clone(), span: self.span }) |
There was a problem hiding this comment.
Assuming that ensure_sufficient_stack was necessary for cloning deeply nested tokens, this Clone impl can be a #[derive(Clone)] instead.
There was a problem hiding this comment.
Interesting suggestion! But self.kind can be recursive, so it might also/instead for deeply nested types.
|
It would also be nice to remove |
|
This is very nice, especially for Left some comment nits. |
|
Reminder, once the PR becomes ready for a review, use |
dbcb5a4 to
589a21e
Compare
This comment has been minimized.
This comment has been minimized.
These ones are always `None` and never read.
Specifically, from `Block`, `Pat`, `Path`, `Ty`, `Visibility`. This field is usually `None`. It only gets filled in for paths that might later be re-tokenized via `TokenStream::from_ast`, e.g. because of macro or cfg use. All such cases go through a single place: `parse_nonterminal`. This commit changes `parse_nonterminal` to store the non-`None` lazy attr token stream *next* to the node in `ParseNtResult` (using the new `WithTokens` type) instead of *inside* the parsed node. Along with some minor changes to the relevant `HasTokens` and `HasAttrs` impls, this is enough for things to work. These AST nodes all shrink by 8 bytes, as do various other nodes that contain nodes of these types. A guide to the changes: - `compiler/rustc_ast/src/tokenstream.rs` has the new `WithTokens` type. - `compiler/rustc_parse/src/parser/nonterminal.rs`, `compiler/rustc_expand/src/mbe/transcribe.rs` and `compiler/rustc_parse/src/parser/mod.rs` have minor changes due to the changes to `ParseNtResult`. - `compiler/rustc_ast/src/ast_traits.rs` has the `HasTokens`/`HasAttrs` changes. - Everything else is just mechanical changes for the removal of the `tokens` field.
The same basic idea from the previous commit applies: the tokens are only sometimes needed and we can store them next to the `AttrItem` (using `WithTokens`) instead of inside the `AttrItem`. The change is a bit more complex because more than just `parse_nonterminal` is involved (e.g. `parse_attr_item`, `parse_cfg_attr`, `expand_cfg_attr_item`).
589a21e to
351026d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
The PR got broken by another PR that landed and added some new code. I have fixed the breakage. @bors r=petrochenkov |
This comment has been minimized.
This comment has been minimized.
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing ae705ae (parent) -> 375b143 (this PR) Test differencesShow 42 test diffs42 doctest diffs were found. These are ignored, as they are noisy. Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 375b1431b7d89d1c2e2bc168c011848ae12b7d14 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (375b143): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.0%, secondary -0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.4%, secondary -5.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 491.745s -> 490.777s (-0.20%) |
View all comments
This commit removes/moves the
tokensfield from various AST node types, shrinking them. Details in individual commits.