@@ -125,14 +125,32 @@ macro_rules! __rust_force_expr {
125
125
} ;
126
126
}
127
127
128
- // ----- CoAlloc constant-like macros:
128
+ // ----- CoAlloc ICE workaround macro:
129
+ /// This "validates" type of a given `const` expression, and it casts it. That helps to prevent mix ups with macros/integer constant values.
130
+ #[ doc( hidden) ]
131
+ #[ macro_export]
132
+ #[ unstable( feature = "global_co_alloc_meta" , issue = "none" ) ] macro_rules! check_type_and_cast {
133
+ // Use the following for compile-time/build check only. And use it
134
+ // with a hard-coded `0` version of `meta_num_slots` - otherwise you get an ICE.
135
+ //
136
+ /*($e:expr, $t_check:ty, $t_cast:ty) => {
137
+ ($e + 0 as $t_check) as $t_cast
138
+ }*/
139
+ // Use the following to build for testing/using, while rustc causes an ICE with the above and
140
+ // with a full version of `meta_num_slots`.
141
+ ( $e: expr, $t_check: ty, $t_cast: ty) => {
142
+ $e
143
+ }
144
+ }
129
145
146
+ // ----- CoAlloc constant-like macros:
130
147
/// Coallocation option/parameter about using metadata that does prefer to use meta data. This is of type [::alloc::co_alloc::CoAllocMetaNumSlotsPref] (but not a whole []::alloc::co_alloc::CoAllocPref]).
148
+ #[ doc( hidden) ]
131
149
#[ unstable( feature = "global_co_alloc_meta" , issue = "none" ) ]
132
150
#[ macro_export]
133
151
macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ONE {
134
152
( ) => {
135
- ( 1 as $crate:: co_alloc:: CoAllocMetaNumSlotsPref )
153
+ $crate :: check_type_and_cast! ( 1 , i32 , $crate:: co_alloc:: CoAllocMetaNumSlotsPref )
136
154
} ;
137
155
}
138
156
@@ -141,7 +159,7 @@ macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ONE {
141
159
#[ macro_export]
142
160
macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ZERO {
143
161
( ) => {
144
- ( 0 as $crate:: co_alloc:: CoAllocMetaNumSlotsPref )
162
+ $crate :: check_type_and_cast! ( 0 , i32 , $crate:: co_alloc:: CoAllocMetaNumSlotsPref )
145
163
} ;
146
164
}
147
165
@@ -150,7 +168,7 @@ macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_ZERO {
150
168
#[ macro_export]
151
169
macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT {
152
170
( ) => {
153
- ( 0 as $crate:: co_alloc:: CoAllocMetaNumSlotsPref )
171
+ $crate :: check_type_and_cast! ( 0 , i32 , $crate:: co_alloc:: CoAllocMetaNumSlotsPref )
154
172
} ;
155
173
}
156
174
@@ -167,6 +185,7 @@ macro_rules! CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT {
167
185
#[ macro_export]
168
186
macro_rules! CO_ALLOC_PREF_META_YES {
169
187
( ) => {
188
+ //1usize
170
189
$crate:: co_alloc_pref!( $crate:: CO_ALLOC_PREF_NUM_META_SLOTS_ONE !( ) )
171
190
} ;
172
191
}
@@ -184,6 +203,7 @@ macro_rules! CO_ALLOC_PREF_META_YES {
184
203
#[ macro_export]
185
204
macro_rules! CO_ALLOC_PREF_META_NO {
186
205
( ) => {
206
+ //0usize
187
207
$crate:: co_alloc_pref!( $crate:: CO_ALLOC_PREF_NUM_META_SLOTS_ZERO !( ) )
188
208
} ;
189
209
}
@@ -202,6 +222,7 @@ macro_rules! CO_ALLOC_PREF_META_NO {
202
222
#[ macro_export]
203
223
macro_rules! CO_ALLOC_PREF_META_DEFAULT {
204
224
( ) => {
225
+ //0usize
205
226
$crate:: co_alloc_pref!( $crate:: CO_ALLOC_PREF_NUM_META_SLOTS_DEFAULT !( ) )
206
227
} ;
207
228
}
@@ -211,6 +232,7 @@ macro_rules! CO_ALLOC_PREF_META_DEFAULT {
211
232
#[ macro_export]
212
233
macro_rules! CO_ALLOC_PREF_DEFAULT {
213
234
( ) => {
235
+ //0usize
214
236
$crate:: CO_ALLOC_PREF_META_DEFAULT !( )
215
237
} ;
216
238
}
@@ -221,6 +243,7 @@ macro_rules! CO_ALLOC_PREF_DEFAULT {
221
243
#[ macro_export]
222
244
macro_rules! SHORT_TERM_VEC_CO_ALLOC_PREF {
223
245
( ) => {
246
+ //0usize
224
247
$crate:: CO_ALLOC_PREF_META_NO !( )
225
248
} ;
226
249
}
@@ -242,8 +265,8 @@ macro_rules! co_alloc_pref {
242
265
// report the incorrect type of $meta_pref (if $meta_pref were some other integer, casting would
243
266
// compile, and we would not be notified).
244
267
( $meta_pref: expr) => {
245
- ( ( $meta_pref + ( 0 as $crate:: co_alloc:: CoAllocMetaNumSlotsPref ) )
246
- as $crate:: co_alloc:: CoAllocPref )
268
+ $crate :: check_type_and_cast! ( $meta_pref, $crate:: co_alloc:: CoAllocMetaNumSlotsPref ,
269
+ $crate:: co_alloc:: CoAllocPref )
247
270
} ;
248
271
}
249
272
@@ -267,18 +290,29 @@ macro_rules! co_alloc_pref {
267
290
#[ unstable( feature = "global_co_alloc" , issue = "none" ) ]
268
291
#[ macro_export]
269
292
macro_rules! meta_num_slots {
270
- // Generating, for example, (0 as usize), here, triggers an ICE.
271
-
272
- // This "validates" types of both params - to prevent mix ups.
273
- // @FIXME remove this comment line: Removing/commenting out the part: <$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS +
274
- // does NOT fix the ICE (unless there are multiple ICE's).
293
+ // @FIXME Use this only
294
+ // - once the ICE gets fixed, or
295
+ // - (until the ICE is fixed) with a related change in `check_type_and_cast` that makes it pass
296
+ // the given expression (parameter) unchecked & uncast.
297
+ /*($alloc:ty, $co_alloc_pref:expr) => {
298
+ $crate::check_type_and_cast!(<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS,::core::alloc::CoAllocatorMetaNumSlots,
299
+ usize) *
300
+ $crate::check_type_and_cast!($co_alloc_pref, $crate::co_alloc::CoAllocPref, usize)
301
+ };*/
302
+ // Use for testing & production, until ICE gets fixed. (Regardless of $co_alloc_pref.)
303
+ //
304
+ // Why still ICE?!
275
305
( $alloc: ty, $co_alloc_pref: expr) => {
276
- /*(
277
- ((<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS + (0 as ::core::alloc::CoAllocatorMetaNumSlots))0
278
- as usize)
279
- * ($co_alloc_pref + (0 as $crate::co_alloc::CoAllocPref))
280
- as usize)*/ 0usize
281
- } ;
306
+ // The following fails here - even if not used from meta_num_slots_default nor from meta_num_slots_global!
307
+ //<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS
308
+ //<$crate::alloc::Global as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS
309
+ //1usize
310
+ $co_alloc_pref
311
+ }
312
+ // Use for testing & production as enforcing no meta.
313
+ /*($alloc:ty, $co_alloc_pref:expr) => {
314
+ 0usize // compiles
315
+ }*/
282
316
}
283
317
// -\---> replace with something like:
284
318
/*
@@ -304,7 +338,10 @@ macro_rules! meta_num_slots_default {
304
338
// Can't generate if ... {1} else {0}
305
339
// because it's "overly complex generic constant".
306
340
( $alloc: ty) => {
341
+ // EITHER of the following are OK here
307
342
$crate:: meta_num_slots!( $alloc, $crate:: CO_ALLOC_PREF_DEFAULT !( ) )
343
+ //<$alloc as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS
344
+ //<$crate::alloc::Global as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS
308
345
} ;
309
346
}
310
347
@@ -320,10 +357,13 @@ macro_rules! meta_num_slots_default {
320
357
#[ macro_export]
321
358
macro_rules! meta_num_slots_global {
322
359
( $co_alloc_pref: expr) => {
360
+ // EITHER of the following are OK here
323
361
$crate:: meta_num_slots!( $crate:: alloc:: Global , $co_alloc_pref)
362
+ // The following is OK here:
363
+ //<$crate::alloc::Global as ::core::alloc::Allocator>::CO_ALLOC_META_NUM_SLOTS
324
364
} ;
325
365
}
326
-
366
+ /*
327
367
/// Like `meta_num_slots`, but for `Global allocator and default coallocation preference
328
368
/// (`CO_ALLOC_PREF_DEFAULT`).
329
369
///
@@ -336,3 +376,4 @@ macro_rules! meta_num_slots_default_global {
336
376
$crate::meta_num_slots!($crate::alloc::Global, $crate::CO_ALLOC_PREF_DEFAULT!())
337
377
};
338
378
}
379
+ */
0 commit comments