Add Step::forward/backward_overflowing to enable RangeInclusive loop optimizations#155114
Open
pitaj wants to merge 2 commits intorust-lang:mainfrom
Open
Add Step::forward/backward_overflowing to enable RangeInclusive loop optimizations#155114pitaj wants to merge 2 commits intorust-lang:mainfrom
Step::forward/backward_overflowing to enable RangeInclusive loop optimizations#155114pitaj wants to merge 2 commits intorust-lang:mainfrom
Conversation
but RangeInclusive loops do not
This comment has been minimized.
This comment has been minimized.
f26532b to
d0c1f8d
Compare
This comment has been minimized.
This comment has been minimized.
and optimize the RangeInclusive iterator implementation with them This changes the `exhausted` field to represent an overflow flag for the bounds, essentially acting as an extra bit for `Idx`. This was found to enable optimizations previously only applicable to the exclusive-ended Range type.
d0c1f8d to
39e74a3
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ACP: rust-lang/libs-team#767
This adds new required methods to the Step trait:
It was found that using these to implement RangeInclusive's Iterator impl enabled optimizations previously only applicable to the exclusive-ended
Range.This required changing how "exhaustion" works for
RangeInclusive. I've nominated this for libs-api discussion because of one insta-stable change:PartialEqimpl now always returnsfalseif eitherRangeInclusiveis exhaustedI changed this because the new implementations now only set
exhaustedwhen overflow occurs, andstartis now advanced pastendotherwise. I doubt anyone depends on the prior behavior, but it's probably worth a crater run.The exhaustion changes also affect
Debugbut my understanding is that debug formatting is never guaranteed stable.Note: I did not change the
nthimpls to use the new functions yet. I want buyoff on these changes first. If the changes to legacyops::RangeInclusiveare rejected, I will change this PR to target the newrange::RangeInclusiveinstead.r? libs