-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Query's ExactSizeIterator does not account for partial iteration #5149
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
Comments
Confirmed that our behavior is a bug: rust-lang/rust#98729 |
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Jul 5, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149 (although, if bevyengine#5148 is merged, bevyengine#5149 will re-open) - bevyengine#5149 - bevyengine#5148
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Jul 5, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149 (although, if bevyengine#5148 is merged, bevyengine#5149 will re-open) - bevyengine#5149 - bevyengine#5148
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Jul 5, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Jul 5, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Jul 13, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Jul 19, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Jul 22, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Sep 1, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
nicopap
added a commit
to nicopap/bevy
that referenced
this issue
Nov 1, 2022
Instead of returning the total count of elements in the `QueryIter` in `size_hint`, we return the count of remaining elements in it. This Fixes bevyengine#5149. This is also true of `QueryCombinationIter`. - bevyengine#5149 - bevyengine#5148
cart
pushed a commit
that referenced
this issue
Nov 30, 2022
…er (#5214) # Objective Fix #5149 ## Solution Instead of returning the **total count** of elements in the `QueryIter` in `size_hint`, we return the **count of remaining elements**. This Fixes #5149 even when #5148 gets merged. - #5149 - #5148 --- ## Changelog - Fix partially consumed `QueryIter` and `QueryCombinationIter` having invalid `size_hint` Co-authored-by: Nicola Papale <[email protected]>
ItsDoot
pushed a commit
to ItsDoot/bevy
that referenced
this issue
Feb 1, 2023
…er (bevyengine#5214) # Objective Fix bevyengine#5149 ## Solution Instead of returning the **total count** of elements in the `QueryIter` in `size_hint`, we return the **count of remaining elements**. This Fixes bevyengine#5149 even when bevyengine#5148 gets merged. - bevyengine#5149 - bevyengine#5148 --- ## Changelog - Fix partially consumed `QueryIter` and `QueryCombinationIter` having invalid `size_hint` Co-authored-by: Nicola Papale <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bevy version
0.8-dev
Problem
The [
ExactSizeIterator
] docs imply that the value returned bylen()
should change as the iterator is partially consumed.Our implementations do not do this.
We should carefully check to ensure that our
size_hint
methods are correct too.Possible solutions
Solution 1: track directly
This solution solves the problem at hand, but creates unavoidable overhead in cases where we don't care.
Solution 2: create a
ExactSizeQueryIter
typeOnly implement the
ExactSizeIterator
trait for this type.Avoids overhead, gains the correct behavior, but ergonomics are a bit meh.
If we do this, this must be documented carefully.
Solution 3: scrap the ExactSizeIterator trait, and implement
len()
directlyThis is a bit sad, because it reduces compatibility with other ecosystem crates that care about this trait.
Solution 4: YOLO
Keep the current behavior that does not comply with the spec. The docs do say you can't rely on this for soundness...
The text was updated successfully, but these errors were encountered: