Skip to content
Open
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
6 changes: 5 additions & 1 deletion src/optimization/analyzerTexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -828,8 +828,12 @@ module Fusion = struct
end;
b
in
let can_fuse_var_init v init e_assign = match init with
| None -> true
| Some e -> config.local_dce && not (has_var_flag v VCaptured) && not (has_side_effect e) && not (has_var_read (InterferenceReport.from_texpr e_assign) v)
in
let rec fuse acc el = match el with
| ({eexpr = TVar(v1,None)} as e1) :: {eexpr = TBinop(OpAssign,{eexpr = TLocal v2},e2)} :: el when v1 == v2 ->
| ({eexpr = TVar(v1,init)} as e1) :: {eexpr = TBinop(OpAssign,{eexpr = TLocal v2},e2)} :: el when v1 == v2 && can_fuse_var_init v1 init e2 ->
state#changed;
let e1 = {e1 with eexpr = TVar(v1,Some e2)} in
state#dec_writes v1;
Expand Down
12 changes: 12 additions & 0 deletions tests/optimization/src/TestInlineConstructors.hx
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,16 @@ class TestInlineConstructors extends TestBase {
var p2 = {v: new PA(5)};
return [p2.v.x];
}

@:js('
var x = Std.random(0);
if(x == null) {x = 0;}
TestInlineConstructors.sink.x = x;
')
static function testDeadFieldInitFusion() {
var p = new P(Std.random(0));
sink.x = p.x;
}

static var sink:P = new P();
}
Loading