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

Some parser cleanups #127233

Merged
merged 12 commits into from
Jul 3, 2024
Merged

Some parser cleanups #127233

merged 12 commits into from
Jul 3, 2024

Conversation

nnethercote
Copy link
Contributor

Cleanups I made while looking closely at this code.

r? @petrochenkov

It can contain an owned value instead of a reference.
I.e. change the return type from `TokenStream` to `Vec<TokenTree>`.

Most of the callsites require a `TokenStream`, but the recursive call
used to create `target_tokens` requires a `Vec<TokenTree>`. It's easy
to convert a `Vec<TokenTree>` to a `TokenStream` (just call
`TokenStream::new`) but it's harder to convert a `TokenStream` to a
`Vec<TokenTree>` (either iterate/clone/collect, or use `Lrc::into_inner`
if appropriate).

So this commit changes the return value to simplify that `target_tokens`
call site.
`tts` is a better name than `streams` for a `Vec<TokenTree>`.
Currently it uses a mixture of functional style (`flat_map`) and
imperative style (`push`), which is a bit hard to read. This commit
converts it to fully imperative, which is more concise and avoids the
need for `smallvec`.
Both the indenting, and the missing `)`.
So that the `capturing` state is adjusted immediately before and after
the call to `f`.
To make things a little clearer, and to avoid some `mut` variables.
@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. labels Jul 2, 2024
The number of source code bytes can't exceed a `u32`'s range, so a token
position also can't. This reduces the size of `Parser` and
`LazyAttrTokenStreamImpl` by eight bytes each.
And update the comment. Clearly the return type of this function was
changed at some point in the past, but its name and comment weren't
updated to match.
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jul 2, 2024

📌 Commit 6f60156 has been approved by petrochenkov

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 2, 2024

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 2, 2024
@nnethercote
Copy link
Contributor Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Jul 2, 2024

📌 Commit edeebe6 has been approved by petrochenkov

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jul 2, 2024

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 2, 2024
…rochenkov

Some parser cleanups

Cleanups I made while looking closely at this code.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 3, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#126403 (Actually report normalization-based type errors correctly for alias-relate obligations in new solver)
 - rust-lang#126803 (Change `asm-comments` to `verbose-asm`, always emit user comments)
 - rust-lang#126917 (Disable rmake test `inaccessible-temp-dir` on riscv64)
 - rust-lang#127050 (Make mtime of reproducible tarballs dependent on git commit)
 - rust-lang#127145 (Add `as_lang_item` to `LanguageItems`, new trait solver)
 - rust-lang#127184 (More refactorings to rustc_interface)
 - rust-lang#127202 (Remove global error count checks from typeck)
 - rust-lang#127233 (Some parser cleanups)
 - rust-lang#127245 (Add a test for `generic_const_exprs`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 3, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#126403 (Actually report normalization-based type errors correctly for alias-relate obligations in new solver)
 - rust-lang#126803 (Change `asm-comments` to `verbose-asm`, always emit user comments)
 - rust-lang#126917 (Disable rmake test `inaccessible-temp-dir` on riscv64)
 - rust-lang#127050 (Make mtime of reproducible tarballs dependent on git commit)
 - rust-lang#127145 (Add `as_lang_item` to `LanguageItems`, new trait solver)
 - rust-lang#127184 (More refactorings to rustc_interface)
 - rust-lang#127202 (Remove global error count checks from typeck)
 - rust-lang#127233 (Some parser cleanups)
 - rust-lang#127245 (Add a test for `generic_const_exprs`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 3, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#126803 (Change `asm-comments` to `verbose-asm`, always emit user comments)
 - rust-lang#127050 (Make mtime of reproducible tarballs dependent on git commit)
 - rust-lang#127145 (Add `as_lang_item` to `LanguageItems`, new trait solver)
 - rust-lang#127202 (Remove global error count checks from typeck)
 - rust-lang#127233 (Some parser cleanups)
 - rust-lang#127248 (Add parse fail test using safe trait/impl trait)
 - rust-lang#127264 (Small `run-make-support` API improvements)
 - rust-lang#127270 (bootstrap: pass correct struct size to winapi)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7fdb2f5 into rust-lang:master Jul 3, 2024
6 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jul 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 3, 2024
Rollup merge of rust-lang#127233 - nnethercote:parser-cleanups, r=petrochenkov

Some parser cleanups

Cleanups I made while looking closely at this code.

r? ``@petrochenkov``
@nnethercote nnethercote deleted the parser-cleanups branch July 3, 2024 22:41
nnethercote added a commit to nnethercote/rust that referenced this pull request Jul 4, 2024
These should have been removed in rust-lang#127233 when the positions were
changed from `usize` to `u32`.
nnethercote added a commit to nnethercote/rust that referenced this pull request Jul 4, 2024
These should have been removed in rust-lang#127233 when the positions were
changed from `usize` to `u32`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants