-
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
Zip's __iterator_get_unchecked doesn't preserve side-effects #82303
Comments
We could also update the documentation to clarify that next() might not always be called on empty iterators. For example a valid implementation would be checking Note that this isn't specific to Zip. Another adapter wrapping zip could introduce this kind of behavior. |
In the meantime I have introduced some additional specializations relying on
Indeed, I would be in favor of getting rid of it and rewording the documentation instead. |
Original discussion about side-effects: #33090 (comment) I don't find those to be particularly strong arguments, primarily concerns about consistency between default and specialized code. |
The documentation of
Which pretty clearly describes the behavior of Edit: I suppose that’s exactly what #83791 tries to address. |
…ntee, r=dtolnay Weaken guarantee around advancing underlying iterators in zip The current guarantee (introduced in rust-lang#52279) is too strong as it prevents adapters from exploiting knowledge about the iterator length and using counted loops for example because they would stop calling `next()` before it ever returned `None`. Additionally several nested zip iterators already fail to uphold this. This does not yet remove any of the specialization code that tries (and sometimes fails) to uphold the guarantee for `next()` because removing it would also affect `next_back()` in more surprising ways. The intent is to be able to remove for example this branch https://github.com/rust-lang/rust/blob/36bcf4069717b9dff90270d13b53a3b130329960/library/core/src/iter/adapters/zip.rs#L234-L243 or this test https://github.com/rust-lang/rust/blob/36bcf4069717b9dff90270d13b53a3b130329960/library/core/tests/iter/adapters/zip.rs#L177-L188 Solves rust-lang#82303 by declaring it a non-issue.
…ntee, r=dtolnay Weaken guarantee around advancing underlying iterators in zip The current guarantee (introduced in rust-lang#52279) is too strong as it prevents adapters from exploiting knowledge about the iterator length and using counted loops for example because they would stop calling `next()` before it ever returned `None`. Additionally several nested zip iterators already fail to uphold this. This does not yet remove any of the specialization code that tries (and sometimes fails) to uphold the guarantee for `next()` because removing it would also affect `next_back()` in more surprising ways. The intent is to be able to remove for example this branch https://github.com/rust-lang/rust/blob/36bcf4069717b9dff90270d13b53a3b130329960/library/core/src/iter/adapters/zip.rs#L234-L243 or this test https://github.com/rust-lang/rust/blob/36bcf4069717b9dff90270d13b53a3b130329960/library/core/tests/iter/adapters/zip.rs#L177-L188 Solves rust-lang#82303 by declaring it a non-issue.
I believe with #83791 merged this can be closed since it turns it into a non-promise |
Closing this as this isn't promised. |
I tried this code:
Playground link
I would expect the two iterators to behave the same, so either both asserts fail (actually the first should stop the program) or neither of them. Instead, the second iterator doesn't preserve side-effects. causing the second assert (and only that one) to fail.
I don't think there's a way to solve this without completly changing the
TrustedRandomAccess
trait to use some type level trickery to replacemay_have_side_effect
. I wonder if there's even a point to keep the simulated side effects in the specializedZipImpl::next
if it doesn't cover all cases.The text was updated successfully, but these errors were encountered: