Skip to content

Commit 348cff7

Browse files
committed
More object format work, before I finally remove it
1 parent a837672 commit 348cff7

File tree

7 files changed

+122
-103
lines changed

7 files changed

+122
-103
lines changed

libs/context/src/collector.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ use zerogc::{Gc, GcSafe, GcSystem, Trace, GcSimpleAlloc, NullTrace, TraceImmutab
1313
use crate::{CollectorContext};
1414
use crate::state::{CollectionManager, RawContext};
1515
use std::ffi::c_void;
16+
use zerogc::format::{ObjectFormat, GcLayoutInternals};
1617

1718
/// A specific implementation of a collector
18-
pub unsafe trait RawCollectorImpl: 'static + Sized {
19-
/// A dynamic pointer to a GC object
19+
pub unsafe trait RawCollectorImpl: GcLayoutInternals + 'static + Sized {
20+
/// A dynamic pointer to a `Trace` root
2021
///
2122
/// The simple collector implements this as
2223
/// a trait object pointer.
23-
type GcDynPointer: Copy + Debug + 'static;
24-
25-
unsafe fn dyn_ptr_from_raw(raw: *mut c_void) -> Self::GcDynPointer;
24+
type DynTracePtr: Copy + Debug + 'static;
25+
type Fmt: ObjectFormat<Self>;
2626

2727
/// A pointer to this collector
2828
///
@@ -48,7 +48,7 @@ pub unsafe trait RawCollectorImpl: 'static + Sized {
4848
where 'gc: 'a, T: GcSafe + ?Sized + 'gc;
4949

5050
/// Convert the specified value into a dyn pointer
51-
unsafe fn create_dyn_pointer<T: GcSafe>(&self, t: *mut T) -> Self::GcDynPointer;
51+
unsafe fn create_dyn_pointer<T: Trace>(&self, t: *mut T) -> Self::DynTracePtr;
5252

5353
/// Initialize an instance of the collector
5454
///

libs/context/src/handle.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{Gc, WeakCollectorRef, CollectorId, CollectorContext, CollectorRef, C
1313
use crate::collector::RawCollectorImpl;
1414
use std::ffi::c_void;
1515
use crate::utils::AtomicCell;
16+
use zerogc::format::ObjectFormat;
1617

1718
const INITIAL_HANDLE_CAPACITY: usize = 64;
1819

@@ -234,7 +235,7 @@ impl<C: RawHandleImpl> GcHandleList<C> {
234235
/// Now that's behind a layer of abstraction,
235236
/// the unsafety has technically been moved to the caller.
236237
pub unsafe fn trace<F, E>(&mut self, mut visitor: F) -> Result<(), E>
237-
where F: FnMut(C::GcDynPointer, &C::TypeInfo) -> Result<(), E> {
238+
where F: FnMut(<C::Fmt as ObjectFormat<C>>::DynObject, &C::TypeInfo) -> Result<(), E> {
238239
/*
239240
* TODO: This fence seems unnecessary since we should
240241
* already have exclusive access.....
@@ -380,11 +381,11 @@ impl<C: RawHandleImpl> GcRawHandle<C> {
380381
/// - It is assumed that the appropriate atomic fences (if any)
381382
/// have already been applied (TODO: Don't we have exclusive access?)
382383
unsafe fn trace_inner<F, E>(&self, trace: &mut F) -> Result<(), E>
383-
where F: FnMut(C::GcDynPointer, &C::TypeInfo) -> Result<(), E> {
384+
where F: FnMut(<C::Fmt as ObjectFormat<C>>::DynObject, &C::TypeInfo) -> Result<(), E> {
384385
let raw_value = self.value.load(Ordering::Relaxed);
385386
assert_eq!(
386387
std::mem::size_of::<*mut ()>(),
387-
std::mem::size_of::<C::GcDynPointer>(),
388+
std::mem::size_of::<C::DynTracePtr>(),
388389
);
389390
if raw_value.is_null() {
390391
debug_assert_eq!(
@@ -397,7 +398,7 @@ impl<C: RawHandleImpl> GcRawHandle<C> {
397398
self.refcnt.load(Ordering::Relaxed),
398399
0
399400
);
400-
let value = C::dyn_ptr_from_raw(raw_value as *mut c_void);
401+
let value = C::Fmt::untyped_object_from_raw(raw_value as *mut c_void);
401402
let type_info = self.type_info.load();
402403
trace(value, &type_info)
403404
}

libs/context/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,16 @@ impl<C: RawCollectorImpl> Debug for ShadowStack<C> {
241241
pub struct ShadowStack<C: RawCollectorImpl> {
242242
/// The last element in the shadow stack,
243243
/// or NULL if it's empty
244-
pub(crate) last: *const ShadowStackLink<C::GcDynPointer>
244+
pub(crate) last: *const ShadowStackLink<C::DynTracePtr>
245245
}
246246
impl<C: RawCollectorImpl> ShadowStack<C> {
247-
unsafe fn as_vec(&self) -> Vec<C::GcDynPointer> {
247+
unsafe fn as_vec(&self) -> Vec<C::DynTracePtr> {
248248
let mut result: Vec<_> = self.reverse_iter().collect();
249249
result.reverse();
250250
result
251251
}
252252
#[inline]
253-
pub unsafe fn reverse_iter(&self) -> impl Iterator<Item=C::GcDynPointer> + '_ {
253+
pub unsafe fn reverse_iter(&self) -> impl Iterator<Item=C::DynTracePtr> + '_ {
254254
core::iter::successors(
255255
self.last.as_ref(),
256256
|link| link.prev.as_ref()

libs/simple/src/layout.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::mem::ManuallyDrop;
1+
use std::mem::{ManuallyDrop, MaybeUninit};
22
use std::ffi::c_void;
33
use std::alloc::Layout;
44
use std::mem;
@@ -69,23 +69,23 @@ impl<Fmt: RawObjectFormat> SimpleMarkData<Fmt> {
6969
pub struct SimpleMarkDataSnapshot<Fmt: RawObjectFormat> {
7070
pub state: RawMarkState,
7171
#[cfg(feature = "multiple-collectors")]
72-
pub collector_id: CollectorId<Fmt>
72+
pub collector_id_ptr: *mut CollectorId<Fmt>
7373
}
7474
impl<Fmt: RawObjectFormat> SimpleMarkDataSnapshot<Fmt> {
75-
pub fn new(state: RawMarkState, collector_id: CollectorId<Fmt>) -> Self {
75+
pub fn new(state: RawMarkState, collector_id_ptr: *mut CollectorId<Fmt>) -> Self {
7676
#[cfg(feature = "multiple-collectors")] {
77-
SimpleMarkDataSnapshot { state, collector_id }
77+
SimpleMarkDataSnapshot { state, collector_id_ptr }
7878
}
7979
#[cfg(not(feature = "multiple-collectors"))] {
80-
drop(collector_id); // avoid warnings
80+
drop(collector_id_ptr); // avoid warnings
8181
SimpleMarkDataSnapshot { state }
8282
}
8383
}
8484
#[inline]
8585
fn packed(&self) -> usize {
8686
let base: usize;
8787
#[cfg(feature = "multiple-collectors")] {
88-
base = self.collector_id.as_ref() as *const RawSimpleCollector<Fmt> as usize;
88+
base = (*self.collector_id_ptr).as_ref() as *const RawSimpleCollector<Fmt> as usize;
8989
}
9090
#[cfg(not(feature = "multiple-collectors"))] {
9191
base = 0;
@@ -98,8 +98,8 @@ impl<Fmt: RawObjectFormat> SimpleMarkDataSnapshot<Fmt> {
9898
let state = MarkState::from_byte((packed & STATE_MASK) as u8);
9999
let id_bytes: usize = packed & !STATE_MASK;
100100
#[cfg(feature="multiple-collectors")] {
101-
let collector_id = CollectorId::from_raw(NonNull::new_unchecked(id_bytes));
102-
SimpleMarkDataSnapshot { state, collector_id }
101+
let collector_id_ptr = id_bytes as *mut CollectorId<Fmt>;
102+
SimpleMarkDataSnapshot { state, collector_id_ptr }
103103
}
104104
#[cfg(not(feature = "multiple-collectors"))] {
105105
SimpleMarkDataSnapshot { state }
@@ -112,7 +112,7 @@ struct DynamicObj;
112112

113113
#[repr(C)]
114114
pub(crate) struct BigGcObject<Fmt: RawObjectFormat, T = DynamicObj> {
115-
pub(crate) header: Fmt::SizedHeaderType,
115+
pub(crate) header: MaybeUninit<Fmt::SizedHeaderType>,
116116
/// This is dropped using dynamic type info
117117
pub(crate) static_value: ManuallyDrop<T>
118118
}

0 commit comments

Comments
 (0)