Skip to content

Commit

Permalink
Remove unstable GATs implementation.
Browse files Browse the repository at this point in the history
This change migrates to a stable GATs implementation for entity storage
(i.e., graphs) and removes the `unstable` Cargo feature and its
corresponding `build.rs`.

As part of this change, the input type parameter `G` used in many view
implementations has been removed anywhere the compiler required a
lifetime bound. The `GraphData` type parameter is not actually composed
into view types, but the compiler cannot determine this. As such, any
bounds on this type should be avoided. The parameter `G` may be
completely removed in a subsequent change, because while it sometimes
makes the code a bit easier to read, it may also cause confusion.
  • Loading branch information
olson-sean-k committed Sep 20, 2023
1 parent 563e594 commit ea7340f
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 285 deletions.
1 change: 0 additions & 1 deletion plexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ geometry-glam = ["theon/geometry-glam"]
geometry-mint = ["theon/geometry-mint"]
geometry-nalgebra = ["theon/geometry-nalgebra"]
geometry-ultraviolet = ["theon/geometry-ultraviolet"]
unstable = []

[dependencies]
approx = "^0.3.0"
Expand Down
7 changes: 0 additions & 7 deletions plexus/build.rs

This file was deleted.

14 changes: 1 addition & 13 deletions plexus/src/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@ pub enum EntityError {
Data,
}

#[cfg(not(all(nightly, feature = "unstable")))]
pub trait Lifetime: 'static {}

#[cfg(not(all(nightly, feature = "unstable")))]
impl<T> Lifetime for T where T: 'static {}

#[cfg(all(nightly, feature = "unstable"))]
pub trait Lifetime {}

#[cfg(all(nightly, feature = "unstable"))]
impl<T> Lifetime for T {}

pub trait Entity: Lifetime + Sized {
pub trait Entity: Sized {
type Key: Key;
type Storage: Default + Dispatch<Self> + Storage<Self>;
}
Expand Down
37 changes: 3 additions & 34 deletions plexus/src/entity/storage/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,63 +117,32 @@ where
}
}

#[cfg(not(all(nightly, feature = "unstable")))]
impl<E> Dispatch<E> for HashStorage<E, (), Dynamic>
where
E: Entity<Storage = Self>,
InnerKey<E::Key>: Eq + Hash,
{
type Target = dyn 'static + DependentStorage<E>;
}

#[cfg(all(nightly, feature = "unstable"))]
#[rustfmt::skip]
impl<E> Dispatch<E> for HashStorage<E, (), Dynamic>
where
E: Entity<Storage = Self>,
InnerKey<E::Key>: Eq + Hash,
{
type Target<'a> where E: 'a = dyn 'a + DependentStorage<E>;
}

#[cfg(not(all(nightly, feature = "unstable")))]
impl<E> Dispatch<E> for HashStorage<E, IncrementalKeyer, Dynamic>
where
E: Entity<Storage = Self>,
E::Key: Key<Inner = u64>,
{
type Target = dyn 'static + IndependentStorage<E>;
type Target<'a> = dyn 'a + DependentStorage<E> where E: 'a;
}

#[cfg(all(nightly, feature = "unstable"))]
#[rustfmt::skip]
impl<E> Dispatch<E> for HashStorage<E, IncrementalKeyer, Dynamic>
where
E: Entity<Storage = Self>,
E::Key: Key<Inner = u64>,
{
type Target<'a> where E: 'a = dyn 'a + IndependentStorage<E>;
}

#[cfg(not(all(nightly, feature = "unstable")))]
impl<E, R> Dispatch<E> for HashStorage<E, R, Static>
where
E: Entity<Storage = Self>,
InnerKey<E::Key>: Eq + Hash,
R: 'static + Default,
{
type Target = Self;
type Target<'a> = dyn 'a + IndependentStorage<E> where E: 'a;
}

#[cfg(all(nightly, feature = "unstable"))]
#[rustfmt::skip]
impl<E, R> Dispatch<E> for HashStorage<E, R, Static>
where
E: Entity<Storage = Self>,
InnerKey<E::Key>: Eq + Hash,
R: 'static + Default,
{
type Target<'a> where E: 'a = Self;
type Target<'a> = Self where E: 'a;
}

impl<E, R, P> Enumerate<E> for HashStorage<E, R, P>
Expand Down
12 changes: 0 additions & 12 deletions plexus/src/entity/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ pub mod prelude {
pub use crate::entity::storage::{Enumerate, Get, Insert, InsertWithKey, Remove};
}

#[cfg(not(all(nightly, feature = "unstable")))]
pub type StorageTarget<E> = <<E as Entity>::Storage as Dispatch<E>>::Target;
#[cfg(all(nightly, feature = "unstable"))]
pub type StorageTarget<'a, E> = <<E as Entity>::Storage as Dispatch<E>>::Target<'a>;

pub type InnerKey<K> = <K as Key>::Inner;
Expand Down Expand Up @@ -48,15 +45,6 @@ where
}
}

#[cfg(not(all(nightly, feature = "unstable")))]
pub trait Dispatch<E>
where
E: Entity,
{
type Target: ?Sized + Storage<E>;
}

#[cfg(all(nightly, feature = "unstable"))]
#[rustfmt::skip]
pub trait Dispatch<E>
where
Expand Down
25 changes: 19 additions & 6 deletions plexus/src/entity/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,12 @@ where

impl<'a, E> Orphan<'a, E>
where
E: 'a + Payload,
E: Payload,
E::Data: 'a,
{
pub fn bind<M>(storage: &'a mut M, key: E::Key) -> Option<Self>
where
E: 'a,
M: AsStorageMut<E>,
{
View::bind(storage, key).map(Orphan::from)
Expand All @@ -336,6 +338,7 @@ where

pub fn bind_into<T, M>(storage: &'a mut M, key: E::Key) -> Option<T>
where
E: 'a,
T: From<Self>,
M: AsStorageMut<E>,
{
Expand All @@ -357,7 +360,8 @@ where

impl<'a, E> AsRef<E::Key> for Orphan<'a, E>
where
E: 'a + Payload,
E: Payload,
E::Data: 'a,
{
fn as_ref(&self) -> &E::Key {
&self.key
Expand All @@ -366,7 +370,8 @@ where

impl<'a, E> ClosedView for Orphan<'a, E>
where
E: 'a + Payload,
E: Payload,
E::Data: 'a,
{
type Key = E::Key;
type Entity = E;
Expand All @@ -379,6 +384,7 @@ where
impl<'a, E, M> From<View<&'a mut M, E>> for Orphan<'a, E>
where
E: 'a + Payload,
E::Data: 'a,
M: AsStorageMut<E>,
{
fn from(view: View<&'a mut M, E>) -> Self {
Expand All @@ -391,11 +397,17 @@ where
}
}

impl<'a, E> Eq for Orphan<'a, E> where E: 'a + Payload {}
impl<'a, E> Eq for Orphan<'a, E>
where
E: Payload,
E::Data: 'a,
{
}

impl<'a, E> Hash for Orphan<'a, E>
where
E: 'a + Payload,
E: Payload,
E::Data: 'a,
{
fn hash<H>(&self, state: &mut H)
where
Expand All @@ -407,7 +419,8 @@ where

impl<'a, E> PartialEq for Orphan<'a, E>
where
E: 'a + Payload,
E: Payload,
E::Data: 'a,
{
fn eq(&self, other: &Self) -> bool {
self.key == other.key
Expand Down
19 changes: 9 additions & 10 deletions plexus/src/graph/data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::entity::borrow::Reborrow;
use crate::entity::Lifetime;

pub type Data<M> = <M as Parametric>::Data;

Expand Down Expand Up @@ -64,11 +63,11 @@ pub type Data<M> = <M as Parametric>::Data;
///
/// [`AsPosition`]: crate::geometry::AsPosition
/// [`MeshGraph`]: crate::graph::MeshGraph
pub trait GraphData: Lifetime + Sized {
type Vertex: Clone + Lifetime;
type Arc: Clone + Default + Lifetime;
type Edge: Clone + Default + Lifetime;
type Face: Clone + Default + Lifetime;
pub trait GraphData: Sized {
type Vertex: Clone;
type Arc: Clone + Default;
type Edge: Clone + Default;
type Face: Clone + Default;
}

impl GraphData for () {
Expand All @@ -80,7 +79,7 @@ impl GraphData for () {

impl<T> GraphData for (T, T)
where
T: Clone + Lifetime,
T: Clone,
{
type Vertex = Self;
type Arc = ();
Expand All @@ -90,7 +89,7 @@ where

impl<T> GraphData for (T, T, T)
where
T: Clone + Lifetime,
T: Clone,
{
type Vertex = Self;
type Arc = ();
Expand All @@ -100,7 +99,7 @@ where

impl<T> GraphData for [T; 2]
where
T: Clone + Lifetime,
T: Clone,
{
type Vertex = Self;
type Arc = ();
Expand All @@ -110,7 +109,7 @@ where

impl<T> GraphData for [T; 3]
where
T: Clone + Lifetime,
T: Clone,
{
type Vertex = Self;
type Arc = ();
Expand Down
Loading

0 comments on commit ea7340f

Please sign in to comment.