[erlang-questions] Warning not emitted on string matching clauses

Björn-Egil Dahlberg wallentin.dahlberg@REDACTED
Wed Apr 8 10:27:43 CEST 2015


This is a part of the compiler I'm not really an expert on, I would defer
to Robert or Björn in this case.
However, I believe it is the "variable split" that happens in match
compilation in kernel that is the cause of this. First I believed it was
just the order in which the compiler chooses the values to match (left to
right) but i don't think it's the case here (though i've seen that too).

Ideally, we shouldn't traverse the clauses left to right but instead weight
and sniff out the optimal matching path in the tree but that's a debate for
another time perhaps (and a fun one).

One could also question why the kernel should emit this warning and not the
linter. I guess pragmatism.

2015-04-08 9:52 GMT+02:00 Anthony Ramine <n.oxyde@REDACTED>:

> Le 8 avr. 2015 à 08:46, Erik Søe Sørensen <eriksoe@REDACTED> a écrit :
>
> > It would of course make sense to have the compiler warn in this case.
> > However - if my understanding of the compiler implementation is correct
> - matching of binaries is handled specially, and apparently in such a
> manner that it doesn't realise that the two binary patterns are identical.
> > /Erik
>
> That would be a reasonable explanation, but unfortunately it's not the
> case. If you compile that module to BEAM assembly, you can see very that
> the two patterns are indeed merged together, there is only one occurrence
> of "user_auth" in it.
>
> {function, authenticate_nouns, 1, 2}.
>   {label,1}.
>     {line,[{location,"wat_clauses.erl",3}]}.
>     {func_info,{atom,wat_clauses},{atom,authenticate_nouns},1}.
>   {label,2}.
>     {test,is_nonempty_list,{f,4},[{x,0}]}.
>     {get_list,{x,0},{x,1},{x,2}}.
>     {test,is_tuple,{f,4},[{x,1}]}.
>     {test,test_arity,{f,4},[{x,1},2]}.
>     {get_tuple_element,{x,1},0,{x,3}}.
>     {get_tuple_element,{x,1},1,{x,4}}.
>     {test,bs_start_match2,{f,4},5,[{x,3},0],{x,5}}.
>     {test,bs_match_string,{f,4},[{x,5},72,{string,"user_auth"}]}.
>     {test,bs_test_tail2,{f,4},[{x,5},0]}.
>     {test,is_nil,{f,3},[{x,2}]}.
>     {move,{atom,true},{x,0}}.
>     return.
>   {label,3}.
>     {test,is_nonempty_list,{f,4},[{x,4}]}.
>     {get_list,{x,4},{x,6},{x,7}}.
>     {test,bs_start_match2,{f,4},8,[{x,6},0],{x,8}}.
>     {test,bs_match_string,{f,4},[{x,8},64,{string,"recovery"}]}.
>     {test,bs_test_tail2,{f,4},[{x,8},0]}.
>     {test,is_nil,{f,4},[{x,7}]}.
>     {test,is_nil,{f,4},[{x,2}]}.
>     {move,{atom,hi},{x,0}}.
>     return.
>   {label,4}.
>     {move,{atom,false},{x,0}}.
>     return.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150408/54c4dbbe/attachment.htm>


More information about the erlang-questions mailing list