Skip to content

Commit fca1ef2

Browse files
committed
Update comments
1 parent 25498a4 commit fca1ef2

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
@@ -1509,34 +1509,21 @@ macro_rules! impl_anytuple_fetch {
15091509
fn update_component_access(state: &Self::State, _access: &mut FilteredAccess<ComponentId>) {
15101510
let ($($name,)*) = state;
15111511

1512-
// We do not unconditionally add `$name`'s `with`/`without` accesses to `_access`
1513-
// as this would be unsound. For example the following two queries should conflict:
1514-
// - Query<(AnyOf<(&A, ())>, &mut B)>
1515-
// - Query<&mut B, Without<A>>
1516-
//
1517-
// If we were to unconditionally add `$name`'s `with`/`without` accesses then `AnyOf<(&A, ())>`
1518-
// would have a `With<A>` access which is incorrect as this `WorldQuery` will match entities that
1519-
// do not have the `A` component. This is the same logic as the `Or<...>: WorldQuery` impl.
1520-
//
1521-
// The correct thing to do here is to only add a `with`/`without` access to `_access` if all
1522-
// `$name` params have that `with`/`without` access. More jargony put- we add the intersection
1523-
// of all `with`/`without` accesses of the `$name` params to `_access`.
1524-
let mut _intersected_access = _access.clone();
1512+
let mut _new_access = access.clone();
15251513
let mut _not_first = false;
15261514
$(
15271515
if _not_first {
15281516
let mut intermediate = _access.clone();
15291517
$name::update_component_access($name, &mut intermediate);
1530-
_intersected_access.append_or(&intermediate);
1531-
_intersected_access.extend_access(&intermediate);
1518+
_new_access.append_or(&intermediate);
1519+
_new_access.extend_access(&intermediate);
15321520
} else {
1533-
1534-
$name::update_component_access($name, &mut _intersected_access);
1521+
$name::update_component_access($name, &mut _new_access);
15351522
_not_first = true;
15361523
}
15371524
)*
15381525

1539-
*_access = _intersected_access;
1526+
*access = _new_access;
15401527
}
15411528

15421529
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
@@ -348,33 +348,21 @@ macro_rules! impl_query_filter_tuple {
348348
fn update_component_access(state: &Self::State, access: &mut FilteredAccess<ComponentId>) {
349349
let ($($filter,)*) = state;
350350

351-
// We do not unconditionally add `$filter`'s `with`/`without` accesses to `access`
352-
// as this would be unsound. For example the following two queries should conflict:
353-
// - Query<&mut B, Or<(With<A>, ())>>
354-
// - Query<&mut B, Without<A>>
355-
//
356-
// If we were to unconditionally add `$name`'s `with`/`without` accesses then `Or<(With<A>, ())>`
357-
// would have a `With<A>` access which is incorrect as this `WorldQuery` will match entities that
358-
// do not have the `A` component. This is the same logic as the `AnyOf<...>: WorldQuery` impl.
359-
//
360-
// The correct thing to do here is to only add a `with`/`without` access to `_access` if all
361-
// `$filter` params have that `with`/`without` access. More jargony put- we add the intersection
362-
// of all `with`/`without` accesses of the `$filter` params to `access`.
363-
let mut _intersected_access = access.clone();
351+
let mut _new_access = access.clone();
364352
let mut _not_first = false;
365353
$(
366354
if _not_first {
367355
let mut intermediate = access.clone();
368356
$filter::update_component_access($filter, &mut intermediate);
369-
_intersected_access.append_or(&intermediate);
370-
_intersected_access.extend_access(&intermediate);
357+
_new_access.append_or(&intermediate);
358+
_new_access.extend_access(&intermediate);
371359
} else {
372-
$filter::update_component_access($filter, &mut _intersected_access);
360+
$filter::update_component_access($filter, &mut _new_access);
373361
_not_first = true;
374362
}
375363
)*
376364

377-
*access = _intersected_access;
365+
*access = _new_access;
378366
}
379367

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

0 commit comments

Comments
 (0)