RFC: absolutely minimal way to close #18823 #25169
Closed
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.
I think that this would be far less disruptive than the proposal in #18823, not to mention that it's getting too late to make such a huge change to the iteration protocol at this point. This allows iterators that don't know they're done until they've tried to return
nothing
from thenext
method instead of avalue, state
tuple and return early that way. There's no impact on iterators that don't need to do that and there's no impact on code that uses the iteration protocol to process generic iterators as long as they don't need to work with "unforseeable iterators". So any code that works for arrays, strings, etc. needs no changing. Generic code that needs to work with these kinds of iterators can be fixed gradually, as we encounter it failing in the wild. What does need to be done in addition to this minimal changes is to make all the iterators in Base that should use this functionality actually use it.This approach does have a few issues, but which I believe it shares with the proposal in #18823:
The generic
isempty
definition seems wrong now since it checksdone(itr, state)
which for this kind of iterator will returnfalse
, yet the following call tonext
can returnnothing
leaving one with no values, despiteisempty
being false. Perhaps this is ok if we document that for such iterators theisempty
predicate can be unreliable: the iterator may not know that it's empty, yet not return any valules.There are probably other generic uses of
done
like the definition ofisempty
that would have similar problems.@JeffBezanson has expressed some concerns about the expansion of code involved in the new lowering. It doesn't emit that much extra code, but for loops are very common so it could still be a problem.