Diffstat (limited to 'src/walk/walkers/core/struct.rs')
| -rw-r--r-- | src/walk/walkers/core/struct.rs | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs index 283db72..d66d112 100644 --- a/src/walk/walkers/core/struct.rs +++ b/src/walk/walkers/core/struct.rs @@ -2,10 +2,11 @@ use core::any::TypeId; use effectful::{ bound::Dynamic, - effective::Effective, - environment::{DynBind, Environment, NativeForm}, + effective::{Effective, Canonical}, + environment::{Environment}, higher_ranked::{for_lt, Rank1, WithLt}, SendSync, + DynBind, }; use crate::{ @@ -62,11 +63,11 @@ pub trait StructTypeInfo<'ctx, M, E: Environment>: 'static { type T: DynBind<E>; /// Walk the given field. - fn walk_field<'a>( + fn walk_field<'a, 'lt>( index: usize, value: &'ctx Self::T, - visitor: DynVisitor<'a, 'ctx, E>, - ) -> NativeForm<'a, Result<Flow, Self::FieldError>, E>; + visitor: DynVisitor<'a, 'lt, 'ctx, E>, + ) -> Canonical<'a, Result<Flow, Self::FieldError>, E>; } #[derive(Debug, PartialEq, Clone, Copy, SendSync)] @@ -118,26 +119,26 @@ where } } -impl<'ctx, I, S, E, M> crate::Walker<'ctx, E> for StructWalker<'ctx, I, S, M, E> +impl<'lt, 'ctx, I, S, E, M> crate::Walker<'ctx, E> for StructWalker<'ctx, I, S, M, E> where E: Environment, I: StructTypeInfo<'ctx, M, E, S = S>, - Self: AnyTrait<'ctx> + RecoverableScope<'ctx, E>, + Self: AnyTrait<'lt, 'ctx> + RecoverableScope<'ctx, E>, { type Error = StructWalkError<I::FieldError>; type Output = (); #[inline(always)] - fn walk<'b: 'c, 'c>( + fn walk<'b: 'c, 'd: 'c, 'c>( self, - visitor: DynVisitor<'b, 'ctx, E>, - ) -> NativeForm<'c, Result<Self::Output, Self::Error>, E> + visitor: DynVisitor<'b, 'd, 'ctx, E>, + ) -> Canonical<'c, Result<Self::Output, Self::Error>, E> where Self: 'c, { E::value((self, visitor)) - .update((), |_, (this, visitor)| { - RecoverableScope::<'ctx, E>::new_walk::<'_, '_, '_>(this, visitor.cast()).cast() + .update_map((), |_, (this, visitor)| { + RecoverableScope::<'ctx, E>::new_walk::<'_, '_, '_, '_>(this, visitor.cast()).cast() }) .map((), |_, ((this, _), _)| match this.error { Some(err) => Err(StructWalkError { kind: err }), @@ -164,7 +165,7 @@ where pub enum StaticType {} -impl<'ctx, I, M, E> AnyTrait<'ctx> for StructWalker<'ctx, I, StaticType, M, E> +impl<'lt, 'ctx: 'lt, I, M: 'lt, E> AnyTrait<'lt, 'ctx> for StructWalker<'ctx, I, StaticType, M, E> where E: Environment, I: StructTypeInfo<'ctx, M, E, S = StaticType>, @@ -192,23 +193,24 @@ where // ] where // } -impl<'ctx, I, S, M, E> Hint<'ctx, type_name::Raised<'static, 'ctx, dyn Recoverable<'ctx, E>>> +impl<'lt2, 'ctx, I, S, M, E> Hint<'ctx, type_name::Raised<'static, 'ctx, dyn Recoverable<'ctx, E>>> for StructWalker<'ctx, I, S, M, E> where E: Environment, I: StructTypeInfo<'ctx, M, E, S = S>, - Self: AnyTrait<'ctx> + RecoverableScope<'ctx, E>, + Self: AnyTrait<'lt2, 'ctx> + RecoverableScope<'ctx, E>, { #[inline(always)] - fn hint<'this, 'visitor, 'hint, 'e>( + fn hint<'this, 'visitor, 'lt: 'e, 'hint, 'e>( &'this mut self, _visitor: DynVisitorWith< 'visitor, + 'lt, 'ctx, type_name::Raised<'static, 'ctx, dyn Recoverable<'ctx, E>>, >, _hint: (), - ) -> NativeForm<'e, VisitResult, E> + ) -> Canonical<'e, VisitResult, E> where 'ctx: 'this + 'visitor + 'hint + 'e, { @@ -225,7 +227,7 @@ where fn known<'a>( &'a mut self, hint: &'a WithLt<'a, Rank1<()>>, - ) -> NativeForm<'a, Result<WithLt<'a, Rank1<()>>, ()>, E> + ) -> Canonical<'a, Result<WithLt<'a, Rank1<()>>, ()>, E> where WithLt<'a, Rank1<()>>: DynBind<E>, { @@ -249,7 +251,7 @@ where // dyn Tag<'ctx, tags::FieldNames, E> + 'c, // >, // _hint: TagHint<tags::FieldNames>, -// ) -> NativeForm<'e, VisitResult, E> +// ) -> Canonical<'e, VisitResult, E> // where // 'ctx: 'this + 'visitor + 'hint + 'e, // { @@ -275,7 +277,7 @@ where // fn known<'a>( // &'a mut self, // hint: &'a WithLt<'a, Rank1<()>>, -// ) -> NativeForm<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> +// ) -> Canonical<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> // where // WithLt<'a, Rank1<TagKnown>>: DynBind<Protocol::Env> // { @@ -298,7 +300,7 @@ where // &'this mut self, // _visitor: DynVisitorWith<'visitor, 'ctx, dyn Tag<'ctx, tags::TypeName, E> + 'c>, // _hint: TagHint<tags::TypeName>, -// ) -> NativeForm<'e, VisitResult, E> +// ) -> Canonical<'e, VisitResult, E> // where // 'ctx: 'this + 'visitor + 'hint + 'e, // { @@ -324,7 +326,7 @@ where // fn known<'a>( // &'a mut self, // hint: &'a WithLt<'a, Rank1<()>>, -// ) -> NativeForm<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> +// ) -> Canonical<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> // where // WithLt<'a, Rank1<TagKnown>>: DynBind<Protocol::Env> // { @@ -347,7 +349,7 @@ where // &'this mut self, // _visitor: DynVisitorWith<'visitor, 'ctx, dyn Tag<'ctx, tags::Map, E> + 'c>, // _hint: TagHint<tags::Map>, -// ) -> NativeForm<'e, VisitResult, E> +// ) -> Canonical<'e, VisitResult, E> // where // 'ctx: 'this + 'visitor + 'hint + 'e, // { @@ -369,7 +371,7 @@ where // fn known<'a>( // &'a mut self, // hint: &'a WithLt<'a, Rank1<()>>, -// ) -> NativeForm<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> +// ) -> Canonical<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> // where // WithLt<'a, Rank1<TagKnown>>: DynBind<Protocol::Env> // { @@ -392,7 +394,7 @@ where // &'this mut self, // visitor: DynVisitorWith<'visitor, 'ctx, dyn Tag<'ctx, tags::Struct, E> + 'c>, // _hint: TagHint<tags::Struct>, -// ) -> NativeForm<'e, VisitResult, E> +// ) -> Canonical<'e, VisitResult, E> // where // 'ctx: 'this + 'visitor + 'hint + 'e, // { @@ -416,7 +418,7 @@ where // fn known<'a>( // &'a mut self, // hint: &'a WithLt<'a, Rank1<()>>, -// ) -> NativeForm<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> +// ) -> Canonical<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> // where // WithLt<'a, Rank1<TagKnown>>: DynBind<Protocol::Env> // { @@ -440,7 +442,7 @@ where // &'this mut self, // _visitor: DynVisitorWith<'visitor, 'ctx, dyn Tag<'ctx, tags::TypeId, E> + 'c>, // _hint: TagHint<tags::TypeId>, -// ) -> NativeForm<'e, VisitResult, E> +// ) -> Canonical<'e, VisitResult, E> // where // 'ctx: 'this + 'visitor + 'hint + 'e, // { @@ -466,7 +468,7 @@ where // fn known<'a>( // &'a mut self, // hint: &'a WithLt<'a, Rank1<()>>, -// ) -> NativeForm<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> +// ) -> Canonical<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> // where // WithLt<'a, Rank1<TagKnown>>: DynBind<Protocol::Env> // { @@ -489,7 +491,7 @@ where // &'this mut self, // _visitor: DynVisitorWith<'visitor, 'ctx, dyn Tag<'ctx, TagDyn, E> + 'c>, // _hint: TagHint<TagDyn>, -// ) -> NativeForm<'e, VisitResult, E> +// ) -> Canonical<'e, VisitResult, E> // where // 'ctx: 'this + 'visitor + 'hint + 'e, // { @@ -533,7 +535,7 @@ where // fn known<'a>( // &'a mut self, // hint: &'a WithLt<'a, Rank1<TagHint<TagDyn>>>, -// ) -> NativeForm<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> +// ) -> Canonical<'a, Result<WithLt<'a, Rank1<TagKnown>>, ()>, Protocol::Env> // where // WithLt<'a, Rank1<TagKnown>>: DynBind<Protocol::Env> // { @@ -563,7 +565,7 @@ where // &'this mut self, // _visitor: DynVisitorWith<'visitor, 'ctx, dyn Value<'ctx, BorrowedStatic<'ctx, I::T>, E> + 'x>, // _hint: (), -// ) -> NativeForm<'e, VisitResult, E> +// ) -> Canonical<'e, VisitResult, E> // where // 'ctx: 'this + 'visitor + 'hint + 'e, // { @@ -581,7 +583,7 @@ where // fn known<'a>( // &'a mut self, // hint: &'a WithLt<'a, Rank1<()>>, -// ) -> NativeForm<'a, Result<WithLt<'a, Rank1<ValueKnown<'a, BorrowedStatic<'ctx, I::T>>>>, ()>, Protocol::Env> +// ) -> Canonical<'a, Result<WithLt<'a, Rank1<ValueKnown<'a, BorrowedStatic<'ctx, I::T>>>>, ()>, Protocol::Env> // where // WithLt<'a, Rank1<ValueKnown<'a, BorrowedStatic<'ctx, I::T>>>>: DynBind<Protocol::Env> // { @@ -598,19 +600,21 @@ where { #[inline(always)] - fn hint<'this: 'e, 'visitor: 'e, 'hint: 'e, 'e>( + fn hint<'this: 'e, 'visitor: 'e, 'lt: 'e, 'hint: 'e, 'e>( &'this mut self, visitor: DynVisitorWith< 'visitor, + 'lt, 'ctx, type_name::Raised<'static, 'ctx, dyn Sequence<'ctx, E>>, >, _hint: SequenceHint, - ) -> NativeForm<'e, VisitResult, E> + ) -> Canonical<'e, VisitResult, E> where 'ctx: 'this + 'visitor + 'hint + 'e, { - E::with((self, visitor), |(this, visitor)| { + E::value((self, visitor)) + .update_map((), |_, (this, visitor)| { visitor .as_known() .visit(*this) @@ -631,7 +635,7 @@ where fn known<'a>( &'a mut self, hint: &'a WithLt<'a, Rank1<SequenceHint>>, - ) -> NativeForm<'a, Result<WithLt<'a, Rank1<SequenceKnown>>, ()>, E> + ) -> Canonical<'a, Result<WithLt<'a, Rank1<SequenceKnown>>, ()>, E> where WithLt<'a, Rank1<SequenceKnown>>: DynBind<E>, { @@ -651,17 +655,17 @@ where I: StructTypeInfo<'ctx, M, E, S = S>, { #[inline(always)] - fn size_hint(&mut self) -> NativeForm<'_, (usize, Option<usize>), E> { + fn size_hint(&mut self) -> Canonical<'_, (usize, Option<usize>), E> { let len = I::FIELDS.len(); E::value((len, Some(len))).cast() } #[inline(always)] - fn next<'a: 'c, 'b: 'c, 'c>( + fn next<'a: 'c, 'd: 'c, 'b: 'c, 'c>( &'a mut self, - visitor: DynVisitor<'b, 'ctx, E>, - ) -> NativeForm<'c, Flow, E> { + visitor: DynVisitor<'b, 'd, 'ctx, E>, + ) -> Canonical<'c, Flow, E> { if self.index >= I::FIELDS.len() { return E::value(Flow::Done).cast(); } @@ -706,10 +710,10 @@ where Dynamic<OwnedStatic<TypeId>>: DynBind<E>, { #[inline(always)] - fn new_walk<'a: 'c, 'b: 'c, 'c>( + fn new_walk<'a: 'c, 'b: 'c, 'd: 'c, 'c>( &'a mut self, - visitor: DynVisitor<'b, 'ctx, E>, - ) -> NativeForm<'c, Status, E> { + visitor: DynVisitor<'b, 'd, 'ctx, E>, + ) -> Canonical<'c, Status, E> { // Reset the errors to default state. self.error = None; @@ -717,7 +721,7 @@ where self.index = 0; E::value((self, visitor)) - .update((), |_, (this, visitor)| { + .update_map((), |_, (this, visitor)| { request_hint::<E>(visitor.cast(), DynWalker(*this)) .map((), |_, x| VisitResult::unit_skipped(x)) .cast() |