@@ -12,6 +12,8 @@ use zerogc::{Gc, GcSafe, GcSystem, Trace, GcSimpleAlloc, NullTrace, TraceImmutab
12
12
13
13
use crate :: { CollectorContext } ;
14
14
use crate :: state:: { CollectionManager , RawContext } ;
15
+ use zerogc:: vec:: GcVec ;
16
+ use zerogc:: vec:: repr:: GcVecRepr ;
15
17
16
18
/// A specific implementation of a collector
17
19
pub unsafe trait RawCollectorImpl : ' static + Sized {
@@ -20,6 +22,8 @@ pub unsafe trait RawCollectorImpl: 'static + Sized {
20
22
/// The simple collector implements this as
21
23
/// a trait object pointer.
22
24
type DynTracePtr : Copy + Debug + ' static ;
25
+ /// The configuration
26
+ type Config : Sized + Default ;
23
27
24
28
/// A pointer to this collector
25
29
///
@@ -31,6 +35,8 @@ pub unsafe trait RawCollectorImpl: 'static + Sized {
31
35
32
36
/// The context
33
37
type RawContext : RawContext < Self > ;
38
+ /// The raw representation of a vec
39
+ type RawVecRepr : GcVecRepr ;
34
40
35
41
/// True if this collector is a singleton
36
42
///
@@ -50,18 +56,18 @@ pub unsafe trait RawCollectorImpl: 'static + Sized {
50
56
/// Initialize an instance of the collector
51
57
///
52
58
/// 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 > ;
54
60
55
61
/// The id of this collector
56
62
#[ inline]
57
63
fn id ( & self ) -> CollectorId < Self > {
58
64
CollectorId { ptr : unsafe { Self :: Ptr :: from_raw ( self as * const _ as * mut _ ) } }
59
65
}
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 > > ,
62
68
value : & Gc < ' gc , V , CollectorId < Self > > ,
63
69
field_offset : usize
64
- ) where T : GcSafe + ?Sized + ' gc , V : GcSafe + ?Sized + ' gc ;
70
+ ) where O : GcSafe + ?Sized + ' gc , V : GcSafe + ?Sized + ' gc ;
65
71
/// The logger associated with this collector
66
72
fn logger ( & self ) -> & Logger ;
67
73
@@ -90,7 +96,7 @@ pub unsafe trait SingletonCollector: RawCollectorImpl<Ptr=PhantomData<&'static S
90
96
/// Initialize the global singleton
91
97
///
92
98
/// Panics if already initialized
93
- fn init_global ( logger : Logger ) ;
99
+ fn init_global ( config : Self :: Config , logger : Logger ) ;
94
100
}
95
101
96
102
impl < C : RawCollectorImpl > PartialEq for CollectorId < C > {
@@ -278,6 +284,7 @@ impl<C: RawCollectorImpl> CollectorId<C> {
278
284
}
279
285
unsafe impl < C : RawCollectorImpl > :: zerogc:: CollectorId for CollectorId < C > {
280
286
type System = CollectorRef < C > ;
287
+ type RawVecRepr = C :: RawVecRepr ;
281
288
282
289
#[ inline]
283
290
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> {
286
293
287
294
288
295
#[ 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 > ,
291
298
value : & Gc < ' gc , V , Self > ,
292
299
field_offset : usize
293
- ) where T : GcSafe + ?Sized + ' gc , V : GcSafe + ?Sized + ' gc {
300
+ ) where O : GcSafe + ?Sized + ' gc , V : GcSafe + ?Sized + ' gc {
294
301
C :: gc_write_barrier ( owner, value, field_offset)
295
302
}
296
303
@@ -341,13 +348,36 @@ impl<C: RawCollectorImpl> WeakCollectorRef<C> {
341
348
342
349
pub unsafe trait RawSimpleAlloc : RawCollectorImpl {
343
350
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 ;
344
357
}
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 {
347
360
#[ 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 {
349
363
C :: alloc ( self , value)
350
364
}
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
+ }
351
381
}
352
382
353
383
/// A reference to the collector.
@@ -371,26 +401,26 @@ unsafe impl<C: SyncCollector> Sync for CollectorRef<C> {}
371
401
#[ doc( hidden) ]
372
402
pub trait CollectorInit < C : RawCollectorImpl < Ptr =Self > > : CollectorPtr < C > {
373
403
fn create ( ) -> CollectorRef < C > {
374
- Self :: with_logger ( Logger :: root (
404
+ Self :: with_logger ( C :: Config :: default ( ) , Logger :: root (
375
405
slog:: Discard ,
376
406
o ! ( )
377
407
) )
378
408
}
379
- fn with_logger ( logger : Logger ) -> CollectorRef < C > ;
409
+ fn with_logger ( config : C :: Config , logger : Logger ) -> CollectorRef < C > ;
380
410
}
381
411
382
412
impl < 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 > {
384
414
assert ! ( !C :: SINGLETON ) ;
385
- let raw_ptr = C :: init ( logger) ;
415
+ let raw_ptr = C :: init ( config , logger) ;
386
416
CollectorRef { ptr : raw_ptr }
387
417
}
388
418
}
389
419
impl < C > CollectorInit < C > for PhantomData < & ' static C >
390
420
where C : SingletonCollector {
391
- fn with_logger ( logger : Logger ) -> CollectorRef < C > {
421
+ fn with_logger ( config : C :: Config , logger : Logger ) -> CollectorRef < C > {
392
422
assert ! ( C :: SINGLETON ) ;
393
- C :: init_global ( logger) ; // TODO: Is this safe?
423
+ C :: init_global ( config , logger) ; // TODO: Is this safe?
394
424
// NOTE: The raw pointer is implicit (now that we're leaked)
395
425
CollectorRef { ptr : PhantomData }
396
426
}
@@ -405,7 +435,11 @@ impl<C: RawCollectorImpl> CollectorRef<C> {
405
435
406
436
#[ inline]
407
437
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)
409
443
}
410
444
411
445
#[ inline]
0 commit comments