Skip to content

Commit cfc634d

Browse files
committed
Update comments
1 parent 831e1c7 commit cfc634d

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

crates/bevy_ecs/src/query/access.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ impl<T: SparseSetIndex> Default for AccessFilters<T> {
403403

404404
impl<T: SparseSetIndex> AccessFilters<T> {
405405
fn is_ruled_out_by(&self, other: &Self) -> bool {
406+
// Although not technically complete, we don't consider the case when `AccessFilters`'s
407+
// `without` bitset contradicts its own `with` bitset (e.g. `(With<A>, Without<A>)`).
408+
// Such query would be considered compatible with any other query, but as it's almost
409+
// always an error, we ignore this case instead of treating such query as compatible
410+
// with others.
406411
!self.with.is_disjoint(&other.without) || !self.without.is_disjoint(&other.with)
407412
}
408413
}

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,34 +1275,21 @@ macro_rules! impl_anytuple_fetch {
12751275
fn update_component_access(state: &Self::State, _access: &mut FilteredAccess<ComponentId>) {
12761276
let ($($name,)*) = state;
12771277

1278-
// We do not unconditionally add `$name`'s `with`/`without` accesses to `_access`
1279-
// as this would be unsound. For example the following two queries should conflict:
1280-
// - Query<(AnyOf<(&A, ())>, &mut B)>
1281-
// - Query<&mut B, Without<A>>
1282-
//
1283-
// If we were to unconditionally add `$name`'s `with`/`without` accesses then `AnyOf<(&A, ())>`
1284-
// would have a `With<A>` access which is incorrect as this `WorldQuery` will match entities that
1285-
// do not have the `A` component. This is the same logic as the `Or<...>: WorldQuery` impl.
1286-
//
1287-
// The correct thing to do here is to only add a `with`/`without` access to `_access` if all
1288-
// `$name` params have that `with`/`without` access. More jargony put- we add the intersection
1289-
// of all `with`/`without` accesses of the `$name` params to `_access`.
1290-
let mut _intersected_access = _access.clone();
1278+
let mut _new_access = _access.clone();
12911279
let mut _not_first = false;
12921280
$(
12931281
if _not_first {
12941282
let mut intermediate = _access.clone();
12951283
$name::update_component_access($name, &mut intermediate);
1296-
_intersected_access.append_or(&intermediate);
1297-
_intersected_access.extend_access(&intermediate);
1284+
_new_access.append_or(&intermediate);
1285+
_new_access.extend_access(&intermediate);
12981286
} else {
1299-
1300-
$name::update_component_access($name, &mut _intersected_access);
1287+
$name::update_component_access($name, &mut _new_access);
13011288
_not_first = true;
13021289
}
13031290
)*
13041291

1305-
*_access = _intersected_access;
1292+
*_access = _new_access;
13061293
}
13071294

13081295
fn update_archetype_component_access(state: &Self::State, _archetype: &Archetype, _access: &mut Access<ArchetypeComponentId>) {

crates/bevy_ecs/src/query/filter.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -336,33 +336,21 @@ macro_rules! impl_query_filter_tuple {
336336
fn update_component_access(state: &Self::State, access: &mut FilteredAccess<ComponentId>) {
337337
let ($($filter,)*) = state;
338338

339-
// We do not unconditionally add `$filter`'s `with`/`without` accesses to `access`
340-
// as this would be unsound. For example the following two queries should conflict:
341-
// - Query<&mut B, Or<(With<A>, ())>>
342-
// - Query<&mut B, Without<A>>
343-
//
344-
// If we were to unconditionally add `$name`'s `with`/`without` accesses then `Or<(With<A>, ())>`
345-
// would have a `With<A>` access which is incorrect as this `WorldQuery` will match entities that
346-
// do not have the `A` component. This is the same logic as the `AnyOf<...>: WorldQuery` impl.
347-
//
348-
// The correct thing to do here is to only add a `with`/`without` access to `_access` if all
349-
// `$filter` params have that `with`/`without` access. More jargony put- we add the intersection
350-
// of all `with`/`without` accesses of the `$filter` params to `access`.
351-
let mut _intersected_access = access.clone();
339+
let mut _new_access = access.clone();
352340
let mut _not_first = false;
353341
$(
354342
if _not_first {
355343
let mut intermediate = access.clone();
356344
$filter::update_component_access($filter, &mut intermediate);
357-
_intersected_access.append_or(&intermediate);
358-
_intersected_access.extend_access(&intermediate);
345+
_new_access.append_or(&intermediate);
346+
_new_access.extend_access(&intermediate);
359347
} else {
360-
$filter::update_component_access($filter, &mut _intersected_access);
348+
$filter::update_component_access($filter, &mut _new_access);
361349
_not_first = true;
362350
}
363351
)*
364352

365-
*access = _intersected_access;
353+
*access = _new_access;
366354
}
367355

368356
fn update_archetype_component_access(state: &Self::State, archetype: &Archetype, access: &mut Access<ArchetypeComponentId>) {

0 commit comments

Comments
 (0)