@@ -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,33 @@ 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_with_capacity < ' gc , T > ( context : & ' gc CollectorContext < Self > , capacity : usize ) -> GcVec < ' gc , T , CollectorContext < Self > > where T : GcSafe + ' gc ;
344
354
}
345
- unsafe impl < ' gc , T , C > GcSimpleAlloc < ' gc , T > for CollectorContext < C >
346
- where T : GcSafe + ' gc , C : RawSimpleAlloc {
355
+ unsafe impl < C > GcSimpleAlloc for CollectorContext < C >
356
+ where C : RawSimpleAlloc {
347
357
#[ inline]
348
- fn alloc ( & ' gc self , value : T ) -> Gc < ' gc , T , Self :: Id > {
358
+ fn alloc < ' gc , T > ( & ' gc self , value : T ) -> Gc < ' gc , T , Self :: Id >
359
+ where T : GcSafe + ' gc {
349
360
C :: alloc ( self , value)
350
361
}
362
+
363
+ #[ inline]
364
+ unsafe fn alloc_uninit_slice < ' gc , T > ( & ' gc self , len : usize ) -> ( Self :: Id , * mut T )
365
+ where T : GcSafe + ' gc {
366
+ C :: alloc_uninit_slice ( self , len)
367
+ }
368
+
369
+ #[ inline]
370
+ fn alloc_vec < ' gc , T > ( & ' gc self ) -> GcVec < ' gc , T , Self > where T : GcSafe + ' gc {
371
+ self . alloc_vec_with_capacity ( 0 )
372
+ }
373
+
374
+ #[ inline]
375
+ fn alloc_vec_with_capacity < ' gc , T > ( & ' gc self , capacity : usize ) -> GcVec < ' gc , T , Self > where T : GcSafe + ' gc {
376
+ C :: alloc_vec_with_capacity ( self , capacity)
377
+ }
351
378
}
352
379
353
380
/// A reference to the collector.
@@ -371,26 +398,26 @@ unsafe impl<C: SyncCollector> Sync for CollectorRef<C> {}
371
398
#[ doc( hidden) ]
372
399
pub trait CollectorInit < C : RawCollectorImpl < Ptr =Self > > : CollectorPtr < C > {
373
400
fn create ( ) -> CollectorRef < C > {
374
- Self :: with_logger ( Logger :: root (
401
+ Self :: with_logger ( C :: Config :: default ( ) , Logger :: root (
375
402
slog:: Discard ,
376
403
o ! ( )
377
404
) )
378
405
}
379
- fn with_logger ( logger : Logger ) -> CollectorRef < C > ;
406
+ fn with_logger ( config : C :: Config , logger : Logger ) -> CollectorRef < C > ;
380
407
}
381
408
382
409
impl < C : RawCollectorImpl < Ptr =NonNull < C > > > CollectorInit < C > for NonNull < C > {
383
- fn with_logger ( logger : Logger ) -> CollectorRef < C > {
410
+ fn with_logger ( config : C :: Config , logger : Logger ) -> CollectorRef < C > {
384
411
assert ! ( !C :: SINGLETON ) ;
385
- let raw_ptr = C :: init ( logger) ;
412
+ let raw_ptr = C :: init ( config , logger) ;
386
413
CollectorRef { ptr : raw_ptr }
387
414
}
388
415
}
389
416
impl < C > CollectorInit < C > for PhantomData < & ' static C >
390
417
where C : SingletonCollector {
391
- fn with_logger ( logger : Logger ) -> CollectorRef < C > {
418
+ fn with_logger ( config : C :: Config , logger : Logger ) -> CollectorRef < C > {
392
419
assert ! ( C :: SINGLETON ) ;
393
- C :: init_global ( logger) ; // TODO: Is this safe?
420
+ C :: init_global ( config , logger) ; // TODO: Is this safe?
394
421
// NOTE: The raw pointer is implicit (now that we're leaked)
395
422
CollectorRef { ptr : PhantomData }
396
423
}
@@ -405,7 +432,11 @@ impl<C: RawCollectorImpl> CollectorRef<C> {
405
432
406
433
#[ inline]
407
434
pub fn with_logger ( logger : Logger ) -> Self where C :: Ptr : CollectorInit < C > {
408
- <C :: Ptr as CollectorInit < C > >:: with_logger ( logger)
435
+ Self :: with_config ( C :: Config :: default ( ) , logger)
436
+ }
437
+
438
+ pub fn with_config ( config : C :: Config , logger : Logger ) -> Self where C :: Ptr : CollectorInit < C > {
439
+ <C :: Ptr as CollectorInit < C > >:: with_logger ( config, logger)
409
440
}
410
441
411
442
#[ inline]
0 commit comments