-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Deprecate Query::get_many
(etc) and make many
return a Result
#18120
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
@Carter0 can I have your review here too? Double check that I didn't screw anything up: this was an annoying change set due to all the duplicated APIs. |
entities: [Entity; N], | ||
) -> Result<[D::Item<'w>; N], QueryEntityError<'w>> { | ||
// Verify that all entities are unique | ||
for i in 0..N { |
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.
Could you do something like this if you wanted to? It might be easier to understand. Totally a nit though
if len(x) > len(set(x)):
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.
Probably, but I've opted to not change the logic in this PR. Despite the diff, this was just a pair of renames.
/// y: f32, | ||
/// } | ||
/// | ||
/// fn spring_forces(spring_query: Query<&Spring>, mut mass_query: Query<(&Position, &mut Force)>){ |
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.
Is it possible to move these docs to the result version of many_mut with some changes? Its seems like such a nice example!
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 these too, and I've double-checked: we already have nice doc tests for all of the retained result versions of these 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.
I like it overall! I'm down with returning results!
Though I actually don't really like the 'many' function name, which is a different thing than this PR is trying to deal with. I actually sorta like the name get_many more since it's an action, like we are "getting" components. But whatever haha
Oh also, doc comment stuff
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.
Yay!
@@ -952,12 +965,12 @@ impl<D: QueryData, F: QueryFilter> QueryState<D, F> { | |||
/// assert_eq!(match query_state.get_many(&mut world, [wrong_entity]).unwrap_err() {QueryEntityError::EntityDoesNotExist(error) => error.entity, _ => panic!()}, wrong_entity); | |||
/// ``` | |||
#[inline] | |||
pub fn get_many<'w, const N: usize>( | |||
pub fn many<'w, const N: usize>( |
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.
For what it's worth, I'm hoping to deprecate all the querying methods on QueryState
in favor of the methods on Query
. If we think that's likely to be approved, then we might want to deprecate these two and recommend query(world).many_inner(entities)
now so that users don't have to first change get_many()
to many()
and then change a second time to use query()
.
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 think it's unlikely that that change makes it into 0.16.
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.
Oh, I know! I wasn't even going to attempt it for 0.16 :).
But if we expect to do it in 0.17, then it might be nice to advise users of QueryState::get_many
to switch to query
directly instead of switching to QueryState::many
in 0.16 and then having to update that code again in the next release.
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 think that the set of users calling QueryState::get_many is small enough that I'm not concerned about that :)
self, | ||
entities: [Entity; N], | ||
) -> Result<[D::Item<'w>; N], QueryEntityError<'w>> { | ||
// Verify that all entities are unique |
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.
Should this delegate to many_inner
rather than duplicating the code?
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.
Probably, but I've opted to not change the logic in this PR. Despite the diff, this was just a pair of renames.
Man, the diff is terrible on Github. Git really does not like the renames. Strongly recommend checking out the code locally if you end up wanting to review further. |
I think it'd be nice to have doc aliases of the old names on the new ones! Even once the old ones disappear, users might still search for the equivalent of the (I personally prefer |
Hmm, thinking on it a bit more I am actually unsure about this change. It seems the reasoning for this is the same as for With However with Moreover, In addition, Further, unlike usual I'd personally say we remove the panicking But that's my few cents, the decision is still left up to you! |
I'd like to avoid more renames as part of this PR: we can always tweak that later. How would you feel about just deprecating the panicking |
That'd be completely fine! They always seemed somewhat weird to me. The same criticisms already apply to the current panicking |
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.
Same reasons I approved the sibling PR. Just noted there appears to be a leftover hunk from a merge conflict.
On reflection, I prefer the simple deprecation approach here. Closing. |
# Objective Alternative to and closes #18120. Sibling to #18082, see that PR for broader reasoning. Folks weren't sold on the name `many` (get_many is clearer, and this is rare), and that PR is much more complex. ## Solution - Simply deprecate `Query::many` and `Query::many_mut` - Clean up internal usages Mentions of this in the docs can wait until it's fully removed in the 0.17 cycle IMO: it's much easier to catch the problems when doing that. ## Testing CI! ## Migration Guide `Query::many` and `Query::many_mut` have been deprecated to reduce panics and API duplication. Use `Query::get_many` and `Query::get_many_mut` instead, and handle the `Result`. --------- Co-authored-by: Chris Russell <[email protected]>
Objective
This PR is the less contentious sibling to #18082. See that PR for detailed motivation!
This PR affects APIs that are called much less often: as a result, handling said
Result
is much less onerous.Solution
Query::many
methods return aResult
.Query::get_many
methods now that they've been renamed.Testing
No more compiler errors left! We'll see what CI finds.
Migration Guide
As part of a broad shift to reduce panics in Bevy,
Query::many
,Query::many_mut
and the same methods onQueryState
now return aResult
, which should be handled by the caller. Theget_many
andget_many_mut
methods that previously did this operation while returning aResult
have been deprecated, as they have effectively been renamed.