Skip to content

Commit 81e4a44

Browse files
committed
Compiler: fix global DCE with effects
1 parent 5b7f560 commit 81e4a44

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

compiler/lib/global_deadcode.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ let zero prog sentinal live_table =
352352
let branch =
353353
(* Zero out return values in last instruction, otherwise do nothing. *)
354354
match block.branch with
355-
| Return x, loc ->
356-
if Config.Flag.effects () then block.branch else Return (zero_var x), loc
355+
| Return x, loc -> Return (zero_var x), loc
357356
| Raise (_, _), _
358357
| Stop, _
359358
| Branch _, _

compiler/tests-compiler/direct_calls.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,27 @@ let%expect_test "direct calls with --enable effects" =
130130
[%expect
131131
{|
132132
function test1(param, cont){
133-
function f(g, x){return g(undef);}
134-
f(function(x){return x + 1 | 0;}, undef);
135-
f(function(x){return x * 2.;}, undef);
133+
function f(g, x){g(undef); return;}
134+
f(function(x){return;}, undef);
135+
f(function(x){return;}, undef);
136136
return cont(0);
137137
}
138138
//end
139139
function test2(param, cont){
140-
function f(g, x, cont){return caml_cps_exact_call2(g, x, cont);}
140+
function f(g, x, cont){
141+
return caml_cps_exact_call2(g, x, function(_m_){return cont(undef);});
142+
}
141143
var _f_ = 7;
142-
function _g_(x, cont){return cont(x + 1 | 0);}
144+
function _g_(x, cont){return cont(undef);}
143145
return caml_cps_exact_call3
144146
(f,
145147
_g_,
146148
_f_,
147149
function(_h_){
148150
function _i_(x, cont){
149-
return caml_cps_call3(Stdlib[28], x, cst_a$0, cont);
151+
var _k_ = Stdlib[28];
152+
return caml_cps_call3
153+
(_k_, x, cst_a$0, function(_l_){return cont(undef);});
150154
}
151155
return caml_cps_exact_call3
152156
(f, _i_, cst_a, function(_j_){return cont(0);});

compiler/tests-compiler/effects_toplevel.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
7373
[11, caml_string_of_jsbytes("abc"), 0],
7474
caml_string_of_jsbytes("abc")];
7575
function g(param, cont){
76-
return caml_cps_call2(Stdlib_Printf[2], _a_, cont);
76+
var _f_ = Stdlib_Printf[2];
77+
return caml_cps_call2
78+
(_f_, _a_, function(_g_){return cont(undef);});
7779
}
7880
caml_callback(g, [undef]);
7981
var _b_ = 1;

0 commit comments

Comments
 (0)