-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #218 from getditto/pa/integrate-stabby-allocs
Add initial support for stabby
- Loading branch information
Showing
7 changed files
with
226 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.66.1 | ||
1.72.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
pub use stabby::*; | ||
|
||
mod boxed_impl; | ||
mod sync_impl; | ||
mod fatptr_impl { | ||
use core::ops::Not; | ||
|
||
use crate::{ | ||
CVoid, Tuple2, | ||
ඞ::{CLayoutOf, ConcreteReprC, ReprC}, | ||
}; | ||
use stabby::abi::{vtable::HasDropVt, IPtrOwned}; | ||
|
||
unsafe impl<Ptr: ConcreteReprC + IPtrOwned, VTable: HasDropVt> ReprC | ||
for stabby::abi::Dyn<'_, Ptr, VTable> | ||
{ | ||
type CLayout = CLayoutOf<Tuple2<Ptr, *const CVoid>>; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
Ptr::is_valid(&it._0) && it._1.is_null().not() | ||
} | ||
} | ||
|
||
unsafe impl<VTable: HasDropVt> ReprC for stabby::abi::DynRef<'_, VTable> { | ||
type CLayout = CLayoutOf<Tuple2<*const CVoid, *const CVoid>>; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
it._0.is_null().not() && it._1.is_null().not() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::{ | ||
CVoid, Tuple2_Layout, | ||
ඞ::{ReprC, __HasNiche__}, | ||
}; | ||
pub use stabby::boxed::{Box, BoxedSlice, BoxedStr}; | ||
use stabby::{abi::U1, alloc::IAlloc, IStable}; | ||
|
||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> ReprC for Box<T, Alloc> | ||
where | ||
Box<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
type CLayout = *const CVoid; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
!Self::is_niche(it) && it.align_offset(core::mem::align_of::<T>()) == 0 | ||
} | ||
} | ||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> __HasNiche__ for Box<T, Alloc> | ||
where | ||
Box<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
fn is_niche(it: &'_ <Self as ReprC>::CLayout) -> bool { | ||
it.is_null() | ||
} | ||
} | ||
|
||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> ReprC for BoxedSlice<T, Alloc> | ||
where | ||
Box<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
type CLayout = Tuple2_Layout<*const CVoid, *const CVoid>; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
!Self::is_niche(it) | ||
&& it._0.align_offset(core::mem::align_of::<T>()) == 0 | ||
&& it._1.align_offset(core::mem::align_of::<T>()) == 0 | ||
} | ||
} | ||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> __HasNiche__ for BoxedSlice<T, Alloc> | ||
where | ||
Box<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
fn is_niche(it: &'_ <Self as ReprC>::CLayout) -> bool { | ||
it._0.is_null() || it._1.is_null() | ||
} | ||
} | ||
unsafe impl<Alloc: IStable + IAlloc> ReprC for BoxedStr<Alloc> | ||
where | ||
BoxedSlice<u8, Alloc>: ReprC, | ||
{ | ||
type CLayout = <BoxedSlice<u8, Alloc> as ReprC>::CLayout; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
BoxedSlice::<u8, Alloc>::is_valid(it) | ||
} | ||
} | ||
unsafe impl<Alloc: IStable + IAlloc> __HasNiche__ for BoxedStr<Alloc> | ||
where | ||
BoxedSlice<u8, Alloc>: __HasNiche__, | ||
{ | ||
fn is_niche(it: &'_ Self::CLayout) -> bool { | ||
BoxedSlice::<u8, Alloc>::is_niche(it) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
use crate::{ | ||
CVoid, Tuple2_Layout, | ||
ඞ::{ReprC, __HasNiche__}, | ||
}; | ||
pub use stabby::sync::{Arc, ArcSlice, ArcStr, Weak, WeakSlice, WeakStr}; | ||
use stabby::{abi::U1, alloc::IAlloc, IStable}; | ||
|
||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> ReprC for Arc<T, Alloc> | ||
where | ||
Arc<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
type CLayout = *const CVoid; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
!Self::is_niche(it) && it.align_offset(core::mem::align_of::<T>()) == 0 | ||
} | ||
} | ||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> __HasNiche__ for Arc<T, Alloc> | ||
where | ||
Arc<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
fn is_niche(it: &'_ <Self as ReprC>::CLayout) -> bool { | ||
it.is_null() | ||
} | ||
} | ||
|
||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> ReprC for ArcSlice<T, Alloc> | ||
where | ||
Arc<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
type CLayout = Tuple2_Layout<*const CVoid, *const CVoid>; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
!Self::is_niche(it) | ||
&& it._0.align_offset(core::mem::align_of::<T>()) == 0 | ||
&& it._1.align_offset(core::mem::align_of::<T>()) == 0 | ||
} | ||
} | ||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> __HasNiche__ for ArcSlice<T, Alloc> | ||
where | ||
Arc<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
fn is_niche(it: &'_ <Self as ReprC>::CLayout) -> bool { | ||
it._0.is_null() || it._1.is_null() | ||
} | ||
} | ||
unsafe impl<Alloc: IStable + IAlloc> ReprC for ArcStr<Alloc> | ||
where | ||
ArcSlice<u8, Alloc>: ReprC, | ||
{ | ||
type CLayout = <ArcSlice<u8, Alloc> as ReprC>::CLayout; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
ArcSlice::<u8, Alloc>::is_valid(it) | ||
} | ||
} | ||
unsafe impl<Alloc: IStable + IAlloc> __HasNiche__ for ArcStr<Alloc> | ||
where | ||
ArcSlice<u8, Alloc>: __HasNiche__, | ||
{ | ||
fn is_niche(it: &'_ Self::CLayout) -> bool { | ||
ArcSlice::<u8, Alloc>::is_niche(it) | ||
} | ||
} | ||
|
||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> ReprC for Weak<T, Alloc> | ||
where | ||
Weak<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
type CLayout = *const CVoid; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
!Self::is_niche(it) && it.align_offset(core::mem::align_of::<T>()) == 0 | ||
} | ||
} | ||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> __HasNiche__ for Weak<T, Alloc> | ||
where | ||
Weak<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
fn is_niche(it: &'_ <Self as ReprC>::CLayout) -> bool { | ||
it.is_null() | ||
} | ||
} | ||
|
||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> ReprC for WeakSlice<T, Alloc> | ||
where | ||
Weak<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
type CLayout = Tuple2_Layout<*const CVoid, *const CVoid>; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
!Self::is_niche(it) | ||
&& it._0.align_offset(core::mem::align_of::<T>()) == 0 | ||
&& it._1.align_offset(core::mem::align_of::<T>()) == 0 | ||
} | ||
} | ||
unsafe impl<T: IStable, Alloc: IStable + IAlloc> __HasNiche__ for WeakSlice<T, Alloc> | ||
where | ||
Weak<T, Alloc>: IStable<Size = U1>, | ||
{ | ||
fn is_niche(it: &'_ <Self as ReprC>::CLayout) -> bool { | ||
it._0.is_null() || it._1.is_null() | ||
} | ||
} | ||
unsafe impl<Alloc: IStable + IAlloc> ReprC for WeakStr<Alloc> | ||
where | ||
WeakSlice<u8, Alloc>: ReprC, | ||
{ | ||
type CLayout = <WeakSlice<u8, Alloc> as ReprC>::CLayout; | ||
fn is_valid(it: &'_ Self::CLayout) -> bool { | ||
WeakSlice::<u8, Alloc>::is_valid(it) | ||
} | ||
} | ||
unsafe impl<Alloc: IStable + IAlloc> __HasNiche__ for WeakStr<Alloc> | ||
where | ||
WeakSlice<u8, Alloc>: __HasNiche__, | ||
{ | ||
fn is_niche(it: &'_ Self::CLayout) -> bool { | ||
WeakSlice::<u8, Alloc>::is_niche(it) | ||
} | ||
} |