Skip to content
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

[Merged by Bors] - Remove ExactSizeIterator from QueryCombinationIter #5895

Closed
wants to merge 2 commits into from
Closed

[Merged by Bors] - Remove ExactSizeIterator from QueryCombinationIter #5895

wants to merge 2 commits into from

Conversation

ottah
Copy link
Contributor

@ottah ottah commented Sep 6, 2022

Objective

Solution

  • Only the implementation of ExactSizeIterator has been removed. Instead of using query_combination.len(), you can use query_combination.size_hint().0 to get the same value as before.

Migration Guide

  • Switch to using other methods of getting the length.

Comment on lines -116 to -121
for query: {query_type}
expected: {expected_size}
len(): {len}
size_hint().0: {size_hint_0}
size_hint().1: {size_hint_1:?}
count(): {count}"#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test doesn't only check for len being consistent, but also size_hint being equivalent to count. Removing the ExactSize impl doesn't imply the size_hint cannot be accurate.

Note that this test both checks both the QueryIter and QueryCombinationIter counts. I suggest extracting the assert_combination, assert_all_sizes_equal, assert_all_sizes_iterator_equal functions, split this test in two, and not test len for QueryCombinationIter.

Also if you are running tests, I recommend you use cargo test --package bevy_ecs query_filtered_exactsizeiterator_len (or whatever new name you come up with) this will save you time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've implemented what you suggested by splitting to 2 tests. Is query_filtered_exactsizeiterator_len correct?

@djeedai djeedai added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Regression Functionality that used to work but no longer does. Add a test for this! C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide and removed C-Regression Functionality that used to work but no longer does. Add a test for this! labels Sep 6, 2022
@nicopap
Copy link
Contributor

nicopap commented Sep 6, 2022

I'd suggest you edit the PR comment to improve the migration guide. Ideally it contains actionable instructions. Here is an example:

  • Only the implementation of ExactSizeIterator is removed, instead of using query_combination.len(), you can use query_combination.size_hint().0 to get the same value as before

@ottah ottah changed the title Remove ExactSizeIterator from QueryCominationIter Remove ExactSizeIterator from QueryCombinationIter Sep 6, 2022
Copy link
Contributor

@nicopap nicopap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM

Comment on lines 73 to 79
r#"query declared sizes:
for query: {query_type}
expected: {expected_size}
len: {len}
size_hint().0: {size_hint_0}
size_hint().1: {size_hint_1:?}
count(): {count}"#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r#"query declared sizes:
for query: {query_type}
expected: {expected_size}
len: {len}
size_hint().0: {size_hint_0}
size_hint().1: {size_hint_1:?}
count(): {count}"#
"query declared sizes: \
for query: {query_type} \
expected: {expected_size} \
len: {len} \
size_hint().0: {size_hint_0} \
size_hint().1: {size_hint_1:?} \
count(): {count}"

Nit, non blocking, but formatting can be improved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed both.

Comment on lines 210 to 215
r#"query declared sizes:
for query: {query_type}
for query: {query_type}
expected: {expected_size}
len(): {len}
size_hint().0: {size_hint_0}
size_hint().1: {size_hint_1:?}
count(): {count}"#
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: same as previous

                "query declared sizes: \
                for query:     {query_type} \
                expected:      {expected_size} \
                size_hint().0: {size_hint_0} \
                size_hint().1: {size_hint_1:?} \
                count():       {count}"

@ottah
Copy link
Contributor Author

ottah commented Oct 11, 2022

@nicopap Hey I updated the PR due to fix conflicts from main.

@james7132 james7132 added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 20, 2022
@alice-i-cecile
Copy link
Member

Oh no, more merge conflicts. I'll merge it ASAP once those are resolved.

QueryCombinationIter can have sizes greater than usize::MAX.

- Remove implementation of ExactSizeIterator
- Remove UI compile fail tests for ExactSizeIterator
- Align println! strings

Fixes #5846
WorldQuery -> ReadOnlyWorldQuery
world.spawn().insert_bundle(...) -> world.spawn(...)
@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Oct 24, 2022
# Objective

- `QueryCombinationIter` can have sizes greater than `usize::MAX`.
- Fixes #5846 

## Solution

- Only the implementation of `ExactSizeIterator` has been removed. Instead of using `query_combination.len()`, you can use `query_combination.size_hint().0` to get the same value as before.

---

## Migration Guide

- Switch to using other methods of getting the length.
@bors bors bot changed the title Remove ExactSizeIterator from QueryCombinationIter [Merged by Bors] - Remove ExactSizeIterator from QueryCombinationIter Oct 24, 2022
@bors bors bot closed this Oct 24, 2022
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
# Objective

- `QueryCombinationIter` can have sizes greater than `usize::MAX`.
- Fixes bevyengine#5846 

## Solution

- Only the implementation of `ExactSizeIterator` has been removed. Instead of using `query_combination.len()`, you can use `query_combination.size_hint().0` to get the same value as before.

---

## Migration Guide

- Switch to using other methods of getting the length.
Pietrek14 pushed a commit to Pietrek14/bevy that referenced this pull request Dec 17, 2022
# Objective

- `QueryCombinationIter` can have sizes greater than `usize::MAX`.
- Fixes bevyengine#5846 

## Solution

- Only the implementation of `ExactSizeIterator` has been removed. Instead of using `query_combination.len()`, you can use `query_combination.size_hint().0` to get the same value as before.

---

## Migration Guide

- Switch to using other methods of getting the length.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- `QueryCombinationIter` can have sizes greater than `usize::MAX`.
- Fixes bevyengine#5846 

## Solution

- Only the implementation of `ExactSizeIterator` has been removed. Instead of using `query_combination.len()`, you can use `query_combination.size_hint().0` to get the same value as before.

---

## Migration Guide

- Switch to using other methods of getting the length.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Bug An unexpected or incorrect behavior C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QueryCombinationIter should not implement ExactSizeIterator
5 participants