@@ -25,23 +25,6 @@ use crate::error::Error;
25
25
use crate :: fmt;
26
26
use crate :: ptr:: { self , NonNull } ;
27
27
28
- // @FIXME Make this target-specific
29
- /// Metadata for `Vec/VecDeque/RawVec` to assist the allocator. Make sure its
30
- /// alignment is not bigger than alignment of `usize`. Otherwise, even if (a
31
- /// particular) `Vec/VecDeque/RawVec` generic instance doesn't use cooperation,
32
- /// it would increase size of that `Vec/VecDeque/RawVec` because of alignment
33
- /// rules! @FIXME compile time test that `GlobalCoAllocMeta` alignment <=
34
- /// `usize` alignment.
35
- #[ unstable( feature = "global_co_alloc_meta" , issue = "none" ) ]
36
- #[ allow( missing_debug_implementations) ]
37
- #[ derive( Clone , Copy ) ]
38
- pub struct GlobalCoAllocMeta {
39
- //pub one: usize,
40
- /*pub two: usize,
41
- pub three: usize,
42
- pub four: usize,*/
43
- }
44
-
45
28
/// The `AllocError` error indicates an allocation failure
46
29
/// that may be due to resource exhaustion or to
47
30
/// something wrong when combining the given input arguments with this
@@ -68,18 +51,20 @@ impl fmt::Display for AllocError {
68
51
/// (Non-Null) Pointer and coallocation metadata.
69
52
#[ unstable( feature = "global_co_alloc_meta" , issue = "none" ) ]
70
53
#[ allow( missing_debug_implementations) ]
71
- pub struct PtrAndMeta {
54
+ #[ derive( Clone , Copy ) ]
55
+ pub struct PtrAndMeta < M : Clone + Copy > {
72
56
pub ptr : NonNull < u8 > ,
73
- pub meta : GlobalCoAllocMeta ,
57
+ pub meta : M ,
74
58
}
75
59
76
60
/// (NonNull) Slice and coallocation metadata.
77
61
#[ unstable( feature = "global_co_alloc_meta" , issue = "none" ) ]
78
62
#[ allow( missing_debug_implementations) ]
63
+ #[ derive( Clone , Copy ) ]
79
64
/// Used for results (from `CoAllocator`'s functions, where applicable).
80
- pub struct SliceAndMeta {
65
+ pub struct SliceAndMeta < M : Clone + Copy > {
81
66
pub slice : NonNull < [ u8 ] > ,
82
- pub meta : GlobalCoAllocMeta ,
67
+ pub meta : M ,
83
68
}
84
69
85
70
#[ unstable( feature = "global_co_alloc_short_term_pref" , issue = "none" ) ]
@@ -94,8 +79,9 @@ macro_rules! SHORT_TERM_VEC_PREFERS_COOP {
94
79
/// `Result` of `SliceAndMeta` or `AllocError`.
95
80
#[ unstable( feature = "global_co_alloc_meta" , issue = "none" ) ]
96
81
#[ allow( missing_debug_implementations) ]
97
- pub type SliceAndMetaResult = Result < SliceAndMeta , AllocError > ;
82
+ pub type SliceAndMetaResult < M > = Result < SliceAndMeta < M > , AllocError > ;
98
83
84
+ // @FIXME REMOVE
99
85
/// Return 0 or 1, indicating whether to use coallocation metadata or not.
100
86
/// Param `coop_preferred` - if false, then this returns `0`, regardless of
101
87
/// whether allocator `A` is cooperative.
@@ -172,6 +158,8 @@ pub unsafe trait Allocator {
172
158
// It applies to the global (default) allocator only. And/or System allocator?! @FIXME
173
159
const CO_ALLOCATES_WITH_META : bool = false ;
174
160
161
+ /// @FIXME Validate (preferrable at compile time, otherwise as a test) that this type's
162
+ /// alignment <= `usize` alignment.
175
163
type CoAllocMeta : Clone + Copy = ( ) ;
176
164
177
165
/// Attempts to allocate a block of memory.
@@ -196,7 +184,7 @@ pub unsafe trait Allocator {
196
184
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
197
185
fn allocate ( & self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocError > ;
198
186
199
- fn co_allocate ( & self , _layout : Layout , _result : & mut SliceAndMetaResult ) {
187
+ fn co_allocate ( & self , _layout : Layout , _result : & mut SliceAndMetaResult < Self :: CoAllocMeta > ) {
200
188
panic ! ( "FIXME" )
201
189
}
202
190
@@ -222,7 +210,11 @@ pub unsafe trait Allocator {
222
210
Ok ( ptr)
223
211
}
224
212
225
- fn co_allocate_zeroed ( & self , layout : Layout , mut result : & mut SliceAndMetaResult ) {
213
+ fn co_allocate_zeroed (
214
+ & self ,
215
+ layout : Layout ,
216
+ mut result : & mut SliceAndMetaResult < Self :: CoAllocMeta > ,
217
+ ) {
226
218
self . co_allocate ( layout, & mut result) ;
227
219
if let Ok ( SliceAndMeta { slice, .. } ) = result {
228
220
// SAFETY: `alloc` returns a valid memory block
@@ -241,7 +233,7 @@ pub unsafe trait Allocator {
241
233
/// [*fit*]: #memory-fitting
242
234
unsafe fn deallocate ( & self , ptr : NonNull < u8 > , layout : Layout ) ;
243
235
244
- unsafe fn co_deallocate ( & self , _ptr_and_meta : PtrAndMeta , _layout : Layout ) {
236
+ unsafe fn co_deallocate ( & self , _ptr_and_meta : PtrAndMeta < Self :: CoAllocMeta > , _layout : Layout ) {
245
237
panic ! ( "FIXME" )
246
238
}
247
239
@@ -311,10 +303,10 @@ pub unsafe trait Allocator {
311
303
312
304
unsafe fn co_grow (
313
305
& self ,
314
- ptr_and_meta : PtrAndMeta ,
306
+ ptr_and_meta : PtrAndMeta < Self :: CoAllocMeta > ,
315
307
old_layout : Layout ,
316
308
new_layout : Layout ,
317
- mut result : & mut SliceAndMetaResult ,
309
+ mut result : & mut SliceAndMetaResult < Self :: CoAllocMeta > ,
318
310
) {
319
311
debug_assert ! (
320
312
new_layout. size( ) >= old_layout. size( ) ,
@@ -405,10 +397,10 @@ pub unsafe trait Allocator {
405
397
406
398
unsafe fn co_grow_zeroed (
407
399
& self ,
408
- ptr_and_meta : PtrAndMeta ,
400
+ ptr_and_meta : PtrAndMeta < Self :: CoAllocMeta > ,
409
401
old_layout : Layout ,
410
402
new_layout : Layout ,
411
- mut result : & mut SliceAndMetaResult ,
403
+ mut result : & mut SliceAndMetaResult < Self :: CoAllocMeta > ,
412
404
) {
413
405
debug_assert ! (
414
406
new_layout. size( ) >= old_layout. size( ) ,
@@ -500,10 +492,10 @@ pub unsafe trait Allocator {
500
492
501
493
unsafe fn co_shrink (
502
494
& self ,
503
- ptr_and_meta : PtrAndMeta ,
495
+ ptr_and_meta : PtrAndMeta < Self :: CoAllocMeta > ,
504
496
old_layout : Layout ,
505
497
new_layout : Layout ,
506
- mut result : & mut SliceAndMetaResult ,
498
+ mut result : & mut SliceAndMetaResult < Self :: CoAllocMeta > ,
507
499
) {
508
500
debug_assert ! (
509
501
new_layout. size( ) <= old_layout. size( ) ,
0 commit comments