Skip to content

Commit

Permalink
Compiler: fix global DCE with effects
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Nov 29, 2023
1 parent a3be888 commit 78cd08e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
3 changes: 1 addition & 2 deletions compiler/lib/global_deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ let zero prog sentinal live_table =
let branch =
(* Zero out return values in last instruction, otherwise do nothing. *)
match block.branch with
| Return x, loc ->
if Config.Flag.effects () then block.branch else Return (zero_var x), loc
| Return x, loc -> Return (zero_var x), loc
| Raise (_, _), _
| Stop, _
| Branch _, _
Expand Down
16 changes: 10 additions & 6 deletions compiler/tests-compiler/direct_calls.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,27 @@ let%expect_test "direct calls with --enable effects" =
[%expect
{|
function test1(param, cont){
function f(g, x){return g(undef);}
f(function(x){return x + 1 | 0;}, undef);
f(function(x){return x * 2.;}, undef);
function f(g, x){g(undef); return;}
f(function(x){return;}, undef);
f(function(x){return;}, undef);
return cont(0);
}
//end
function test2(param, cont){
function f(g, x, cont){return caml_cps_exact_call2(g, x, cont);}
function f(g, x, cont){
return caml_cps_exact_call2(g, x, function(_m_){return cont(undef);});
}
var _f_ = 7;
function _g_(x, cont){return cont(x + 1 | 0);}
function _g_(x, cont){return cont(undef);}
return caml_cps_exact_call3
(f,
_g_,
_f_,
function(_h_){
function _i_(x, cont){
return caml_cps_call3(Stdlib[28], x, cst_a$0, cont);
var _k_ = Stdlib[28];
return caml_cps_call3
(_k_, x, cst_a$0, function(_l_){return cont(undef);});
}
return caml_cps_exact_call3
(f, _i_, cst_a, function(_j_){return cont(0);});
Expand Down
4 changes: 3 additions & 1 deletion compiler/tests-compiler/effects_toplevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
[11, caml_string_of_jsbytes("abc"), 0],
caml_string_of_jsbytes("abc")];
function g(param, cont){
return caml_cps_call2(Stdlib_Printf[2], _a_, cont);
var _f_ = Stdlib_Printf[2];
return caml_cps_call2
(_f_, _a_, function(_g_){return cont(undef);});
}
caml_callback(g, [undef]);
var _b_ = 1;
Expand Down

0 comments on commit 78cd08e

Please sign in to comment.