Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/lib/global_deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,14 @@ 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 -> Return (zero_var x), loc
| Return x, loc ->
let tc =
(* We don't want to break tailcalls. *)
match List.last body with
| Some (Let (x', Apply _), _) when Code.Var.equal x' x -> true
| Some _ | None -> false
in
if tc then Return x, loc else Return (zero_var x), loc
| Raise (_, _), _
| Stop, _
| Branch _, _
Expand Down
14 changes: 5 additions & 9 deletions compiler/tests-compiler/direct_calls.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let%expect_test "direct calls without --enable effects" =
[%expect
{|
function test1(param){
function f(g, x){caml_call1(g, x); return;}
function f(g, x){return caml_call1(g, x);}
var _d_ = 7;
f(function(x){return x + 1 | 0;}, _d_);
var _e_ = 4.;
Expand All @@ -66,7 +66,7 @@ let%expect_test "direct calls without --enable effects" =
}
//end
function test2(param){
function f(g, x){caml_call1(g, x); return;}
function f(g, x){return caml_call1(g, x);}
var _c_ = 7;
f(function(x){return x + 1 | 0;}, _c_);
f(function(x){return caml_call2(Stdlib[28], x, cst_a$0);}, cst_a);
Expand Down Expand Up @@ -130,16 +130,14 @@ let%expect_test "direct calls with --enable effects" =
[%expect
{|
function test1(param, cont){
function f(g, x){g(undef); return;}
function f(g, x){return g(undef);}
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, function(_m_){return cont(undef);});
}
function f(g, x, cont){return caml_cps_exact_call2(g, x, cont);}
var _f_ = 7;
function _g_(x, cont){return cont(undef);}
return caml_cps_exact_call3
Expand All @@ -148,9 +146,7 @@ let%expect_test "direct calls with --enable effects" =
_f_,
function(_h_){
function _i_(x, cont){
var _k_ = Stdlib[28];
return caml_cps_call3
(_k_, x, cst_a$0, function(_l_){return cont(undef);});
return caml_cps_call3(Stdlib[28], x, cst_a$0, cont);
}
return caml_cps_exact_call3
(f, _i_, cst_a, function(_j_){return cont(0);});
Expand Down
4 changes: 1 addition & 3 deletions compiler/tests-compiler/effects_toplevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ 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){
var _f_ = Stdlib_Printf[2];
return caml_cps_call2
(_f_, _a_, function(_g_){return cont(undef);});
return caml_cps_call2(Stdlib_Printf[2], _a_, cont);
}
caml_callback(g, [undef]);
var _b_ = 1;
Expand Down
Loading