From ead3472c7f2bd054b469200776d61dc55a1213b3 Mon Sep 17 00:00:00 2001 From: Anders429 Date: Mon, 17 Apr 2023 11:32:38 -0700 Subject: [PATCH] Replace query::view::Reshape with hlist::Reshape. --- src/archetype/mod.rs | 8 +-- src/query/entries.rs | 34 ++++------- src/query/view/mod.rs | 2 - src/query/view/reshape.rs | 82 --------------------------- src/registry/contains/views/sealed.rs | 55 +++++++++++------- src/world/entry.rs | 2 +- 6 files changed, 45 insertions(+), 138 deletions(-) delete mode 100644 src/query/view/reshape.rs diff --git a/src/archetype/mod.rs b/src/archetype/mod.rs index 0251af6a..ad80e660 100644 --- a/src/archetype/mod.rs +++ b/src/archetype/mod.rs @@ -349,13 +349,7 @@ where pub(crate) unsafe fn view_row_maybe_uninit_unchecked<'a, Views, Indices>( &mut self, index: usize, - ) -> <<>::Viewable as ContainsViewsOuter< - 'a, - Views, - >::Containments, - >::Indices, - >::ReshapeIndices, - >>::Canonical as ViewsSealed<'a>>::MaybeUninit + ) -> Views::MaybeUninit where Views: view::Views<'a>, R: ContainsViews<'a, Views, Indices>, diff --git a/src/query/entries.rs b/src/query/entries.rs index 0dba010d..17772412 100644 --- a/src/query/entries.rs +++ b/src/query/entries.rs @@ -12,10 +12,7 @@ use crate::{ query::{ filter::And, view, - view::{ - Reshape, - SubSet, - }, + view::SubSet, }, registry, registry::contains::views::{ @@ -88,26 +85,15 @@ where // viewable by every possible `SubViews` (for example, in a `System` where the // `Registry` is generic). Therefore, we instead prove that the `Views` can be viewed // by the `SubViews`. - let super_views = <>::Viewable as ContainsViewsOuter< - Views, - Registry::Containments, - Registry::Indices, - Registry::ReshapeIndices - >>::Canonical::reshape_maybe_uninit( - // SAFETY: `self.location.index` is a valid - // index into this archetype, as guaranteed - // by the entity allocator. - unsafe { - (*self.entries.world).archetypes - .get_mut(self.location.identifier)? - .view_row_maybe_uninit_unchecked::< - Views, - Indices, - >(self.location.index) - }); + + // SAFETY: `self.location.index` is a valid index into this archetype, as guaranteed by + // the entity allocator. + let super_views = unsafe { + (*self.entries.world) + .archetypes + .get_mut(self.location.identifier)? + .view_row_maybe_uninit_unchecked::(self.location.index) + }; // SAFETY: `super_views` is viewed on the archetype identified by // `self.location.identifier`. The `indices` also correspond to the registry the diff --git a/src/query/view/mod.rs b/src/query/view/mod.rs index eb3ad8f2..9e828510 100644 --- a/src/query/view/mod.rs +++ b/src/query/view/mod.rs @@ -57,7 +57,6 @@ mod disjoint; mod merge; #[cfg(feature = "rayon")] mod par; -mod reshape; mod sealed; mod subset; @@ -82,7 +81,6 @@ pub(crate) use par::{ ParViewsSeal, RepeatNone, }; -pub(crate) use reshape::Reshape; pub(crate) use sealed::ViewsSealed; use crate::{ diff --git a/src/query/view/reshape.rs b/src/query/view/reshape.rs deleted file mode 100644 index 4d919122..00000000 --- a/src/query/view/reshape.rs +++ /dev/null @@ -1,82 +0,0 @@ -use crate::{ - hlist::{ - Get, - Null, - }, - query::view, -}; - -pub trait Reshape<'a, R, I>: view::Views<'a> + Sized -where - R: view::Views<'a>, -{ - fn reshape(self) -> R; - - fn reshape_maybe_uninit(views: Self::MaybeUninit) -> R::MaybeUninit; - - fn reshape_indices(indices: Self::Indices) -> R::Indices; -} - -impl Reshape<'_, view::Null, Null> for view::Null { - fn reshape(self) -> view::Null { - self - } - - fn reshape_maybe_uninit(views: view::Null) -> view::Null { - views - } - - fn reshape_indices(indices: view::Null) -> view::Null { - indices - } -} - -impl<'a, I, IS, R, S, T> Reshape<'a, (R, S), (I, IS)> for T -where - T: Get + view::Views<'a>, - T::MaybeUninit: Get< - R::MaybeUninit, - I, - Remainder = <>::Remainder as view::ViewsSealed<'a>>::MaybeUninit, - >, - T::Indices: Get< - R::Index, - I, - Remainder = <>::Remainder as view::ViewsSealed<'a>>::Indices, - >, - T::Remainder: Reshape<'a, S, IS>, - R: view::View<'a>, - (R, S): view::Views<'a> - + view::ViewsSealed< - 'a, - Indices = ( - >::Index, - >::Indices, - ), - MaybeUninit = ( - >::MaybeUninit, - >::MaybeUninit, - ), - >, - S: view::Views<'a>, -{ - fn reshape(self) -> (R, S) { - let (target, remainder) = self.get(); - (target, remainder.reshape()) - } - - fn reshape_maybe_uninit( - views: Self::MaybeUninit, - ) -> <(R, S) as view::ViewsSealed<'a>>::MaybeUninit { - let (target, remainder) = views.get(); - (target, T::Remainder::reshape_maybe_uninit(remainder)) - } - - fn reshape_indices(indices: Self::Indices) -> <(R, S) as view::ViewsSealed<'a>>::Indices { - let (target, remainder) = indices.get(); - ( - target, - >::Remainder::reshape_indices(remainder), - ) - } -} diff --git a/src/registry/contains/views/sealed.rs b/src/registry/contains/views/sealed.rs index 7b9a8ea1..40e56a61 100644 --- a/src/registry/contains/views/sealed.rs +++ b/src/registry/contains/views/sealed.rs @@ -9,7 +9,6 @@ use crate::{ query::{ view, view::{ - Reshape as _, Views, ViewsSealed, }, @@ -88,7 +87,7 @@ where /// The canonical form of the views `V`. type Canonical: Views<'a> + ViewsSealed<'a, Results = Self::CanonicalResults> - + view::Reshape<'a, V, Q>; + + Reshape; /// The canonical form of the results of the views `V`. Equivalent to /// `Self::Canonical::Results`. type CanonicalResults: Reshape>>; @@ -134,7 +133,7 @@ where entity_identifiers: (*mut entity::Identifier, usize), length: usize, archetype_identifier: archetype::identifier::Iter, - ) -> >::MaybeUninit + ) -> V::MaybeUninit where R: Registry; @@ -178,7 +177,7 @@ where P, IS, >>::Canonical, - ): view::Reshape<'a, V, Q> + ): Reshape + ViewsSealed< 'a, Results = ( @@ -209,6 +208,24 @@ where >>::Canonical as ViewsSealed<'a>>::MaybeUninit, ), >, + <( + entity::Identifier, + >::Remainder, + P, + IS, + >>::Canonical, + ) as ViewsSealed<'a>>::Indices: Reshape, + <( + entity::Identifier, + >::Remainder, + P, + IS, + >>::Canonical, + ) as ViewsSealed<'a>>::MaybeUninit: Reshape, { type Registry = R; type Canonical = ( @@ -277,7 +294,7 @@ where entity_identifiers: (*mut entity::Identifier, usize), length: usize, archetype_identifier: archetype::identifier::Iter, - ) -> >::MaybeUninit + ) -> V::MaybeUninit where R_: Registry, { @@ -293,7 +310,7 @@ where // `Vec`s of length `length` for each of the components identified by // `archetype_identifier`. `index` is guaranteed to be less than `length`. unsafe { R::view_one_maybe_uninit(index, columns, length, archetype_identifier) }, - ) + ).reshape() } #[cfg(feature = "rayon")] @@ -303,7 +320,7 @@ where } fn indices() -> V::Indices { - let canonical_indices = ( + ( view::Null, >::Canonical, P, >>::indices::(), - ); - <( - entity::Identifier, - >::Remainder, - P, - IS, - >>::Canonical, - )>::reshape_indices(canonical_indices) + ).reshape() } } @@ -335,7 +343,11 @@ where + ContainsViewsInner<'a, V, P, I>, <>::Canonical as ViewsSealed<'a>>::Results: Reshape<>::Results, Q, iter::Take>>, - >::Canonical: view::Reshape<'a, V, Q>, + >::Canonical: Reshape, + <>::Canonical as ViewsSealed<'a>>::Indices: + Reshape, + <>::Canonical as ViewsSealed<'a>>::MaybeUninit: + Reshape, V: Views<'a>, { type Registry = R; @@ -379,12 +391,12 @@ where _entity_identifiers: (*mut entity::Identifier, usize), length: usize, archetype_identifier: archetype::identifier::Iter, - ) -> >::MaybeUninit + ) -> V::MaybeUninit where R_: Registry, { // SAFETY: The safety contract of this function applies to this function call. - unsafe { R::view_one_maybe_uninit(index, columns, length, archetype_identifier) } + unsafe { R::view_one_maybe_uninit(index, columns, length, archetype_identifier) }.reshape() } #[cfg(feature = "rayon")] @@ -394,8 +406,7 @@ where } fn indices() -> V::Indices { - let canonical_indices = R::indices::(); - Self::Canonical::reshape_indices(canonical_indices) + R::indices::().reshape() } } diff --git a/src/world/entry.rs b/src/world/entry.rs index 99d9b59c..6a73d93b 100644 --- a/src/world/entry.rs +++ b/src/world/entry.rs @@ -2,10 +2,10 @@ use crate::{ archetype, component::Component, entity::allocator::Location, + hlist::Reshape, query::{ filter::And, view, - view::Reshape, Query, }, registry,