Skip to content

Commit

Permalink
Merge pull request #90 from ZettaScaleLabs/36.1.1
Browse files Browse the repository at this point in the history
v36.1.1
  • Loading branch information
p-avital committed Jul 31, 2024
2 parents 13e0c9c + 70d88ab commit 15fe769
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 54 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,54 @@ jobs:
with:
command: clean

check-wasm:
name: Run wasm checks on ${{ matrix.os }}
runs-on: [self-hosted, "${{ matrix.os }}"]
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
steps:
- uses: actions/checkout@v2
- name: Install Rust toolchain 1.72
uses: actions-rs/toolchain@v1
with:
profile: minimal
target: wasm32-unknown-unknown
- name: Check
uses: actions-rs/cargo@v1
with:
command: check
args: -p stabby
- name: Clean artifacts
uses: actions-rs/cargo@v1
with:
command: clean

check-32bits:
name: Run 32bits checks on ${{ matrix.os }}
runs-on: [self-hosted, "${{ matrix.os }}"]
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
steps:
- uses: actions/checkout@v2
- name: Install Rust toolchain 1.72
uses: actions-rs/toolchain@v1
with:
profile: minimal
target: i686-unknown-linux-gnu
- name: Check
uses: actions-rs/cargo@v1
with:
command: check
args: -p stabby
- name: Clean artifacts
uses: actions-rs/cargo@v1
with:
command: clean

test:
name: Run tests on ${{ matrix.os }}
runs-on: [self-hosted, "${{ matrix.os }}"]
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# 36.1.1 (api=2.0.0, abi=2.0.0)
`36.1.1` is the sum of all the previous release candidates. Here's a recap!
- `#[stabby::stabby]` can now understand when a type refers to itself to avoid forming proof cycles.
- `stabby::collections::arc_btree`'s types are now ABI-stable!
- 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`.
- FIx single-niche evaluation for structures.
- Add support for `#[repr(transparent)]` and `#[repr(align(n))]` in `#[stabby::stabby]` structs up to n=64kiB.
- Added more constructors (such as `FromIterator`) for `BoxedSlice` and `ArcSlice`.
- Added support for more niche platforms.
- BREAKING CHANGES: Mostly due to a large rework of allocations.
- The in-place constructors for `Box` and `Arc` now require the initializer function to return a result, yielding the uninitialized allocation if allocation succeeded but initialization reported a failure.
- `serde` and `libc` features are no longer part of the default features set.
- `RustAlloc` is the new default allocator of `stabby`: this allocator is a simple pointer to a v-table allowing cross-ffi use of Rust's `alloc::GlobalAlloc`.
- This allocator is global, thread-safe, and guaranteed to work properly with pointers passed across the FFI.
- Benchmarks indicate that performance between `RustAlloc` and `LibcAlloc` is equivalent.
- However, it is non-zero-sized, and therefore makes types that don't always shove it into their `AllocPrefix` are slightly bigger when using `RustAlloc` rather than `LibcAlloc`.
- The reason for this change is that `LibcAlloc` isn't available on certain platforms, whereas `RustAlloc` is available on any platform supported by Rust. Importantly, the `wasm32` architecture was unsupported until now.
- The `libc_alloc` module was replaced by the `allocators` module to improve readability.
- While the previous `IAlloc` version was fine to interface with `libc::malloc`'s API, it actually had a few big holes that required patching for custom allocators to be able to do interesting stuff.
- This was unearthed by implementing `RustAlloc`
- The `AllocPrefix`'s location relative to prefixed allocations (such as those used by all of `stabby`'s container types) has changed for types with alignments greater than pointer-size.
- The prefix was previously placed as if the allocation held `Tuple2<AllocPrefix, T>`, meaning that for larger alignments, there could be padding between the prefix and the pointed value.

# 36.1.1-rc8 (api=2.0.0, abi=2.0.0)
- Improve `DefaultAllocator` handling

Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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-rc8" # Track
version = "36.1.1" # Track

[workspace.dependencies]
stabby-macros = { path = "./stabby-macros/", version = "36.1.1-rc8", default-features = false } # Track
stabby-abi = { path = "./stabby-abi/", version = "36.1.1-rc8", default-features = false } # Track
stabby = { path = "./stabby/", version = "36.1.1-rc8", default-features = false } # Track
stabby-macros = { path = "./stabby-macros/", version = "36.1.1", default-features = false } # Track
stabby-abi = { path = "./stabby-abi/", version = "36.1.1", default-features = false } # Track
stabby = { path = "./stabby/", version = "36.1.1", default-features = false } # Track

abi_stable = "0.11.0"
libc = "0.2"
Expand Down
104 changes: 61 additions & 43 deletions stabby-abi/src/stable_impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// Pierre Avital, <pierre.avital@me.com>
//

use unsigned::{Bool, IBitBase};

use crate::{str::Str, *};

macro_rules! same_as {
Expand All @@ -35,6 +37,21 @@ macro_rules! same_as {
};
}

macro_rules! expr_to_type {
($e: expr) => {
<Bool<{ {$e == 8} }> as IBitBase>::_ATernary<
U8,
<Bool<{ {$e == 4} }> as IBitBase>::_ATernary<
U4,
<Bool<{ {$e == 2} }> as IBitBase>::_ATernary<
U2,
<Bool<{ {$e == 1} }> as IBitBase>::_ATernary<U1, U16>,
>,
>,
>
};
}

#[allow(dead_code)]
const ARCH: &[u8] = _ARCH;
#[cfg(target_arch = "aarch64")]
Expand Down Expand Up @@ -89,8 +106,6 @@ const _ARCH: &[u8] = b"wasm64";
const _ARCH: &[u8] = b"x86";
#[cfg(target_arch = "x86_64")]
const _ARCH: &[u8] = b"x86_64";
#[cfg(target_arch = "xtensa")]
const _ARCH: &[u8] = b"xtensa";
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "arm",
Expand Down Expand Up @@ -118,7 +133,6 @@ const _ARCH: &[u8] = b"xtensa";
target_arch = "wasm64",
target_arch = "x86",
target_arch = "x86_64",
target_arch = "xtensa"
)))]
const _ARCH: &[u8] = b"unknown_arch";

Expand Down Expand Up @@ -274,12 +288,13 @@ unsafe impl IStable for bool {
type Size = U1;
type ForbiddenValues = crate::istable::ForbiddenRange<U2, U255, U0>;
type UnusedBits = End;
type HasExactlyOneNiche = B0;
type HasExactlyOneNiche = Saturator;
type ContainsIndirections = B0;
#[cfg(feature = "experimental-ctypes")]
type CType = <Self::Align as Alignment>::AsUint;
primitive_report!("bool");
}
check!(bool);

// SAFETY: Automatic checks verify this.
unsafe impl IStable for u8 {
Expand Down Expand Up @@ -360,7 +375,7 @@ unsafe impl IStable for core::num::NonZeroU32 {
unsafe impl IStable for u64 {
type UnusedBits = End;
type ForbiddenValues = End;
type Align = U8;
type Align = expr_to_type!(core::mem::align_of::<Self>());
type Size = U8;
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
Expand All @@ -373,7 +388,7 @@ check!(u64);
unsafe impl IStable for core::num::NonZeroU64 {
type UnusedBits = End;
type ForbiddenValues = nz_holes!(U0, U1, U2, U3, U4, U5, U6, U7);
type Align = U8;
type Align = expr_to_type!(core::mem::align_of::<Self>());
type Size = U8;
type HasExactlyOneNiche = B1;
type ContainsIndirections = B0;
Expand All @@ -388,47 +403,28 @@ unsafe impl IStable for u128 {
type ForbiddenValues = End;
type Size = U16;
type HasExactlyOneNiche = B0;

#[rustversion::before(1.77)]
#[cfg(not(target_arch = "aarch64"))]
type Align = U8;
#[rustversion::before(1.77)]
#[cfg(target_arch = "aarch64")]
type Align = U16;
#[rustversion::since(1.77)]
#[cfg(not(target_arch = "wasm32"))]
type Align = U16;
#[rustversion::since(1.77)]
#[cfg(target_arch = "wasm32")]
type Align = U8;
type Align = expr_to_type!(core::mem::align_of::<Self>());

type ContainsIndirections = B0;
#[cfg(feature = "experimental-ctypes")]
type CType = <Self::Align as Alignment>::AsUint;
#[rustversion::before(1.77)]
#[cfg(not(target_arch = "aarch64"))]
primitive_report!("u128(8)");
#[rustversion::before(1.77)]
#[cfg(target_arch = "aarch64")]
primitive_report!("u128(16)");
#[rustversion::since(1.77)]
#[cfg(not(target_arch = "wasm32"))]
primitive_report!("u128(16)");
#[rustversion::since(1.77)]
#[cfg(target_arch = "wasm32")]
primitive_report!("u128(8)");
primitive_report!(if core::mem::align_of::<Self>() == 8 {
"u128(8)"
} else {
"u128(16)"
});
}

check!(u128);

// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::num::NonZeroU128 {
type Size = expr_to_type!(core::mem::size_of::<Self>());
type Align = expr_to_type!(core::mem::align_of::<Self>());
type UnusedBits = End;
type ForbiddenValues =
nz_holes!(U0, U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, U14, U15);
type Size = U16;
type HasExactlyOneNiche = B1;
type Align = <u128 as IStable>::Align;
#[cfg(feature = "experimental-ctypes")]
type CType = <Self::Align as Alignment>::AsUint;
type ContainsIndirections = B0;
Expand All @@ -437,14 +433,15 @@ unsafe impl IStable for core::num::NonZeroU128 {

// SAFETY: Automatic checks verify this.
unsafe impl IStable for usize {
#[cfg(target_pointer_width = "64")]
same_as!(u64, "usize");
#[cfg(target_pointer_width = "32")]
same_as!(u32, "usize");
#[cfg(target_pointer_width = "16")]
same_as!(u16, "usize");
type Size = expr_to_type!(core::mem::size_of::<Self>());
type Align = expr_to_type!(core::mem::align_of::<Self>());
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
type ForbiddenValues = End;
type UnusedBits = End;
#[cfg(feature = "experimental-ctypes")]
type CType = usize;
primitive_report!("usize");
}

check!(usize);
Expand All @@ -459,6 +456,7 @@ unsafe impl IStable for core::num::NonZeroUsize {
type HasExactlyOneNiche = B1;
type ContainsIndirections = B0;
}
check!(core::num::NonZeroUsize);

// SAFETY: Automatic checks verify this.
unsafe impl IStable for i8 {
Expand Down Expand Up @@ -579,69 +577,89 @@ unsafe impl<T: IStable> IStable for core::sync::atomic::AtomicPtr<T> {
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicBool {
same_as!(bool, "core::sync::atomic::AtomicBool");
type HasExactlyOneNiche = B0;
type HasExactlyOneNiche = Saturator;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicBool);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicI8 {
same_as!(i8, "core::sync::atomic::AtomicI8");
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicI8);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicI16 {
same_as!(i16, "core::sync::atomic::AtomicI16");
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicI16);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicI32 {
same_as!(i32, "core::sync::atomic::AtomicI32");
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicI32);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicI64 {
same_as!(i64, "core::sync::atomic::AtomicI64");
type Size = U8;
type Align = expr_to_type!(core::mem::align_of::<Self>());
type ForbiddenValues = End;
type UnusedBits = End;
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
#[cfg(feature = "experimental-ctypes")]
type CType = <Self::Align as Alignment>::AsUint;
primitive_report!("core::sync::atomic::AtomicI64");
}
check!(core::sync::atomic::AtomicI64);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicIsize {
same_as!(isize, "core::sync::atomic::AtomicIsize");
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicIsize);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicU8 {
same_as!(u8, "core::sync::atomic::AtomicU8");
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicU8);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicU16 {
same_as!(u16, "core::sync::atomic::AtomicU16");
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicU16);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicU32 {
same_as!(u32, "core::sync::atomic::AtomicU32");
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicU32);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicU64 {
same_as!(u64, "core::sync::atomic::AtomicU64");
same_as!(
core::sync::atomic::AtomicI64,
"core::sync::atomic::AtomicU64"
);
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicU64);
// SAFETY: Automatic checks verify this.
unsafe impl IStable for core::sync::atomic::AtomicUsize {
same_as!(usize, "core::sync::atomic::AtomicUsize");
type HasExactlyOneNiche = B0;
type ContainsIndirections = B0;
}
check!(core::sync::atomic::AtomicUsize);
// SAFETY: Automatic checks verify this.
unsafe impl<T: IStable> IStable for &T {
same_as!(core::num::NonZeroUsize, "&", T);
Expand Down Expand Up @@ -933,7 +951,7 @@ macro_rules! sliceimpl {
type Size = <T::Size as Unsigned>::Mul<$size>;
type Align = T::Align;
type ForbiddenValues = <<$size as Unsigned>::Equal<U1> as Bit>::FvTernary<T::ForbiddenValues, End>;
type UnusedBits = <<$size as Unsigned>::Equal<U1> as Bit>::UbTernary<T::UnusedBits, End>;
type UnusedBits = <<$size as Unsigned>::Equal<U1> as Bit>::BmTernary<T::UnusedBits, End>;
type HasExactlyOneNiche = <<$size as Unsigned>::Equal<U0> as Bit>::SaddTernary<
B0,
<<$size as Unsigned>::Equal<U1> as Bit>::SaddTernary<T::HasExactlyOneNiche, Saturator>,
Expand Down
Loading

0 comments on commit 15fe769

Please sign in to comment.