-
-
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
Let query items borrow from query state to avoid needing to clone #15396
Open
chescock
wants to merge
27
commits into
bevyengine:main
Choose a base branch
from
chescock:state-in-queryitem
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e99a0c1
Don't obtain two NameOrEntity items at once from QueryState::get().
chescock f295624
Introduce a ReleaseStateQueryData trait that will release borrows on …
chescock 648eb31
Add a 'state lifetime to query items and fetches.
chescock b870249
Merge remote-tracking branch 'remotes/origin/main' into state-in-quer…
chescock f6f4259
Fix merge conflicts with traversal changes.
chescock be7a1de
Merge remote-tracking branch 'remotes/origin/main' into state-in-quer…
chescock 0872293
Link to update_archetypes() and corresponding _manual() methods where…
chescock 70ced02
Merge remote-tracking branch 'remotes/origin/main' into state-in-quer…
chescock d1fbada
Fix merge conflicts with QuerySingle.
chescock 22eee9e
Merge remote-tracking branch 'remotes/origin/main' into state-in-quer…
chescock 174af45
Fix new uses of Item<'w>.
chescock 18520ef
Merge commit '6be11a8a42c2c73646cc994392bbd628b6de523b' into state-in…
chescock a080cb0
Fix build.
chescock ac313fd
Update AssetChanged.
chescock 9a74906
impl ReleaseStateQueryData for Traversal types.
chescock 6188a86
Add `expect` and `reason` for `allow(clippy::unused_unit)` in tuple i…
chescock 9871970
Merge commit '03af547c2898cb905b3917725b13081e48654b15' into state-in…
chescock 371ca14
Merge remote-tracking branch 'remotes/origin/main' into state-in-quer…
chescock 5dce18f
Restore changes lost by bad merging.
chescock d63f936
impl ReleaseStateQueryData for Option, MainEntity, and RenderEntity.
chescock 7ad98aa
Implement ReleaseStateQueryData for derived QueryData.
chescock e89a909
Use `collect()` in `QueryIter::sort()`.
chescock df2fcce
Merge remote-tracking branch 'remotes/origin/main' into state-in-quer…
chescock f7c3b27
Update new uses of `QueryItem` to include `'s` lifetime.
chescock 4e60256
Document that most QueryData types impl ReleaseStateQueryData.
chescock 42d5aa3
Merge remote-tracking branch 'remotes/origin/main' into state-in-quer…
chescock a748abe
Add `'s` lifetime to new uses of QueryItem.
chescock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 needing to be moved is suspicious. Can you not call get multiple times on an immutable borrow of the world anymore?
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.
Not in this case, but I promise it's not as bad as it looks!
QueryState::get()
takes&mut self
so that it can callupdate_archetypes()
. AndNameOrEntity
uses#[derive(QueryData)]
, which now generates an item struct that includes the's
lifetime. So the item is treated as having a mutable borrow of theQueryState
.This doesn't affect
Query::get()
, which always takes&self
.And this doesn't affect concrete types where
QueryData::Item
doesn't include's
. That is, it only affects generic parameters,#[derive(QueryData)]
types, and (in the future)FilteredEntityRef|Mut
. If we uselet mut query = world.query::<(Option<&Name>, Entity)>();
here, it will compile.And there is a workaround in this case, which is to call
query.update_archetypes()
manually and then usequery.get_manual()
, which takes&self
and so will allow overlapping borrows.But, yeah, it is a breaking change 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.
After digesting this for a bit, maybe it isn't such a bad change.
get
takes an&mut self
so hopefully it won't be that surprising for new users if you can't get multiple items out of it. And the workaround is more performant, so leading users to that is probably better.But we should document the workaround on
QueryState::get
and in the migration guide.I haven't done a full review yet, but hopefully will get to that soon.
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.
Does this not also affect query iteration? As in, for the affected types, any item would have to be dropped before another can be retrieved?
(Like what happens in
QueryManyIter::fetch_next()
, where item lifetimes are shrunk like this intentionally)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.
No, it doesn't.
Query
has a&'s QueryState
, so we can copy that reference and hand it out with the full's
lifetime. This change only affects methods that take&mut QueryState
.(The issue with things like
QueryManyIter::fetch_next()
andQuery::iter_mut()
are that theUnsafeWorldCell<'w>
is acting like a&'w mut
, so we can't copy it and instead have to reborrow it with a shorter'w
lifetime.)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.
Okay, so this does not present an issue within individual iterators.
However, this will be a breaking change to more methods of
QueryState
than what you've currently listed:get
get_single
(no checked manual version)get_many
(no manual version)single
(no manual version)iter
iter_many
iter_combinations
(no manual version)par_iter
(no manual version)&'a QueryState
while the query items returned by one of the above is live.The lack of manual versions can be considered API holes for some of the above, however not all of them (f.e.
single
)Do I understand correctly?
If so, I think the ability to mix these methods of
QueryState
contains important use cases, and I would see those as more valuable than this change in its current form :/