From 9028e3736439fa96b9f8e4c65e8d8d5c993c6aa9 Mon Sep 17 00:00:00 2001 From: Alice Date: Wed, 23 Mar 2022 15:58:36 -0400 Subject: [PATCH 1/3] Rename Access.reads_and_writes to reads --- crates/bevy_ecs/src/query/access.rs | 30 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/bevy_ecs/src/query/access.rs b/crates/bevy_ecs/src/query/access.rs index 1de838ae01745..e765825781aed 100644 --- a/crates/bevy_ecs/src/query/access.rs +++ b/crates/bevy_ecs/src/query/access.rs @@ -9,7 +9,7 @@ use std::marker::PhantomData; pub struct Access { reads_all: bool, /// A combined set of T read and write accesses. - reads_and_writes: FixedBitSet, + reads: FixedBitSet, writes: FixedBitSet, marker: PhantomData, } @@ -18,7 +18,7 @@ impl Default for Access { fn default() -> Self { Self { reads_all: false, - reads_and_writes: Default::default(), + reads: Default::default(), writes: Default::default(), marker: PhantomData, } @@ -27,21 +27,21 @@ impl Default for Access { impl Access { pub fn grow(&mut self, bits: usize) { - self.reads_and_writes.grow(bits); + self.reads.grow(bits); self.writes.grow(bits); } /// Adds a read access for the given index. pub fn add_read(&mut self, index: T) { - self.reads_and_writes.grow(index.sparse_set_index() + 1); - self.reads_and_writes.insert(index.sparse_set_index()); + self.reads.grow(index.sparse_set_index() + 1); + self.reads.insert(index.sparse_set_index()); } /// Adds a write access for the given index. pub fn add_write(&mut self, index: T) { - self.reads_and_writes.grow(index.sparse_set_index() + 1); + self.reads.grow(index.sparse_set_index() + 1); self.writes.grow(index.sparse_set_index() + 1); - self.reads_and_writes.insert(index.sparse_set_index()); + self.reads.insert(index.sparse_set_index()); self.writes.insert(index.sparse_set_index()); } @@ -50,7 +50,7 @@ impl Access { if self.reads_all { true } else { - self.reads_and_writes.contains(index.sparse_set_index()) + self.reads.contains(index.sparse_set_index()) } } @@ -72,14 +72,14 @@ impl Access { /// Clears all recorded accesses. pub fn clear(&mut self) { self.reads_all = false; - self.reads_and_writes.clear(); + self.reads.clear(); self.writes.clear(); } /// Extends this `Access` with another, copying all accesses of `other` into this. pub fn extend(&mut self, other: &Access) { self.reads_all = self.reads_all || other.reads_all; - self.reads_and_writes.union_with(&other.reads_and_writes); + self.reads.union_with(&other.reads); self.writes.union_with(&other.writes); } @@ -93,8 +93,8 @@ impl Access { } else if other.reads_all { 0 == self.writes.count_ones(..) } else { - self.writes.is_disjoint(&other.reads_and_writes) - && self.reads_and_writes.is_disjoint(&other.writes) + self.writes.is_disjoint(&other.reads) + && self.reads.is_disjoint(&other.writes) } } @@ -108,8 +108,8 @@ impl Access { if other.reads_all { conflicts.extend(self.writes.ones()); } - conflicts.extend(self.writes.intersection(&other.reads_and_writes)); - conflicts.extend(self.reads_and_writes.intersection(&other.writes)); + conflicts.extend(self.writes.intersection(&other.reads)); + conflicts.extend(self.reads.intersection(&other.writes)); conflicts .ones() .map(SparseSetIndex::get_sparse_set_index) @@ -118,7 +118,7 @@ impl Access { /// Returns all read accesses. pub fn reads(&self) -> impl Iterator + '_ { - self.reads_and_writes + self.reads .difference(&self.writes) .map(T::get_sparse_set_index) } From 2518db73105ad3262db839fd4b6c532cfb97f460 Mon Sep 17 00:00:00 2001 From: Alice Date: Wed, 23 Mar 2022 16:00:30 -0400 Subject: [PATCH 2/3] Update doc comments --- crates/bevy_ecs/src/query/access.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/bevy_ecs/src/query/access.rs b/crates/bevy_ecs/src/query/access.rs index e765825781aed..6e6ab2198b8b9 100644 --- a/crates/bevy_ecs/src/query/access.rs +++ b/crates/bevy_ecs/src/query/access.rs @@ -7,9 +7,14 @@ use std::marker::PhantomData; /// This is used for ensuring systems are executed soundly. #[derive(Debug, Eq, PartialEq, Clone)] pub struct Access { + /// Does this access require reading from all values? reads_all: bool, - /// A combined set of T read and write accesses. + /// The values that can be read from + /// + /// Note that the ability to write to data implies the ability to read from it, + /// and so this must always be a superset of `writes`. reads: FixedBitSet, + /// The values that can be written to writes: FixedBitSet, marker: PhantomData, } @@ -93,8 +98,7 @@ impl Access { } else if other.reads_all { 0 == self.writes.count_ones(..) } else { - self.writes.is_disjoint(&other.reads) - && self.reads.is_disjoint(&other.writes) + self.writes.is_disjoint(&other.reads) && self.reads.is_disjoint(&other.writes) } } From dfe0e5b0f7ed795cf440b3b661951109975611d2 Mon Sep 17 00:00:00 2001 From: Alice Date: Wed, 23 Mar 2022 16:01:14 -0400 Subject: [PATCH 3/3] Use _name for PhantomData field --- crates/bevy_ecs/src/query/access.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/query/access.rs b/crates/bevy_ecs/src/query/access.rs index 6e6ab2198b8b9..31959b98f5cb8 100644 --- a/crates/bevy_ecs/src/query/access.rs +++ b/crates/bevy_ecs/src/query/access.rs @@ -16,7 +16,7 @@ pub struct Access { reads: FixedBitSet, /// The values that can be written to writes: FixedBitSet, - marker: PhantomData, + _marker: PhantomData, } impl Default for Access { @@ -25,7 +25,7 @@ impl Default for Access { reads_all: false, reads: Default::default(), writes: Default::default(), - marker: PhantomData, + _marker: PhantomData, } } }