bevy/crates/bevy_ecs/src/query
Nicola Papale 00684d95f7 Fix FilteredAccessSet get_conflicts inconsistency (#5105)
# Objective

* Enable `Res` and `Query` parameter mutual exclusion
* Required for https://github.com/bevyengine/bevy/pull/5080

The `FilteredAccessSet::get_conflicts` methods didn't work properly with
`Res` and `ResMut` parameters. Because those added their access by using
the `combined_access_mut` method and directly modifying the global
access state of the FilteredAccessSet. This caused an inconsistency,
because get_conflicts assumes that ALL added access have a corresponding
`FilteredAccess` added to the `filtered_accesses` field.

In practice, that means that SystemParam that adds their access through
the `Access` returned by `combined_access_mut` and the ones that add
their access using the `add` method lived in two different universes. As
a result, they could never be mutually exclusive.

## Solution

This commit fixes it by removing the `combined_access_mut` method. This
ensures that the `combined_access` field of FilteredAccessSet is always
updated consistently with the addition of a filter. When checking for
filtered access, it is now possible to account for `Res` and `ResMut`
invalid access. This is currently not needed, but might be in the
future.

We add the `add_unfiltered_{read,write}` methods to replace previous
usages of `combined_access_mut`.

We also add improved Debug implementations on FixedBitSet so that their
meaning is much clearer in debug output.


---

## Changelog

* Fix `Res` and `Query` parameter never being mutually exclusive.

## Migration Guide

Note: this mostly changes ECS internals, but since the API is public, it is technically breaking:
* Removed `FilteredAccessSet::combined_access_mut`
  * Replace _immutable_ usage of those by `combined_access`
  * For _mutable_ usages, use the new `add_unfiltered_{read,write}` methods instead of `combined_access_mut` followed by `add_{read,write}`
2022-11-16 11:05:48 +00:00
..
access.rs Fix FilteredAccessSet get_conflicts inconsistency (#5105) 2022-11-16 11:05:48 +00:00
fetch.rs Remove unnecesary branches/panics from Query accesses (#6461) 2022-11-04 06:04:55 +00:00
filter.rs Remove unnecesary branches/panics from Query accesses (#6461) 2022-11-04 06:04:55 +00:00
iter.rs Remove unnecesary branches/panics from Query accesses (#6461) 2022-11-04 06:04:55 +00:00
mod.rs debug_checked_unwrap should track its caller (#6452) 2022-11-05 16:15:08 +00:00
state.rs Fix get_unchecked_manual using archetype index instead of table row. (#6625) 2022-11-15 00:19:11 +00:00