-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Move implementations of Query
methods from QueryState
to Query
.
#17822
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
Conversation
Add missing `iter_many_unique_inner` and `single_inner` methods.
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.
Very satisfying PR, it's nice to see it all come together
… `QueryState` to the file with `Query`.
We should run the query benches to make sure nothing weird is happening. |
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 like it!
That makes sense! I'll try to figure out how to do that, but I probably won't have time until Friday. |
# Conflicts: # crates/bevy_ecs/src/system/query.rs
…_unchecked_manual` for parallel iteration.
…s()` and make it a safety requirement.
I ran the benches, and found some slowdowns caused by extra calls to I changed the safety requirements of the |
Here are the results of running
|
Objective
Simplify the API surface by removing duplicated functionality between
Query
andQueryState
.Reduce the amount of
unsafe
code required inQueryState
.This is a follow-up to #15858.
Solution
Move implementations of
Query
methods fromQueryState
toQuery
. Instead of the original methods being onQueryState
, withQuery
methods calling them by passing the individual parameters, the original methods are now onQuery
, withQueryState
methods calling them by constructing aQuery
.This also adds two
_inner
methods that were missed in #15858:iter_many_unique_inner
andsingle_inner
.One goal here is to be able to deprecate and eventually remove many of the methods on
QueryState
, reducing the overall API surface. (I expected to do that in this PR, but this change was large enough on its own!) Now that theQueryState
methods each consist of a simple expression likeself.query(world).get_inner(entity)
, a future PR can deprecate some or all of them with simple migration instructions.The other goal is to reduce the amount of
unsafe
code. The current implementation of a read-only method likeQueryState::get
directly calls theunsafe fn get_unchecked_manual
and needs to repeat the proof that&World
has enough access. With this change,QueryState::get
is entirely safe code, with the proof that&World
has enough access done by thequery()
method and shared across all read-only operations.Future Work
The next step will be to mark the
QueryState
methods as#[deprecated]
and migrate callers to the methods onQuery
.