Skip to content

Commit 2ee705a

Browse files
authored
flambda-backend: Backport #946 to ocaml/ subfolder (#1061)
1 parent 569703f commit 2ee705a

25 files changed

+344
-168
lines changed

asmcomp/cmmgen.ml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ type rhs_kind =
131131
let rec expr_size env = function
132132
| Uvar id ->
133133
begin try V.find_same id env with Not_found -> RHS_nonrec end
134-
| Uclosure(fundecls, clos_vars) ->
135-
RHS_block (fundecls_size fundecls + List.length clos_vars)
134+
| Uclosure { functions ; not_scanned_slots ; scanned_slots } ->
135+
RHS_block (fundecls_size functions + List.length not_scanned_slots
136+
+ List.length scanned_slots)
136137
| Ulet(_str, _kind, id, exp, body) ->
137138
expr_size (V.add (VP.var id) (expr_size env exp) env) body
138139
| Uletrec(bindings, body) ->
@@ -369,18 +370,18 @@ let rec transl env e =
369370
end
370371
| Uconst sc ->
371372
transl_constant Debuginfo.none sc
372-
| Uclosure(fundecls, []) ->
373+
| Uclosure { functions ; not_scanned_slots = [] ; scanned_slots = [] } ->
373374
let sym = Compilenv.new_const_symbol() in
374-
Cmmgen_state.add_constant sym (Const_closure (Local, fundecls, []));
375-
List.iter (fun f -> Cmmgen_state.add_function f) fundecls;
375+
Cmmgen_state.add_constant sym (Const_closure (Local, functions, []));
376+
List.iter (fun f -> Cmmgen_state.add_function f) functions;
376377
let dbg =
377-
match fundecls with
378+
match functions with
378379
| [] -> Debuginfo.none
379380
| fundecl::_ -> fundecl.dbg
380381
in
381382
Cconst_symbol (sym, dbg)
382-
| Uclosure(fundecls, clos_vars) ->
383-
let startenv = fundecls_size fundecls in
383+
| Uclosure { functions ; not_scanned_slots ; scanned_slots } ->
384+
let startenv = fundecls_size functions + List.length not_scanned_slots in
384385
let mode =
385386
Option.get @@
386387
List.fold_left (fun s { mode; dbg; _ } ->
@@ -390,10 +391,10 @@ let rec transl env e =
390391
if not (Lambda.eq_mode mode m') then
391392
Misc.fatal_errorf "Inconsistent modes in let rec at %s"
392393
(Debuginfo.to_string dbg);
393-
s) None fundecls in
394+
s) None functions in
394395
let rec transl_fundecls pos = function
395396
[] ->
396-
List.map (transl env) clos_vars
397+
List.map (transl env) (not_scanned_slots @ scanned_slots)
397398
| f :: rem ->
398399
let is_last = match rem with [] -> true | _::_ -> false in
399400
Cmmgen_state.add_function f;
@@ -417,11 +418,11 @@ let rec transl env e =
417418
else alloc_infix_header pos f.dbg :: without_header
418419
in
419420
let dbg =
420-
match fundecls with
421+
match functions with
421422
| [] -> Debuginfo.none
422423
| fundecl::_ -> fundecl.dbg
423424
in
424-
make_alloc ~mode dbg Obj.closure_tag (transl_fundecls 0 fundecls)
425+
make_alloc ~mode dbg Obj.closure_tag (transl_fundecls 0 functions)
425426
| Uoffset(arg, offset) ->
426427
(* produces a valid Caml value, pointing just after an infix header *)
427428
let ptr = transl env arg in

middle_end/clambda.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ and ulambda =
5252
function_label * ulambda list * Lambda.probe * apply_kind * Debuginfo.t
5353
| Ugeneric_apply of
5454
ulambda * ulambda list * apply_kind * Debuginfo.t
55-
| Uclosure of ufunction list * ulambda list
55+
| Uclosure of {
56+
functions : ufunction list ;
57+
not_scanned_slots : ulambda list ;
58+
scanned_slots : ulambda list ;
59+
}
5660
| Uoffset of ulambda * int
5761
| Ulet of mutable_flag * value_kind * Backend_var.With_provenance.t
5862
* ulambda * ulambda

middle_end/clambda.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ and ulambda =
6363
function_label * ulambda list * Lambda.probe * apply_kind * Debuginfo.t
6464
| Ugeneric_apply of
6565
ulambda * ulambda list * apply_kind * Debuginfo.t
66-
| Uclosure of ufunction list * ulambda list
66+
| Uclosure of {
67+
functions : ufunction list ;
68+
not_scanned_slots : ulambda list ;
69+
scanned_slots : ulambda list
70+
}
6771
| Uoffset of ulambda * int
6872
| Ulet of mutable_flag * value_kind * Backend_var.With_provenance.t
6973
* ulambda * ulambda

0 commit comments

Comments
 (0)