-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Simplify TokenStream
some more
#57486
Conversation
(Note that the first commit is from #57004, and will be removed before landing.) |
I added a new commit that changes |
src/libsyntax/tokenstream.rs
Outdated
None => true, | ||
Some(ref stream) => { | ||
// An empty stream should be represented as `None`, not as an empty `Vec`. | ||
debug_assert!(stream.len() > 0); |
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.
Hmm, do we have operations that remove trees from the stream's vector?
It's correct that we should not create new empty streams as Some
, but perhaps previously non-empty streams can turn into empty?
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.
Not that I know of. But if it does happen, the old code for this function would silently do the wrong thing, while the new code will assert. I could change it to check for a length of zero in the Some
case.
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, could you use the correct Some(ref stream) => stream.is_empty()
, that would be more future-proof.
@bors r+ |
📌 Commit ea2784b8701bfd63dada95ea12bd854479b88e45 has been approved by |
@bors r- |
Also, it would be nice to make a perf run once #57004 is merged and this PR contains only the following diff. |
☔ The latest upstream changes (presumably #57577) made this pull request unmergeable. Please resolve the merge conflicts. |
`TokenStream::Stream` can represent a token stream containing any number of token trees. `TokenStream::Tree` is the special case representing a single token tree. The latter doesn't occur all that often dynamically, so this commit removes it, which simplifies the code quite a bit. This change has mixed performance effects. - The size of `TokenStream` drops from 32 bytes to 8 bytes, and there is one less case for all the match statements. - The conversion of a `TokenTree` to a `TokenStream` now requires two allocations, for the creation of a single element Lrc<Vec<_>>. (But a subsequent commit in this PR will reduce the main source of such conversions.)
`TokenStream` is now almost identical to `ThinTokenStream`. This commit removes the latter, replacing it with the former.
This avoids some allocations.
Because that's the more typical way of representing an all-or-nothing type.
ea2784b
to
7285724
Compare
I updated |
@bors try |
⌛ Trying commit 7285724 with merge ad694da89a85d9e7fa5f5eee94b1159f186c2778... |
Travis says the build completed successfully, but this wasn't reported to this thread for some reason. @rust-timer build ad694da89a85d9e7fa5f5eee94b1159f186c2778 |
Insufficient permissions to issue commands to rust-timer. |
@bors r- |
(The "comparison URL" didn't work for me previously and showed "missing commit" or something like that, but now it seems ok.) @bors r+ |
📌 Commit 7285724 has been approved by |
…re, r=petrochenkov Simplify `TokenStream` some more These commits simplify `TokenStream`, remove `ThinTokenStream`, and avoid some clones. The end result is simpler code and a slight perf win on some benchmarks. r? @petrochenkov
Failed in rollup #57624 (comment) due to toolstate change. @bors r- |
Marking as blocked, we'll be able to merge this in few days when 1.32 is released and the pre-release toolstate restriction is lifted. |
What is toolstate? |
@nnethercote |
Rust 1.32 has been released. @bors r=petrochenkov |
📌 Commit 7285724 has been approved by |
…re, r=petrochenkov Simplify `TokenStream` some more These commits simplify `TokenStream`, remove `ThinTokenStream`, and avoid some clones. The end result is simpler code and a slight perf win on some benchmarks. r? @petrochenkov
Rollup of 7 pull requests Successful merges: - #57486 (Simplify `TokenStream` some more) - #57502 (make trait-aliases work across crates) - #57598 (Add missing unpretty option help message) - #57649 (privacy: Account for associated existential types) - #57659 (Fix release manifest generation) - #57699 (add applicability to remaining suggestions) - #57719 (Tweak `expand_node`) Failed merges: r? @ghost
These commits simplify
TokenStream
, removeThinTokenStream
, and avoid some clones. The end result is simpler code and a slight perf win on some benchmarks.r? @petrochenkov