Skip to content

Commit 85efecf

Browse files
committed
Move handle implementation into the context crate
This can be shared between the GC implementations quite easily
1 parent 44b3463 commit 85efecf

File tree

4 files changed

+658
-46
lines changed

4 files changed

+658
-46
lines changed

libs/context/src/collector.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use std::fmt::{self, Debug, Formatter};
66

77
use slog::{Logger, o};
88

9-
use zerogc::{Gc, GcSafe, GcSystem, Trace, GcSimpleAlloc, GcBrand, GcHandle, GcHandleSystem};
9+
use zerogc::{Gc, GcSafe, GcSystem, Trace, GcSimpleAlloc};
1010

11-
use crate::{SimpleCollectorContext, CollectionManager};
11+
use crate::{CollectorContext, CollectionManager};
1212

1313
/// A specific implementation of a collector
1414
pub unsafe trait RawCollectorImpl: 'static + Sized {
@@ -205,9 +205,9 @@ impl<C: RawCollectorImpl> WeakCollectorRef<C> {
205205
}
206206

207207
pub unsafe trait RawSimpleAlloc: RawCollectorImpl {
208-
fn alloc<'gc, T: GcSafe + 'gc>(context: &'gc SimpleCollectorContext<Self>, value: T) -> Gc<'gc, T, CollectorId<Self>>;
208+
fn alloc<'gc, T: GcSafe + 'gc>(context: &'gc CollectorContext<Self>, value: T) -> Gc<'gc, T, CollectorId<Self>>;
209209
}
210-
unsafe impl<'gc, T, C> GcSimpleAlloc<'gc, T> for SimpleCollectorContext<C>
210+
unsafe impl<'gc, T, C> GcSimpleAlloc<'gc, T> for CollectorContext<C>
211211
where T: GcSafe + 'gc, C: RawSimpleAlloc {
212212
#[inline]
213213
fn alloc(&'gc self, value: T) -> Gc<'gc, T, Self::Id> {
@@ -282,18 +282,18 @@ impl<C: RawCollectorImpl> CollectorRef<C> {
282282
/// Warning: Only one collector should be created per thread.
283283
/// Doing otherwise can cause deadlocks/panics.
284284
#[cfg(feature = "sync")]
285-
pub fn create_context(&self) -> SimpleCollectorContext<C> {
286-
unsafe { SimpleCollectorContext::register_root(&self) }
285+
pub fn create_context(&self) -> CollectorContext<C> {
286+
unsafe { CollectorContext::register_root(&self) }
287287
}
288288
/// Convert this collector into a unique context
289289
///
290290
/// The single-threaded implementation only allows a single context,
291291
/// so this method is nessicarry to support it.
292-
pub fn into_context(self) -> SimpleCollectorContext<C> {
292+
pub fn into_context(self) -> CollectorContext<C> {
293293
#[cfg(feature = "sync")]
294294
{ self.create_context() }
295295
#[cfg(not(feature = "sync"))]
296-
unsafe { SimpleCollectorContext::from_collector(&self) }
296+
unsafe { CollectorContext::from_collector(&self) }
297297
}
298298
}
299299
impl<C: RawCollectorImpl> Drop for CollectorRef<C> {
@@ -306,32 +306,5 @@ impl<C: RawCollectorImpl> Drop for CollectorRef<C> {
306306

307307
unsafe impl<C: RawCollectorImpl> GcSystem for CollectorRef<C> {
308308
type Id = CollectorId<C>;
309-
type Context = SimpleCollectorContext<C>;
310-
}
311-
312-
unsafe impl<'gc, T, C> GcHandleSystem<'gc, T> for CollectorRef<C>
313-
where C: RawHandleImpl<'gc, T>,
314-
T: GcSafe + 'gc,
315-
T: GcBrand<'static, CollectorId<C>>,
316-
T::Branded: GcSafe {
317-
type Handle = C::Handle;
318-
319-
#[inline]
320-
fn create_handle(gc: Gc<'gc, T, Self::Id>) -> Self::Handle {
321-
C::create_handle(gc)
322-
}
323-
}
324-
325-
pub unsafe trait RawHandleImpl<'gc, T>: RawCollectorImpl
326-
where T: GcSafe + 'gc,
327-
T: GcBrand<'static, CollectorId<Self>>,
328-
<T as GcBrand<'static, CollectorId<Self>>>::Branded: GcSafe {
329-
/// The type of handles to the object `T`.
330-
type Handle: GcHandle<<T as GcBrand<'static, CollectorId<Self>>>::Branded, System=CollectorRef<Self>>;
331-
332-
/// Create a handle to the specified GC pointer,
333-
/// which can be used without a context
334-
///
335-
/// The system is implicit in the [Gc]
336-
fn create_handle(gc: Gc<'gc, T, CollectorId<Self>>) -> Self::Handle;
309+
type Context = CollectorContext<C>;
337310
}

0 commit comments

Comments
 (0)