diff options
author | John Högberg <[email protected]> | 2018-07-16 15:21:04 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-08-08 13:10:45 +0200 |
commit | a2b94643d345505bcee103b114147e3cb962b8ac (patch) | |
tree | 77b7405d816b0021d1ebb72f4a5c38d2c76587b4 /lib/compiler/test/core_SUITE_data/fun_letrec_effect.core | |
parent | 212e8b4caa9968d50f0701ce70aa0ebe5b25f1a6 (diff) | |
download | otp-a2b94643d345505bcee103b114147e3cb962b8ac.tar.gz otp-a2b94643d345505bcee103b114147e3cb962b8ac.tar.bz2 otp-a2b94643d345505bcee103b114147e3cb962b8ac.zip |
Fix side-effect optimization when compiling from Core Erlang
When an expression is only used for its side effects, we try to
remove everything that doesn't tie into a side-effect, but we
went a bit too far when we applied the optimization to funs
defined in such a context. Consider the following:
do letrec 'f'/0 = fun () -> ... whatever ...
in call 'side':'effect'(apply 'f'/0())
'ok'
When f/0 is optimized under the assumption that its return value
is unused, side:effect/1 will be fed the result of the last
side-effecting expression in f/0 instead of its actual result.
https://bugs.erlang.org/browse/ERL-658
Co-authored-by: Björn Gustavsson <[email protected]>
Diffstat (limited to 'lib/compiler/test/core_SUITE_data/fun_letrec_effect.core')
-rw-r--r-- | lib/compiler/test/core_SUITE_data/fun_letrec_effect.core | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/compiler/test/core_SUITE_data/fun_letrec_effect.core b/lib/compiler/test/core_SUITE_data/fun_letrec_effect.core new file mode 100644 index 0000000000..ab6f5b7940 --- /dev/null +++ b/lib/compiler/test/core_SUITE_data/fun_letrec_effect.core @@ -0,0 +1,25 @@ +module 'fun_letrec_effect' ['fun_letrec_effect'/0, 'ok'/0, 'wat'/0] +attributes [] + +'fun_letrec_effect'/0 = + fun () -> + do apply 'wat'/0() + receive + <'bar'> when 'true' -> 'ok' + <_0> when 'true' -> 'failed' + after 'infinity' -> + 'true' + +%% The return value (bar) of the fun was optimized away because the result of +%% the `letrec ... in` was unused, despite the fun's return value being +%% relevant for the side-effect of the expression. +'wat'/0 = + fun () -> + let <Self> = call 'erlang':'self'() in + do letrec 'f'/0 = fun () -> + do call 'maps':'put'('foo', 'bar', ~{}~) + 'bar' + in call 'erlang':'send'(Self, apply 'f'/0()) + 'undefined' + +end |