Skip to content

Commit f81cd59

Browse files
committed
Forward port is_last closinfo flag
1 parent 3478d80 commit f81cd59

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

ocaml/runtime/alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ CAMLprim value caml_alloc_dummy_infix(value vsize, value voffset)
312312
block contains no pointers into the heap. However, the block
313313
cannot be marshaled or hashed, because not all closinfo fields
314314
and infix header fields are correctly initialized. */
315-
Closinfo_val(v) = Make_closinfo(0, wosize);
315+
Closinfo_val(v) = Make_closinfo(0, wosize, 1);
316316
if (offset > 0) {
317317
v += Bsize_wsize(offset);
318318
(((header_t *) (v)) [-1]) = Make_header(offset, Infix_tag, 0);

ocaml/runtime/caml/mlvalues.h

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,28 @@ Caml_inline void* Ptr_val(value val)
276276
#define Code_val(val) (((code_t *) (val)) [0]) /* Also an l-value. */
277277
#define Closinfo_val(val) Field((val), 1) /* Arity and start env */
278278
/* In the closure info field, the top 8 bits are the arity (signed).
279+
The next least significant bit is set iff the current closure is the
280+
last one to occur in the block. (This is used in the compactor.)
279281
The low bit is set to one, to look like an integer.
280-
The remaining bits are the field number for the first word of the
281-
environment, or, in other words, the offset (in words) from the closure
282-
to the environment part. */
282+
The remaining bits are the field number for the first word of the scannable
283+
part of the environment, or, in other words, the offset (in words) from the
284+
closure to the scannable part of the environment.
285+
The non-scannable part of the environment lives between the end of the
286+
last closure and the start of the scannable environment within the block. */
283287
#ifdef ARCH_SIXTYFOUR
284288
#define Arity_closinfo(info) ((intnat)(info) >> 56)
285-
#define Start_env_closinfo(info) (((uintnat)(info) << 8) >> 9)
286-
#define Make_closinfo(arity,delta) \
287-
(((uintnat)(arity) << 56) + ((uintnat)(delta) << 1) + 1)
289+
#define Start_env_closinfo(info) (((uintnat)(info) << 9) >> 10)
290+
#define Is_last_closinfo(info) (((uintnat)(info) << 8) >> 63)
291+
#define Make_closinfo(arity,delta,is_last) \
292+
(((uintnat)(arity) << 56) + ((uintnat)(is_last) << 55) \
293+
+ ((uintnat)(delta) << 1) + 1)
288294
#else
289295
#define Arity_closinfo(info) ((intnat)(info) >> 24)
290-
#define Start_env_closinfo(info) (((uintnat)(info) << 8) >> 9)
291-
#define Make_closinfo(arity,delta) \
292-
(((uintnat)(arity) << 24) + ((uintnat)(delta) << 1) + 1)
296+
#define Start_env_closinfo(info) (((uintnat)(info) << 9) >> 10)
297+
#define Is_last_closinfo(info) (((uintnat)(info) << 8) >> 31)
298+
#define Make_closinfo(arity,delta,is_last) \
299+
(((uintnat)(arity) << 24) + ((uintnat)(is_last) << 23) \
300+
+ ((uintnat)(delta) << 1) + 1)
293301
#endif
294302

295303
/* This tag is used (with Forcing_tag & Forward_tag) to implement lazy values.

ocaml/runtime/interp.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ value caml_interprete(code_t prog, asize_t prog_size)
300300
raise_unhandled_effect_closure = caml_alloc_small (2, Closure_tag);
301301
Code_val(raise_unhandled_effect_closure) =
302302
(code_t)raise_unhandled_effect_code;
303-
Closinfo_val(raise_unhandled_effect_closure) = Make_closinfo(0, 2);
303+
Closinfo_val(raise_unhandled_effect_closure) = Make_closinfo(0, 2, 1);
304304
raise_unhandled_effect = raise_unhandled_effect_closure;
305305
caml_register_generational_global_root(&raise_unhandled_effect);
306306
caml_global_data = Val_unit;
@@ -624,7 +624,7 @@ value caml_interprete(code_t prog, asize_t prog_size)
624624
Field(accu, 2) = env;
625625
for (i = 0; i < num_args; i++) Field(accu, i + 3) = sp[i];
626626
Code_val(accu) = pc - 3; /* Point to the preceding RESTART instr. */
627-
Closinfo_val(accu) = Make_closinfo(0, 2);
627+
Closinfo_val(accu) = Make_closinfo(0, 2, 1);
628628
sp += num_args;
629629
goto do_return;
630630
}
@@ -648,7 +648,7 @@ value caml_interprete(code_t prog, asize_t prog_size)
648648
/* The code pointer is not in the heap, so no need to go through
649649
caml_initialize. */
650650
Code_val(accu) = pc + *pc;
651-
Closinfo_val(accu) = Make_closinfo(0, 2);
651+
Closinfo_val(accu) = Make_closinfo(0, 2, 1);
652652
pc++;
653653
sp += nvars;
654654
Next;
@@ -680,13 +680,13 @@ value caml_interprete(code_t prog, asize_t prog_size)
680680
*--sp = accu;
681681
p = &Field(accu, 0);
682682
*p++ = (value) (pc + pc[0]);
683-
*p++ = Make_closinfo(0, envofs);
683+
*p++ = Make_closinfo(0, envofs, nfuncs < 2);
684684
for (i = 1; i < nfuncs; i++) {
685685
*p++ = Make_header(i * 3, Infix_tag, 0); /* color irrelevant */
686686
*--sp = (value) p;
687687
*p++ = (value) (pc + pc[i]);
688688
envofs -= 3;
689-
*p++ = Make_closinfo(0, envofs);
689+
*p++ = Make_closinfo(0, envofs, i == nfuncs - 1);
690690
}
691691
pc += nfuncs;
692692
Next;

ocaml/runtime/meta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ CAMLprim value caml_reify_bytecode(value ls_prog,
121121

122122
clos = caml_alloc_small (2, Closure_tag);
123123
Code_val(clos) = (code_t) prog;
124-
Closinfo_val(clos) = Make_closinfo(0, 2);
124+
Closinfo_val(clos) = Make_closinfo(0, 2, 1);
125125
bytecode = caml_alloc_small (2, Abstract_tag);
126126
Bytecode_val(bytecode)->prog = prog;
127127
Bytecode_val(bytecode)->len = len;

ocaml/runtime/obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ CAMLprim value caml_obj_block(value tag, value size)
108108
/* Closinfo_val is the second field, so we need size at least 2 */
109109
if (sz < 2) caml_invalid_argument ("Obj.new_block");
110110
res = caml_alloc(sz, tg);
111-
Closinfo_val(res) = Make_closinfo(0, 2); /* does not allocate */
111+
Closinfo_val(res) = Make_closinfo(0, 2, 1); /* does not allocate */
112112
break;
113113
}
114114
case String_tag: {

0 commit comments

Comments
 (0)