-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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] - Add get_multiple and get_multiple_mut APIs for Query and QueryState #4298
[Merged by Bors] - Add get_multiple and get_multiple_mut APIs for Query and QueryState #4298
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully this doesnt result in a bunch of unreadable compiler errors 🤦♀️
Co-authored-by: Boxy <supbscripter@gmail.com>
0d3b765
to
3bc9432
Compare
6972e2b
to
1932ee7
Compare
I can just say that looks good and even better than the last one, thanks for continuing this. I did read through the pull once to know exactly what was in there, but don't have time for a proper review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Just one comment on world validation.
crates/bevy_ecs/src/query/state.rs
Outdated
last_change_tick: u32, | ||
change_tick: u32, | ||
) -> Result<[<Q::Fetch as Fetch<'w, 's>>::Item; N], QueryEntityError> { | ||
self.validate_world(world); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _unchecked_manual
variants don't validate World in any other cases. This saves us on a lot of redundant work, as functions like Query::get()
might get called hundreds of thousands of times, even in a single system. Instead, we (currently) put the burden on the scheduler to do this.
Sadly I didn't include this in the Safety docs in QueryState (or in System::run_unsafe
) and theres a gap here because the "safe" System::run
doesn't validate world.
Obviously thats not good. But I'd prefer to solve the problem holistically / leave the current pattern in-tact. I think validating world at the System::run_unsafe
level (and updating the _unchecked_manual
safety docs) has my preference here, given that we are embracing the "just run a system" pattern.
Barring any conflicting thoughts on this (this feels like it will be a divisive topic), can you move validate_world
"up a level" and out of the _unchecked_manual
variants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the other _manual
stuff validates world so I think it would be weird for this PR to go and update everything to work differently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
manual
validates. manual_unchecked
does not. I'm only talking about manual_unchecked here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops: unchecked_manual
, not manual_unchecked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"manual" means you're on the hook to update archetypes (but by default should be assumed to be "safe"). "unchecked" is "fast / unvalidated / unsafe baseline impl"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm definitely not asking for changes to unrelated code here. Just for consistency (despite the fact that the pattern being used has some holes, as previously stated).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm okay yeah I guess we are missing a lot of methods here so its hard to see a pattern 🤣 _unchecked
not validating world seems fine I guess 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Barring any conflicting thoughts on this (this feels like it will be a divisive topic), can you move validate_world "up a level" and out of the _unchecked_manual variants?
Yep, can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(leaving unresolved so the link in #4363 works nicely)
c142f40
to
f7aa741
Compare
You didn't fix that. |
Co-authored-by: Boxy <supbscripter@gmail.com>
There we go... Thanks @BoxyUwU. |
bors r+ |
…4298) # Objective - The inability to have multiple active mutable borrows into a query is a common source of borrow-checker pain for users. - This is a pointless restriction if and only if we can guarantee that the entities they are accessing are unique. - This could already by bypassed with get_unchecked, but that is an extremely unsafe API. - Closes #2042. ## Solution - Add `get_multiple`, `get_multiple_mut` and their unchecked equivalents (`multiple` and `multiple_mut`) to `Query` and `QueryState`. - Improve the `QueryEntityError` type to provide more useful error information. ## Changelog - Added `get_multiple`, `get_multiple_mut` and their unchecked equivalents (`multiple` and `multiple_mut`) to Query and QueryState. ## Migration Guide - The `QueryEntityError` enum now has a `AliasedMutability variant, and returns the offending entity. ## Context This is a fresh attempt at #3333; rebasing was behaving very badly and it was important to rebase on top of the recent query soundness fixes. Many thanks to all the reviewers in that thread, especially @BoxyUwU for the help with lifetimes. ## To-do - [x] Add compile fail tests - [x] Successfully deduplicate code - [x] Decide what to do about failing doc tests - [x] Get some reviews for lifetime soundness
…evyengine#4298) # Objective - The inability to have multiple active mutable borrows into a query is a common source of borrow-checker pain for users. - This is a pointless restriction if and only if we can guarantee that the entities they are accessing are unique. - This could already by bypassed with get_unchecked, but that is an extremely unsafe API. - Closes bevyengine#2042. ## Solution - Add `get_multiple`, `get_multiple_mut` and their unchecked equivalents (`multiple` and `multiple_mut`) to `Query` and `QueryState`. - Improve the `QueryEntityError` type to provide more useful error information. ## Changelog - Added `get_multiple`, `get_multiple_mut` and their unchecked equivalents (`multiple` and `multiple_mut`) to Query and QueryState. ## Migration Guide - The `QueryEntityError` enum now has a `AliasedMutability variant, and returns the offending entity. ## Context This is a fresh attempt at bevyengine#3333; rebasing was behaving very badly and it was important to rebase on top of the recent query soundness fixes. Many thanks to all the reviewers in that thread, especially @BoxyUwU for the help with lifetimes. ## To-do - [x] Add compile fail tests - [x] Successfully deduplicate code - [x] Decide what to do about failing doc tests - [x] Get some reviews for lifetime soundness
…evyengine#4298) # Objective - The inability to have multiple active mutable borrows into a query is a common source of borrow-checker pain for users. - This is a pointless restriction if and only if we can guarantee that the entities they are accessing are unique. - This could already by bypassed with get_unchecked, but that is an extremely unsafe API. - Closes bevyengine#2042. ## Solution - Add `get_multiple`, `get_multiple_mut` and their unchecked equivalents (`multiple` and `multiple_mut`) to `Query` and `QueryState`. - Improve the `QueryEntityError` type to provide more useful error information. ## Changelog - Added `get_multiple`, `get_multiple_mut` and their unchecked equivalents (`multiple` and `multiple_mut`) to Query and QueryState. ## Migration Guide - The `QueryEntityError` enum now has a `AliasedMutability variant, and returns the offending entity. ## Context This is a fresh attempt at bevyengine#3333; rebasing was behaving very badly and it was important to rebase on top of the recent query soundness fixes. Many thanks to all the reviewers in that thread, especially @BoxyUwU for the help with lifetimes. ## To-do - [x] Add compile fail tests - [x] Successfully deduplicate code - [x] Decide what to do about failing doc tests - [x] Get some reviews for lifetime soundness
Objective
Solution
get_multiple
,get_multiple_mut
and their unchecked equivalents (multiple
andmultiple_mut
) toQuery
andQueryState
.QueryEntityError
type to provide more useful error information.Changelog
get_multiple
,get_multiple_mut
and their unchecked equivalents (multiple
andmultiple_mut
) to Query and QueryState.Migration Guide
QueryEntityError
enum now has a `AliasedMutability variant, and returns the offending entity.Context
This is a fresh attempt at #3333; rebasing was behaving very badly and it was important to rebase on top of the recent query soundness fixes. Many thanks to all the reviewers in that thread, especially @BoxyUwU for the help with lifetimes.
To-do