diff options
author | Björn Gustavsson <[email protected]> | 2015-02-06 13:22:20 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-03-09 10:10:27 +0100 |
commit | 9e15be5f241730b127d89dca01c6ad5f1e7508d7 (patch) | |
tree | fd02b9b724b079e6d8a3817a959f7292ac478eeb /lib/compiler/test | |
parent | e2ced63dfaf14f38d2a334d51b3ca45030d55e0c (diff) | |
download | otp-9e15be5f241730b127d89dca01c6ad5f1e7508d7.tar.gz otp-9e15be5f241730b127d89dca01c6ad5f1e7508d7.tar.bz2 otp-9e15be5f241730b127d89dca01c6ad5f1e7508d7.zip |
v3_core: Teach pat_alias/2 to eliminate duplicated variables
Duplicated variables as aliases in patterns, such as:
f({_,_}=Dup=Dup) -> ...
will work, but produce sub-optimal code similar to:
f({_,_}=Dup=NewVar) when Dup =:= NewVar -> ...
with one extra guard test for each duplicated variable.
Rewrite pat_alias/2 to eliminate all duplicated variables. While
we are at it, also simplify handling of tuples, conses, and literals
by using the data functions in the cerl module.
Diffstat (limited to 'lib/compiler/test')
-rw-r--r-- | lib/compiler/test/match_SUITE.erl | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/compiler/test/match_SUITE.erl b/lib/compiler/test/match_SUITE.erl index 7522ee985f..9aec0b3d4e 100644 --- a/lib/compiler/test/match_SUITE.erl +++ b/lib/compiler/test/match_SUITE.erl @@ -141,6 +141,13 @@ aliases(Config) when is_list(Config) -> ?line {a,b} = list_alias2([a,b]), ?line {a,b} = list_alias3([a,b]), + %% Non-matching aliases. + none = mixed_aliases(<<42>>), + none = mixed_aliases([b]), + none = mixed_aliases([d]), + none = mixed_aliases({a,42}), + none = mixed_aliases(42), + ok. str_alias(V) -> @@ -244,6 +251,12 @@ list_alias2([X,Y]=[a,b]) -> list_alias3([X,b]=[a,Y]) -> {X,Y}. +mixed_aliases(<<X:8>> = x) -> {a,X}; +mixed_aliases([b] = <<X:8>>) -> {b,X}; +mixed_aliases(<<X:8>> = {a,X}) -> {c,X}; +mixed_aliases([X] = <<X:8>>) -> {d,X}; +mixed_aliases(_) -> none. + %% OTP-7018. match_in_call(Config) when is_list(Config) -> |