diff options
author | Anthony Ramine <[email protected]> | 2013-04-09 22:42:33 +0200 |
---|---|---|
committer | Anthony Ramine <[email protected]> | 2013-04-09 23:09:50 +0200 |
commit | 16f820be15674f81f9fa5bb61b221eee9deff15d (patch) | |
tree | cb6d67474106d2067d1684c21aae248439d9017b /lib | |
parent | e72043e3519cb14aabf461849eba959b97e07410 (diff) | |
download | otp-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')
-rw-r--r-- | lib/compiler/src/sys_core_fold.erl | 19 |
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}) -> |