-
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
Overhaul token cursors #134161
Overhaul token cursors #134161
Conversation
efad936
to
7874297
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…r=<try> Overhaul token cursors r? `@ghost`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (29ae3e8): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking 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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary 1.3%, secondary -0.2%)This 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.
CyclesResults (primary 6.0%, secondary -0.5%)This 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: 767.862s -> 766.941s (-0.12%) |
7874297
to
999cb16
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
@rustbot ready |
@petrochenkov: I know your time is limited at the moment. Unlike PRs such as #133436 this PR is not that complicated, so I will ask someone else to review. r? @davidtwco |
Could not assign reviewer from: |
)) = self.toks.look_ahead(0) | ||
)) = self.iter.peek() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we're replacing calls to .look_ahead()
with .peek()
. Is .peek()
equivalent to both .look_ahead(0)
here and .look_ahead(1)
above in MacroParser::parse
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Full details are in the individual commit messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that it doesn't matter if you use 0
, 1
, or 2
as the look ahead, and that things only start failing if you choose 3
or more. I know you mentioned it's due to the structure of the code, but I'm wondering if you could elaborate a little more to help me fully understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AIUI, the existing code says "If there are at least two tokens remaining, try to parse a branch". The new code says "if there is at least one token remaining, try to parse a branch". parse_branch
has three self.toks.next()?
calls in it, and all three must succeed for the function to succeed, i.e. there must actually be at least three tokens remaining.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for walking me through that. We're good on the rustfmt changes.
r? @spastorino |
999cb16
to
464d0ee
Compare
I rebased. @bors r=spastorino rollup=maybe |
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
- Move it to `rustc_parse`, which is the only crate that uses it. This lets us remove all the `pub` markers from it. - Change `next_ref` and `look_ahead` to `get` and `bump`, which work better for the `rustc_parse` uses. - This requires adding a `TokenStream::get` method, which is simple. - In `TokenCursor`, we currently duplicate the `DelimSpan`/`DelimSpacing`/`Delimiter` from the surrounding `TokenTree::Delimited` in the stack. This isn't necessary so long as we don't prematurely move past the `Delimited`, and is a small perf win on a very hot code path. - In `parse_token_tree`, we clone the relevant `TokenTree::Delimited` instead of constructing an identical one from pieces.
464d0ee
to
2903356
Compare
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
…, r=spastorino Overhaul token cursors Some nice cleanups here. r? `@davidtwco`
…, r=spastorino Overhaul token cursors Some nice cleanups here. r? ``@davidtwco``
…, r=spastorino Overhaul token cursors Some nice cleanups here. r? ```@davidtwco```
…, r=spastorino Overhaul token cursors Some nice cleanups here. r? ````@davidtwco````
Rollup of 8 pull requests Successful merges: - rust-lang#133702 (Variants::Single: do not use invalid VariantIdx for uninhabited enums) - rust-lang#133926 (Fix const conditions for RPITITs) - rust-lang#134161 (Overhaul token cursors) - rust-lang#134253 (Overhaul keyword handling) - rust-lang#134394 (Clarify the match ergonomics 2024 migration lint's output) - rust-lang#134420 (refactor: replace &PathBuf with &Path to enhance generality) - rust-lang#134444 (Fix `x build --stage 1 std` when using cg_cranelift as the default backend) - rust-lang#134452 (fix(LazyCell): documentation of get[_mut] was wrong) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 11 pull requests Successful merges: - rust-lang#130786 ( mir-opt: a sub-BB of a cleanup BB must also be a cleanup BB in `EarlyOtherwiseBranch`) - rust-lang#133926 (Fix const conditions for RPITITs) - rust-lang#134161 (Overhaul token cursors) - rust-lang#134253 (Overhaul keyword handling) - rust-lang#134394 (Clarify the match ergonomics 2024 migration lint's output) - rust-lang#134399 (Do not do if ! else, use unnegated cond and swap the branches instead) - rust-lang#134420 (refactor: replace &PathBuf with &Path to enhance generality) - rust-lang#134436 (tests/assembly/asm: Remove uses of rustc_attrs and lang_items features by using minicore) - rust-lang#134444 (Fix `x build --stage 1 std` when using cg_cranelift as the default backend) - rust-lang#134452 (fix(LazyCell): documentation of get[_mut] was wrong) - rust-lang#134460 (Merge some patterns together) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#134161 - nnethercote:overhaul-token-cursors, r=spastorino Overhaul token cursors Some nice cleanups here. r? `````@davidtwco`````
…, r=spastorino Overhaul token cursors Some nice cleanups here. r? `````@davidtwco`````
Some nice cleanups here.
r? @davidtwco