-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Remove TreeAndSpacing
.
#99887
Remove TreeAndSpacing
.
#99887
Conversation
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
This comment has been minimized.
This comment has been minimized.
A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`.
1810421
to
332dffb
Compare
I think this is a step to the right direction. I wanted to make one more step though and add the jointness flag right to |
@bors r+ |
Thank you for the fast review!
I had thought about this, but I decided to see if moving it into The jointness wouldn't need to be on every token, just the punctuation tokens, right? Would it be every punctuation token? Ones like |
I don't expect this to affect performance, but just to be sure: @bors try @rust-timer queue |
🙅 Please do not |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
@bors r- |
@bors try |
⌛ Trying commit 332dffb with merge 765888ed01bd9f231a2c38d345efe4e65a2621d0... |
☀️ Try build successful - checks-actions |
Queued 765888ed01bd9f231a2c38d345efe4e65a2621d0 with parent 5dda74a, future comparison URL. |
Finished benchmarking commit (765888ed01bd9f231a2c38d345efe4e65a2621d0): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. 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 @bors rollup=never Footnotes |
There's a single regressing result and 25 improved results. The changes are all very small. This is fine. @rustbot label: +perf-regression-triaged |
@bors r=petrochenkov |
That's a detail of proc macro API, internally in the compiler I'd like to just preserve this information for all tokens. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (1202bba): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Footnotes |
Much like above: there are 2 regressing results and 21 improved results. The changes are all very small. This is fine. @rustbot label: +perf-regression-triaged |
…ochenkov Remove `TreeAndSpacing`. A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`. r? `@petrochenkov`
And into `AttrAnnotatedTokenTree::Token`. PR rust-lang#99887 did the same thing for `TokenStream`.
A
TokenStream
contains aLrc<Vec<(TokenTree, Spacing)>>
. But this isnot quite right.
Spacing
makes sense forTokenTree::Token
, but doesnot make sense for
TokenTree::Delimited
, because aTokenTree::Delimited
cannot be joined with anotherTokenTree
.This commit fixes this problem, by adding
Spacing
toTokenTree::Token
,changing
TokenStream
to contain aLrc<Vec<TokenTree>>
, and removing theTreeAndSpacing
typedef.The commit removes these two impls:
impl From<TokenTree> for TokenStream
impl From<TokenTree> for TreeAndSpacing
These were useful, but also resulted in code with many
.into()
callsthat was hard to read, particularly for anyone not highly familiar with
the relevant types. This commit makes some other changes to compensate:
TokenTree::token()
becomesTokenTree::token_{alone,joint}()
.TokenStream::token_{alone,joint}()
are added.TokenStream::delimited
is added.This results in things like this:
changing to this:
This makes the type of the result, and its spacing, clearer.
These changes also simplifies
Cursor
andCursorRef
, because they no longerneed to distinguish between
next
andnext_with_spacing
.r? @petrochenkov