Diffstat (limited to 'src/protocol/visitor/value.rs')
| -rw-r--r-- | src/protocol/visitor/value.rs | 122 |
1 files changed, 48 insertions, 74 deletions
diff --git a/src/protocol/visitor/value.rs b/src/protocol/visitor/value.rs index 9967f66..5ab8887 100644 --- a/src/protocol/visitor/value.rs +++ b/src/protocol/visitor/value.rs @@ -3,19 +3,17 @@ //! In some sense, this is the most basic protocol. use effectful::{ - bound::{Bool, Dynamic, IsSend, IsSync}, + bound::Dynamic, effective::Effective, - environment::{DynBind, EnvConfig, Environment, NativeForm}, + environment::{DynBind, Environment, NativeForm}, + higher_ranked::{for_lt, Rank1}, SendSync, }; use crate::{ - any::TypeName, + any::type_name, hkt::Marker, - protocol::{ - walker::hint::{HasProtocol, HintMeta, Meta}, - DynVisitor, - }, + protocol::{walker::hint::HintMeta, DynVisitor}, }; use super::VisitResult; @@ -23,7 +21,7 @@ use super::VisitResult; /// Trait object for the [`Value`] protocol. /// /// Types implementing the [`Value`] protocol will implement this trait. -pub trait Value<'ctx, T: ?Sized + TypeName::MemberType<E>, E: Environment>: DynBind<E> { +pub trait Value<'ctx, T: ?Sized + type_name::Static, E: Environment>: DynBind<E> { /// Visit a value of type `T`. /// /// Use this to give a value to a visitor. Its expected that a walker @@ -33,36 +31,49 @@ pub trait Value<'ctx, T: ?Sized + TypeName::MemberType<E>, E: Environment>: DynB /// If a [`ControlFlow::Break`] is returned then the walker /// should stop walking as soon as possible as there has likely been /// and error. - fn visit<'a>( - &'a mut self, - value: TypeName::T<'a, 'ctx, T, E>, - ) -> NativeForm<'a, VisitResult<Dynamic<TypeName::T<'a, 'ctx, T, E>>>, E> + fn visit<'this: 'value, 'value: 'e, 'e>( + &'this mut self, + value: type_name::Lowered<'value, 'ctx, T>, + ) -> NativeForm<'e, VisitResult<Dynamic<type_name::Lowered<'value, 'ctx, T>>>, E> where - Dynamic<TypeName::T<'a, 'ctx, T, E>>: DynBind<E>, - TypeName::T<'a, 'ctx, T, E>: Sized, - 'ctx: 'a; + type_name::Lowered<'value, 'ctx, T>: Sized, + Dynamic<type_name::Lowered<'value, 'ctx, T>>: DynBind<E>, + 'ctx: 'this + 'value; } -#[derive(SendSync)] -pub struct ValueProto<T: ?Sized + TypeName::MemberType<E>, E: Environment>(Marker<(*const T, E)>); +const _: () = { + pub struct ValueProto<T: ?Sized, E>(Marker<(*const T, E)>); -impl<'a, 'ctx, T: ?Sized, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> - for ValueProto<T, E> -where - E: Environment, - T: TypeName::MemberType<E>, -{ - type T = dyn Value<'ctx, T, E> + 'a; -} + impl<'a, 'ctx, T: ?Sized, E> type_name::Lower<'a, 'ctx, &'a &'ctx ()> for ValueProto<T, E> + where + E: Environment, + T: type_name::Static, + { + type Lowered = dyn Value<'ctx, T, E> + 'a; + } -impl<'a, 'ctx, T: ?Sized, E> TypeName::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for dyn Value<'ctx, T, E> + 'a -where - E: Environment, - T: TypeName::MemberType<E>, -{ - type Higher = ValueProto<T, E>; -} + impl<'a, 'ctx, T: ?Sized, E> type_name::Raise<'a, 'ctx, &'a &'ctx ()> for dyn Value<'ctx, T, E> + 'a + where + E: Environment, + T: type_name::Static, + { + type Raised = ValueProto<T, E>; + } + + // This enrolls the Value protocol into the walker hint system. + impl<T, E: Environment> HintMeta for ValueProto<T, E> + where + T: ?Sized + type_name::Static, + { + type Known = for_lt!(<'b> ValueKnown<'b, T>); + + type Hint = Rank1<()>; + } + + impl<T: ?Sized, E: Environment> effectful::environment::InEnvironment for ValueProto<T, E> { + type Env = E; + } +}; #[derive(Copy, Clone, PartialEq, Debug, SendSync)] pub struct ValueKnown<'a, T: ?Sized> { @@ -72,56 +83,24 @@ pub struct ValueKnown<'a, T: ?Sized> { pub preview: Option<Dynamic<&'a T>>, } -#[derive(Copy, Clone, Debug, SendSync)] -pub struct ValueKnownHrt<T: ?Sized>(Marker<T>); - -impl<'a, 'ctx, E: EnvConfig, T> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> - for ValueKnownHrt<T> -where - T: ?Sized + TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()>, - Dynamic<&'a TypeName::T<'a, 'ctx, T, E>>: DynBind<E>, -{ - type T = ValueKnown<'a, TypeName::T<'a, 'ctx, T, E>>; -} - -impl<'a, 'ctx, E: EnvConfig, T: ?Sized> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> - for ValueKnown<'a, T> -where - T: TypeName::LowerType<'a, 'ctx, E>, - Dynamic<&'a T>: DynBind<E>, -{ - type Higher = ValueKnownHrt<TypeName::HigherRanked<'a, 'ctx, T, E>>; -} - -// This enrolls the Value protocol into the walker hint system. -impl<T: TypeName::MemberType<E>, E: Environment> HintMeta for ValueProto<T, E> -where - for<'a, 'ctx> Dynamic<&'a TypeName::T<'a, 'ctx, T, E>>: DynBind<E>, -{ - type Known = ValueKnownHrt<T>; - - type Hint = (); - - type Effect = E; -} - pub fn visit_value< 'ctx: 'visitor, 'visitor: 'e, 'e, - T: TypeName::LowerType<'e, 'ctx, E>, + T: type_name::WithLt<'e, 'ctx>, E: Environment, >( visitor: DynVisitor<'visitor, 'ctx, E>, value: T, ) -> NativeForm<'e, VisitResult<Dynamic<T>>, E> where - TypeName::HigherRanked<'e, 'ctx, T, E>: TypeName::MemberType<E>, Dynamic<T>: DynBind<E>, + type_name::Raised<'e, 'ctx, T>: type_name::Static, { if let Some(object) = visitor .0 - .upcast_mut::<ValueProto<TypeName::HigherRanked<'e, 'ctx, T, E>, E>>() + .cast_mut() + .upcast_mut::<dyn Value<'ctx, type_name::Raised<'e, 'ctx, T>, E> + '_>() { // Allow the visitor to give a hint if it wants. object.visit(value) @@ -130,8 +109,3 @@ where E::value(VisitResult::Skipped(Dynamic(value))).cast() } } - -impl<'ctx, T, U: TypeName::MemberType<E>, E: Environment> HasProtocol<ValueProto<U, E>> for T where - T: Value<'ctx, U, E> -{ -} |