aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test
diff options
context:
space:
mode:
authorMichał Muskała <[email protected]>2018-02-17 09:33:17 +0100
committerMichał Muskała <[email protected]>2018-06-06 23:19:34 +0200
commit5ba1635518459f581811b30f386fdf1f21f54178 (patch)
treee10b62472cd5393860f566fcd8540d77af30e142 /lib/compiler/test
parent9ae2044073e6433030ce30756658b103ce67c3c1 (diff)
downloadotp-5ba1635518459f581811b30f386fdf1f21f54178.tar.gz
otp-5ba1635518459f581811b30f386fdf1f21f54178.tar.bz2
otp-5ba1635518459f581811b30f386fdf1f21f54178.zip
Fold is_function/1,2 during compilation
This can often appear in code after inlining some higher-order functions. * mark is_function/2 as pure * track function types in sys_core_fold * use those types to eval is_function/1,2 at compile-time when possible
Diffstat (limited to 'lib/compiler/test')
-rw-r--r--lib/compiler/test/core_fold_SUITE.erl17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/compiler/test/core_fold_SUITE.erl b/lib/compiler/test/core_fold_SUITE.erl
index ab7f36abf7..00b0e4ad42 100644
--- a/lib/compiler/test/core_fold_SUITE.erl
+++ b/lib/compiler/test/core_fold_SUITE.erl
@@ -278,6 +278,8 @@ coverage(Config) when is_list(Config) ->
a = cover_remove_non_vars_alias({a,b,c}),
error = cover_will_match_lit_list(),
{ok,[a]} = cover_is_safe_bool_expr(a),
+ false = cover_is_safe_bool_expr2(a),
+ ok = cover_eval_is_function(fun id/1),
ok = cover_opt_guard_try(#cover_opt_guard_try{list=[a]}),
error = cover_opt_guard_try(#cover_opt_guard_try{list=[]}),
@@ -341,6 +343,15 @@ cover_is_safe_bool_expr(X) ->
false
end.
+cover_is_safe_bool_expr2(X) ->
+ try
+ V = [X],
+ is_function(V, 1)
+ catch
+ _:_ ->
+ false
+ end.
+
cover_opt_guard_try(Msg) ->
if
length(Msg#cover_opt_guard_try.list) =/= 1 ->
@@ -349,6 +360,12 @@ cover_opt_guard_try(Msg) ->
ok
end.
+cover_eval_is_function(X) ->
+ case X of
+ {a,_} -> is_function(X);
+ _ -> ok
+ end.
+
bsm_an_inlined(<<_:8>>, _) -> ok;
bsm_an_inlined(_, _) -> error.