Diffstat (limited to 'src/walk/walkers/core/struct.rs')
-rw-r--r--src/walk/walkers/core/struct.rs108
1 files changed, 57 insertions, 51 deletions
diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs
index f20ab0d..899f99f 100644
--- a/src/walk/walkers/core/struct.rs
+++ b/src/walk/walkers/core/struct.rs
@@ -1,9 +1,10 @@
use core::any::TypeId;
+use effectful::{bound::{IsSend, IsSync}, environment::{DynBind, Environment, NativeForm}, forward_send_sync};
+
use crate::{
any::{AnyTrait, BorrowedStatic, BorrowedStaticHrt, StaticType},
any_trait,
- effect::{Effect, EffectExt as _, Effective, EffectiveExt, ErasedEffective, ReadyExt as _},
hkt::Marker,
never::Never,
protocol::{
@@ -25,7 +26,7 @@ use super::{noop::NoopWalker, value::ValueWalker};
/// Walker for a borrow of a struct.
///
/// This walker implements the struct flow. The struct cannot contain lifetimes.
-pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Effect> {
+pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Environment> {
/// Struct value to walk.
value: &'ctx I::T,
@@ -40,8 +41,11 @@ pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Eff
_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> {}
+
/// Type info about a struct needed by [`StructWalker`].
-pub trait StructTypeInfo<'ctx, M, E: Effect>: 'static {
+pub trait StructTypeInfo<'ctx, M, E: Environment>: 'static {
/// Name of the struct.
const NAME: &'static str;
@@ -49,19 +53,19 @@ pub trait StructTypeInfo<'ctx, M, E: Effect>: 'static {
const FIELDS: &'static [&'static str];
/// The walking errors for the fields.
- type FieldError: Send + Sync + core::fmt::Debug;
+ type FieldError: DynBind<E> + core::fmt::Debug;
type S: 'static;
/// The struct being described.
- type T: Send + Sync;
+ type T: DynBind<E>;
/// Walk the given field.
fn walk_field<'a>(
index: usize,
value: &'ctx Self::T,
- visitor: DynVisitor<'a, 'ctx>,
- ) -> ErasedEffective<'a, Result<Flow, Self::FieldError>, E>;
+ visitor: DynVisitor<'a, 'ctx, E>,
+ ) -> NativeForm<'a, Result<Flow, Self::FieldError>, E>;
}
#[derive(Debug, PartialEq, Clone, Copy)]
@@ -88,7 +92,9 @@ pub struct StructWalkError<T> {
kind: StructWalkErrorKind<T>,
}
-impl<'ctx, I, S, M, E: Effect> StructWalker<'ctx, I, S, M, E>
+forward_send_sync!({T} {} StructWalkError<T>);
+
+impl<'ctx, I, S, M, E: Environment> StructWalker<'ctx, I, S, M, E>
where
I: StructTypeInfo<'ctx, M, E, S = S>,
{
@@ -115,9 +121,9 @@ where
impl<'ctx, I, S, E, M> crate::Walker<'ctx, E> for StructWalker<'ctx, I, S, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = S>,
- Self: AnyTrait<'ctx> + RecoverableScope<'ctx, E>,
+ Self: AnyTrait<'ctx, E> + RecoverableScope<'ctx, E>,
{
type Error = StructWalkError<I::FieldError>;
type Output = ();
@@ -125,8 +131,8 @@ where
#[inline(always)]
fn walk<'b: 'c, 'c>(
self,
- visitor: DynVisitor<'b, 'ctx>,
- ) -> ErasedEffective<'c, Result<Self::Output, Self::Error>, E>
+ visitor: DynVisitor<'b, 'ctx, E>,
+ ) -> NativeForm<'c, Result<Self::Output, Self::Error>, E>
where
Self: 'c,
{
@@ -160,7 +166,7 @@ where
}
any_trait! {
- impl['ctx, I, M, E] StructWalker<'ctx, I, StaticType, M, E> = [
+ impl['ctx, I, M][E] StructWalker<'ctx, I, StaticType, M, E> = [
HintProto<RecoverableProto<E>>,
HintProto<SequenceProto<E>>,
HintProto<ValueProto<BorrowedStaticHrt<I::T>, E>>,
@@ -171,24 +177,24 @@ any_trait! {
HintProto<TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>,
HintProto<TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>,
] where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
M: 'ctx,
- I::T: 'static
+ I::T: IsSync<E::NeedSend> + 'static
}
impl<'ctx, I, S, M, E> Hint<'ctx, RecoverableProto<E>> for StructWalker<'ctx, I, S, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = S>,
- Self: AnyTrait<'ctx> + RecoverableScope<'ctx, E>,
+ Self: AnyTrait<'ctx, E> + RecoverableScope<'ctx, E>,
{
#[inline(always)]
fn hint<'this, 'visitor, 'hint, 'e>(
&'this mut self,
_visitor: DynVisitorWith<'visitor, 'ctx, RecoverableProto<E>>,
_hint: MetaHint<'hint, 'ctx, RecoverableProto<E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -206,7 +212,7 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a <RecoverableProto<E> as HintMeta>::Hint,
- ) -> ErasedEffective<'a, Result<MetaKnown<'a, 'ctx, RecoverableProto<E>>, ()>, E> {
+ ) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, RecoverableProto<E>>, ()>, E> {
E::ready(Ok(RecoverableKnown))
}
}
@@ -214,7 +220,7 @@ where
impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>
for StructWalker<'ctx, I, S, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = S>,
{
#[inline(always)]
@@ -226,7 +232,7 @@ where
TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>,
>,
_hint: MetaHint<'hint, 'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -252,7 +258,7 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a MetaHint<'a, 'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>,
- ) -> ErasedEffective<
+ ) -> NativeForm<
'a,
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_FIELD_NAMES.to_int() }>, E>>, ()>,
E,
@@ -266,7 +272,7 @@ where
impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>
for StructWalker<'ctx, I, S, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = S>,
{
#[inline(always)]
@@ -274,7 +280,7 @@ where
&'this mut self,
_visitor: DynVisitorWith<'visitor, 'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>,
_hint: MetaHint<'hint, 'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -300,7 +306,7 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a <TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E> as HintMeta>::Hint,
- ) -> ErasedEffective<
+ ) -> NativeForm<
'a,
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_TYPE_NAME.to_int() }>, E>>, ()>,
E,
@@ -314,7 +320,7 @@ where
impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>>
for StructWalker<'ctx, I, S, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = S>,
{
#[inline(always)]
@@ -322,7 +328,7 @@ where
&'this mut self,
_visitor: DynVisitorWith<'visitor, 'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>>,
_hint: MetaHint<'hint, 'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -344,7 +350,7 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a <TagProto<TagConst<{ TAG_MAP.to_int() }>, E> as HintMeta>::Hint,
- ) -> ErasedEffective<
+ ) -> NativeForm<
'a,
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_MAP.to_int() }>, E>>, ()>,
E,
@@ -358,7 +364,7 @@ where
impl<'ctx, I, S, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>
for StructWalker<'ctx, I, S, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = S>,
{
#[inline(always)]
@@ -366,7 +372,7 @@ where
&'this mut self,
visitor: DynVisitorWith<'visitor, 'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>,
_hint: MetaHint<'hint, 'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -388,7 +394,7 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a <TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E> as HintMeta>::Hint,
- ) -> ErasedEffective<
+ ) -> NativeForm<
'a,
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_STRUCT.to_int() }>, E>>, ()>,
E,
@@ -402,7 +408,7 @@ where
impl<'ctx, I, M, E> Hint<'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>
for StructWalker<'ctx, I, StaticType, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
I::T: 'static,
{
@@ -411,7 +417,7 @@ where
&'this mut self,
_visitor: DynVisitorWith<'visitor, 'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>,
_hint: MetaHint<'hint, 'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -437,7 +443,7 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a <TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E> as HintMeta>::Hint,
- ) -> ErasedEffective<
+ ) -> NativeForm<
'a,
Result<MetaKnown<'a, 'ctx, TagProto<TagConst<{ TAG_TYPE_ID.to_int() }>, E>>, ()>,
E,
@@ -450,7 +456,7 @@ where
impl<'ctx, I, M, E> Hint<'ctx, TagProto<TagDyn, E>> for StructWalker<'ctx, I, StaticType, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
I::T: 'static,
{
@@ -459,7 +465,7 @@ where
&'this mut self,
_visitor: DynVisitorWith<'visitor, 'ctx, TagProto<TagDyn, E>>,
_hint: MetaHint<'hint, 'ctx, TagProto<TagDyn, E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -503,7 +509,7 @@ where
fn known<'a>(
&'a mut self,
hint: &'a <TagProto<TagDyn, E> as HintMeta>::Hint,
- ) -> ErasedEffective<'a, Result<MetaKnown<'a, 'ctx, TagProto<TagDyn, E>>, ()>, E> {
+ ) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, TagProto<TagDyn, E>>, ()>, E> {
E::ready(match hint.kind {
TagDyn(crate::TAG_TYPE_ID) | TagDyn(crate::TAG_STRUCT) => Ok(TagKnown {
kind_available: Some(true),
@@ -518,16 +524,16 @@ where
impl<'ctx, I, M, E> Hint<'ctx, ValueProto<BorrowedStaticHrt<I::T>, E>>
for StructWalker<'ctx, I, StaticType, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
- I::T: 'static,
+ I::T: IsSync<E::NeedSend> + 'static,
{
#[inline(always)]
fn hint<'this, 'visitor, 'hint, 'e>(
&'this mut self,
_visitor: DynVisitorWith<'visitor, 'ctx, ValueProto<BorrowedStaticHrt<I::T>, E>>,
_hint: MetaHint<'hint, 'ctx, ValueProto<BorrowedStaticHrt<I::T>, E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -545,14 +551,14 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a (),
- ) -> ErasedEffective<'a, Result<ValueKnown<'a, BorrowedStatic<'ctx, I::T>>, ()>, E> {
+ ) -> NativeForm<'a, Result<ValueKnown<'a, BorrowedStatic<'ctx, I::T>>, ()>, E> {
E::ready(Ok(ValueKnown { preview: None }))
}
}
impl<'ctx, I, S, M: 'ctx, E> Hint<'ctx, SequenceProto<E>> for StructWalker<'ctx, I, S, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = S>,
{
#[inline(always)]
@@ -561,7 +567,7 @@ where
&'this mut self,
visitor: DynVisitorWith<'visitor, 'ctx, SequenceProto<E>>,
_hint: MetaHint<'hint, 'ctx, SequenceProto<E>>,
- ) -> ErasedEffective<'e, VisitResult, E>
+ ) -> NativeForm<'e, VisitResult, E>
where
'ctx: 'this + 'visitor + 'hint + 'e,
{
@@ -584,7 +590,7 @@ where
fn known<'a>(
&'a mut self,
_hint: &'a <SequenceProto<E> as HintMeta>::Hint,
- ) -> ErasedEffective<'a, Result<MetaKnown<'a, 'ctx, SequenceProto<E>>, ()>, E> {
+ ) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, SequenceProto<E>>, ()>, E> {
let len = I::FIELDS.len();
E::ready(Ok(SequenceKnown {
@@ -595,11 +601,11 @@ where
impl<'ctx, I, S, M: 'ctx, E> SequenceScope<'ctx, E> for StructWalker<'ctx, I, S, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = S>,
{
#[inline(always)]
- fn size_hint(&mut self) -> ErasedEffective<'_, (usize, Option<usize>), E> {
+ fn size_hint(&mut self) -> NativeForm<'_, (usize, Option<usize>), E> {
let len = I::FIELDS.len();
E::ready((len, Some(len)))
@@ -608,8 +614,8 @@ where
#[inline(always)]
fn next<'a: 'c, 'b: 'c, 'c>(
&'a mut self,
- visitor: DynVisitor<'b, 'ctx>,
- ) -> ErasedEffective<'c, Flow, E> {
+ visitor: DynVisitor<'b, 'ctx, E>,
+ ) -> NativeForm<'c, Flow, E> {
if self.index >= I::FIELDS.len() {
return Flow::Done.ready();
}
@@ -642,15 +648,15 @@ where
impl<'ctx, I, M: 'ctx, E> RecoverableScope<'ctx, E> for StructWalker<'ctx, I, StaticType, M, E>
where
- E: Effect,
+ E: Environment,
I: StructTypeInfo<'ctx, M, E, S = StaticType>,
I::T: 'static,
{
#[inline(always)]
fn new_walk<'a: 'c, 'b: 'c, 'c>(
&'a mut self,
- visitor: DynVisitor<'b, 'ctx>,
- ) -> ErasedEffective<'c, Status, E> {
+ visitor: DynVisitor<'b, 'ctx, E>,
+ ) -> NativeForm<'c, Status, E> {
// Reset the errors to default state.
self.error = None;