[erlang-patches] binary matching optimization error

Christian von Roques roques@REDACTED
Thu Aug 21 22:08:56 CEST 2008


Christian von Roques <roques@REDACTED> writes:
> Using R12B-3 I recently wrote code similar to the following:
>
> -module(bug).
> -export([foo/2]).
>
> %% foo(<<1,2>>, 2) should evaluate to <<1,2>>, but evaluates to <<2>>
> %% when compiled without no_bsm_opt
> foo(Bin, 0) ->
>     foo(Bin, 42);
> foo(<<_A, Rest/bitstring>>, 1) ->
>     foo(Rest, 43);
> foo(Bin, _I)  ->
>     Bin.

Unfortunately this is not the whole problem.
bar(<<1,2>>, 3) should evaluate to <<1,2>> as well:

bar(Bin, 0) ->
    bar(Bin, 42);
bar(<<_A, Rest/bitstring>>, 1) ->
    bar(Rest, 43);
bar(<<>>, 2) ->
    bar(<<>>, 44);
bar(Bin, _I)  ->
    Bin.

Here the problem is with bs_restore2.
I've amended my patch, but still hope for a more complete solution
from the Erlang team e.g. by placing the bs_save2 only in those
control flow paths where they are needed and not modifying the
original match context where it is still needed.

	Christian.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: beam_bsm.erl.patch
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20080821/f955da9f/attachment.ksh>


More information about the erlang-patches mailing list