diff --git a/CHANGELOG.md b/CHANGELOG.md index f21ca7b..aaa8435 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 36.1.1-rc3 (api=2.0.0, abi=2.0.0) +- Allow structures to compute their single-niche evaluation properly. + # 36.1.1-rc2 (api=2.0.0, abi=2.0.0) - Add the `#[stabby::vt_attr(_)]` sub-attribute to `#[stabby::stabby]` on traits, letting you place custom attributes on the v-tables generated for a trait. - Add support for `core::ffi::c_void`. diff --git a/Cargo.toml b/Cargo.toml index 860f1bc..b336357 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,12 +33,12 @@ license = " EPL-2.0 OR Apache-2.0" categories = ["development-tools::ffi", "no-std::no-alloc"] repository = "https://github.com/ZettaScaleLabs/stabby" readme = "stabby/README.md" -version = "36.1.1-rc2" # Track +version = "36.1.1-rc3" # Track [workspace.dependencies] -stabby-macros = { path = "./stabby-macros/", version = "36.1.1-rc2", default-features = false } # Track -stabby-abi = { path = "./stabby-abi/", version = "36.1.1-rc2", default-features = false } # Track -stabby = { path = "./stabby/", version = "36.1.1-rc2", default-features = false } # Track +stabby-macros = { path = "./stabby-macros/", version = "36.1.1-rc3", default-features = false } # Track +stabby-abi = { path = "./stabby-abi/", version = "36.1.1-rc3", default-features = false } # Track +stabby = { path = "./stabby/", version = "36.1.1-rc3", default-features = false } # Track abi_stable = "0.11.0" libc = "0.2" diff --git a/stabby-abi/src/istable.rs b/stabby-abi/src/istable.rs index 11c03e9..3713150 100644 --- a/stabby-abi/src/istable.rs +++ b/stabby-abi/src/istable.rs @@ -385,9 +385,13 @@ unsafe impl IStable for FieldPair { ::BitOr< as IStable>::UnusedBits>; type Size = as IStable>::Size; type Align = ::Max; - type HasExactlyOneNiche = ::SaturatingAdd< - as IStable>::HasExactlyOneNiche, - >; + type HasExactlyOneNiche = + <::Equal<::Add> as Bit>::SaddTernary< + ::SaturatingAdd< + as IStable>::HasExactlyOneNiche, + >, + Saturator, + >; type ContainsIndirections = ::Or; #[cfg(feature = "experimental-ctypes")] type CType = (); @@ -426,6 +430,7 @@ impl ISaturatingAdd for Saturator { type SaturatingAddB1 = Saturator; type SaturatingAdd = Saturator; } +#[derive(Default)] /// An Exception-like value that indicates a computation can never succeed. pub struct Saturator; @@ -553,7 +558,10 @@ unsafe impl IStable for Struct { type ForbiddenValues = T::ForbiddenValues; type UnusedBits = ::BitOr< <::NextMultipleOf - T::Size) as IUnsignedBase>::PaddingBitMask as IBitMask>::Shift>; - type HasExactlyOneNiche = Saturator; + type HasExactlyOneNiche = <::Equal as Bit>::SaddTernary< + T::HasExactlyOneNiche, + Saturator, + >; type ContainsIndirections = T::ContainsIndirections; #[cfg(feature = "experimental-ctypes")] type CType = (); diff --git a/stabby/src/tests/layouts.rs b/stabby/src/tests/layouts.rs index b16b3ff..d245270 100644 --- a/stabby/src/tests/layouts.rs +++ b/stabby/src/tests/layouts.rs @@ -16,12 +16,12 @@ use core::num::{NonZeroU16, NonZeroU32, NonZeroU8}; use crate as stabby; use stabby::tuple::{Tuple2, Tuple3, Tuple8}; -use stabby_abi::{typenum2::*, Array, End, Result}; +use stabby_abi::{istable::Saturator, typenum2::*, Array, End, IStable, Result}; #[stabby::stabby] -pub union UTest { +pub union UnionTest { u8: u8, - usize: usize, + u64: u64, } #[stabby::stabby] pub union UTest2 { @@ -88,7 +88,7 @@ pub enum SameFieldsFourTimes { pub struct WeirdStructBadLayout { fields: FieldsC, no_fields: NoFields, - utest: UTest, + utest: UnionTest, u32: u32, } @@ -96,7 +96,7 @@ pub struct WeirdStructBadLayout { pub struct WeirdStructBadLayout2 { fields: FieldsC, no_fields: NoFields, - utest: UTest, + utest: UnionTest, } #[stabby::stabby] @@ -104,7 +104,7 @@ pub struct WeirdStruct { fields: FieldsC, no_fields: NoFields, u32: u32, - utest: UTest, + utest: UnionTest, } #[stabby::stabby] @@ -117,9 +117,25 @@ pub struct Test { a: u32, } +#[stabby::stabby] +pub struct SingleNiche { + a: usize, + b: &'static u8, +} +#[stabby::stabby] +pub struct EndPadding { + a: usize, + b: u8, +} + #[test] fn layouts() { use stabby::abi::istable::IForbiddenValues; + let _: B1 = <::HasExactlyOneNiche>::default(); + let _: Saturator = <::HasExactlyOneNiche>::default(); + let _: B0 = < as IStable>::HasExactlyOneNiche>::default(); + let _: Saturator = < as IStable>::HasExactlyOneNiche>::default(); + let _: Saturator = <::HasExactlyOneNiche>::default(); macro_rules! test { () => {}; ($t: ty, $unused: ty, $illegal: ty) => { @@ -199,7 +215,7 @@ fn layouts() { test!(stabby::abi::Union, End, End); test!(stabby::abi::Union<(), u8>, End, End); test!(stabby::result::Result<(), ()>, Array, End); - test!(UTest, End, End); + test!(UnionTest, End, End); test!(FieldsC, Array>>, End); test!(FieldsStabby, End, End); test!(MultiFieldsC, Array, End);