Skip to content

Commit c0d1e32

Browse files
committed
Compiler: less agressive flushing for function
1 parent c6394d1 commit c0d1e32

File tree

3 files changed

+1049
-1112
lines changed

3 files changed

+1049
-1112
lines changed

compiler/lib/generate.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,13 +1393,19 @@ and translate_instrs (ctx : Ctx.t) expr_queue instr last =
13931393
let names, mut, pcs, all, rem = collect_closures ctx instr in
13941394
match Code.Var.Set.cardinal mut with
13951395
| 0 ->
1396-
let st_rev, expr_queue =
1397-
List.fold_left all ~init:([], expr_queue) ~f:(fun (st_rev, expr_queue) i ->
1398-
let l, expr_queue = translate_instr ctx expr_queue i in
1396+
let st_rev, expr_queue_fun =
1397+
List.fold_left all ~init:([], []) ~f:(fun (st_rev, expr_queue) i ->
1398+
let l, expr_queue_fun = translate_instr ctx [] i in
1399+
let expr_queue =
1400+
match expr_queue_fun with
1401+
| [] -> expr_queue
1402+
| [ x ] -> x :: expr_queue
1403+
| _ -> assert false
1404+
in
13991405
List.rev_append l st_rev, expr_queue)
14001406
in
1401-
let instrs, expr_queue = translate_instrs ctx expr_queue rem last in
1402-
List.rev_append st_rev instrs, expr_queue
1407+
let instrs, expr_queue_after = translate_instrs ctx expr_queue_fun rem last in
1408+
flush_all expr_queue (List.rev_append st_rev instrs), expr_queue_after
14031409
| _ ->
14041410
let muts =
14051411
Code.Var.Set.diff mut names
@@ -1436,7 +1442,7 @@ and translate_instrs (ctx : Ctx.t) expr_queue instr last =
14361442
in
14371443
(J.variable_declaration ~kind:Let (List.rev l_rev), J.N) :: st_rev, expr_queue
14381444
in
1439-
(* Mutually recursive need to be properly scoped. *)
1445+
(* Mutually recursive functions need to be properly scoped. *)
14401446
let st_rev, expr_queue =
14411447
List.fold_left all ~init:([], expr_queue) ~f:(fun (st_rev, expr_queue) i ->
14421448
let l, expr_queue = translate_instr ctx expr_queue i in

compiler/tests-compiler/direct_calls.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,18 @@ let%expect_test "direct calls with --enable effects" =
139139
function test2(param, cont){
140140
function f(g, x, cont){return caml_cps_exact_call2(g, x, cont);}
141141
var _f_ = 7;
142-
function _g_(x, cont){return cont(undef);}
143142
return caml_cps_exact_call3
144143
(f,
145-
_g_,
144+
function(x, cont){return cont(undef);},
146145
_f_,
147-
function(_h_){
148-
function _i_(x, cont){
149-
return caml_cps_call3(Stdlib[28], x, cst_a$0, cont);
150-
}
146+
function(_g_){
151147
return caml_cps_exact_call3
152-
(f, _i_, cst_a, function(_j_){return cont(0);});
148+
(f,
149+
function(x, cont){
150+
return caml_cps_call3(Stdlib[28], x, cst_a$0, cont);
151+
},
152+
cst_a,
153+
function(_h_){return cont(0);});
153154
});
154155
}
155156
//end

0 commit comments

Comments
 (0)