removed unneeded unsafe
42 files changed, 214 insertions, 350 deletions
@@ -102,7 +102,7 @@ dependencies = [ "proc-macro2", "quote", "rustc-hash", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -116,6 +116,17 @@ name = "effectful" version = "0.1.0" dependencies = [ "disjoint_impls", + "effectful-derive", + "mini-macro-magic", +] + +[[package]] +name = "effectful-derive" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", ] [[package]] @@ -202,7 +213,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -321,6 +332,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] +name = "mini-macro-magic" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6936b42d508a1b4fea14e4cf811cf2962a3dd6aba7df23fee8224b04bc25210" + +[[package]] name = "miniz_oxide" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -364,7 +381,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -442,7 +459,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -515,9 +532,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -550,9 +567,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -677,7 +694,7 @@ checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -737,9 +754,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -792,7 +809,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.68", ] [[package]] @@ -11,7 +11,7 @@ use core::marker::PhantomData; use effectful::{ bound::IsSync, - environment::{DynBind, EnvConfig, Environment, InEnvironment}, + environment::{DynBind, EnvConfig, Environment, InEnvironment}, SendSync, }; pub use static_wrapper::*; pub use type_name_id::*; @@ -27,7 +27,7 @@ pub enum LifetimeType {} pub mod TypeName { use effectful::environment::{DynBind, EnvConfig}; - pub trait MemberTypeForLt<'a, 'ctx: 'a, E: EnvConfig, B> { + pub trait MemberTypeForLt<'a, 'ctx: 'a, E: EnvConfig, B>: DynBind<E> { type T: ?Sized + LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx (), Higher = Self>; } @@ -60,6 +60,7 @@ pub mod TypeName { <__ as LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()>>::Higher; } +#[derive(SendSync)] pub struct RefHrt<T: ?Sized>(Marker<T>); impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B> @@ -80,6 +81,7 @@ where type Higher = RefHrt<<T as TypeName::LowerTypeWithBound<'a, 'lt, E, &'a &'lt B>>::Higher>; } +#[derive(SendSync)] pub struct MutHrt<T: ?Sized>(Marker<T>); impl<'a, 'lt, T: ?Sized, E: EnvConfig, B> TypeName::MemberTypeForLt<'a, 'lt, E, &'a &'lt B> @@ -431,6 +433,7 @@ impl<'a, 'ctx, I: Indirect<'a>, E: EnvConfig> AnyTraitObject<'a, 'ctx, I, E> { // // See the tests at the bottom of the file for a proof that the type name is bijective // to T. + #[allow(unsafe_code)] Ok(unsafe { self.indirect.into_inner::<T>() }) } else { Err(self) diff --git a/src/any/indirect.rs b/src/any/indirect.rs index f337e02..2b4eccd 100644 --- a/src/any/indirect.rs +++ b/src/any/indirect.rs @@ -32,6 +32,7 @@ pub(super) mod sealed { /// `value` must have been created by `Self::into_raw`. /// This function must not be called twice for the same `value`. /// The type `T` must be the one given to `Self::into_raw`. + #[allow(unsafe_code)] unsafe fn from_raw<T: ?Sized + 'a>( value: MaybeUninit<[u8; INDIRECT_SIZE]>, ) -> Self::ForT<T>; @@ -58,6 +59,7 @@ pub(super) mod sealed { /// # Safety /// The type `T` must be the same one used in `Self::new`. + #[allow(unsafe_code)] pub unsafe fn into_inner<T: ?Sized>(self) -> I::ForT<T> { // SAFETY: indirect was created with this I's into_raw in Self::new. // This function cannot be called twice because we take ownership of self and @@ -94,9 +96,11 @@ pub(super) mod sealed { impl<'a> Sealed<'a> for Ref { fn into_raw<T: ?Sized + 'a>(value: Self::ForT<T>) -> MaybeUninit<[u8; INDIRECT_SIZE]> { // SAFETY: A possibly fat borrow can be stores in a 2 usize wide maybe uninit array. + #[allow(unsafe_code)] unsafe { transmute::<&'a T, MaybeUninit<[u8; INDIRECT_SIZE]>>(value) } } + #[allow(unsafe_code)] unsafe fn from_raw<T: ?Sized + 'a>(any: MaybeUninit<[u8; INDIRECT_SIZE]>) -> Self::ForT<T> { // SAFETY: We know the value is from Self::into_raw because of the caller invariants. unsafe { transmute::<MaybeUninit<[u8; INDIRECT_SIZE]>, &'a T>(any) } @@ -106,9 +110,11 @@ pub(super) mod sealed { impl<'a> Sealed<'a> for Mut { fn into_raw<T: ?Sized + 'a>(value: Self::ForT<T>) -> MaybeUninit<[u8; INDIRECT_SIZE]> { // SAFETY: A possibly fat borrow can be stores in a 2 usize wide maybe uninit array. + #[allow(unsafe_code)] unsafe { transmute::<&'a mut T, MaybeUninit<[u8; INDIRECT_SIZE]>>(value) } } + #[allow(unsafe_code)] unsafe fn from_raw<T: ?Sized + 'a>(any: MaybeUninit<[u8; INDIRECT_SIZE]>) -> Self::ForT<T> { // SAFETY: We know the value is from Self::into_raw because of the caller invariants. unsafe { transmute::<MaybeUninit<[u8; INDIRECT_SIZE]>, &'a mut T>(any) } @@ -136,6 +142,7 @@ impl<'a> Indirect<'a> for Mut {} /// # Safety /// Same rules as [`core::mem::transmute()`]. +#[allow(unsafe_code)] unsafe fn transmute<T, U>(value: T) -> U { // Create union type that can store a `T` or a `U`. // We can then use this to convert between them. @@ -173,6 +180,7 @@ mod test { let z = RawIndirect::<Ref>::new(y); // SAFETY: Same type as y which we made it from. + #[allow(unsafe_code)] let w: &i32 = unsafe { z.into_inner() }; assert_eq!(w, y); @@ -195,6 +203,7 @@ mod test { let z = RawIndirect::<Ref>::new(y); // SAFETY: Same type as y which we made it from. + #[allow(unsafe_code)] let w: &i32 = unsafe { z.into_inner() }; assert_eq!(w.as_int(), x); @@ -207,6 +216,7 @@ mod test { let z = RawIndirect::<Mut>::new(y); // SAFETY: Same type as y which we made it from. + #[allow(unsafe_code)] let w: &mut i32 = unsafe { z.into_inner() }; *w += 1; @@ -230,6 +240,7 @@ mod test { let z = RawIndirect::<Mut>::new(y); // SAFETY: Same type as y which we made it from. + #[allow(unsafe_code)] let w: &mut dyn AddOne = unsafe { z.into_inner() }; w.add_one(); diff --git a/src/any/static_wrapper.rs b/src/any/static_wrapper.rs index efc6839..6184509 100644 --- a/src/any/static_wrapper.rs +++ b/src/any/static_wrapper.rs @@ -1,18 +1,16 @@ //! Wrapper types that impl [`TypeName`] when their generic type `T` is `'static`. -use effectful::forward_send_sync; +use effectful::SendSync; use crate::hkt::Marker; use super::*; /// Owned static `T`. -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug, SendSync)] #[repr(transparent)] pub struct OwnedStatic<T: ?Sized>(pub T); -forward_send_sync!({T: (?Sized)} {} OwnedStatic<T>); - impl<'a, 'ctx, E: EnvConfig, T> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for OwnedStatic<T> where @@ -30,12 +28,11 @@ where } /// Borrowed static `T` for `'ctx`. -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug, SendSync)] #[repr(transparent)] pub struct BorrowedStatic<'ctx, T: ?Sized>(pub &'ctx T); -forward_send_sync!({} {T: (?Sized + 'ctx)} {{'ctx}} BorrowedStatic<'ctx, T>); - +#[derive(SendSync)] pub struct BorrowedStaticHrt<T: ?Sized>(Marker<T>); impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> @@ -55,12 +52,11 @@ where } /// Borrowed static `T` for `'a`. -#[derive(PartialEq, Clone, Copy, Debug)] +#[derive(PartialEq, Clone, Copy, Debug, SendSync)] #[repr(transparent)] pub struct TempBorrowedStatic<'a, T: ?Sized>(pub &'a T); -forward_send_sync!({} {T: (?Sized + 'ctx)} {{'ctx}} TempBorrowedStatic<'ctx, T>); - +#[derive(SendSync)] pub struct TempBorrowedStaticHrt<T: ?Sized>(Marker<T>); impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> @@ -80,12 +76,11 @@ where } /// Mutably borrowed static `T` for `'ctx`. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, SendSync)] #[repr(transparent)] pub struct BorrowedMutStatic<'ctx, T: ?Sized>(pub &'ctx mut T); -forward_send_sync!({T: (?Sized + 'ctx)} {} {{'ctx}} BorrowedMutStatic<'ctx, T>); - +#[derive(SendSync)] pub struct BorrowedMutStaticHrt<T: ?Sized>(Marker<T>); impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> @@ -105,12 +100,11 @@ where } /// Mutably borrowed static `T` for `'a`. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Debug, SendSync)] #[repr(transparent)] pub struct TempBorrowedMutStatic<'a, T: ?Sized>(pub &'a mut T); -forward_send_sync!({T: (?Sized + 'ctx)} {} {{'ctx}} TempBorrowedMutStatic<'ctx, T>); - +#[derive(SendSync)] pub struct TempBorrowedMutStaticHrt<T: ?Sized>(Marker<T>); impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> @@ -131,13 +125,11 @@ where /// Boxed static `T`. #[cfg(feature = "alloc")] +#[derive(SendSync)] #[repr(transparent)] pub struct BoxedStatic<T: ?Sized>(pub Box<T>); #[cfg(feature = "alloc")] -forward_send_sync!({T: (?Sized)} {} BoxedStatic<T>); - -#[cfg(feature = "alloc")] impl<'a, 'ctx, E: EnvConfig, T: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for BoxedStatic<T> where diff --git a/src/build/builders/core.rs b/src/build/builders/core.rs index caff6eb..a717b13 100644 --- a/src/build/builders/core.rs +++ b/src/build/builders/core.rs @@ -1,8 +1,7 @@ use effectful::{ effective::Effective, environment::{Environment, NativeForm}, - higher_ranked::Mut, - is_send_sync, + higher_ranked::Mut, SendSync, }; use crate::{ @@ -21,12 +20,10 @@ pub mod r#enum; pub mod r#struct; pub mod tag_name; -#[derive(Default)] +#[derive(Default, SendSync)] #[non_exhaustive] pub struct NoopVisitor; -is_send_sync!(NoopVisitor); - impl NoopVisitor { pub fn new() -> Self { Self diff --git a/src/build/builders/core/enum.rs b/src/build/builders/core/enum.rs index aaa44ff..da66e9d 100644 --- a/src/build/builders/core/enum.rs +++ b/src/build/builders/core/enum.rs @@ -3,8 +3,8 @@ use core::fmt::{Debug, Display}; use effectful::bound::{Bool, IsSend, IsSync}; use effectful::effective::Effective; use effectful::environment::{DynBind, Environment, NativeForm}; -use effectful::forward_send_sync; use effectful::higher_ranked::Mut; +use effectful::SendSync; use crate::any::{OwnedStatic, TempBorrowedStatic, TempBorrowedStaticHrt}; use crate::protocol::visitor::{DynRecoverableScope, Recoverable, RecoverableProto}; @@ -20,6 +20,7 @@ use crate::{ Builder, BuilderTypes, DynWalkerObjSafe, Flow, }; +#[derive(SendSync)] pub struct EnumBuilder<'ctx, Info, Mode, E: Environment> where Info: EnumBuildInfo<'ctx, Mode, E>, @@ -27,20 +28,7 @@ where inner: Inner<'ctx, Info, Mode, E>, } -unsafe impl<'ctx, Info, Mode, E: Environment> IsSend<E::NeedSend> - for EnumBuilder<'ctx, Info, Mode, E> -where - Info: EnumBuildInfo<'ctx, Mode, E>, -{ -} - -unsafe impl<'ctx, Info, Mode, E: Environment> IsSync<E::NeedSync> - for EnumBuilder<'ctx, Info, Mode, E> -where - Info: EnumBuildInfo<'ctx, Mode, E>, -{ -} - +#[derive(SendSync)] enum Inner<'ctx, Info, Mode, E: Environment> where Info: EnumBuildInfo<'ctx, Mode, E>, @@ -51,16 +39,6 @@ where Value(Result<Info::T, Info::Error>), } -unsafe impl<'ctx, Info, Mode, E: Environment> IsSend<E::NeedSend> for Inner<'ctx, Info, Mode, E> where - Info: EnumBuildInfo<'ctx, Mode, E> -{ -} - -unsafe impl<'ctx, Info, Mode, E: Environment> IsSync<E::NeedSync> for Inner<'ctx, Info, Mode, E> where - Info: EnumBuildInfo<'ctx, Mode, E> -{ -} - pub trait EnumBuildInfo<'ctx, Mode, E: Environment> { type Builders: DynBind<E>; @@ -259,6 +237,7 @@ where } } +#[derive(SendSync)] struct VariantVisitor<'ctx, Info, Mode, E: Environment> where Info: EnumBuildInfo<'ctx, Mode, E>, @@ -266,20 +245,6 @@ where marker: Option<Info::VariantMarker>, } -unsafe impl<'ctx, Info, Mode, E: Environment> IsSend<E::NeedSend> - for VariantVisitor<'ctx, Info, Mode, E> -where - Info: EnumBuildInfo<'ctx, Mode, E>, -{ -} - -unsafe impl<'ctx, Info, Mode, E: Environment> IsSync<E::NeedSync> - for VariantVisitor<'ctx, Info, Mode, E> -where - Info: EnumBuildInfo<'ctx, Mode, E>, -{ -} - any_trait! { impl['ctx, Info, Mode][E] VariantVisitor<'ctx, Info, Mode, E> = [ ValueProto<TempBorrowedStaticHrt<str>, E>, diff --git a/src/build/builders/core/struct.rs b/src/build/builders/core/struct.rs index 6752acb..f874fac 100644 --- a/src/build/builders/core/struct.rs +++ b/src/build/builders/core/struct.rs @@ -5,6 +5,7 @@ use effectful::{ effective::Effective, environment::{DynBind, Environment, NativeForm}, higher_ranked::Mut, + SendSync, tri, }; @@ -27,6 +28,7 @@ use crate::{ use super::NoopVisitor; /// A builder for a struct. +#[derive(SendSync)] pub struct StructBuilder<'ctx, Info, Mode, E: Environment> where Info: StructTypeInfo<'ctx, Mode, E>, @@ -34,20 +36,7 @@ where inner: Inner<'ctx, Info, Mode, E>, } -unsafe impl<'ctx, Info, Mode, E: Environment> IsSend<E::NeedSend> - for StructBuilder<'ctx, Info, Mode, E> -where - Info: StructTypeInfo<'ctx, Mode, E>, -{ -} - -unsafe impl<'ctx, Info, Mode, E: Environment> IsSync<E::NeedSync> - for StructBuilder<'ctx, Info, Mode, E> -where - Info: StructTypeInfo<'ctx, Mode, E>, -{ -} - +#[derive(SendSync)] enum Inner<'ctx, Info, Mode, E: Environment> where Info: StructTypeInfo<'ctx, Mode, E>, @@ -65,6 +54,7 @@ where } /// Structs are either tuple-like or map-like. +#[derive(SendSync)] enum StructKind { /// A tuple-like struct uses the order of the fields. Tuple, @@ -132,6 +122,7 @@ pub trait StructTypeInfo<'ctx, Mode: 'ctx, E: Environment>: 'static { } /// Error that [`StructBuilder`] returns. +#[derive(SendSync)] pub struct StructError<'ctx, Info, M, E: Environment> where Info: StructTypeInfo<'ctx, M, E>, @@ -140,20 +131,6 @@ where error: Info::Error, } -unsafe impl<'ctx, Info, Mode, E: Environment> IsSend<E::NeedSend> - for StructError<'ctx, Info, Mode, E> -where - Info: StructTypeInfo<'ctx, Mode, E>, -{ -} - -unsafe impl<'ctx, Info, Mode, E: Environment> IsSync<E::NeedSync> - for StructError<'ctx, Info, Mode, E> -where - Info: StructTypeInfo<'ctx, Mode, E>, -{ -} - impl<'ctx, Info, Mode, E: Environment> StructError<'ctx, Info, Mode, E> where Info: StructTypeInfo<'ctx, Mode, E>, @@ -194,6 +171,7 @@ where impl<'ctx, Info, Mode: 'ctx, E: Environment> StructBuilder<'ctx, Info, Mode, E> where + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, { fn make_builders<'e>(&'e mut self) -> NativeForm<'e, (), E> @@ -220,6 +198,7 @@ where impl<'ctx, Info, Mode: 'ctx, E: Environment> Builder<'ctx, E> for StructBuilder<'ctx, Info, Mode, E> where + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>, { @@ -261,6 +240,7 @@ where impl<'ctx, Info, Mode: 'ctx, E: Environment> AsVisitor<'ctx, E> for StructBuilder<'ctx, Info, Mode, E> where + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>, { @@ -281,6 +261,7 @@ any_trait! { SequenceProto<E> ] where E: Environment, + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>, Mode: 'ctx, @@ -288,6 +269,7 @@ any_trait! { impl<'ctx, Info, Mode: 'ctx, E> RequestHint<'ctx, E> for StructBuilder<'ctx, Info, Mode, E> where + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, for<'b, 'c> TypeName::T<'b, 'c, Info::ValueT, E>: IsSync<E::NeedSend>, E: Environment, @@ -353,6 +335,7 @@ where /// This skips needing to go through each field individually. impl<'ctx, Info, Mode, E> Value<'ctx, Info::ValueT, E> for StructBuilder<'ctx, Info, Mode, E> where + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, E: Environment, for<'a> TypeName::T<'a, 'ctx, Info::ValueT, E>: DynBind<E>, @@ -378,6 +361,7 @@ where /// By default [`StructBuilder`] expects a tuple-like struct. impl<'ctx, Info, Mode: 'ctx, E> Tag<'ctx, tags::Struct, E> for StructBuilder<'ctx, Info, Mode, E> where + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, E: Environment, { @@ -407,6 +391,7 @@ where /// By default [`StructBuilder`] expects a tuple-like struct. impl<'ctx, Info, Mode: 'ctx, E> Tag<'ctx, tags::Map, E> for StructBuilder<'ctx, Info, Mode, E> where + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, E: Environment, { @@ -439,6 +424,7 @@ where /// a sequence of key value pairs. Where the key is the field name. impl<'ctx, Info, Mode: 'ctx, E> Sequence<'ctx, E> for StructBuilder<'ctx, Info, Mode, E> where + Self: DynBind<E>, Info: StructTypeInfo<'ctx, Mode, E>, E: Environment, { @@ -522,26 +508,13 @@ where } } +#[derive(SendSync)] struct FieldVisitor<'a, 'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Environment> { builders: &'a mut I::Builders, marker: Option<I::FieldMarker>, _marker: Marker<E>, } -unsafe impl<'a, 'ctx, Info, Mode, E: Environment> IsSend<E::NeedSend> - for FieldVisitor<'a, 'ctx, Info, Mode, E> -where - Info: StructTypeInfo<'ctx, Mode, E>, -{ -} - -unsafe impl<'a, 'ctx, Info, Mode, E: Environment> IsSync<E::NeedSync> - for FieldVisitor<'a, 'ctx, Info, Mode, E> -where - Info: StructTypeInfo<'ctx, Mode, E>, -{ -} - any_trait! { impl['ctx, 'a, I, M][E] FieldVisitor<'a, 'ctx, I, M, E> = [ TagProto<tags::Key, E>, @@ -587,25 +560,12 @@ where } } +#[derive(SendSync)] struct NameVisitor<'ctx, I: StructTypeInfo<'ctx, M, E>, M, E: Environment> { field_marker: Option<I::FieldMarker>, _marker: Marker<E>, } -unsafe impl<'ctx, Info, Mode, E: Environment> IsSend<E::NeedSend> - for NameVisitor<'ctx, Info, Mode, E> -where - Info: StructTypeInfo<'ctx, Mode, E>, -{ -} - -unsafe impl<'ctx, Info, Mode, E: Environment> IsSync<E::NeedSync> - for NameVisitor<'ctx, Info, Mode, E> -where - Info: StructTypeInfo<'ctx, Mode, E>, -{ -} - any_trait! { impl['ctx, I, M][E] NameVisitor<'ctx, I, M, E> = [ ValueProto<OwnedStatic<usize>, E>, diff --git a/src/build/builders/core/value.rs b/src/build/builders/core/value.rs index cd25bdc..1109b51 100644 --- a/src/build/builders/core/value.rs +++ b/src/build/builders/core/value.rs @@ -4,8 +4,7 @@ use effectful::{ bound::IsSync, effective::Effective, environment::{DynBind, Environment, NativeForm}, - forward_send_sync, - higher_ranked::Mut, + higher_ranked::Mut, SendSync, }; use crate::{ @@ -26,11 +25,10 @@ use crate::{ Flow, }; +#[derive(SendSync)] #[non_exhaustive] pub struct ValueError<T>(Marker<T>); -forward_send_sync!({} {} {T} ValueError<T>); - impl<T> ::core::fmt::Debug for ValueError<T> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "missing value of type `{}`", core::any::type_name::<T>()) @@ -53,13 +51,12 @@ pub enum NotCloneable {} #[doc = crate::doc_macro::mermaid!("value.mmd", 100)] /// /// After +#[derive(SendSync)] pub struct ValueBuilder<T, Clone, E> { value: Option<T>, _marker: Marker<(E, Clone)>, } -forward_send_sync!({T} {} {Clone, E} ValueBuilder<T, Clone, E>); - impl<T, Clone, E: Environment> crate::BuilderTypes<E> for ValueBuilder<T, Clone, E> where T: DynBind<E>, @@ -21,10 +21,11 @@ use core::marker::PhantomData; -#[derive(Debug, Default, Copy, Clone)] +#[derive(Debug, Default, Copy, Clone, SendSync)] #[repr(transparent)] pub struct Invariant<'a>(PhantomData<fn(&'a ()) -> &'a ()>); +#[derive(SendSync)] #[repr(transparent)] pub struct Marker<T: ?Sized>(PhantomData<fn() -> *const T>); @@ -125,6 +126,7 @@ macro_rules! higher_ranked_trait { } } } +use effectful::SendSync; pub use higher_ranked_trait; #[doc(hidden)] @@ -3,6 +3,7 @@ #![cfg_attr(all(not(test), not(feature = "std")), no_std)] #![deny(elided_lifetimes_in_paths)] +#![deny(unsafe_code)] #[cfg(feature = "alloc")] extern crate alloc; @@ -21,7 +22,7 @@ mod walk; use core::ops::ControlFlow; pub use build::*; -use effectful::{is_send_sync, short::ConvertShort}; +use effectful::{short::ConvertShort, SendSync}; // use effect::ConvertShort; pub use transform::*; pub use walk::*; @@ -29,7 +30,7 @@ pub use walk::*; use symbol::Symbol; pub mod never { - use effectful::is_send_sync; + use effectful::SendSync; mod sealed { pub trait Extract { @@ -43,10 +44,8 @@ pub mod never { /// Test // pub type Never = <fn() -> ! as sealed::Extract>::Never; - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] + #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, SendSync)] pub enum Never {} - - is_send_sync!(Never); } pub const TAG_TYPE_NAME: Symbol = Symbol::new("Type Name"); @@ -67,15 +66,13 @@ pub const TAG_ENUM: Symbol = Symbol::new("Enum"); pub enum DefaultMode {} #[must_use] -#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone)] +#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Copy, Clone, SendSync)] pub enum Status { Ok, Err, } -is_send_sync!(Status, Flow); - -#[derive(Clone, Copy, PartialEq, Debug)] +#[derive(Clone, Copy, PartialEq, Debug, SendSync)] #[must_use] pub enum Flow { Continue, diff --git a/src/macros/build.rs b/src/macros/build.rs index f56ece9..c77426d 100644 --- a/src/macros/build.rs +++ b/src/macros/build.rs @@ -23,13 +23,11 @@ macro_rules! Build { unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSend<E::NeedSend> for Builders<'ctx, M, E> {} unsafe impl<'ctx, M: 'ctx, E: effectful::environment::Environment> effectful::bound::IsSync<E::NeedSync> for Builders<'ctx, M, E> {} - #[derive(Copy, Clone, Debug)] + #[derive(Copy, Clone, Debug, SendSync)] $vis enum Field { $($field),* } - effectful::is_send_sync!(Field); - mod field_index { enum __Fields { $($field),* diff --git a/src/protocol.rs b/src/protocol.rs index 6293e3d..0d25b0f 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -60,16 +60,14 @@ use core::ops::{Deref, DerefMut}; use effectful::{ bound::{IsSend, IsSync}, environment::Environment, + SendSync, }; use crate::any::AnyTrait; +#[derive(SendSync)] pub struct DynVisitor<'a, 'ctx, Env: Environment>(pub &'a mut (dyn AnyTrait<'ctx, Env> + 'a)); -unsafe impl<'a, 'ctx, E: Environment> IsSend<E::NeedSend> for DynVisitor<'a, 'ctx, E> {} - -unsafe impl<'a, 'ctx, E: Environment> IsSync<E::NeedSync> for DynVisitor<'a, 'ctx, E> {} - impl<'a, 'ctx, Env: Environment> DynVisitor<'a, 'ctx, Env> { pub fn cast<'b>(&'b mut self) -> DynVisitor<'b, 'ctx, Env> { DynVisitor(&mut *self.0) @@ -105,12 +103,9 @@ impl<'b, 'ctx, Env: Environment> AsVisitor<'ctx, Env> for DynVisitor<'b, 'ctx, E } } +#[derive(SendSync)] pub struct DynWalker<'a, 'ctx, Env: Environment>(pub &'a mut (dyn AnyTrait<'ctx, Env> + 'a)); -unsafe impl<'a, 'ctx, E: Environment> IsSend<E::NeedSend> for DynWalker<'a, 'ctx, E> {} - -unsafe impl<'a, 'ctx, E: Environment> IsSync<E::NeedSync> for DynWalker<'a, 'ctx, E> {} - impl<'a, 'ctx, Env: Environment> DynWalker<'a, 'ctx, Env> { pub fn cast<'b>(&'b mut self) -> DynWalker<'b, 'ctx, Env> { DynWalker(&mut *self.0) diff --git a/src/protocol/visitor.rs b/src/protocol/visitor.rs index 5916235..087174e 100644 --- a/src/protocol/visitor.rs +++ b/src/protocol/visitor.rs @@ -12,8 +12,8 @@ use effectful::{ bound::HasSendAndSync, effective::{Effective, SplitUpdateEffective}, environment::{DynBind, Environment, NativeForm}, - for_lt, forward_send_sync, - higher_ranked::Mut, + for_lt, + higher_ranked::Mut, SendSync, }; pub use recoverable::*; pub use request_hint::*; @@ -21,7 +21,7 @@ pub use sequence::*; pub use tag::*; pub use value::*; -#[derive(Copy, Clone)] +#[derive(Copy, Clone, SendSync)] #[must_use] pub enum VisitResult<S = ()> { /// The protocol was not used. @@ -34,8 +34,6 @@ pub enum VisitResult<S = ()> { Control(Flow), } -forward_send_sync!({S} {} VisitResult<S>); - impl<S> VisitResult<S> { pub fn unit_skipped(self) -> VisitResult<()> { match self { diff --git a/src/protocol/visitor/recoverable.rs b/src/protocol/visitor/recoverable.rs index 4f39e8a..ef20345 100644 --- a/src/protocol/visitor/recoverable.rs +++ b/src/protocol/visitor/recoverable.rs @@ -1,7 +1,6 @@ use effectful::{ effective::Effective, - environment::{DynBind, EnvConfig, Environment, NativeForm}, - is_send_sync, + environment::{DynBind, EnvConfig, Environment, NativeForm}, SendSync, }; use crate::{ @@ -23,6 +22,7 @@ pub trait Recoverable<'ctx, E: Environment>: DynBind<E> { ) -> NativeForm<'a, VisitResult, E>; } +#[derive(SendSync)] pub struct RecoverableProto<E: Environment>(Marker<E>); impl<'a, 'ctx, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for RecoverableProto<E> @@ -49,10 +49,9 @@ pub trait RecoverableScope<'ctx, E: Environment>: DynBind<E> { pub type DynRecoverableScope<'a, 'ctx, E> = &'a mut (dyn RecoverableScope<'ctx, E> + 'a); +#[derive(SendSync)] pub struct RecoverableKnown; -is_send_sync!(RecoverableKnown); - impl<'a, 'ctx, E: EnvConfig> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for RecoverableKnown { type T = RecoverableKnown; } diff --git a/src/protocol/visitor/request_hint.rs b/src/protocol/visitor/request_hint.rs index 2fd6255..76de7a0 100644 --- a/src/protocol/visitor/request_hint.rs +++ b/src/protocol/visitor/request_hint.rs @@ -2,7 +2,7 @@ use effectful::{ effective::Effective, environment::{DynBind, Environment, NativeForm}, for_lt, - higher_ranked::Mut, + higher_ranked::Mut, SendSync, }; use crate::{ @@ -27,6 +27,7 @@ pub trait RequestHint<'ctx, E: Environment>: DynBind<E> { 'ctx: 'this + 'walker; } +#[derive(SendSync)] pub struct RequestHintProto<E: Environment>(Marker<E>); impl<'a, 'ctx, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for RequestHintProto<E> diff --git a/src/protocol/visitor/sequence.rs b/src/protocol/visitor/sequence.rs index de9666d..3239faf 100644 --- a/src/protocol/visitor/sequence.rs +++ b/src/protocol/visitor/sequence.rs @@ -1,7 +1,6 @@ use effectful::{ effective::Effective, - environment::{DynBind, EnvConfig, Environment, NativeForm}, - is_send_sync, + environment::{DynBind, EnvConfig, Environment, NativeForm}, SendSync, }; use crate::{ @@ -29,6 +28,7 @@ pub trait Sequence<'ctx, E: Environment>: DynBind<E> { 'ctx: 'a; } +#[derive(SendSync)] pub struct SequenceProto<E: Environment>(Marker<E>); impl<'a, 'ctx, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for SequenceProto<E> @@ -59,13 +59,11 @@ pub trait SequenceScope<'ctx, E: Environment>: DynBind<E> { pub type DynSequenceScope<'a, 'ctx, E> = &'a mut (dyn SequenceScope<'ctx, E> + 'a); -#[derive(Default)] +#[derive(Default, SendSync)] pub struct SequenceKnown { pub len: (usize, Option<usize>), } -is_send_sync!(SequenceKnown, SequenceHint); - impl<'a, 'ctx, E: EnvConfig> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for SequenceKnown { type T = SequenceKnown; } @@ -74,6 +72,7 @@ impl<'a, 'ctx, E: EnvConfig> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> type Higher = SequenceKnown; } +#[derive(SendSync)] pub struct SequenceHint { pub len: (usize, Option<usize>), } diff --git a/src/protocol/visitor/tag.rs b/src/protocol/visitor/tag.rs index 0473f5a..9c5fc16 100644 --- a/src/protocol/visitor/tag.rs +++ b/src/protocol/visitor/tag.rs @@ -4,9 +4,9 @@ use effectful::{ bound::{Bool, IsSend, IsSync}, effective::{Effective, EffectiveExt}, environment::{DynBind, EnvConfig, Environment, NativeForm}, - for_lt, forward_send_sync, + for_lt, higher_ranked::Mut, - is_send_sync, tri, + tri, SendSync, }; use crate::{ @@ -39,17 +39,12 @@ pub trait TagKind<E: EnvConfig>: Copy + DynBind<E> + 'static { fn symbol(&self) -> Symbol; } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, SendSync)] pub struct TagConst<const SYMBOL: u64>; -unsafe impl<F: Bool, const SYMBOL: u64> IsSend<F> for TagConst<SYMBOL> {} -unsafe impl<F: Bool, const SYMBOL: u64> IsSync<F> for TagConst<SYMBOL> {} - -#[derive(Copy, Clone)] +#[derive(Copy, Clone, SendSync)] pub struct TagDyn(pub Symbol); -is_send_sync!(TagDyn); - impl<const SYMBOL: u64, E: EnvConfig> TagKind<E> for TagConst<SYMBOL> { fn symbol(&self) -> Symbol { Symbol::from_int(SYMBOL) @@ -74,6 +69,7 @@ pub trait Tag<'ctx, K: TagKind<E>, E: Environment>: DynBind<E> { ) -> NativeForm<'c, VisitResult, E>; } +#[derive(SendSync)] pub struct TagProto<K: TagKind<E>, E: Environment>(Marker<(K, E)>); impl<'a, 'ctx, K: TagKind<E>, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> @@ -92,12 +88,11 @@ where type Higher = TagProto<K, E>; } +#[derive(SendSync)] pub struct TagKnown { pub kind_available: Option<bool>, } -is_send_sync!(TagKnown); - impl<'a, 'ctx, E: EnvConfig> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for TagKnown { type T = TagKnown; } @@ -106,12 +101,11 @@ impl<'a, 'ctx, E: EnvConfig> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx ()> type Higher = TagKnown; } +#[derive(SendSync)] pub struct TagHint<K> { pub kind: K, } -forward_send_sync!({K} {} {} TagHint<K>); - impl<'a, 'ctx, E: EnvConfig, K: DynBind<E> + 'static> Meta::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> for TagHint<K> { @@ -132,7 +126,7 @@ impl<K: TagKind<E>, E: Environment> HintMeta for TagProto<K, E> { type Effect = E; } -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Debug, PartialEq, Clone, Copy, SendSync)] pub enum TagErrorKind<E> { NeverWalked, @@ -145,15 +139,13 @@ pub enum TagErrorKind<E> { SkippedWasWalked, } -#[derive(Debug, PartialEq, Copy, Clone)] +#[derive(Debug, PartialEq, Copy, Clone, SendSync)] #[allow(unused)] pub struct TagError<E> { symbol: Symbol, err: TagErrorKind<E>, } -forward_send_sync!({E} {} TagError<E>); - impl<E> TagError<E> { fn new<K: TagKind<Env>, Env: EnvConfig>(tag: K, err: E) -> Self { Self { diff --git a/src/protocol/visitor/value.rs b/src/protocol/visitor/value.rs index 59bf907..5a6e7c2 100644 --- a/src/protocol/visitor/value.rs +++ b/src/protocol/visitor/value.rs @@ -5,7 +5,7 @@ use effectful::{ bound::{Bool, IsSend, IsSync}, effective::Effective, - environment::{DynBind, EnvConfig, Environment, NativeForm}, + environment::{DynBind, EnvConfig, Environment, NativeForm}, SendSync, }; use crate::{ @@ -41,6 +41,7 @@ pub trait Value<'ctx, T: ?Sized + TypeName::MemberType<E>, E: Environment>: DynB 'ctx: 'a; } +#[derive(SendSync)] pub struct ValueProto<T: ?Sized + TypeName::MemberType<E>, E: Environment>(Marker<(*const T, E)>); impl<'a, 'ctx, T: ?Sized, E> TypeName::MemberTypeForLt<'a, 'ctx, E, &'a &'ctx ()> @@ -61,7 +62,7 @@ where type Higher = ValueProto<T, E>; } -#[derive(Copy, Clone, PartialEq, Debug)] +#[derive(Copy, Clone, PartialEq, Debug, SendSync)] pub struct ValueKnown<'a, T: ?Sized> { /// A preview of the value. /// @@ -69,10 +70,7 @@ pub struct ValueKnown<'a, T: ?Sized> { pub preview: Option<&'a T>, } -unsafe impl<'a, T: ?Sized + IsSync<F>, F: Bool> IsSend<F> for ValueKnown<'a, T> {} -unsafe impl<'a, T: ?Sized + IsSync<F>, F: Bool> IsSync<F> for ValueKnown<'a, T> {} - -#[derive(Copy, Clone, Debug)] +#[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 ()> diff --git a/src/protocol/walker/hint.rs b/src/protocol/walker/hint.rs index 2084b5b..5d1dee9 100644 --- a/src/protocol/walker/hint.rs +++ b/src/protocol/walker/hint.rs @@ -10,7 +10,7 @@ use effectful::{ bound::{IsSend, IsSync}, effective::Effective, environment::{DynBind, EnvConfig, Environment, NativeForm}, - higher_ranked::Mut, + higher_ranked::Mut, SendSync, }; use crate::{ @@ -24,7 +24,7 @@ use crate::{ pub mod Meta { use effectful::environment::{DynBind, EnvConfig}; - pub trait MemberTypeForLt<'a, 'ctx: 'a, E: EnvConfig, B> { + pub trait MemberTypeForLt<'a, 'ctx: 'a, E: EnvConfig, B>: DynBind<E> { type T: ?Sized + LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx (), Higher = Self>; } @@ -68,7 +68,7 @@ impl<'a, 'ctx: 'a, E: EnvConfig> Meta::LowerTypeWithBound<'a, 'ctx, E, &'a &'ctx /// Meta information for the hint. /// /// This gives the visitor more information to work from when selecting a hint. -pub trait HintMeta: TypeName::MemberType<Self::Effect> + 'static { +pub trait HintMeta: Send + Sync + TypeName::MemberType<Self::Effect> + 'static { /// Information known by the walker. /// /// This should be information easy to get without changing the state of the walker @@ -106,21 +106,12 @@ pub trait Hint<'ctx, Protocol: ?Sized + HintMeta>: DynBind<Protocol::Effect> { ) -> NativeForm<'a, Result<MetaKnown<'a, 'ctx, Protocol>, ()>, Protocol::Effect>; } +#[derive(SendSync)] pub struct DynVisitorWith<'temp, 'ctx, Protocol: ?Sized + HintMeta> { visitor: DynVisitor<'temp, 'ctx, Protocol::Effect>, _marker: Marker<Protocol>, } -unsafe impl<'a, 'ctx, P: HintMeta> IsSend<<P::Effect as EnvConfig>::NeedSend> - for DynVisitorWith<'a, 'ctx, P> -{ -} - -unsafe impl<'a, 'ctx, P: HintMeta> IsSync<<P::Effect as EnvConfig>::NeedSync> - for DynVisitorWith<'a, 'ctx, P> -{ -} - pub trait HasProtocol<Protocol: ?Sized> {} impl<'temp, 'ctx: 'temp, Protocol: ?Sized + HintMeta> DynVisitorWith<'temp, 'ctx, Protocol> { @@ -157,6 +148,7 @@ impl<'temp, 'ctx, Protocol: ?Sized + HintMeta> DerefMut for DynVisitorWith<'temp } } +#[derive(SendSync)] pub struct HintProto<Protocol: ?Sized>(Marker<Protocol>); impl<'a, 'ctx, Protocol: ?Sized> TypeName::MemberTypeForLt<'a, 'ctx, Protocol::Effect, &'a &'ctx ()> diff --git a/src/symbol.rs b/src/symbol.rs index 1809897..63606ca 100644 --- a/src/symbol.rs +++ b/src/symbol.rs @@ -5,6 +5,7 @@ // arithmetic coding consider the https://docs.rs/arcode/latest/arcode/ crate. // This algorithm is able to compress about 10-12 characters into a u64. +use effectful::SendSync; use range::*; /// Unique symbol, given a unique tag. @@ -21,7 +22,7 @@ use range::*; /// /// Internally each [`Symbol`] is just a [`u64`]. As such, a [`Symbol`] is very cheap /// to copy and compare. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, SendSync)] #[repr(transparent)] pub struct Symbol(u64); diff --git a/src/transform.rs b/src/transform.rs index 6930ba1..2f57a90 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -1,7 +1,7 @@ use effectful::{ block_on::Spin, blocking::Blocking, - bound::{Ds, No, Ss, Yes, D}, + bound::{No, Yes, DynamicShim}, effective::Effective, environment::{Cfg, Environment, NativeForm}, higher_ranked::Mut, @@ -109,7 +109,7 @@ pub trait BuildExt { <Self::Builder as BuilderTypes<Async<Cfg<Spin, Yes, Yes>>>>::Seed: Default, W: Walker<'ctx, Async<Cfg<Spin, Yes, Yes>>>, { - let walker = Ds(walker); + let walker = DynamicShim(walker); async { let walker = walker; match transform::<Self::Builder, _, _>(Default::default(), walker.0) diff --git a/src/walk.rs b/src/walk.rs index fa7fcae..8eb5656 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -7,6 +7,7 @@ use effectful::{ effective::Effective, environment::{DynBind, Environment, NativeForm}, higher_ranked::Mut, + SendSync, }; use crate::{protocol::DynVisitor, Flow}; @@ -61,6 +62,7 @@ pub trait WalkerObjSafe<'ctx, E: Environment>: DynBind<E> { pub type DynWalkerObjSafe<'a, 'ctx, E> = &'a mut (dyn WalkerObjSafe<'ctx, E> + 'a); +#[derive(SendSync)] enum DynWalkerState<'ctx, W: Walker<'ctx, E>, E: Environment> { Walking, Pending(W), @@ -80,20 +82,11 @@ pub enum DynWalkerError<'ctx, W: Walker<'ctx, E>, E: Environment> { WasWalked(W::Output), } +#[derive(SendSync)] pub struct DynWalkerAdapter<'ctx, W: Walker<'ctx, E>, E: Environment> { state: DynWalkerState<'ctx, W, E>, } -unsafe impl<'ctx, W: Walker<'ctx, E>, E: Environment> IsSend<E::NeedSend> - for DynWalkerAdapter<'ctx, W, E> -{ -} - -unsafe impl<'ctx, W: Walker<'ctx, E>, E: Environment> IsSync<E::NeedSync> - for DynWalkerAdapter<'ctx, W, E> -{ -} - impl<'ctx, W: Walker<'ctx, E>, E: Environment> DynWalkerAdapter<'ctx, W, E> { #[inline(always)] pub fn new(walker: W) -> Self { @@ -125,6 +118,8 @@ impl<'ctx, W: Walker<'ctx, E>, E: Environment> DynWalkerAdapter<'ctx, W, E> { impl<'ctx, W: Walker<'ctx, E>, E: Environment> WalkerObjSafe<'ctx, E> for DynWalkerAdapter<'ctx, W, E> +where + Self: DynBind<E>, { #[inline(always)] fn walk<'a: 'c, 'b: 'c, 'c>( diff --git a/src/walk/walkers/core/int.rs b/src/walk/walkers/core/int.rs index bef10d8..bf6b8c8 100644 --- a/src/walk/walkers/core/int.rs +++ b/src/walk/walkers/core/int.rs @@ -1,7 +1,7 @@ use effectful::effective::Effective; use effectful::environment::{DynBind, Environment, NativeForm}; -use effectful::forward_send_sync; use effectful::higher_ranked::Mut; +use effectful::SendSync; use crate::{ any::OwnedStatic, @@ -18,13 +18,12 @@ use crate::{ Flow, Walker, }; +#[derive(SendSync)] pub struct IntegerWalker<T, E> { value: T, _marker: Marker<E>, } -forward_send_sync!({T} {} {E} IntegerWalker<T, E>); - pub trait Integer: 'static + Copy @@ -58,12 +57,11 @@ impl<'ctx, T, E> IntegerWalker<T, E> { } } +#[derive(SendSync)] pub struct IntegerWalkerError<T> { value: T, } -forward_send_sync!({T} {} IntegerWalkerError<T>); - impl<T: Integer> ::core::fmt::Debug for IntegerWalkerError<T> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("IntegerWalkerError") diff --git a/src/walk/walkers/core/key_value.rs b/src/walk/walkers/core/key_value.rs index e1b38ac..66e04ec 100644 --- a/src/walk/walkers/core/key_value.rs +++ b/src/walk/walkers/core/key_value.rs @@ -1,7 +1,6 @@ use effectful::{ effective::Effective, - environment::{Environment, NativeForm}, - forward_send_sync, + environment::{Environment, NativeForm}, SendSync, }; use crate::{ @@ -13,14 +12,13 @@ use crate::{ Flow, }; +#[derive(SendSync)] pub struct KeyValueWalker<T, K, V> { key_walker: K, value_walker: V, _tag: T, } -forward_send_sync!({T, K, V} {} KeyValueWalker<T, K, V>); - impl<T, K, V> KeyValueWalker<T, K, V> { #[inline(always)] pub fn new(tag: T, key_walker: K, value_walker: V) -> Self { @@ -32,7 +30,7 @@ impl<T, K, V> KeyValueWalker<T, K, V> { } } -#[derive(Debug)] +#[derive(Debug, SendSync)] #[allow(unused)] enum KeyValueErrorKind<K, V> { Tag(TagError<Never>), @@ -40,11 +38,9 @@ enum KeyValueErrorKind<K, V> { Value(V), } -#[derive(Debug)] +#[derive(Debug, SendSync)] pub struct KeyValueError<K, V>(KeyValueErrorKind<K, V>); -forward_send_sync!({K, V} {} KeyValueError<K, V>); - impl<'ctx, T, K, V, E> crate::Walker<'ctx, E> for KeyValueWalker<T, K, V> where E: Environment, diff --git a/src/walk/walkers/core/noop.rs b/src/walk/walkers/core/noop.rs index 0229048..81425c3 100644 --- a/src/walk/walkers/core/noop.rs +++ b/src/walk/walkers/core/noop.rs @@ -1,7 +1,6 @@ use effectful::{ effective::Effective, - environment::{Environment, NativeForm}, - is_send_sync, + environment::{Environment, NativeForm}, SendSync, }; use crate::{never::Never, protocol::DynVisitor}; @@ -10,11 +9,9 @@ use crate::{never::Never, protocol::DynVisitor}; /// /// This walker is useful for tags that don't need a value. #[non_exhaustive] -#[derive(Debug, Default)] +#[derive(Debug, Default, SendSync)] pub struct NoopWalker; -is_send_sync!(NoopWalker); - impl NoopWalker { pub fn new() -> Self { Self diff --git a/src/walk/walkers/core/struct.rs b/src/walk/walkers/core/struct.rs index 3150273..c4a9d49 100644 --- a/src/walk/walkers/core/struct.rs +++ b/src/walk/walkers/core/struct.rs @@ -3,8 +3,7 @@ use core::any::TypeId; use effectful::{ bound::{IsSend, IsSync}, effective::Effective, - environment::{DynBind, Environment, NativeForm}, - forward_send_sync, + environment::{DynBind, Environment, NativeForm}, SendSync, }; use crate::{ @@ -31,6 +30,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. +#[derive(SendSync)] pub struct StructWalker<'ctx, I: StructTypeInfo<'ctx, M, E, S = S>, S, M, E: Environment> { /// Struct value to walk. value: &'ctx I::T, @@ -46,15 +46,6 @@ 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> -{ -} - /// Type info about a struct needed by [`StructWalker`]. pub trait StructTypeInfo<'ctx, M, E: Environment>: 'static { /// Name of the struct. @@ -79,7 +70,7 @@ pub trait StructTypeInfo<'ctx, M, E: Environment>: 'static { ) -> NativeForm<'a, Result<Flow, Self::FieldError>, E>; } -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Debug, PartialEq, Clone, Copy, SendSync)] #[allow(unused)] enum StructWalkErrorKind<T> { /// Error with visiting a tag for the struct. @@ -97,14 +88,12 @@ enum StructWalkErrorKind<T> { } /// Error from walking a struct. -#[derive(Debug, PartialEq, Copy, Clone)] +#[derive(Debug, PartialEq, Copy, Clone, SendSync)] #[allow(unused)] pub struct StructWalkError<T> { kind: StructWalkErrorKind<T>, } -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>, @@ -229,6 +218,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 + Self: DynBind<E>, E: Environment, I: StructTypeInfo<'ctx, M, E, S = S>, { @@ -282,6 +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 + Self: DynBind<E>, E: Environment, I: StructTypeInfo<'ctx, M, E, S = S>, { @@ -331,6 +322,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 + Self: DynBind<E>, E: Environment, I: StructTypeInfo<'ctx, M, E, S = S>, { @@ -376,6 +368,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 + Self: DynBind<E>, E: Environment, I: StructTypeInfo<'ctx, M, E, S = S>, { @@ -423,6 +416,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 + Self: DynBind<E>, E: Environment, I: StructTypeInfo<'ctx, M, E, S = StaticType>, I::T: 'static, @@ -472,6 +466,7 @@ where impl<'ctx, I, M, E> Hint<'ctx, TagProto<TagDyn, E>> for StructWalker<'ctx, I, StaticType, M, E> where + Self: DynBind<E>, E: Environment, I: StructTypeInfo<'ctx, M, E, S = StaticType>, I::T: 'static, @@ -575,6 +570,7 @@ where impl<'ctx, I, S, M: 'ctx, E> Hint<'ctx, SequenceProto<E>> for StructWalker<'ctx, I, S, M, E> where + Self: DynBind<E>, E: Environment, I: StructTypeInfo<'ctx, M, E, S = S>, { @@ -621,6 +617,7 @@ where impl<'ctx, I, S, M: 'ctx, E> SequenceScope<'ctx, E> for StructWalker<'ctx, I, S, M, E> where + Self: DynBind<E>, E: Environment, I: StructTypeInfo<'ctx, M, E, S = S>, { diff --git a/src/walk/walkers/core/tag.rs b/src/walk/walkers/core/tag.rs index 378c063..40303ab 100644 --- a/src/walk/walkers/core/tag.rs +++ b/src/walk/walkers/core/tag.rs @@ -3,8 +3,7 @@ use core::marker::PhantomData; use effectful::{ bound::IsSync, effective::Effective, - environment::{Environment, NativeForm}, - forward_send_sync, + environment::{Environment, NativeForm}, SendSync, }; use crate::{ @@ -17,14 +16,13 @@ use crate::{ Flow, }; +#[derive(SendSync)] pub struct StaticSliceWalker<T: 'static, W> { names: &'static [T], current: usize, _marker: PhantomData<fn() -> W>, } -forward_send_sync!({} {T: ('static)} {W} StaticSliceWalker<T, W>); - impl<T, W> StaticSliceWalker<T, W> { pub fn new(names: &'static [T]) -> Self { Self { diff --git a/src/walk/walkers/core/value.rs b/src/walk/walkers/core/value.rs index d3f9159..9baea0e 100644 --- a/src/walk/walkers/core/value.rs +++ b/src/walk/walkers/core/value.rs @@ -1,8 +1,7 @@ use effectful::{ bound::IsSync, effective::Effective, - environment::{DynBind, Environment, NativeForm}, - forward_send_sync, + environment::{DynBind, Environment, NativeForm}, SendSync, }; use crate::{ @@ -18,11 +17,9 @@ use crate::{ /// /// Primitive types use this walker as their main walker. /// This walker doesn't consider it an error if the visitor doesn't have the protocol. -#[derive(Debug)] +#[derive(Debug, SendSync)] pub struct ValueWalker<T>(T); -forward_send_sync!({T} {} ValueWalker<T>); - impl<T> ValueWalker<T> { /// Create walker from a value. #[inline(always)] @@ -68,10 +65,9 @@ where /// Borrowed form of [`ValueWalker`]. /// /// This walker supports values borrowed for `'ctx` or longer. +#[derive(SendSync)] pub struct BorrowWalker<'ctx, T: ?Sized>(&'ctx T); -forward_send_sync!({} {T: (?Sized + 'ctx)} {{'ctx}} BorrowWalker<'ctx, T>); - impl<'ctx, T: ?Sized> BorrowWalker<'ctx, T> { /// Create walker from a value. #[inline(always)] diff --git a/tests/builder_enum.rs b/tests/builder_enum.rs index 7eb4574..91ab6ac 100644 --- a/tests/builder_enum.rs +++ b/tests/builder_enum.rs @@ -18,23 +18,19 @@ use crate::common::{ }; use effectful::{ - environment::{Environment, NativeForm}, - effective::Effective, - is_send_sync, + effective::Effective, environment::{Environment, NativeForm}, SendSync }; use macro_rules_attribute::derive; mod common; -#[derive(Build!, PartialEq, Debug)] +#[derive(Build!, PartialEq, Debug, SendSync)] enum X { A(f32), B(bool), } -is_send_sync!(X); - #[test] fn enum_builder_takes_unsigned_integer_variant_tag() { let mut builder = X::new_builder(); diff --git a/tests/builder_struct.rs b/tests/builder_struct.rs index f8eb0d6..d63e572 100644 --- a/tests/builder_struct.rs +++ b/tests/builder_struct.rs @@ -1,4 +1,4 @@ -use effectful::is_send_sync; +use effectful::SendSync; use macro_rules_attribute::derive; use treaty::{ any::{OwnedStatic, TempBorrowedStatic}, @@ -18,14 +18,12 @@ use crate::common::{ mod common; -#[derive(Build!, Debug, PartialEq)] +#[derive(Build!, Debug, PartialEq, SendSync)] struct X { a: bool, b: bool, } -is_send_sync!(X); - #[test] fn a_struct_builder_can_build_from_a_sequence_of_field_values() { let mut scope; diff --git a/tests/common/builder.rs b/tests/common/builder.rs index 64d77f9..b2bb1ff 100644 --- a/tests/common/builder.rs +++ b/tests/common/builder.rs @@ -1,9 +1,6 @@ use core::fmt::{Debug, Display}; use effectful::{ - bound::{Bool, IsSend, IsSync}, - environment::{DynBind, Environment, NativeForm}, - effective::Effective, - forward_send_sync, + bound::{Bool, DynamicShim, IsSend, IsSync}, effective::Effective, environment::{DynBind, Environment, NativeForm}, forward_send_sync, SendSync }; use mockall::mock; use treaty::{ @@ -14,11 +11,11 @@ use treaty::{ use crate::common::{ContextLock, StaticTypeMap}; -use self::__mock_MockBuilder::__from_seed::Context; - use super::ContextGuard; -#[derive(Debug)] +use crate::common::builder::__mock_MockBuilder::__from_seed::Context; + +#[derive(Debug, SendSync)] pub struct EmptyError; impl Display for EmptyError { @@ -32,21 +29,12 @@ mock! { pub fn from_seed(seed: Seed) -> Self; pub fn build(self) -> Result<Value, Error>; - pub fn traits(&self, id: TypeNameId) -> &Option<Box<dyn for<'ctx> AnyTrait<'ctx, E>>>; - pub fn traits_mut(&mut self, id: TypeNameId) -> &mut Option<Box<dyn for<'ctx> AnyTrait<'ctx, E>>>; + pub fn traits(&self, id: TypeNameId) -> &Option<Box<DynamicShim<dyn for<'ctx> AnyTrait<'ctx, E>>>>; + pub fn traits_mut(&mut self, id: TypeNameId) -> &mut Option<Box<DynamicShim<dyn for<'ctx> AnyTrait<'ctx, E>>>>; } } -// forward_send_sync!({Seed: ('static), Value: ('static), Error: ('static)} {} {E: (Environment)} MockBuilder<Seed, Value, Error, E>); - -unsafe impl<Seed: 'static, Value: 'static, Error: 'static, E: Environment, F: Bool> IsSend<F> - for MockBuilder<Seed, Value, Error, E> -{ -} -unsafe impl<Seed: 'static, Value: 'static, Error: 'static, E: Environment, F: Bool> IsSync<F> - for MockBuilder<Seed, Value, Error, E> -{ -} +forward_send_sync!({Seed: ('static), Value: ('static), Error: ('static)} {} {E: (Environment)} MockBuilder<Seed, Value, Error, E>); impl<Seed, Value, Error: Display + Debug, E: Environment> BuilderTypes<E> for MockBuilder<Seed, Value, Error, E> @@ -103,6 +91,10 @@ impl< impl<'ctx, Seed, Value, Error: Display + Debug, E: Environment> AsVisitor<'ctx, E> for MockBuilder<Seed, Value, Error, E> +where + Seed: DynBind<E>, + Value: DynBind<E>, + Error: DynBind<E>, { fn as_visitor<'a>(&'a mut self) -> DynVisitor<'a, 'ctx, E> where @@ -114,6 +106,10 @@ impl<'ctx, Seed, Value, Error: Display + Debug, E: Environment> AsVisitor<'ctx, impl<'ctx, Seed, Value, Error, E: Environment> AnyTrait<'ctx, E> for MockBuilder<Seed, Value, Error, E> +where + Seed: DynBind<E>, + Value: DynBind<E>, + Error: DynBind<E>, { fn upcast_to_id<'a>( &'a self, @@ -123,7 +119,7 @@ impl<'ctx, Seed, Value, Error, E: Environment> AnyTrait<'ctx, E> 'ctx: 'a, { // Find the first trait handler that wants to upcast. - self.traits(id).as_ref().and_then(|t| t.upcast_to_id(id)) + self.traits(id).as_ref().and_then(|t| t.0.upcast_to_id(id)) } fn upcast_to_id_mut<'a>( @@ -136,7 +132,7 @@ impl<'ctx, Seed, Value, Error, E: Environment> AnyTrait<'ctx, E> // Find the first trait handler that wants to upcast. self.traits_mut(id) .as_mut() - .and_then(|t| t.upcast_to_id_mut(id)) + .and_then(|t| t.0.upcast_to_id_mut(id)) } type Available = () where Self: Sized; diff --git a/tests/common/mod.rs b/tests/common/mod.rs index a856898..e5f4cc3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,4 +1,5 @@ #![allow(unused)] +#![deny(unsafe_code)] use core::{ any::{Any, TypeId}, diff --git a/tests/common/protocol/hint.rs b/tests/common/protocol/hint.rs index 5884132..2bc6c7f 100644 --- a/tests/common/protocol/hint.rs +++ b/tests/common/protocol/hint.rs @@ -2,6 +2,7 @@ use effectful::{ bound::{Bool, IsSend, IsSync}, effective::Effective, environment::{Environment, NativeForm}, + forward_send_sync, }; use mockall::mock; use treaty::{ @@ -25,8 +26,7 @@ mock! { } } -unsafe impl<P: HintMeta, F: Bool> IsSend<F> for MockHintWalker<P> {} -unsafe impl<P: HintMeta, F: Bool> IsSync<F> for MockHintWalker<P> {} +forward_send_sync!({} {} {P: (HintMeta)} MockHintWalker<P>); any_trait! { impl['ctx, P][E] MockHintWalker<P> = [ diff --git a/tests/common/protocol/recoverable.rs b/tests/common/protocol/recoverable.rs index 9f98afb..0f84369 100644 --- a/tests/common/protocol/recoverable.rs +++ b/tests/common/protocol/recoverable.rs @@ -3,6 +3,7 @@ use effectful::{ bound::{Bool, IsSend, IsSync}, effective::Effective, environment::{Environment, NativeForm}, + forward_send_sync, }; use mockall::mock; use treaty::{ @@ -21,13 +22,12 @@ use treaty::{ use crate::common::Blocking; mock! { - pub RecoverableVisitor<E> { + pub RecoverableVisitor<E: Environment> { pub fn visit<'a, 'ctx>(&mut self, scope: DynRecoverableScope<'a, 'ctx, E>) -> VisitResult; } } -unsafe impl<E: Environment, F: Bool> IsSend<F> for MockRecoverableVisitor<E> {} -unsafe impl<E: Environment, F: Bool> IsSync<F> for MockRecoverableVisitor<E> {} +forward_send_sync!({} {} {E: (Environment)} MockRecoverableVisitor<E>); any_trait! { impl['ctx][E] MockRecoverableVisitor<E> = [ @@ -51,8 +51,7 @@ mock! { } } -unsafe impl<E: Environment, F: Bool> IsSend<F> for MockRecoverableScopeVisitor<E> {} -unsafe impl<E: Environment, F: Bool> IsSync<F> for MockRecoverableScopeVisitor<E> {} +forward_send_sync!({} {} {E: (Environment)} MockRecoverableScopeVisitor<E>); impl<'ctx, E: Environment> RecoverableScope<'ctx, E> for MockRecoverableScopeVisitor<E> { fn new_walk<'a: 'c, 'b: 'c, 'c>( diff --git a/tests/common/protocol/request_hint.rs b/tests/common/protocol/request_hint.rs index 83de82b..9ba68f7 100644 --- a/tests/common/protocol/request_hint.rs +++ b/tests/common/protocol/request_hint.rs @@ -1,7 +1,7 @@ use effectful::{ bound::{Bool, IsSend, IsSync}, effective::Effective, - environment::{Environment, NativeForm}, + environment::{Environment, NativeForm}, forward_send_sync, }; use mockall::mock; use treaty::{ @@ -17,8 +17,7 @@ mock! { } } -unsafe impl<E: Environment, F: Bool> IsSend<F> for MockRequestHintVisitor<E> {} -unsafe impl<E: Environment, F: Bool> IsSync<F> for MockRequestHintVisitor<E> {} +forward_send_sync!({} {} {E: (Environment)} MockRequestHintVisitor<E>); any_trait! { impl['ctx][E] MockRequestHintVisitor<E> = [ diff --git a/tests/common/protocol/sequence.rs b/tests/common/protocol/sequence.rs index c580f05..12b4e05 100644 --- a/tests/common/protocol/sequence.rs +++ b/tests/common/protocol/sequence.rs @@ -1,7 +1,7 @@ use effectful::{ bound::{Bool, IsSend, IsSync}, effective::Effective, - environment::{Environment, NativeForm}, + environment::{Environment, NativeForm}, forward_send_sync, }; use mockall::mock; use treaty::{ @@ -23,8 +23,7 @@ mock! { } } -unsafe impl<E: Environment, F: Bool> IsSend<F> for MockSequenceVisitor<E> {} -unsafe impl<E: Environment, F: Bool> IsSync<F> for MockSequenceVisitor<E> {} +forward_send_sync!({} {} {E: (Environment)} MockSequenceVisitor<E>); any_trait! { impl['ctx][E] MockSequenceVisitor<E> = [ @@ -49,8 +48,7 @@ mock! { } } -unsafe impl<E: Environment, F: Bool> IsSend<F> for MockSequenceScope<E> {} -unsafe impl<E: Environment, F: Bool> IsSync<F> for MockSequenceScope<E> {} +forward_send_sync!({} {} {E: (Environment)} MockSequenceScope<E>); impl<'ctx, E: Environment> SequenceScope<'ctx, E> for MockSequenceScope<E> { fn size_hint(&mut self) -> NativeForm<'_, (usize, Option<usize>), E> { diff --git a/tests/common/protocol/tag.rs b/tests/common/protocol/tag.rs index 9ce76f3..4c17eda 100644 --- a/tests/common/protocol/tag.rs +++ b/tests/common/protocol/tag.rs @@ -2,6 +2,7 @@ use effectful::{ bound::{Bool, IsSend, IsSync}, effective::Effective, environment::{Environment, NativeForm}, + forward_send_sync, }; use mockall::mock; use treaty::{ @@ -21,6 +22,8 @@ mock! { } } +forward_send_sync!({K: (TagKind<E>)} {} {E: (Environment)} MockTagVisitor<K, E>); + any_trait! { impl['ctx, K][E] MockTagVisitor<K, E> = [ TagProto<K, E>, @@ -29,9 +32,6 @@ any_trait! { E: Environment, } -unsafe impl<K: TagKind<E>, E: Environment, F: Bool> IsSend<F> for MockTagVisitor<K, E> {} -unsafe impl<K: TagKind<E>, E: Environment, F: Bool> IsSync<F> for MockTagVisitor<K, E> {} - impl<'ctx, K: TagKind<E>, E: Environment> Tag<'ctx, K, E> for MockTagVisitor<K, E> { fn visit<'a: 'c, 'b: 'c, 'c>( &'a mut self, diff --git a/tests/common/protocol/value.rs b/tests/common/protocol/value.rs index fe470fa..038853a 100644 --- a/tests/common/protocol/value.rs +++ b/tests/common/protocol/value.rs @@ -2,6 +2,7 @@ use effectful::{ environment::{Environment, NativeForm}, bound::{Bool, IsSend, IsSync}, effective::Effective, + forward_send_sync, }; use mockall::mock; use treaty::{ @@ -24,14 +25,9 @@ mock! { } } -unsafe impl<T: TypeName::MemberType<E>, E: Environment, F: Bool> IsSend<F> for MockValueVisitor<T, E> -where - for<'a, 'ctx> TypeName::T<'a, 'ctx, T, E>: Sized - {} -unsafe impl<T: TypeName::MemberType<E>, E: Environment, F: Bool> IsSync<F> for MockValueVisitor<T, E> -where - for<'a, 'ctx> TypeName::T<'a, 'ctx, T, E>: Sized - {} +forward_send_sync!({T: (TypeName::MemberType<E>)} {} {E: (Environment)} MockValueVisitor<T, E> where { + for<'a, 'ctx> TypeName::T<'a, 'ctx, T, E>: Sized +}); any_trait! { impl['ctx, T][E] MockValueVisitor<T, E> = [ diff --git a/tests/common/walker.rs b/tests/common/walker.rs index 7e90b7e..b64e0f6 100644 --- a/tests/common/walker.rs +++ b/tests/common/walker.rs @@ -2,6 +2,7 @@ use effectful::{ effective::Effective, bound::{Bool, IsSend, IsSync}, environment::{Environment, NativeForm, DynBind}, + forward_send_sync, }; use mockall::mock; use treaty::{ @@ -20,14 +21,7 @@ mock! { } } -unsafe impl<Output, Error, E: Environment, F: Bool> IsSend<F> - for MockWalker<Output, Error, E> -{ -} -unsafe impl<Output, Error, E: Environment, F: Bool> IsSync<F> - for MockWalker<Output, Error, E> -{ -} +forward_send_sync!({Output, Error} {} {E: (Environment)} MockWalker<Output, Error, E>); impl<'ctx, Output: DynBind<E>, Error: DynBind<E> + core::fmt::Debug, E: Environment> Walker<'ctx, E> for MockWalker<Output, Error, E> @@ -47,7 +41,7 @@ impl<'ctx, Output: DynBind<E>, Error: DynBind<E> + core::fmt::Debug, E: Environm } } -impl<'ctx, Output, Error, E: Environment> AnyTrait<'ctx, E> for MockWalker<Output, Error, E> { +impl<'ctx, Output: DynBind<E>, Error: DynBind<E>, E: Environment> AnyTrait<'ctx, E> for MockWalker<Output, Error, E> { fn upcast_to_id<'a>( &'a self, id: TypeNameId, diff --git a/tests/protocol_visitor_value.rs b/tests/protocol_visitor_value.rs index cd835ea..a566670 100644 --- a/tests/protocol_visitor_value.rs +++ b/tests/protocol_visitor_value.rs @@ -4,7 +4,7 @@ use common::protocol::{ hint::{KnownFactory, MockHintWalker}, value::MockValueVisitor, }; -use effectful::is_send_sync; +use effectful::SendSync; use mockall::predicate::eq; use treaty::{ any::{ @@ -29,11 +29,9 @@ mod common; #[test] fn custom_value_type() { // The value we want to visit in the value visitor. - #[derive(PartialEq, Debug, Clone)] + #[derive(PartialEq, Debug, Clone, SendSync)] struct MyValue; - is_send_sync!(MyValue); - let mut mock = MockValueVisitor::<OwnedStatic<MyValue>, Blocking>::new(); // Expect the visit method to be called once with the custom type. diff --git a/tests/protocol_walker_hint.rs b/tests/protocol_walker_hint.rs index 0751a11..b1b2092 100644 --- a/tests/protocol_walker_hint.rs +++ b/tests/protocol_walker_hint.rs @@ -1,6 +1,6 @@ use std::any::TypeId; -use effectful::is_send_sync; +use effectful::SendSync; use treaty::{ any::{TypeName, TypeNameId}, protocol::walker::hint::{self, HintMeta, HintProto}, @@ -302,10 +302,9 @@ mod common; #[test] fn hint_proto() { + #[derive(SendSync)] struct MyProtocol; - is_send_sync!(MyProtocol); - impl<'a, 'ctx> TypeName::MemberTypeForLt<'a, 'ctx, Blocking, &'a &'ctx ()> for MyProtocol { type T = MyProtocol; } diff --git a/tests/walker_struct.rs b/tests/walker_struct.rs index 160e9b0..f4cc910 100644 --- a/tests/walker_struct.rs +++ b/tests/walker_struct.rs @@ -1,5 +1,5 @@ use effectful::{ - bound::ForceDynamic, effective::Effective, environment::{Environment, NativeForm}, is_send_sync + bound::{DynamicShim, ForceDynamic}, effective::Effective, environment::{Environment, NativeForm}, SendSync }; use mockall::predicate::eq; use treaty::{ @@ -20,13 +20,12 @@ use crate::common::{ mod common; +#[derive(SendSync)] struct X { a: bool, b: i32, } -is_send_sync!(X); - struct Info; // This gives the struct walker enough information to walk the X struct. @@ -136,7 +135,7 @@ fn sequence_of_field_values() { .with(eq(OwnedStatic(true))) .return_const(Flow::Done); - Some(Box::new(visitor)) + Some(Box::new(DynamicShim(visitor))) }); assert_eq!( @@ -166,7 +165,7 @@ fn sequence_of_field_values() { .with(eq(OwnedStatic(42))) .return_const(Flow::Done); - Some(Box::new(visitor)) + Some(Box::new(DynamicShim(visitor))) }); assert_eq!( @@ -179,7 +178,7 @@ fn sequence_of_field_values() { VisitResult::Control(Flow::Done) }); - Some(Box::new(visitor)) + Some(Box::new(DynamicShim(visitor))) }); // All other protocols are not used for this test. @@ -230,7 +229,7 @@ fn has_struct_tag() { VisitResult::Control(Flow::Done) }); - Some(Box::new(visitor)) + Some(Box::new(DynamicShim(visitor))) }); // Walk the struct. @@ -280,7 +279,7 @@ fn has_map_backup_tag() { VisitResult::Control(Flow::Done) }); - Some(Box::new(visitor)) + Some(Box::new(DynamicShim(visitor))) }); // Walk the struct. @@ -333,7 +332,7 @@ fn borrowed_value_directly() { VisitResult::Control(Flow::Done) }); - Some(Box::new(visitor)) + Some(Box::new(DynamicShim(visitor))) }); // Walk the struct. |