Conversation
crates/bevy_ecs/macros/src/lib.rs
Outdated
| // SAFETY: each item in set is read only | ||
| unsafe impl<'__w, #(#data: ReadOnlyQueryData,)*> ReadOnlyQueryData for DataSet<'__w, (#(#data,)*)> {} | ||
|
|
||
| // SAFETY: deferes to soundness of `#data: WorldQuery` impl |
There was a problem hiding this comment.
| // SAFETY: deferes to soundness of `#data: WorldQuery` impl | |
| // SAFETY: defers to soundness of `#data: WorldQuery` impl |
crates/bevy_ecs/macros/src/lib.rs
Outdated
| let mut current_access; | ||
| #( | ||
| // Updating empty [`FilteredAccess`] and then extending passed access. | ||
| // This is done to avoid conflicts with other members of the set. | ||
| current_access = FilteredAccess::default(); |
There was a problem hiding this comment.
The current_access is separate for each #data, right? That might be more clear if you use a separate variable for each one instead of sharing the same variable.
| let mut current_access; | |
| #( | |
| // Updating empty [`FilteredAccess`] and then extending passed access. | |
| // This is done to avoid conflicts with other members of the set. | |
| current_access = FilteredAccess::default(); | |
| #( | |
| // Updating empty [`FilteredAccess`] and then extending passed access. | |
| // This is done to avoid conflicts with other members of the set. | |
| let mut current_access = FilteredAccess::default(); |
|
It's definitely more niche than I believe it was sound when it was written, since it ensures only one subquery is alive at a time and declares all the access from each. It will need an update in light of #16843, though. It's now valid for a Also, this uses a proc macro, which was consistent with |
hymm
left a comment
There was a problem hiding this comment.
If we had real variadics, I would say just merge this. As it is though this adds a fair amount of codegen for a niche feature, so I'm a little hesitant. This is probably only really useful in generic contexts. Overall I do lean towards merging this, since the alternatives are a lot more awkward to write.
We could limit this to 4 items like ParamSet was originally until a user asks for more.
|
|
||
| #[test] | ||
| #[should_panic] | ||
| fn conflicting_query_with_data_set_system() { |
There was a problem hiding this comment.
Could you add a should_panic test with the Query<DataSet> as the first system parameter too. The conflict checking can be order dependent.
| let mut world = World::default(); | ||
| run_system(&mut world, sys); | ||
| } | ||
|
|
There was a problem hiding this comment.
Could you add a should_panic test with the conflict in the second item of the DataSet?
| type ReadOnly = Ref<'__w, T>; | ||
| } | ||
|
|
||
| /// A collection of potentially conflicting [`QueryData`]s allowed by disjoint access. |
There was a problem hiding this comment.
The docs should make it clear that the query will fetch entitieis that match the union of all the QueryData's in the DataSet.
|
I'm a little reluctant to merge this, given the level of code gen for a niche feature and the absolute headache that ParamSet has been. I'm open to being convinced however. |
Objective
Fixes #14518
Solution
Added
QueryDataimplementer similarly to howParamSetis implementedTesting
2 doc tests and 3 tests that are adapted forms of the same tests for
ParamSetShowcase
Adds
DataSetthat imlementsQueryDataand allows disjoint access to it's members, similarly to howParamSetworks.Mainly would be useful with in generic contexts where you need
QueryData, but can't guarantee it won't conflict with otherQueryData. Or with complex customQueryDataimplementers that conflict with each other.This will compile even if A and B conflict: