aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src/sys_core_fold.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2015-02-04 15:47:07 +0100
committerBjörn Gustavsson <[email protected]>2015-02-04 16:12:10 +0100
commitf79afb23fbd469bed88616784f757707f9985a06 (patch)
tree24164e8557f9d62578bfe94be98fc084f17e6470 /lib/compiler/src/sys_core_fold.erl
parent42d6afe554e11813385dbf175fce58f995c2f9e5 (diff)
downloadotp-f79afb23fbd469bed88616784f757707f9985a06.tar.gz
otp-f79afb23fbd469bed88616784f757707f9985a06.tar.bz2
otp-f79afb23fbd469bed88616784f757707f9985a06.zip
Correct unsafe optimization of '==' and '/='
Since '=:=' is cheaper than '==', the compiler tries to replace '==' with '=:=' if the result of comparison will be the same. As an example: V == {a,b} can be rewritten to: V =:= {a,b} since the literal on the right side contains no numeric values that '==' would compare differently to '=:='. With the introduction of maps, we will need to take them into account. Since the comparison of maps is planned to change in 18.0, we will be very conservative and only do the optimization if both keys and values are non-numeric.
Diffstat (limited to 'lib/compiler/src/sys_core_fold.erl')
-rw-r--r--lib/compiler/src/sys_core_fold.erl5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/compiler/src/sys_core_fold.erl b/lib/compiler/src/sys_core_fold.erl
index f4f5c3f361..ed8f609082 100644
--- a/lib/compiler/src/sys_core_fold.erl
+++ b/lib/compiler/src/sys_core_fold.erl
@@ -1229,6 +1229,11 @@ is_non_numeric([H|T]) ->
is_non_numeric(H) andalso is_non_numeric(T);
is_non_numeric(Tuple) when is_tuple(Tuple) ->
is_non_numeric_tuple(Tuple, tuple_size(Tuple));
+is_non_numeric(Map) when is_map(Map) ->
+ %% Note that 17.x and 18.x compare keys in different ways.
+ %% Be very conservative -- require that both keys and values
+ %% are non-numeric.
+ is_non_numeric(maps:to_list(Map));
is_non_numeric(Num) when is_number(Num) ->
false;
is_non_numeric(_) -> true.