<feed xmlns='http://www.w3.org/2005/Atom'>
<title>otp.git/lib/compiler, branch maint-17</title>
<subtitle>Mirror of Erlang/OTP repository.
</subtitle>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/'/>
<entry>
<title>Prepare release</title>
<updated>2015-03-31T10:24:04+00:00</updated>
<author>
<name>Erlang/OTP</name>
<email>otp@erlang.org</email>
</author>
<published>2015-03-31T10:24:04+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=62870c998955e1498e71bfc90607885e96ecaa27'/>
<id>62870c998955e1498e71bfc90607885e96ecaa27</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Correct unsafe optimization of '==' and '/='</title>
<updated>2015-02-04T15:12:10+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2015-02-04T14:47:07+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=f79afb23fbd469bed88616784f757707f9985a06'/>
<id>f79afb23fbd469bed88616784f757707f9985a06</id>
<content type='text'>
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.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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.
</pre>
</div>
</content>
</entry>
<entry>
<title>Be more careful about map patterns when evalutating element/2</title>
<updated>2015-02-03T06:34:17+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2015-02-02T12:01:10+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=94b36c7c2534f92e1d1ce768fb63d9012bb0c630'/>
<id>94b36c7c2534f92e1d1ce768fb63d9012bb0c630</id>
<content type='text'>
We must not convert map patterns to map expressions.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We must not convert map patterns to map expressions.
</pre>
</div>
</content>
</entry>
<entry>
<title>Do not convert map patterns to map expressions</title>
<updated>2015-02-03T06:34:17+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2015-02-02T14:31:36+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=d9ed708bb5d22cf61029eac0a23b9d3dc94a5146'/>
<id>d9ed708bb5d22cf61029eac0a23b9d3dc94a5146</id>
<content type='text'>
In code such as:

  case {a,Map} of
    {a,#{}}=T -&gt;
      T
  end

we must NOT rewrite a map pattern to a map expression like this:

  case Map of
    #{} -&gt;
      {a,#{}}
  end

because the pattern '#{}' will match any map, but the expression
'#{}' will construct an empty map.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In code such as:

  case {a,Map} of
    {a,#{}}=T -&gt;
      T
  end

we must NOT rewrite a map pattern to a map expression like this:

  case Map of
    #{} -&gt;
      {a,#{}}
  end

because the pattern '#{}' will match any map, but the expression
'#{}' will construct an empty map.
</pre>
</div>
</content>
</entry>
<entry>
<title>core_lib: Handle patterns in map values</title>
<updated>2015-01-19T14:36:22+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2015-01-19T14:10:34+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=bb561b0dd58a89489acb93bdf7b5386e7f306835'/>
<id>bb561b0dd58a89489acb93bdf7b5386e7f306835</id>
<content type='text'>
core_lib:is_var_used/2 would not consider a variable used in the
value of a map pattern such as:

  case Map of
    #{key := &lt;&lt;42:N&gt;&gt;} -&gt; ok
  end

Here the variable 'N' would not be considered used.

It was assumed that there was no need to check map patterns at
all, since maps currently don't support variables in keys.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
core_lib:is_var_used/2 would not consider a variable used in the
value of a map pattern such as:

  case Map of
    #{key := &lt;&lt;42:N&gt;&gt;} -&gt; ok
  end

Here the variable 'N' would not be considered used.

It was assumed that there was no need to check map patterns at
all, since maps currently don't support variables in keys.
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'bjorn/compiler/map-in-record-bug/OTP-12402' into maint</title>
<updated>2015-01-16T08:17:03+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2015-01-16T08:17:03+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=4c68e41041bb178905bff490f3f77f53fef7cc17'/>
<id>4c68e41041bb178905bff490f3f77f53fef7cc17</id>
<content type='text'>
* bjorn/compiler/map-in-record-bug/OTP-12402:
  sys_core_fold: Correct optimization of 'case'
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* bjorn/compiler/map-in-record-bug/OTP-12402:
  sys_core_fold: Correct optimization of 'case'
</pre>
</div>
</content>
</entry>
<entry>
<title>beam_bool: Correct live calculation for GC BIFs</title>
<updated>2015-01-14T13:58:49+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2015-01-13T04:37:26+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=971fc7b39934e9d3e0927d95c45bea6ad7e90566'/>
<id>971fc7b39934e9d3e0927d95c45bea6ad7e90566</id>
<content type='text'>
When optimizing boolean expressions, it is not always possible
to find a number of live registers for a GC BIF that both preserves
all source registers that will be tested and at the same time
does not include registers that are not initialized.

As currently implemented, we have incomplete information about
the register calculated from the free variables. Some registers
are marked as "reserved". Reserved registers means that we don't
know anything about them; they may or may not be initialized.

As a conservative correction (suitable for a maintenance release), we
will abort the optimization if we find any reserved registers when
calculating the number of live registers. We will not attempt to
improve the information about the registers in this commit.

By examining the coverage when running the existing compiler test
suite we find that the optimization is aborted 15 times (before
adding any new test cases). To put that in perspective, the
optimization is successfully applied 4927 times, and aborted for
other reasons 547 times.

Reported-by: Ulf Norell
Reported-by: Anthony Ramine
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When optimizing boolean expressions, it is not always possible
to find a number of live registers for a GC BIF that both preserves
all source registers that will be tested and at the same time
does not include registers that are not initialized.

As currently implemented, we have incomplete information about
the register calculated from the free variables. Some registers
are marked as "reserved". Reserved registers means that we don't
know anything about them; they may or may not be initialized.

As a conservative correction (suitable for a maintenance release), we
will abort the optimization if we find any reserved registers when
calculating the number of live registers. We will not attempt to
improve the information about the registers in this commit.

By examining the coverage when running the existing compiler test
suite we find that the optimization is aborted 15 times (before
adding any new test cases). To put that in perspective, the
optimization is successfully applied 4927 times, and aborted for
other reasons 547 times.

Reported-by: Ulf Norell
Reported-by: Anthony Ramine
</pre>
</div>
</content>
</entry>
<entry>
<title>beam_bool: Correct indentation for try...catch</title>
<updated>2015-01-14T13:55:35+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2015-01-13T04:27:04+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=bd3ba08000a258818e52410c73fcb195db88356f'/>
<id>bd3ba08000a258818e52410c73fcb195db88356f</id>
<content type='text'>
Old versions of the Erlang mode for Emacs used to indent try...catch
strangely - the first clause following the 'catch' would be indented
with one space less than the following clauses.

If we are to use the new Erlang mode when we add more clauses, they
would be indented with one space less than the preceding clauses.
That would look silly.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Old versions of the Erlang mode for Emacs used to indent try...catch
strangely - the first clause following the 'catch' would be indented
with one space less than the following clauses.

If we are to use the new Erlang mode when we add more clauses, they
would be indented with one space less than the preceding clauses.
That would look silly.
</pre>
</div>
</content>
</entry>
<entry>
<title>sys_core_fold: Correct optimization of 'case'</title>
<updated>2015-01-14T13:44:22+00:00</updated>
<author>
<name>Björn Gustavsson</name>
<email>bjorn@erlang.org</email>
</author>
<published>2015-01-14T06:05:21+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=85701edb6bdfe7c616a8486542dc2ca4bd787113'/>
<id>85701edb6bdfe7c616a8486542dc2ca4bd787113</id>
<content type='text'>
The optimization of a 'case' statement could lead to incorrect
code that would cause an exception at run-time.

Here is an example to show how the optimization went wrong. Start
with the following code:

  f({r,#{key:=Val},X}=S) -&gt;
    case S of
      {r,_,_} -&gt;
        setelement(3, Val, S)
    end.

(The record operations have already been translated to the
corresponding tuple operations.) The first step in case_opt/3 is
to substitute S to obtain:

  f({r,#{key:=Val},X}=S) -&gt;
    case {r,#{key:=Val},X} of
      {r,_,_} -&gt;
        setelement(3, Val, S)
    end.

After that substitution the 'case' can be simplified to:

  f({r,#{key:=Val},_}=S) -&gt;
    case #{key:=Val} of
      NewVar -&gt;
       setelement(3, Val, S)
    end.

That is the result from case_opt/3. Now eval_case/2 notices
that since there is only one clause left in the 'case', the
'case' can eliminated:

  f({r,#{key:=Val},_}=S) -&gt;
    NewVar = #{key:=Val},
    setelement(3, Val, S).

Since the map construction may have a side effect, it was not
eliminated, but assigned to a variable that is never used.

The problem is that '#{key:=Val}' is fine as a pattern, but in a
construction of a new map, the '=&gt;' operator must be used. So the
map construction will fail, generating an exception.

As a conservative correction for a maintenance release, we will
abort the 'case' optimization if the substitution into the 'case'
expression is anything but data items (tuples, conses, or
literals) or variables.

Reported-by: Dmitry Aleksandrov
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The optimization of a 'case' statement could lead to incorrect
code that would cause an exception at run-time.

Here is an example to show how the optimization went wrong. Start
with the following code:

  f({r,#{key:=Val},X}=S) -&gt;
    case S of
      {r,_,_} -&gt;
        setelement(3, Val, S)
    end.

(The record operations have already been translated to the
corresponding tuple operations.) The first step in case_opt/3 is
to substitute S to obtain:

  f({r,#{key:=Val},X}=S) -&gt;
    case {r,#{key:=Val},X} of
      {r,_,_} -&gt;
        setelement(3, Val, S)
    end.

After that substitution the 'case' can be simplified to:

  f({r,#{key:=Val},_}=S) -&gt;
    case #{key:=Val} of
      NewVar -&gt;
       setelement(3, Val, S)
    end.

That is the result from case_opt/3. Now eval_case/2 notices
that since there is only one clause left in the 'case', the
'case' can eliminated:

  f({r,#{key:=Val},_}=S) -&gt;
    NewVar = #{key:=Val},
    setelement(3, Val, S).

Since the map construction may have a side effect, it was not
eliminated, but assigned to a variable that is never used.

The problem is that '#{key:=Val}' is fine as a pattern, but in a
construction of a new map, the '=&gt;' operator must be used. So the
map construction will fail, generating an exception.

As a conservative correction for a maintenance release, we will
abort the 'case' optimization if the substitution into the 'case'
expression is anything but data items (tuples, conses, or
literals) or variables.

Reported-by: Dmitry Aleksandrov
</pre>
</div>
</content>
</entry>
<entry>
<title>Prepare release</title>
<updated>2014-12-09T14:21:47+00:00</updated>
<author>
<name>Erlang/OTP</name>
<email>otp@erlang.org</email>
</author>
<published>2014-12-09T14:21:47+00:00</published>
<link rel='alternate' type='text/html' href='http://git.ninenines.eu/otp.git/commit/?id=7f3486a5ddc02a366f2945dfd009c4a2697a2b98'/>
<id>7f3486a5ddc02a366f2945dfd009c4a2697a2b98</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
