aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
diff options
context:
space:
mode:
authorAnthony Ramine <[email protected]>2013-04-09 22:42:33 +0200
committerAnthony Ramine <[email protected]>2013-04-09 23:09:50 +0200
commit16f820be15674f81f9fa5bb61b221eee9deff15d (patch)
treecb6d67474106d2067d1684c21aae248439d9017b /lib/compiler
parente72043e3519cb14aabf461849eba959b97e07410 (diff)
downloadotp-16f820be15674f81f9fa5bb61b221eee9deff15d.tar.gz
otp-16f820be15674f81f9fa5bb61b221eee9deff15d.tar.bz2
otp-16f820be15674f81f9fa5bb61b221eee9deff15d.zip
Move let expressions into sequences
The Core Erlang compiler simplifies let expressions by moving them into their argument when it is another let or a case expression. It can then perform other optimizations such as removing the let expressions altogether, sometimes saving BEAM registers later in the process. This commit teaches sys_core_fold how to move let expressions into sequence arguments.
Diffstat (limited to 'lib/compiler')
-rw-r--r--lib/compiler/src/sys_core_fold.erl19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index cda3f7d81e..6b0ae87172 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -2342,6 +2342,25 @@ move_let_into_expr(#c_let{vars=Lvs0,body=Lbody0}=Let,
Case#c_case{arg=Cexpr,clauses=[Ca,Cb]};
{_,_,_} -> impossible
end;
+move_let_into_expr(#c_let{vars=Lvs0,body=Lbody0}=Let,
+ #c_seq{arg=Sarg0,body=Sbody0}=Seq, Sub0) ->
+ %%
+ %% let <Lvars> = do <Seq-arg>
+ %% <Seq-body>
+ %% in <Let-body>
+ %%
+ %% ==>
+ %%
+ %% do <Seq-arg>
+ %% let <Lvars> = <Seq-body>
+ %% in <Let-body>
+ %%
+ Sarg = body(Sarg0, Sub0),
+ Sbody1 = body(Sbody0, Sub0),
+ {Lvs,Sbody,Sub} = let_substs(Lvs0, Sbody1, Sub0),
+ Lbody = body(Lbody0, Sub),
+ Seq#c_seq{arg=Sarg,body=Let#c_let{vars=Lvs,arg=core_lib:make_values(Sbody),
+ body=Lbody}};
move_let_into_expr(_Let, _Expr, _Sub) -> impossible.
is_failing_clause(#c_clause{body=B}) ->