Skip to content

Commit

Permalink
squishy
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Jan 11, 2023
1 parent 512f376 commit 465bce6
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 88 deletions.
11 changes: 9 additions & 2 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,18 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
}

/// Checks if the query is empty for the given [`World`], where the last change and current tick are given.
///
/// This function will only access `world` in ways that are compliant with the access of `Q::ReadOnly` and
/// `F::ReadOnly` (though may not use those `WorldQuery`'s specifically).
#[inline]
pub fn is_empty(&self, world: &World, last_change_tick: u32, change_tick: u32) -> bool {
// SAFETY: NopFetch does not access any members while &self ensures no one has exclusive access
// SAFETY: `&World` ensures we have readonly access to the whole world. A `NopWorldQuery` does not
// access anything so it is trivially true that it cannot violate any aliasing guarantees. We convert
// the `F` world query to its `ReadOnly` which is guaranteed by the `ReadOnlyWorldQuery` trait to not
// access the world mutably.
unsafe {
self.as_nop()
self.as_readonly()
.as_nop()
.iter_unchecked_manual(world, last_change_tick, change_tick)
.next()
.is_none()
Expand Down
13 changes: 11 additions & 2 deletions crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,17 @@ mod tests {
let mut world1 = World::new();
let world2 = World::new();
let qstate = world1.query::<()>();
// SAFETY: doesnt access anything
let query = unsafe { Query::new(&world2, &qstate, 0, 0, false) };
let query = unsafe {
// SAFETY: query state was made with the same QF as this query has
Query::new(
// SAFETY: doesnt have any access
super::query_world_borrows::QueryLockBorrows::new(&world2),
&qstate,
0,
0,
false,
)
};
query.iter();
}
}
Loading

0 comments on commit 465bce6

Please sign in to comment.