Diffstat (limited to 'src/walk/walkers/core/struct.rs')
-rw-r--r--src/walk/walkers/core/struct.rs190
1 files changed, 112 insertions, 78 deletions
diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs
index 899f99f..3150273 100644
--- a/src/walk/walkers/core/struct.rs
+++ b/src/walk/walkers/core/struct.rs
@@ -1,6 +1,11 @@
use core::any::TypeId;
-use effectful::{bound::{IsSend, IsSync}, environment::{DynBind, Environment, NativeForm}, forward_send_sync};
+use effectful::{
+ bound::{IsSend, IsSync},
+ effective::Effective,
+ environment::{DynBind, Environment, NativeForm},
+ forward_send_sync,
+};
use crate::{
any::{AnyTrait, BorrowedStatic, BorrowedStaticHrt, StaticType},
@@ -41,8 +46,14 @@ pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Env
_generics: Marker<E>,
}
-unsafe impl<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Environment> IsSend<E::NeedSend> for StructWalker<'ctx, I, S, M, E> {}
-unsafe impl<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Environment> IsSync<E::NeedSync> for StructWalker<'ctx, I, S, M, E> {}
+unsafe impl<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Environment> IsSend<E::NeedSend>
+ for StructWalker<'ctx, I, S, M, E>
+{
+}
+unsafe impl<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Environment> IsSync<E::NeedSync>
+ for StructWalker<'ctx, I, S, M, E>
+{
+}
/// Type info about a struct needed by [`StructWalker`].
pub trait StructTypeInfo<'ctx, M, E: Environment>: 'static {
@@ -136,17 +147,15 @@ where
where
Self: 'c,
{
- E::ready((self, visitor))
- .as_ctx(
- #[inline(always)]
- |(this, visitor)| {
- RecoverableScope::<'ctx, E>::new_walk::<'_, '_, '_>(this, visitor.cast()).cast()
- },
- )
- .map(|((this, _), _)| match this.error {
+ E::value((self, visitor))
+ .update((), |_, (this, visitor)| {
+ RecoverableScope::<'ctx, E>::new_walk::<'_, '_, '_>(this, visitor.cast()).cast()
+ })
+ .map((), |_, ((this, _), _)| match this.error {
Some(err) => Err(StructWalkError { kind: err }),
None => Ok(()),
})
+ .cast()
// E::ready(self).as_ctx_for::<'ctx, '_>(|this, _| {
// (RecoverableScope::<'ctx, E>::new_walk::<'_, 'b, '_>(this, visitor), PhantomData)
@@ -213,7 +222,7 @@ where
&'a mut self,
_hint: &'a <RecoverableProto<E> as HintMeta>::Hint,
) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, RecoverableProto<E>>, ()>, E> {
- E::ready(Ok(RecoverableKnown))
+ E::value(Ok(RecoverableKnown)).cast()
}
}
@@ -263,9 +272,10 @@ where
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>, ()>,
E,
> {
- E::ready(Ok(TagKnown {
+ E::value(Ok(TagKnown {
kind_available: Some(true),
}))
+ .cast()
}
}
@@ -311,9 +321,10 @@ where
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>, ()>,
E,
> {
- E::ready(Ok(TagKnown {
+ E::value(Ok(TagKnown {
kind_available: Some(true),
}))
+ .cast()
}
}
@@ -355,9 +366,10 @@ where
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>>, ()>,
E,
> {
- E::ready(Ok(TagKnown {
+ E::value(Ok(TagKnown {
kind_available: Some(true),
}))
+ .cast()
}
}
@@ -376,18 +388,20 @@ where
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
- E::as_ctx(
+ E::with(
(visitor, DynWalkerAdapter::new(NoopWalker::new())),
- #[inline(always)]
|(visitor, noop_walker)| {
visitor
.as_known()
.visit(TagConst, noop_walker)
- .map(|status| VisitResult::Control(status.to_flow().unwrap_or(Flow::Continue)))
+ .map((), |_, status| {
+ VisitResult::Control(status.to_flow().unwrap_or(Flow::Continue))
+ })
.cast()
},
)
- .remove_ctx()
+ .map((), |_, (_, x)| x)
+ .cast()
}
#[inline(always)]
@@ -399,9 +413,10 @@ where
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>, ()>,
E,
> {
- E::ready(Ok(TagKnown {
+ E::value(Ok(TagKnown {
kind_available: Some(true),
}))
+ .cast()
}
}
@@ -448,9 +463,10 @@ where
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>, ()>,
E,
> {
- E::ready(Ok(TagKnown {
+ E::value(Ok(TagKnown {
kind_available: Some(true),
}))
+ .cast()
}
}
@@ -510,7 +526,7 @@ where
&'a mut self,
hint: &'a <TagProto<TagDyn, E> as HintMeta>::Hint,
) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, TagProto<TagDyn, E>>, ()>, E> {
- E::ready(match hint.kind {
+ E::value(match hint.kind {
TagDyn(crate::TAG_TYPE_ID) | TagDyn(crate::TAG_STRUCT) => Ok(TagKnown {
kind_available: Some(true),
}),
@@ -518,6 +534,7 @@ where
kind_available: Some(false),
}),
})
+ .cast()
}
}
@@ -552,7 +569,7 @@ where
&'a mut self,
_hint: &'a (),
) -> NativeForm<'a, Result<ValueKnown<'a, BorrowedStatic<'ctx, I::T>>, ()>, E> {
- E::ready(Ok(ValueKnown { preview: None }))
+ E::value(Ok(ValueKnown { preview: None })).cast()
}
}
@@ -571,11 +588,11 @@ where
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
- E::as_ctx_map((self, visitor), |(this, visitor)| {
+ E::with((self, visitor), |(this, visitor)| {
visitor
.as_known()
.visit(*this)
- .map(|status| {
+ .map((), |_, status| {
match status {
VisitResult::Skipped(_) => Flow::Continue,
VisitResult::Control(flow) => flow,
@@ -584,6 +601,8 @@ where
})
.cast()
})
+ .map((), |_, (_, x)| x)
+ .cast()
}
#[inline(always)]
@@ -593,9 +612,10 @@ where
) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, SequenceProto<E>>, ()>, E> {
let len = I::FIELDS.len();
- E::ready(Ok(SequenceKnown {
+ E::value(Ok(SequenceKnown {
len: (len, Some(len)),
}))
+ .cast()
}
}
@@ -608,7 +628,7 @@ where
fn size_hint(&mut self) -> NativeForm<'_, (usize, Option<usize>), E> {
let len = I::FIELDS.len();
- E::ready((len, Some(len)))
+ E::value((len, Some(len))).cast()
}
#[inline(always)]
@@ -617,20 +637,22 @@ where
visitor: DynVisitor<'b, 'ctx, E>,
) -> NativeForm<'c, Flow, E> {
if self.index >= I::FIELDS.len() {
- return Flow::Done.ready();
+ return E::value(Flow::Done).cast();
}
let index = self.index;
self.index += 1;
- I::walk_field(index, self.value, visitor).map(|result| match result {
- Ok(flow) => flow,
- Err(err) => {
- // Record the error and signal a break.
- self.error = Some(StructWalkErrorKind::Field(err));
- Flow::Err
- }
- })
+ I::walk_field(index, self.value, visitor)
+ .map(self, |this, result| match result {
+ Ok(flow) => flow,
+ Err(err) => {
+ // Record the error and signal a break.
+ this.error = Some(StructWalkErrorKind::Field(err));
+ Flow::Err
+ }
+ })
+ .cast()
// E::map(
// I::walk_field::<E>(index, self.value, visitor),
@@ -650,7 +672,7 @@ impl<'ctx, I, M: 'ctx, E> RecoverableScope<'ctx, E> for StructWalker<'ctx, I, St
where
E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
- I::T: 'static,
+ I::T: IsSync<E::NeedSend> + 'static,
{
#[inline(always)]
fn new_walk<'a: 'c, 'b: 'c, 'c>(
@@ -663,49 +685,61 @@ where
// Reset the field index to the default.
self.index = 0;
- E::as_ctx((self, visitor), |(this, visitor)| {
- request_hint::<E>(visitor.cast(), DynWalker(*this))
- .map(VisitResult::unit_skipped)
+ E::value((self, visitor))
+ .update((), |_, (this, visitor)| {
+ request_hint::<E>(visitor.cast(), DynWalker(*this))
+ .map((), |_, x| VisitResult::unit_skipped(x))
+ .cast()
+ })
+ .cast::<()>()
+ .if_not_finished((), |_, (this, visitor)| {
+ visit_value::<_, E>(visitor.cast(), BorrowedStatic(this.value))
+ .map((), |_, x| VisitResult::unit_skipped(x))
+ .cast()
+ })
+ .cast::<()>()
+ .if_not_finished((), |_, (this, visitor)| {
+ visit_tag::<TagConst<{ TAG_TYPE_ID.to_int() }>, E, _>(
+ TagConst,
+ visitor.cast(),
+ ValueWalker::new(TypeId::of::<I::T>()),
+ )
+ .map(this, |this, result| {
+ this.record_tag_error(result).unit_skipped()
+ })
.cast()
- })
- .if_not_finished(|(this, visitor)| {
- visit_value::<_, E>(visitor.cast(), BorrowedStatic(this.value))
- .map(VisitResult::unit_skipped)
+ })
+ .cast::<()>()
+ .if_not_finished((), |_, (this, visitor)| {
+ visit_tag::<TagConst<{ TAG_STRUCT.to_int() }>, E, _>(
+ TagConst,
+ visitor.cast(),
+ NoopWalker::new(),
+ )
+ .map(this, |this, result| {
+ this.record_tag_error(result).unit_skipped()
+ })
.cast()
- })
- .if_not_finished(|(this, visitor)| {
- visit_tag::<TagConst<{ TAG_TYPE_ID.to_int() }>, E, _>(
- TagConst,
- visitor.cast(),
- ValueWalker::new(TypeId::of::<I::T>()),
- )
- .map(|result| this.record_tag_error(result).unit_skipped())
- .cast()
- })
- .if_not_finished(|(this, visitor)| {
- visit_tag::<TagConst<{ TAG_STRUCT.to_int() }>, E, _>(
- TagConst,
- visitor.cast(),
- NoopWalker::new(),
- )
- .map(|result| this.record_tag_error(result).unit_skipped())
- .cast()
- })
- .if_skipped(|(this, visitor)| {
- visit_tag::<TagConst<{ TAG_MAP.to_int() }>, E, _>(
- TagConst,
- visitor.cast(),
- NoopWalker::new(),
- )
- .map(|result| this.record_tag_error(result).unit_skipped())
- .cast()
- })
- .if_not_finished(|(this, visitor)| {
- visit_sequence::<E>(visitor.cast(), *this)
- .map(VisitResult::unit_skipped)
+ })
+ .cast::<()>()
+ .if_skipped((), |_, (this, visitor)| {
+ visit_tag::<TagConst<{ TAG_MAP.to_int() }>, E, _>(
+ TagConst,
+ visitor.cast(),
+ NoopWalker::new(),
+ )
+ .map(this, |this, result| {
+ this.record_tag_error(result).unit_skipped()
+ })
.cast()
- })
- .remove_ctx()
- .map(VisitResult::to_status)
+ })
+ .cast::<()>()
+ .if_not_finished((), |_, (this, visitor)| {
+ visit_sequence::<E>(visitor.cast(), *this)
+ .map((), |_, x| VisitResult::unit_skipped(x))
+ .cast()
+ })
+ .map((), |_, (_, x)| VisitResult::to_status(x))
+ .cast()
}
}