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] - Update ExactSizeIterator impl to support archetypal filters (With, Without) #5124

Closed
wants to merge 6 commits into from

Conversation

harudagondi
Copy link
Member

@harudagondi harudagondi commented Jun 28, 2022

Objective

Solution

  • Done according to Implement ExactSizeIterator for queries that are only filtered by With and Without #3142
  • Created new marker trait ArchetypeFilter
  • Implement said trait to:
    • With<T>
    • Without<T>
    • tuples containing only types that implement ArchetypeFilter, from 0 to 15 elements
    • Or<T> where T is a tuple as described previously
  • Changed ExactSizeIterator impl to include a new generic that must implement WorldQuery and ArchetypeFilter
  • Added new tests

Changelog

Added

  • Querys with archetypal filters can now use .iter().len() to get the exact size of the iterator.

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.

Great and simple change! Though I'd recommend having more tests. Especially to make sure the ExactSizeIterator invariant is upheld:

When implementing an ExactSizeIterator, you must also implement Iterator. When doing so, the implementation of Iterator::size_hint must return the exact size of the iterator.

This is why I'd like to see a bit more tests:

  • in bevy_ecs_compile_test, make sure that stuff like Query<&Foo, Changed<Foo>> do not implement ExactSizeIterator (by calling .len() on stuff and asserting a compile error)
  • Make sure that all following methods are equal:
    • query.iter().size_hint().0
    • query.iter().size_hint().1.unwrap()
    • query.iter().len()
    • query.iter().count()
  • Add tests for more complex query filters.
  • Maybe modify as well the ExactSizeIterator impl to just use self.size_hint as well.

crates/bevy_ecs/src/query/filter.rs Show resolved Hide resolved
crates/bevy_ecs/src/query/mod.rs Outdated Show resolved Hide resolved
crates/bevy_ecs/src/query/iter.rs Show resolved Hide resolved
crates/bevy_ecs/src/query/filter.rs Show resolved Hide resolved
@harudagondi
Copy link
Member Author

Sorry, I'm not sure I understand how bevy_ecs_compile_test work. Do I write a program that fails, and copy the output to a .stderr file?

@nicopap
Copy link
Contributor

nicopap commented Jun 28, 2022

Do I write a program that fails, and copy the output to a .stderr file?

Sounds about right. Looks like it is using trybuild for testing. Need to run cargo run -p ci -- compile to check if your test worked.

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.

Great! LGTM

crates/bevy_ecs/src/query/mod.rs Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times C-Usability A simple quality-of-life change that makes Bevy easier to use labels Jun 28, 2022
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Nice work. I'd prefer to refactor the tests a little bit, but that's not blocking.

@alice-i-cecile alice-i-cecile 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 Jun 28, 2022
Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

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

It's unfortunate that this is yet another example of const-generics run up against a more complete solution via specialization, but nothing we can do until that gets stablized.

@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Jun 29, 2022
…Without) (#5124)

# Objective

- Fixes #3142

## Solution

- Done according to #3142
- Created new marker trait `ArchetypeFilter`
- Implement said trait to:
  - `With<T>`
  - `Without<T>`
  - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements
  - `Or<T>` where T is a tuple as described previously
- Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter`
- Added new tests

---

## Changelog

### Added
- `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
@alice-i-cecile
Copy link
Member

@superdump IIRC this was useful in a couple places for rendering; just pinging you so this is on your radar.

@bors bors bot changed the title Update ExactSizeIterator impl to support archetypal filters (With, Without) [Merged by Bors] - Update ExactSizeIterator impl to support archetypal filters (With, Without) Jun 29, 2022
@bors bors bot closed this Jun 29, 2022
james7132 pushed a commit to james7132/bevy that referenced this pull request Jul 2, 2022
…Without) (bevyengine#5124)

# Objective

- Fixes bevyengine#3142

## Solution

- Done according to bevyengine#3142
- Created new marker trait `ArchetypeFilter`
- Implement said trait to:
  - `With<T>`
  - `Without<T>`
  - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements
  - `Or<T>` where T is a tuple as described previously
- Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter`
- Added new tests

---

## Changelog

### Added
- `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
bors bot pushed a commit that referenced this pull request Jul 13, 2022
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`.

Also:
- Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`.
- Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator`

---

## Changelog

- Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
bors bot pushed a commit that referenced this pull request Jul 13, 2022
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`.

Also:
- Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`.
- Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator`

---

## Changelog

- Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
bors bot pushed a commit that referenced this pull request Jul 13, 2022
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`.

Also:
- Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`.
- Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator`

---

## Changelog

- Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
bors bot pushed a commit that referenced this pull request Jul 13, 2022
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`.

Also:
- Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`.
- Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator`

---

## Changelog

- Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
bors bot pushed a commit that referenced this pull request Jul 13, 2022
Following #5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`.

Also:
- Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`.
- Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator`

---

## Changelog

- Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
inodentry pushed a commit to IyesGames/bevy that referenced this pull request Aug 8, 2022
…Without) (bevyengine#5124)

# Objective

- Fixes bevyengine#3142

## Solution

- Done according to bevyengine#3142
- Created new marker trait `ArchetypeFilter`
- Implement said trait to:
  - `With<T>`
  - `Without<T>`
  - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements
  - `Or<T>` where T is a tuple as described previously
- Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter`
- Added new tests

---

## Changelog

### Added
- `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
inodentry pushed a commit to IyesGames/bevy that referenced this pull request Aug 8, 2022
…ine#5148)

Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`.

Also:
- Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`.
- Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator`

---

## Changelog

- Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
…Without) (bevyengine#5124)

# Objective

- Fixes bevyengine#3142

## Solution

- Done according to bevyengine#3142
- Created new marker trait `ArchetypeFilter`
- Implement said trait to:
  - `With<T>`
  - `Without<T>`
  - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements
  - `Or<T>` where T is a tuple as described previously
- Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter`
- Added new tests

---

## Changelog

### Added
- `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
james7132 pushed a commit to james7132/bevy that referenced this pull request Oct 28, 2022
…ine#5148)

Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`.

Also:
- Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`.
- Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator`

---

## Changelog

- Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…Without) (bevyengine#5124)

# Objective

- Fixes bevyengine#3142

## Solution

- Done according to bevyengine#3142
- Created new marker trait `ArchetypeFilter`
- Implement said trait to:
  - `With<T>`
  - `Without<T>`
  - tuples containing only types that implement `ArchetypeFilter`, from 0 to 15 elements
  - `Or<T>` where T is a tuple as described previously
- Changed `ExactSizeIterator` impl to include a new generic that must implement `WorldQuery` and `ArchetypeFilter`
- Added new tests

---

## Changelog

### Added
- `Query`s with archetypal filters can now use `.iter().len()` to get the exact size of the iterator.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…ine#5148)

Following bevyengine#5124 I decided to add the `ExactSizeIterator` impl for `QueryCombinationIter`.

Also:
- Clean up the tests for `size_hint` and `len` for both the normal `QueryIter` and `QueryCombinationIter`.
- Add tests to `QueryCombinationIter` when it shouldn't be `ExactSizeIterator`

---

## Changelog

- Added `ExactSizeIterator` implementation for `QueryCombinatonIter`
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-Performance A change motivated by improving speed, memory usage or compile times C-Usability A simple quality-of-life change that makes Bevy easier to use 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.

Implement ExactSizeIterator for queries that are only filtered by With and Without
4 participants