diff options
author | Björn Gustavsson <[email protected]> | 2018-08-08 13:32:16 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2018-08-08 13:32:16 +0200 |
commit | a582364c31658bfddf80a5cad48bdf9f126eb373 (patch) | |
tree | e429de4d2d101a969e49884f1a887dbb0e7ca5d9 /lib/compiler/src | |
parent | df93c4203eed0f6dd424c91f53c3eee698eb88c5 (diff) | |
parent | 44e3810be19f58f0348cd2c38de9bb1b2e9d4c6e (diff) | |
download | otp-a582364c31658bfddf80a5cad48bdf9f126eb373.tar.gz otp-a582364c31658bfddf80a5cad48bdf9f126eb373.tar.bz2 otp-a582364c31658bfddf80a5cad48bdf9f126eb373.zip |
Merge pull request #1904 from michalmuskala/mm/get-stacktrace-to-build
Rewrite erlang:get_stacktrace calls to primop when safe
Diffstat (limited to 'lib/compiler/src')
-rw-r--r-- | lib/compiler/src/sys_core_fold.erl | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl index 5fdd089b6e..ba6f5be0ab 100644 --- a/lib/compiler/src/sys_core_fold.erl +++ b/lib/compiler/src/sys_core_fold.erl @@ -473,9 +473,21 @@ expr(#c_try{anno=A,arg=E0,vars=Vs0,body=B0,evars=Evs0,handler=H0}=Try, _, Sub0) false -> {Evs1,Sub2} = var_list(Evs0, Sub0), H1 = body(H0, value, Sub2), - Try#c_try{arg=E1,vars=Vs1,body=B1,evars=Evs1,handler=H1} + H2 = opt_try_handler(H1, lists:last(Evs1)), + Try#c_try{arg=E1,vars=Vs1,body=B1,evars=Evs1,handler=H2} end. +%% Attempts to convert old erlang:get_stacktrace/0 calls into the new +%% three-argument catch, with possibility of further optimisations. +opt_try_handler(#c_call{anno=A,module=#c_literal{val=erlang},name=#c_literal{val=get_stacktrace},args=[]}, Var) -> + #c_primop{anno=A,name=#c_literal{val=build_stacktrace},args=[Var]}; +opt_try_handler(#c_case{clauses=Cs0} = Case, Var) -> + Cs = [C#c_clause{body=opt_try_handler(B, Var)} || #c_clause{body=B} = C <- Cs0], + Case#c_case{clauses=Cs}; +opt_try_handler(#c_let{arg=Arg} = Let, Var) -> + Let#c_let{arg=opt_try_handler(Arg, Var)}; +opt_try_handler(X, _) -> X. + expr_list(Es, Ctxt, Sub) -> [expr(E, Ctxt, Sub) || E <- Es]. |