@@ -130,7 +130,7 @@ mixed blocks. In the upstream compiler, R is set with the
130
130
131
131
#define Tag_hd (hd ) ((tag_t) ((hd) & HEADER_TAG_MASK))
132
132
#define Hd_with_tag (hd , tag ) (((hd) &~ HEADER_TAG_MASK) | (tag))
133
- #define Wosize_hd (hd ) ((mlsize_t) (((hd) & HEADER_WOSIZE_MASK) \
133
+ #define Allocated_wosize_hd (hd ) ((mlsize_t) (((hd) & HEADER_WOSIZE_MASK) \
134
134
>> HEADER_WOSIZE_SHIFT))
135
135
136
136
/* A "clean" header, without reserved or color bits. */
@@ -192,7 +192,7 @@ Caml_inline mlsize_t Scannable_wosize_hd_native(header_t hd) {
192
192
return
193
193
Is_mixed_block_reserved (res )
194
194
? Mixed_block_scannable_wosize_reserved_native (res )
195
- : Wosize_hd (hd );
195
+ : Allocated_wosize_hd (hd );
196
196
}
197
197
198
198
/* Bytecode versions of mixed block macros.
@@ -203,8 +203,8 @@ Caml_inline mlsize_t Scannable_wosize_hd_native(header_t hd) {
203
203
in the header bits.
204
204
*/
205
205
206
- #define Scannable_wosize_hd_byte (hd ) (Wosize_hd (hd))
207
- #define Scannable_wosize_val_byte (val ) (Wosize_hd (Hd_val (val)))
206
+ #define Scannable_wosize_hd_byte (hd ) (Allocated_wosize_hd (hd))
207
+ #define Scannable_wosize_val_byte (val ) (Allocated_wosize_hd (Hd_val (val)))
208
208
Caml_inline mlsize_t Scannable_wosize_reserved_byte (reserved_t res ,
209
209
mlsize_t size ) {
210
210
(void )res ;
@@ -252,33 +252,64 @@ Caml_inline mlsize_t Scannable_wosize_reserved_byte(reserved_t res,
252
252
#define Num_tags (1ull << HEADER_TAG_BITS)
253
253
#define Max_wosize ((1ull << HEADER_WOSIZE_BITS) - 1ull)
254
254
255
- // Note that Wosize_val and the other macros that read headers will not
256
- // be optimized by common subexpression elimination, because of the
257
- // atomic header loads. It is best to bind the results of such macros
258
- // to variables if they will be tested repeatedly, e.g. as the end condition
259
- // in a for-loop.
260
-
261
- #define Wosize_val (val ) (Wosize_hd (Hd_val (val)))
262
- #define Wosize_op (op ) (Wosize_val (op))
263
- #define Wosize_bp (bp ) (Wosize_val (bp))
264
- #define Wosize_hp (hp ) (Wosize_hd (Hd_hp (hp)))
265
255
#define Whsize_wosize (sz ) ((sz) + 1)
266
256
#define Wosize_whsize (sz ) ((sz) - 1)
267
257
#define Wosize_bhsize (sz ) ((sz) / sizeof (value) - 1)
268
258
#define Bsize_wsize (sz ) ((sz) * sizeof (value))
269
259
#define Wsize_bsize (sz ) ((sz) / sizeof (value))
270
260
#define Bhsize_wosize (sz ) (Bsize_wsize (Whsize_wosize (sz)))
271
261
#define Bhsize_bosize (sz ) ((sz) + sizeof (header_t))
272
- #define Bosize_val (val ) (Bsize_wsize (Wosize_val (val)))
273
- #define Bosize_op (op ) (Bosize_val (Val_op (op)))
274
- #define Bosize_bp (bp ) (Bosize_val (Val_bp (bp)))
275
- #define Bosize_hd (hd ) (Bsize_wsize (Wosize_hd (hd)))
276
- #define Whsize_hp (hp ) (Whsize_wosize (Wosize_hp (hp)))
277
- #define Whsize_val (val ) (Whsize_hp (Hp_val (val)))
278
- #define Whsize_bp (bp ) (Whsize_val (Val_bp (bp)))
279
- #define Whsize_hd (hd ) (Whsize_wosize (Wosize_hd (hd)))
280
- #define Bhsize_hp (hp ) (Bsize_wsize (Whsize_hp (hp)))
281
- #define Bhsize_hd (hd ) (Bsize_wsize (Whsize_hd (hd)))
262
+
263
+ /* Note that Allocated_wosize_val and the other macros that read headers will not
264
+ be optimized by common subexpression elimination, because of the
265
+ atomic header loads. It is best to bind the results of such macros
266
+ to variables if they will be tested repeatedly, e.g. as the end condition
267
+ in a for-loop.
268
+ */
269
+
270
+ /* We rename the size macros to [Allocated_...] internally so that we're forced
271
+ to think about whether imported code needs to updated for mixed blocks,
272
+ which have separate notions of scannable size and total size of
273
+ an object, even for scannable tags. We call an object's size
274
+ (including possibly non-scannable fields) its "allocated" size
275
+ to document the fact that you shouldn't scan fields on the
276
+ basis of this size alone.
277
+ */
278
+
279
+ #define Allocated_wosize_val (val ) (Allocated_wosize_hd (Hd_val (val)))
280
+ #define Allocated_wosize_op (op ) (Allocated_wosize_val (op))
281
+ #define Allocated_wosize_bp (bp ) (Allocated_wosize_val (bp))
282
+ #define Allocated_wosize_hp (hp ) (Allocated_wosize_hd (Hd_hp (hp)))
283
+ #define Allocated_bosize_val (val ) (Bsize_wsize (Allocated_wosize_val (val)))
284
+ #define Allocated_bosize_op (op ) (Allocated_bosize_val (Val_op (op)))
285
+ #define Allocated_bosize_bp (bp ) (Allocated_bosize_val (Val_bp (bp)))
286
+ #define Allocated_bosize_hd (hd ) (Bsize_wsize (Allocated_wosize_hd (hd)))
287
+ #define Allocated_whsize_hp (hp ) (Whsize_wosize (Allocated_wosize_hp (hp)))
288
+ #define Allocated_whsize_val (val ) (Allocated_whsize_hp (Hp_val (val)))
289
+ #define Allocated_whsize_bp (bp ) (Allocated_whsize_val (Val_bp (bp)))
290
+ #define Allocated_whsize_hd (hd ) (Whsize_wosize (Allocated_wosize_hd (hd)))
291
+ #define Allocated_bhsize_hp (hp ) (Bsize_wsize (Allocated_whsize_hp (hp)))
292
+ #define Allocated_bhsize_hd (hd ) (Bsize_wsize (Allocated_whsize_hd (hd)))
293
+
294
+ /* CR nroberts: Soon, we'd like to only define these macros if CAML_INTERNALS
295
+ is defined. This allows us to ban the old names in user code.
296
+ */
297
+ #define Wosize_hd (hd ) Allocated_wosize_hd(hd)
298
+ #define Wosize_val (val ) Allocated_wosize_val(val)
299
+ #define Wosize_op (op ) Allocated_wosize_op(op)
300
+ #define Wosize_bp (bp ) Allocated_wosize_bp(bp)
301
+ #define Wosize_hp (hp ) Allocated_wosize_hp(hp)
302
+ #define Bosize_val (val ) Allocated_bosize_val(val)
303
+ #define Bosize_op (op ) Allocated_bosize_op(op)
304
+ #define Bosize_bp (bp ) Allocated_bosize_bp(bp)
305
+ #define Bosize_hd (hd ) Allocated_bosize_hd(hd)
306
+ #define Whsize_hp (hp ) Allocated_whsize_hp(hp)
307
+ #define Whsize_val (val ) Allocated_whsize_val(val)
308
+ #define Whsize_bp (bp ) Allocated_whsize_bp(bp)
309
+ #define Whsize_hd (hd ) Allocated_whsize_hd(hd)
310
+ #define Bhsize_hp (hp ) Allocated_bhsize_hp(hp)
311
+ #define Bhsize_hd (hd ) Allocated_bhsize_hd(hd)
312
+ #endif // CAML_INTERNALS
282
313
283
314
#define Reserved_val (val ) (Reserved_hd (Hd_val (val)))
284
315
@@ -333,7 +364,7 @@ Caml_inline mlsize_t Scannable_wosize_reserved_byte(reserved_t res,
333
364
with tag Closure_tag (see compact.c). */
334
365
335
366
#define Infix_tag 249
336
- #define Infix_offset_hd (hd ) (Bosize_hd (hd))
367
+ #define Infix_offset_hd (hd ) (Allocated_bosize_hd (hd))
337
368
#define Infix_offset_val (v ) Infix_offset_hd(Hd_val(v))
338
369
339
370
/* Another special case: objects */
0 commit comments