-
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
Specialize iter::ArrayChunks::fold
for TrustedRandomAccess iterators
#103446
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rustbot
added
the
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
label
Oct 23, 2022
This comment was marked as resolved.
This comment was marked as resolved.
(rust-highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
label
Oct 23, 2022
This comment has been minimized.
This comment has been minimized.
the8472
force-pushed
the
tra-array-chunks
branch
2 times, most recently
from
October 23, 2022 19:56
f7a4b02
to
be14127
Compare
Seems broadly okay but I would like to hear your thoughts on especially the second comment around the safety condition. |
Mark-Simulacrum
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
Nov 6, 2022
This also updates the existing iter::Copied::next_chunk benchmark so that the thing it benches doesn't get masked by the ArrayChunks specialization
This is fairly safe use of TRA since it consumes the iterator so no struct in an unsafe state will be left exposed to user code
The type is unsafe and now exposed to the whole crate. Document it properly and add an unsafe method so the caller can make it visible that something unsafe is happening.
the8472
force-pushed
the
tra-array-chunks
branch
from
November 7, 2022 23:13
be14127
to
3925fc0
Compare
@bors r=Mark-Simulacrum rollup |
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
Nov 7, 2022
Maybe don't rollup optimizations? |
This is unstable API that's not used in the compiler yet, it should be fine. |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Nov 8, 2022
Rollup of 7 pull requests Successful merges: - rust-lang#103446 (Specialize `iter::ArrayChunks::fold` for TrustedRandomAccess iterators) - rust-lang#103651 (Fix `rustc_parse_format` spans following escaped utf-8 multibyte chars) - rust-lang#103865 (Move `fallback_has_occurred` state tracking to `FnCtxt`) - rust-lang#103955 (Update linker-plugin-lto.md to contain up to Rust 1.65) - rust-lang#103987 (Remove `in_tail_expr` from FnCtxt) - rust-lang#104067 (fix debuginfo for windows_gnullvm_base.rs) - rust-lang#104094 (fully move `on_unimplemented` to `error_reporting`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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-libs
Relevant to the library team, which will review and decide on the PR/issue.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The resulting assembly is similar to #103166 but the specialization kicks in under different (partially overlapping) conditions compared to that PR. They're complementary.
In principle a TRA-based specialization could be applied to all
ArrayChunks
methods, includingnext()
as we do forZip
but that would have all the same hazards as the Zip specialization. Only doing it forfold
is far less hazardous. The downside is that it only helps with internal, exhaustive iteration. I.e.for _ in
ortry_fold
will not benefit.Note that the regular,
try_fold
-based and the specializedfold()
impl have observably slightly different behavior. Namely the specialized variant does not fetch the remainder elements from the underlying iterator. We do have a few other places in the standard library where beyond-the-end-of-iteration side-effects are being elided under some circumstances but not others.Inspired by https://old.reddit.com/r/rust/comments/yaft60/zerocost_iterator_abstractionsnot_so_zerocost/