Skip to content

Commit 6fa54ee

Browse files
committed
bytecode/native changes
1 parent cad0b7a commit 6fa54ee

File tree

7 files changed

+55
-8
lines changed

7 files changed

+55
-8
lines changed

ocaml/runtime/obj.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ struct queue_chunk {
331331
value entries[ENTRIES_PER_QUEUE_CHUNK];
332332
};
333333

334-
CAMLprim value caml_reserved (value v) {
334+
/* Return 0 for uniform blocks and 1+n for a mixed block with scannable prefix
335+
len n.
336+
*/
337+
CAMLprim value caml_succ_scannable_prefix_len (value v) {
338+
#ifdef NATIVE_CODE
335339
return Val_long(Reserved_val(v));
340+
#else
341+
reserved_t reserved = Reserved_val(v);
342+
if (reserved == Faux_mixed_block_sentinel) {
343+
return Val_long(Scannable_wosize_val(v) + 1);
344+
} else {
345+
return Val_long(0);
346+
}
347+
#endif /* NATIVE_CODE */
336348
}

ocaml/runtime4/obj.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,18 @@ struct queue_chunk {
366366
value entries[ENTRIES_PER_QUEUE_CHUNK];
367367
};
368368

369-
CAMLprim value caml_reserved (value v) {
369+
/* Return 0 for uniform blocks and 1+n for a mixed block with scannable prefix
370+
len n.
371+
*/
372+
CAMLprim value caml_succ_scannable_prefix_len (value v) {
373+
#ifdef NATIVE_CODE
370374
return Val_long(Reserved_val(v));
375+
#else
376+
reserved_t reserved = Reserved_val(v);
377+
if (reserved == Faux_mixed_block_sentinel) {
378+
return Val_long(Scannable_wosize_val(v) + 1);
379+
} else {
380+
return Val_long(0);
381+
}
382+
#endif /* NATIVE_CODE */
371383
}

ocaml/stdlib/obj.ml

+6-3
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,14 @@ end
201201
module Uniform_or_mixed = struct
202202
type obj_t = t
203203

204-
(* The raw reserved header bits, which is either 0 if the block is uniform or
205-
n+1 if the block has a scannable prefix of length n. *)
204+
(* In native code, the raw reserved header bits, which is either 0 if the
205+
block is uniform or n+1 if the block has a scannable prefix of length n.
206+
In bytecode, this will be size+1 for "faux mixed blocks" representing
207+
mixed records, and otherwise 0.
208+
*)
206209
type t = int
207210

208-
external of_block : obj_t -> t = "caml_reserved" [@@noalloc]
211+
external of_block : obj_t -> t = "caml_succ_scannable_prefix_len" [@@noalloc]
209212

210213
type repr =
211214
| Uniform

ocaml/stdlib/obj.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ module Uniform_or_mixed : sig
192192

193193
val repr : t -> repr
194194

195-
external of_block : obj_t -> t = "caml_reserved" [@@noalloc]
195+
external of_block : obj_t -> t = "caml_succ_scannable_prefix_len" [@@noalloc]
196196

197197
val is_uniform : t -> bool
198198
(** Equivalent to [repr] returning [Uniform]. *)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
t_uniform1: uniform
2+
t_uniform2.0: uniform
3+
t_uniform2.1: uniform
4+
t_uniform3: uniform
5+
t_mixed0: mixed (scannable_prefix_len = 1)
6+
t_mixed1: mixed (scannable_prefix_len = 2)
7+
t_mixed2: mixed (scannable_prefix_len = 3)

ocaml/testsuite/tests/lib-obj/uniform_or_mixed.ml

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
(* TEST
2-
flags="-extension layouts_beta";
3-
native;
2+
flags = "-extension layouts_beta";
3+
{
4+
reference = "${test_source_directory}/uniform_or_mixed.native.reference";
5+
compiler_reference2 = "${test_source_directory}/uniform_or_mixed.compiler.reference";
6+
native;
7+
}{
8+
reference = "${test_source_directory}/uniform_or_mixed.bytecode.reference";
9+
compiler_reference2 = "${test_source_directory}/uniform_or_mixed.compiler.reference";
10+
bytecode;
11+
}
12+
*)
13+
14+
(* Bytecode and native code have slightly different outputs for the scannable prefix
15+
of mixed records. The fields of mixed records must be scanned in bytecode.
16+
(They are "faux mixed blocks".)
417
*)
518

619
type t_uniform1 = { x : int }

0 commit comments

Comments
 (0)