<feed xmlns='http://www.w3.org/2005/Atom'>
<title>otp.git/lib/compiler/test, branch OTP-21.0.3</title>
<subtitle>Mirror of Erlang/OTP repository.
</subtitle>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/'/>
<entry>
<title>Merge branch 'bjorn/compiler/fix-beam_jump-crash/ERL-660/OTP-15166' into maint-21</title>
<updated>2018-06-29T12:30:27+00:00</updated>
<author>
<name>Erlang/OTP</name>
<email>otp@erlang.org</email>
</author>
<published>2018-06-29T12:30:27+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=5e3e6747ac924b3d7956630de501316567a15cad'/>
<id>5e3e6747ac924b3d7956630de501316567a15cad</id>
<content type='text'>
* bjorn/compiler/fix-beam_jump-crash/ERL-660/OTP-15166:
  Eliminate a crash in the beam_jump pass
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* bjorn/compiler/fix-beam_jump-crash/ERL-660/OTP-15166:
  Eliminate a crash in the beam_jump pass
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'bjorn/compiler/fix-map_get/OTP-15157' into maint-21</title>
<updated>2018-06-29T12:30:24+00:00</updated>
<author>
<name>Erlang/OTP</name>
<email>otp@erlang.org</email>
</author>
<published>2018-06-29T12:30:24+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=7ea24a343e003c74004a6d82e36ffbb50997f60a'/>
<id>7ea24a343e003c74004a6d82e36ffbb50997f60a</id>
<content type='text'>
* bjorn/compiler/fix-map_get/OTP-15157:
  Fix internal compiler error for map_get/2
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* bjorn/compiler/fix-map_get/OTP-15157:
  Fix internal compiler error for map_get/2
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'bjorn/compiler/fix-skipped-matching/ERL-655/OTP-15156' into maint-21</title>
<updated>2018-06-29T12:30:24+00:00</updated>
<author>
<name>Erlang/OTP</name>
<email>otp@erlang.org</email>
</author>
<published>2018-06-29T12:30:24+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=b2aa37d72997df921e935380a77b0e0226f33401'/>
<id>b2aa37d72997df921e935380a77b0e0226f33401</id>
<content type='text'>
* bjorn/compiler/fix-skipped-matching/ERL-655/OTP-15156:
  beam_type: Fix unsafe optimization
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* bjorn/compiler/fix-skipped-matching/ERL-655/OTP-15156:
  beam_type: Fix unsafe optimization
</pre>
</div>
</content>
</entry>
<entry>
<title>Eliminate a crash in the beam_jump pass</title>
<updated>2018-06-29T12:23:08+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2018-06-29T12:14:40+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=d10fd4596270d7f8503dc46a0a7c229ad08795d2'/>
<id>d10fd4596270d7f8503dc46a0a7c229ad08795d2</id>
<content type='text'>
https://bugs.erlang.org/browse/ERL-660
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://bugs.erlang.org/browse/ERL-660
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix internal compiler error for map_get/2</title>
<updated>2018-06-27T12:01:52+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2018-06-27T11:48:21+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=c221bb38a80f8c3c4263ebdd609ff8ae6e5d117f'/>
<id>c221bb38a80f8c3c4263ebdd609ff8ae6e5d117f</id>
<content type='text'>
Code such as that the following:

    Val = map_get(a, Map),
    Map#{a:=z}   %Could be any map update

would incorrectly cause an internal consistency check failure:

   Internal consistency check failed - please report this bug.
   Instruction: {put_map_exact,{f,0},{x,0},{x,0},1,{list,[{atom,a},{atom,z}]}}
   Error:       {bad_type,{needed,map},{actual,term}}:

Update beam_validator so that it understands that the second
argument for map_get/2 is a map.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Code such as that the following:

    Val = map_get(a, Map),
    Map#{a:=z}   %Could be any map update

would incorrectly cause an internal consistency check failure:

   Internal consistency check failed - please report this bug.
   Instruction: {put_map_exact,{f,0},{x,0},{x,0},1,{list,[{atom,a},{atom,z}]}}
   Error:       {bad_type,{needed,map},{actual,term}}:

Update beam_validator so that it understands that the second
argument for map_get/2 is a map.
</pre>
</div>
</content>
</entry>
<entry>
<title>beam_type: Fix unsafe optimization</title>
<updated>2018-06-27T11:22:20+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2018-06-27T10:51:22+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=81ce942d77826dd7219f1226866ffb2fa71c1d28'/>
<id>81ce942d77826dd7219f1226866ffb2fa71c1d28</id>
<content type='text'>
beam_type assumed that the operand for the bs_context_to_binary
instruction must be a binary. That is not correct;
bs_context_to_binary accepts anything. Based on the incorrect
assumption, beam_type would remove other test instructions.

The bug was introduced in eee8655788d2, which was supposed
to be just a refactoring commit.

https://bugs.erlang.org/browse/ERL-655
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
beam_type assumed that the operand for the bs_context_to_binary
instruction must be a binary. That is not correct;
bs_context_to_binary accepts anything. Based on the incorrect
assumption, beam_type would remove other test instructions.

The bug was introduced in eee8655788d2, which was supposed
to be just a refactoring commit.

https://bugs.erlang.org/browse/ERL-655
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix unsafe optimization when running beam_block the second time</title>
<updated>2018-06-25T11:03:15+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2018-06-25T04:18:47+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=3dd17613fc7af70bc7f1222d7381533df0bd4eab'/>
<id>3dd17613fc7af70bc7f1222d7381533df0bd4eab</id>
<content type='text'>
The compiler would crash when compiling code such as:

    serialize(#{tag := value, id := Id, domain := Domain}) -&gt;
        [case Id of
             nil -&gt;
                 error(id({required, id}));
             _ -&gt;
                 &lt;&lt;10, 1:16/signed, Id:16/signed&gt;&gt;
         end,
         case Domain of
             nil -&gt;
                 error(id({required, domain}));
             _ -&gt;
                 &lt;&lt;8, 2:16/signed, Domain:32/signed&gt;&gt;
         end].

The crash would look like this:

    Function: serialize/1
    t.erl: internal error in block2;
    crash reason: {badmatch,false}

      in function  beam_utils:live_opt/4 (beam_utils.erl, line 861)
      in call from beam_utils:live_opt/1 (beam_utils.erl, line 285)
      in call from beam_block:function/2 (beam_block.erl, line 47)
      in call from beam_block:'-module/2-lc$^0/1-0-'/2 (beam_block.erl, line 33)
      in call from beam_block:'-module/2-lc$^0/1-0-'/2 (beam_block.erl, line 33)
      in call from beam_block:module/2 (beam_block.erl, line 33)
      in call from compile:block2/2 (compile.erl, line 1358)
      in call from compile:'-internal_comp/5-anonymous-1-'/3 (compile.erl, line 349)

The reason for the crash is an assertion failure caused by a previous
unsafe optimization. Here is the code before the unsafe optimization:

       .
       .
       .
    {bs_init2,{f,0},7,0,0,{field_flags,[]},{x,1}}.
    {bs_put_string,3,{string,[8,0,2]}}.
    {bs_put_integer,{f,0},{integer,32},1,{field_flags,[signed,big]},{y,1}}.

    {move,{x,1},{x,0}}.
    {test_heap,4,1}.
       .
       .
       .

beam_block:move_allocate/1 moved up the test_heap/2 instruction past the
move/2 instruction, adjusting the number of live registers at the same
time:

       .
       .
       .
    {bs_init2,{f,0},7,0,0,{field_flags,[]},{x,1}}.
    %% Only x1 is live now.
    {bs_put_string,3,{string,[8,0,2]}}.
    {bs_put_integer,{f,0},{integer,32},1,{field_flags,[signed,big]},{y,1}}.

    {test_heap,4,2}.     %Unsafe. x0 is dead.
    {move,{x,1},{x,0}}.
       .
       .
       .

This optimization is unsafe because the bs_init2 instruction killed
x0.

The bug is in beam_utils:anno_defs/1, which adds annotations indicating
the registers that are defined at the beginning of each block. The
annotation before the move/2 instruction incorrectly indicated that
x0 was live.

https://bugs.erlang.org/browse/ERL-650
https://github.com/elixir-lang/elixir/issues/7782
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The compiler would crash when compiling code such as:

    serialize(#{tag := value, id := Id, domain := Domain}) -&gt;
        [case Id of
             nil -&gt;
                 error(id({required, id}));
             _ -&gt;
                 &lt;&lt;10, 1:16/signed, Id:16/signed&gt;&gt;
         end,
         case Domain of
             nil -&gt;
                 error(id({required, domain}));
             _ -&gt;
                 &lt;&lt;8, 2:16/signed, Domain:32/signed&gt;&gt;
         end].

The crash would look like this:

    Function: serialize/1
    t.erl: internal error in block2;
    crash reason: {badmatch,false}

      in function  beam_utils:live_opt/4 (beam_utils.erl, line 861)
      in call from beam_utils:live_opt/1 (beam_utils.erl, line 285)
      in call from beam_block:function/2 (beam_block.erl, line 47)
      in call from beam_block:'-module/2-lc$^0/1-0-'/2 (beam_block.erl, line 33)
      in call from beam_block:'-module/2-lc$^0/1-0-'/2 (beam_block.erl, line 33)
      in call from beam_block:module/2 (beam_block.erl, line 33)
      in call from compile:block2/2 (compile.erl, line 1358)
      in call from compile:'-internal_comp/5-anonymous-1-'/3 (compile.erl, line 349)

The reason for the crash is an assertion failure caused by a previous
unsafe optimization. Here is the code before the unsafe optimization:

       .
       .
       .
    {bs_init2,{f,0},7,0,0,{field_flags,[]},{x,1}}.
    {bs_put_string,3,{string,[8,0,2]}}.
    {bs_put_integer,{f,0},{integer,32},1,{field_flags,[signed,big]},{y,1}}.

    {move,{x,1},{x,0}}.
    {test_heap,4,1}.
       .
       .
       .

beam_block:move_allocate/1 moved up the test_heap/2 instruction past the
move/2 instruction, adjusting the number of live registers at the same
time:

       .
       .
       .
    {bs_init2,{f,0},7,0,0,{field_flags,[]},{x,1}}.
    %% Only x1 is live now.
    {bs_put_string,3,{string,[8,0,2]}}.
    {bs_put_integer,{f,0},{integer,32},1,{field_flags,[signed,big]},{y,1}}.

    {test_heap,4,2}.     %Unsafe. x0 is dead.
    {move,{x,1},{x,0}}.
       .
       .
       .

This optimization is unsafe because the bs_init2 instruction killed
x0.

The bug is in beam_utils:anno_defs/1, which adds annotations indicating
the registers that are defined at the beginning of each block. The
annotation before the move/2 instruction incorrectly indicated that
x0 was live.

https://bugs.erlang.org/browse/ERL-650
https://github.com/elixir-lang/elixir/issues/7782
</pre>
</div>
</content>
</entry>
<entry>
<title>Update copyright year</title>
<updated>2018-06-18T12:51:18+00:00</updated>
<author>
<name>Henrik Nord</name>
<email>henrik@erlang.org</email>
</author>
<published>2018-06-18T12:51:18+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=5ca92e2eac1e84fd22f60e7abc3aa2b0ff1cb42b'/>
<id>5ca92e2eac1e84fd22f60e7abc3aa2b0ff1cb42b</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>sys_core_fold: Fix name capture problem</title>
<updated>2018-06-04T08:41:21+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2018-06-04T04:14:19+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=7eb06ed5ac1687d38245db2e0aef2756cb43b1ae'/>
<id>7eb06ed5ac1687d38245db2e0aef2756cb43b1ae</id>
<content type='text'>
sys_core_fold could do unsafe transformations on the
code from the old inliner (invoked using the compiler
option `{inline,[{F/A}]}` to request inlining of specific
functions).

To explain the bug, let's first look at an example that
sys_core_fold handles correctly. Consider this code:

    'foo'/2 =
        fun (Arg1,Arg2) -&gt;
          let &lt;B&gt; = Arg2
          in let &lt;A,B&gt; = &lt;B,Arg1&gt;
             in {A,B}

In this example, the lets can be completely eliminated,
since the arguments for the lets are variables (as opposed
to expressions). Since the variable B is rebound in the
inner let, `sys_core_fold` must take special care when
doing the substitutions.

Here is the correct result:

    'foo'/2 =
        fun (Arg1, Arg2) -&gt;
          {Arg2,Arg1}

Consider a slight modifictation of the example:

    'bar'/2 =
        fun (Arg1,Arg2) -&gt;
            let &lt;B&gt; = [Arg2]
            in let &lt;A,B&gt; = &lt;B,[Arg1]&gt;
               in {A,B}

Here some of the arguments for the lets are expressions, so
the lets must be kept. sys_core_fold does not handle this
example correctly:

    'bar'/2 =
        fun (Arg1,Arg2) -&gt;
          let &lt;B&gt; = [Arg2]
    	  in let &lt;B&gt; = [Arg1]
    	     in {B,B}

In the inner let, the variable A has been eliminated and
replaced with the variable B in the body (the first B in
the tuple). Since the B in the outer let is never used,
the outer let will be eliminated, giving:

    'bar'/2 =
        fun (Arg1,Arg2) -&gt;
    	  let &lt;B&gt; = [Arg1]
    	  in {B,B}

To handle this example correctly, sys_core_fold must
rename the variable B in the inner let like this to
avoid capturing B:

    'bar'/2 =
       fun (Arg1,Arg2) -&gt;
         let &lt;B&gt; = [Arg2]
         in let &lt;NewName&gt; = [Arg1]
            in {B,NewName}

(Note: The `v3_kernel` pass alreday handles those examples correctly
in case `sys_core_fold` has been disabled.)
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
sys_core_fold could do unsafe transformations on the
code from the old inliner (invoked using the compiler
option `{inline,[{F/A}]}` to request inlining of specific
functions).

To explain the bug, let's first look at an example that
sys_core_fold handles correctly. Consider this code:

    'foo'/2 =
        fun (Arg1,Arg2) -&gt;
          let &lt;B&gt; = Arg2
          in let &lt;A,B&gt; = &lt;B,Arg1&gt;
             in {A,B}

In this example, the lets can be completely eliminated,
since the arguments for the lets are variables (as opposed
to expressions). Since the variable B is rebound in the
inner let, `sys_core_fold` must take special care when
doing the substitutions.

Here is the correct result:

    'foo'/2 =
        fun (Arg1, Arg2) -&gt;
          {Arg2,Arg1}

Consider a slight modifictation of the example:

    'bar'/2 =
        fun (Arg1,Arg2) -&gt;
            let &lt;B&gt; = [Arg2]
            in let &lt;A,B&gt; = &lt;B,[Arg1]&gt;
               in {A,B}

Here some of the arguments for the lets are expressions, so
the lets must be kept. sys_core_fold does not handle this
example correctly:

    'bar'/2 =
        fun (Arg1,Arg2) -&gt;
          let &lt;B&gt; = [Arg2]
    	  in let &lt;B&gt; = [Arg1]
    	     in {B,B}

In the inner let, the variable A has been eliminated and
replaced with the variable B in the body (the first B in
the tuple). Since the B in the outer let is never used,
the outer let will be eliminated, giving:

    'bar'/2 =
        fun (Arg1,Arg2) -&gt;
    	  let &lt;B&gt; = [Arg1]
    	  in {B,B}

To handle this example correctly, sys_core_fold must
rename the variable B in the inner let like this to
avoid capturing B:

    'bar'/2 =
       fun (Arg1,Arg2) -&gt;
         let &lt;B&gt; = [Arg2]
         in let &lt;NewName&gt; = [Arg1]
            in {B,NewName}

(Note: The `v3_kernel` pass alreday handles those examples correctly
in case `sys_core_fold` has been disabled.)
</pre>
</div>
</content>
</entry>
<entry>
<title>bs_match_SUITE: Add test of multiple matches</title>
<updated>2018-05-21T12:38:20+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2018-05-21T05:34:17+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=e1957dd0920276ea942002477a3317cd8d1e7b5e'/>
<id>e1957dd0920276ea942002477a3317cd8d1e7b5e</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
