Skip to content
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

Merged
merged 7 commits into from
Dec 18, 2024
Merged

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Dec 11, 2024

Some nice cleanups here.

r? @davidtwco

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Dec 11, 2024
@nnethercote nnethercote force-pushed the overhaul-token-cursors branch from efad936 to 7874297 Compare December 11, 2024 08:50
@nnethercote
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 11, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 11, 2024
…r=<try>

Overhaul token cursors

r? `@ghost`
@bors
Copy link
Contributor

bors commented Dec 11, 2024

⌛ Trying commit 7874297 with merge 29ae3e8...

@bors
Copy link
Contributor

bors commented Dec 11, 2024

☀️ Try build successful - checks-actions
Build commit: 29ae3e8 (29ae3e83e7d9a22117bca546c540f18c2cb36a8b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (29ae3e8): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking 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 @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.4% [0.3%, 0.4%] 3
Improvements ✅
(primary)
-0.2% [-0.2%, -0.1%] 2
Improvements ✅
(secondary)
-0.3% [-0.5%, -0.2%] 4
All ❌✅ (primary) -0.2% [-0.2%, -0.1%] 2

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.

mean range count
Regressions ❌
(primary)
2.0% [1.5%, 2.6%] 4
Regressions ❌
(secondary)
1.8% [1.6%, 2.3%] 4
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
-4.3% [-5.1%, -3.4%] 2
All ❌✅ (primary) 1.3% [-1.1%, 2.6%] 5

Cycles

Results (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.

mean range count
Regressions ❌
(primary)
6.0% [3.3%, 9.8%] 3
Regressions ❌
(secondary)
9.4% [9.4%, 9.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-3.5%, -2.5%] 4
All ❌✅ (primary) 6.0% [3.3%, 9.8%] 3

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 767.862s -> 766.941s (-0.12%)
Artifact size: 331.04 MiB -> 331.06 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 11, 2024
@petrochenkov petrochenkov self-assigned this Dec 11, 2024
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 11, 2024
@nnethercote
Copy link
Contributor Author

I saw small but consistent icount improvements locally:
Screenshot from 2024-12-12 07-21-37

The most likely explanation when local wins aren't seen on CI is that PGO is involved. But not every platform has PGO applied, and the improvements here are also to readability, so I think this is still worth going forward.

@nnethercote nnethercote force-pushed the overhaul-token-cursors branch from 7874297 to 999cb16 Compare December 11, 2024 20:40
@nnethercote nnethercote marked this pull request as ready for review December 11, 2024 20:40
@rustbot
Copy link
Collaborator

rustbot commented Dec 11, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

@nnethercote
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 11, 2024
@nnethercote
Copy link
Contributor Author

@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

@rustbot rustbot assigned davidtwco and unassigned petrochenkov Dec 12, 2024
@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 2024

Could not assign reviewer from: davidtwco.
User(s) davidtwco are either the PR author, already assigned, or on vacation, and there are no other candidates.
Use r? to specify someone else to assign.

)) = self.toks.look_ahead(0)
)) = self.iter.peek()
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@nnethercote
Copy link
Contributor Author

r? @spastorino

@nnethercote nnethercote force-pushed the overhaul-token-cursors branch from 999cb16 to 464d0ee Compare December 18, 2024 01:30
@nnethercote
Copy link
Contributor Author

I rebased.

@bors r=spastorino rollup=maybe

@bors
Copy link
Contributor

bors commented Dec 18, 2024

📌 Commit 464d0ee has been approved by spastorino

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 18, 2024
@rust-log-analyzer

This comment has been minimized.

@nnethercote

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.
@nnethercote nnethercote force-pushed the overhaul-token-cursors branch from 464d0ee to 2903356 Compare December 18, 2024 01:50
@rust-log-analyzer

This comment has been minimized.

@nnethercote

This comment was marked as outdated.

@nnethercote

This comment was marked as outdated.

@bors
Copy link
Contributor

bors commented Dec 18, 2024

📌 Commit 8a85bdc has been approved by spastorino

It is now in the queue for this repository.

jieyouxu added a commit to jieyouxu/rust that referenced this pull request Dec 18, 2024
…, r=spastorino

Overhaul token cursors

Some nice cleanups here.

r? `@davidtwco`
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Dec 18, 2024
…, r=spastorino

Overhaul token cursors

Some nice cleanups here.

r? ``@davidtwco``
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Dec 18, 2024
…, r=spastorino

Overhaul token cursors

Some nice cleanups here.

r? ```@davidtwco```
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Dec 18, 2024
…, r=spastorino

Overhaul token cursors

Some nice cleanups here.

r? ````@davidtwco````
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2024
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2024
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
@bors bors merged commit 477f222 into rust-lang:master Dec 18, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2024
Rollup merge of rust-lang#134161 - nnethercote:overhaul-token-cursors, r=spastorino

Overhaul token cursors

Some nice cleanups here.

r? `````@davidtwco`````
@nnethercote nnethercote deleted the overhaul-token-cursors branch December 18, 2024 20:26
flip1995 pushed a commit to flip1995/rust that referenced this pull request Dec 26, 2024
…, r=spastorino

Overhaul token cursors

Some nice cleanups here.

r? `````@davidtwco`````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants