@@ -12,6 +12,8 @@ use zerogc::{Gc, GcSafe, GcSystem, Trace, GcSimpleAlloc, NullTrace, TraceImmutab
1212
1313use crate :: { CollectorContext } ;
1414use crate :: state:: { CollectionManager , RawContext } ;
15+ use zerogc:: vec:: GcVec ;
16+ use zerogc:: vec:: repr:: GcVecRepr ;
1517
1618/// A specific implementation of a collector
1719pub unsafe trait RawCollectorImpl : ' static + Sized {
@@ -20,6 +22,8 @@ pub unsafe trait RawCollectorImpl: 'static + Sized {
2022 /// The simple collector implements this as
2123 /// a trait object pointer.
2224 type DynTracePtr : Copy + Debug + ' static ;
25+ /// The configuration
26+ type Config : Sized + Default ;
2327
2428 /// A pointer to this collector
2529 ///
@@ -31,6 +35,8 @@ pub unsafe trait RawCollectorImpl: 'static + Sized {
3135
3236 /// The context
3337 type RawContext : RawContext < Self > ;
38+ /// The raw representation of a vec
39+ type RawVecRepr : GcVecRepr ;
3440
3541 /// True if this collector is a singleton
3642 ///
@@ -50,18 +56,18 @@ pub unsafe trait RawCollectorImpl: 'static + Sized {
5056 /// Initialize an instance of the collector
5157 ///
5258 /// Must panic if the collector is not a singleton
53- fn init ( logger : Logger ) -> NonNull < Self > ;
59+ fn init ( config : Self :: Config , logger : Logger ) -> NonNull < Self > ;
5460
5561 /// The id of this collector
5662 #[ inline]
5763 fn id ( & self ) -> CollectorId < Self > {
5864 CollectorId { ptr : unsafe { Self :: Ptr :: from_raw ( self as * const _ as * mut _ ) } }
5965 }
60- unsafe fn gc_write_barrier < ' gc , T , V > (
61- owner : & Gc < ' gc , T , CollectorId < Self > > ,
66+ unsafe fn gc_write_barrier < ' gc , O , V > (
67+ owner : & Gc < ' gc , O , CollectorId < Self > > ,
6268 value : & Gc < ' gc , V , CollectorId < Self > > ,
6369 field_offset : usize
64- ) where T : GcSafe + ?Sized + ' gc , V : GcSafe + ?Sized + ' gc ;
70+ ) where O : GcSafe + ?Sized + ' gc , V : GcSafe + ?Sized + ' gc ;
6571 /// The logger associated with this collector
6672 fn logger ( & self ) -> & Logger ;
6773
@@ -90,7 +96,7 @@ pub unsafe trait SingletonCollector: RawCollectorImpl<Ptr=PhantomData<&'static S
9096 /// Initialize the global singleton
9197 ///
9298 /// Panics if already initialized
93- fn init_global ( logger : Logger ) ;
99+ fn init_global ( config : Self :: Config , logger : Logger ) ;
94100}
95101
96102impl < C : RawCollectorImpl > PartialEq for CollectorId < C > {
@@ -278,6 +284,7 @@ impl<C: RawCollectorImpl> CollectorId<C> {
278284}
279285unsafe impl < C : RawCollectorImpl > :: zerogc:: CollectorId for CollectorId < C > {
280286 type System = CollectorRef < C > ;
287+ type RawVecRepr = C :: RawVecRepr ;
281288
282289 #[ inline]
283290 fn from_gc_ptr < ' a , ' gc , T > ( gc : & ' a Gc < ' gc , T , Self > ) -> & ' a Self where T : GcSafe + ?Sized + ' gc , ' gc : ' a {
@@ -286,11 +293,11 @@ unsafe impl<C: RawCollectorImpl> ::zerogc::CollectorId for CollectorId<C> {
286293
287294
288295 #[ inline( always) ]
289- unsafe fn gc_write_barrier < ' gc , T , V > (
290- owner : & Gc < ' gc , T , Self > ,
296+ unsafe fn gc_write_barrier < ' gc , O , V > (
297+ owner : & Gc < ' gc , O , Self > ,
291298 value : & Gc < ' gc , V , Self > ,
292299 field_offset : usize
293- ) where T : GcSafe + ?Sized + ' gc , V : GcSafe + ?Sized + ' gc {
300+ ) where O : GcSafe + ?Sized + ' gc , V : GcSafe + ?Sized + ' gc {
294301 C :: gc_write_barrier ( owner, value, field_offset)
295302 }
296303
@@ -341,13 +348,36 @@ impl<C: RawCollectorImpl> WeakCollectorRef<C> {
341348
342349pub unsafe trait RawSimpleAlloc : RawCollectorImpl {
343350 fn alloc < ' gc , T : GcSafe + ' gc > ( context : & ' gc CollectorContext < Self > , value : T ) -> Gc < ' gc , T , CollectorId < Self > > ;
351+ unsafe fn alloc_uninit_slice < ' gc , T > ( context : & ' gc CollectorContext < Self > , len : usize ) -> ( CollectorId < Self > , * mut T )
352+ where T : GcSafe + ' gc ;
353+ fn alloc_vec < ' gc , T > ( context : & ' gc CollectorContext < Self > ) -> GcVec < ' gc , T , CollectorContext < Self > >
354+ where T : GcSafe + ' gc ;
355+ fn alloc_vec_with_capacity < ' gc , T > ( context : & ' gc CollectorContext < Self > , capacity : usize ) -> GcVec < ' gc , T , CollectorContext < Self > >
356+ where T : GcSafe + ' gc ;
344357}
345- unsafe impl < ' gc , T , C > GcSimpleAlloc < ' gc , T > for CollectorContext < C >
346- where T : GcSafe + ' gc , C : RawSimpleAlloc {
358+ unsafe impl < C > GcSimpleAlloc for CollectorContext < C >
359+ where C : RawSimpleAlloc {
347360 #[ inline]
348- fn alloc ( & ' gc self , value : T ) -> Gc < ' gc , T , Self :: Id > {
361+ fn alloc < ' gc , T > ( & ' gc self , value : T ) -> Gc < ' gc , T , Self :: Id >
362+ where T : GcSafe + ' gc {
349363 C :: alloc ( self , value)
350364 }
365+
366+ #[ inline]
367+ unsafe fn alloc_uninit_slice < ' gc , T > ( & ' gc self , len : usize ) -> ( Self :: Id , * mut T )
368+ where T : GcSafe + ' gc {
369+ C :: alloc_uninit_slice ( self , len)
370+ }
371+
372+ #[ inline]
373+ fn alloc_vec < ' gc , T > ( & ' gc self ) -> GcVec < ' gc , T , Self > where T : GcSafe + ' gc {
374+ C :: alloc_vec ( self )
375+ }
376+
377+ #[ inline]
378+ fn alloc_vec_with_capacity < ' gc , T > ( & ' gc self , capacity : usize ) -> GcVec < ' gc , T , Self > where T : GcSafe + ' gc {
379+ C :: alloc_vec_with_capacity ( self , capacity)
380+ }
351381}
352382
353383/// A reference to the collector.
@@ -371,26 +401,26 @@ unsafe impl<C: SyncCollector> Sync for CollectorRef<C> {}
371401#[ doc( hidden) ]
372402pub trait CollectorInit < C : RawCollectorImpl < Ptr =Self > > : CollectorPtr < C > {
373403 fn create ( ) -> CollectorRef < C > {
374- Self :: with_logger ( Logger :: root (
404+ Self :: with_logger ( C :: Config :: default ( ) , Logger :: root (
375405 slog:: Discard ,
376406 o ! ( )
377407 ) )
378408 }
379- fn with_logger ( logger : Logger ) -> CollectorRef < C > ;
409+ fn with_logger ( config : C :: Config , logger : Logger ) -> CollectorRef < C > ;
380410}
381411
382412impl < C : RawCollectorImpl < Ptr =NonNull < C > > > CollectorInit < C > for NonNull < C > {
383- fn with_logger ( logger : Logger ) -> CollectorRef < C > {
413+ fn with_logger ( config : C :: Config , logger : Logger ) -> CollectorRef < C > {
384414 assert ! ( !C :: SINGLETON ) ;
385- let raw_ptr = C :: init ( logger) ;
415+ let raw_ptr = C :: init ( config , logger) ;
386416 CollectorRef { ptr : raw_ptr }
387417 }
388418}
389419impl < C > CollectorInit < C > for PhantomData < & ' static C >
390420 where C : SingletonCollector {
391- fn with_logger ( logger : Logger ) -> CollectorRef < C > {
421+ fn with_logger ( config : C :: Config , logger : Logger ) -> CollectorRef < C > {
392422 assert ! ( C :: SINGLETON ) ;
393- C :: init_global ( logger) ; // TODO: Is this safe?
423+ C :: init_global ( config , logger) ; // TODO: Is this safe?
394424 // NOTE: The raw pointer is implicit (now that we're leaked)
395425 CollectorRef { ptr : PhantomData }
396426 }
@@ -405,7 +435,11 @@ impl<C: RawCollectorImpl> CollectorRef<C> {
405435
406436 #[ inline]
407437 pub fn with_logger ( logger : Logger ) -> Self where C :: Ptr : CollectorInit < C > {
408- <C :: Ptr as CollectorInit < C > >:: with_logger ( logger)
438+ Self :: with_config ( C :: Config :: default ( ) , logger)
439+ }
440+
441+ pub fn with_config ( config : C :: Config , logger : Logger ) -> Self where C :: Ptr : CollectorInit < C > {
442+ <C :: Ptr as CollectorInit < C > >:: with_logger ( config, logger)
409443 }
410444
411445 #[ inline]
0 commit comments