aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
AgeCommit message (Collapse)Author
2015-02-04Correct unsafe optimization of '==' and '/='Björn Gustavsson
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.
2015-02-03Be more careful about map patterns when evalutating element/2Björn Gustavsson
We must not convert map patterns to map expressions.
2015-02-03Do not convert map patterns to map expressionsBjörn Gustavsson
In code such as: case {a,Map} of {a,#{}}=T -> T end we must NOT rewrite a map pattern to a map expression like this: case Map of #{} -> {a,#{}} end because the pattern '#{}' will match any map, but the expression '#{}' will construct an empty map.
2015-01-19core_lib: Handle patterns in map valuesBjörn Gustavsson
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 := <<42:N>>} -> 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.
2015-01-16Merge branch 'bjorn/compiler/map-in-record-bug/OTP-12402' into maintBjörn Gustavsson
* bjorn/compiler/map-in-record-bug/OTP-12402: sys_core_fold: Correct optimization of 'case'
2015-01-14beam_bool: Correct live calculation for GC BIFsBjörn Gustavsson
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
2015-01-14beam_bool: Correct indentation for try...catchBjörn Gustavsson
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.
2015-01-14sys_core_fold: Correct optimization of 'case'Björn Gustavsson
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) -> case S of {r,_,_} -> 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) -> case {r,#{key:=Val},X} of {r,_,_} -> setelement(3, Val, S) end. After that substitution the 'case' can be simplified to: f({r,#{key:=Val},_}=S) -> case #{key:=Val} of NewVar -> 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) -> 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 '=>' 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
2014-12-09Prepare releaseErlang/OTP
2014-12-01compiler: Coalesce map keys in dialyzer modeBjörn-Egil Dahlberg
This fixes a regression introduced in commit 805f9c89fc01220bc1bb0f27e1b68fd4eca688ba The problem occured with map keys compiled with dialyzer option turned on. In OTP 17, map keys needs to be literals.
2014-10-27Fix miscompilation when module contains multiple named funsAnthony Ramine
A module containing two named funs bearing the same name and arity could be miscompiled. Reported-by: Sam Chapin
2014-09-15Update release notesErlang/OTP
2014-09-15Update version numbersErlang/OTP
2014-09-01sys_core_fold: Eliminate name capture bugBjörn Gustavsson
The scope is supposed to contain all variables that are currently live. We need this information for certain optimizations to avoid capturing a name (a name that is in the scope must be renamed; for an example, see move_let_into_expr/2 or any function that calls sub_subst_scope/1). We also use the scope to optimize sub_del_var/2 and sub_is_val/2. When optimizing case expressions, the scope could be reset to an empty list (because sub_new/0 was called instead of sub_new/1). That could cause name capture if inlining was turned on. As simple way to force this bug is to uncomment the "-define(DEBUG, 1)." near the beginning of the file. Without this correction, most files in the test suite fail to compile.
2014-06-19Prepare releaseErlang/OTP
2014-06-18Merge branch 'egil/fix-doc-links' into maintBjörn-Egil Dahlberg
* egil/fix-doc-links: doc: Fix broken links in Installation Guide doc: Fix broken links
2014-06-17doc: Fix broken linksBjörn-Egil Dahlberg
2014-06-17[dialyzer] Use the option 'dialyzer' to control the compilerHans Bolinder
2014-06-17[dialyzer] Fix handling of literal recordsHans Bolinder
This ticket is about records in Erlang code, and when to check the fields against the (optional) types given when defining records. Dialyzer operates on the Erlang Core format, where there are no trace of records. The fix implemented is a Real Hack: Given the new option 'dialyzer' erl_expand_records marks the line number of records in a way that is undone by v3_core, which in turn inserts annotations that can be recognized by Dialyzer.
2014-06-16Fix handling of latin1 characters in false ifdef branchesBjörn Gustavsson
The fallback to latin-1 encoding would not work if the invalid UTF-8 characters occurred in a skipped branch in an -ifdef/-ifndef.
2014-05-26Merge branch 'egil/fix-maps-pretty-layout/OTP-11947' into maintBjörn-Egil Dahlberg
* egil/fix-maps-pretty-layout/OTP-11947: dialyzer: Add Maps type mismatch test hipe,compiler: Fix Map literals pretty printing
2014-05-04Support maps in cerl:ann_make_tree/3Anthony Ramine
2014-04-28hipe,compiler: Fix Map literals pretty printingBjörn-Egil Dahlberg
2014-04-07Update release notesErlang/OTP
2014-04-03compiler: Fix compiling map keys in patterns from coreBjörn-Egil Dahlberg
2014-04-03compiler,stdlib: Fix Map literals as keys for Maps in patternsBjörn-Egil Dahlberg
2014-03-28Take out no_native compiler attributeKostis Sagonas
2014-03-28Support the translation of the is_map BEAM instruction to IcodeKostis Sagonas
2014-03-26Merge branch 'egil/maps-compiler-coverage'Björn-Egil Dahlberg
* egil/maps-compiler-coverage: compiler: Do not evaluate map expressions with bad keys compiler: Throw 'nomatch' on matching with bad binary keys compiler: Variable keys are not allowed in Maps compiler: Strengthen Maps warnings tests compiler: map_pair cannot be a type clause in v3_life compiler: Remove redudant code in v3_codegen compiler: Test deep map structure compiler: Remove redundant clause in v3_codegen compiler: Cover #{ [] => Var } in testcase
2014-03-25compiler: Do not evaluate map expressions with bad keysBjörn-Egil Dahlberg
Map keys with large (non literal) binary keys must fail.
2014-03-25compiler: Throw 'nomatch' on matching with bad binary keysBjörn-Egil Dahlberg
Even if a binary key is written as a literal the compiler may choose to make an expression. Emit a warning in those cases and saying the case will not match. This is a limitation in current implementation.
2014-03-25compiler: Variable keys are not allowed in MapsBjörn-Egil Dahlberg
No need to check for variables in Map keys.
2014-03-25compiler: Strengthen Maps warnings testsBjörn-Egil Dahlberg
Increases coverage.
2014-03-25compiler: map_pair cannot be a type clause in v3_lifeBjörn-Egil Dahlberg
Map pairs are encapsulated in a map.
2014-03-25Correctly handle non-matching patterns against literal valuesAnthony Ramine
The pass sys_core_fold did not correctly handle non-matching patterns in code such as: 0 = case <<>> of <<>> -> 0; a -> 1 end. Function case_opt_lit/3 is rewritten in two passes to first remove any non-matching clause and only then potentially remove the related patterns in each clause. Reported-by: Ulf Norell
2014-03-24compiler: Remove redudant code in v3_codegenBjörn-Egil Dahlberg
2014-03-24compiler: Test deep map structureBjörn-Egil Dahlberg
2014-03-24compiler: Remove redundant clause in v3_codegenBjörn-Egil Dahlberg
Multiple 'nil' cannot happen on instruction level. Map keys are always unique with literals.
2014-03-24compiler: Cover #{ [] => Var } in testcaseBjörn-Egil Dahlberg
Coverage removed by literals.
2014-03-20Introduce runtime_dependencies in .app filesRickard Green
Most dependencies introduced are exactly the dependencies to other applications found by xref. That is, there might be real dependencies missing. There might also be pure debug dependencies listed that probably should be removed. Each application has to be manually inspected in order to ensure that all real dependencies are listed. All dependencies introduced are to application versions used in OTP 17.0. This since the previously used version scheme wasn't designed for this, and in order to minimize the work of introducing the dependencies.
2014-03-20Bump versions and ensure that all are "normal" versionsRickard Green
Ensure all are "normal" versions according to the new version scheme introduced in OTP 17.0
2014-03-20Merge branch 'ks/cerl-type-fixes'Björn-Egil Dahlberg
* ks/cerl-type-fixes: Restore the alphabetical order of Core Erlang records Clean up the types of cerl
2014-03-19Merge branch 'nox/maps-v3_core-lit_vars'Björn-Egil Dahlberg
* nox/maps-v3_core-lit_vars: Properly collect variables in map expressions in v3_core
2014-03-19Merge branch 'bjorn/compiler/utf8-warning/OTP-11791'Björn Gustavsson
* bjorn/compiler/utf8-warning/OTP-11791: Don't fail compilation for modules that contain invalid UTF-8 epp: Make it possible to specify a default encoding
2014-03-19Restore the alphabetical order of Core Erlang recordsKostis Sagonas
The introduction of c_map{} and c_map_pair{} unnecessarily broke the alphabetical order of Core Erlang records. They were probably placed at the end of the file so as to use other records as types. There is really no need for this since 'cerl' contains appropriate definitions of types that can be used for this purpose. While at it, a type declaration to the c_binary{} definition was added.
2014-03-19Clean up the types of cerlKostis Sagonas
The introduction of c_map and c_map_pair was not done properly. In particular, the definition of ctype() and an important Edoc comment were not up-to-date. While at it, - some more types were cleaned up and exported so as to be used in core_parse.hrl and - some obviously dead code was removed (the type/1 function does not return 'nil', which in turn simplified a clause in the code of meta_1/2).
2014-03-18Don't fail compilation for modules that contain invalid UTF-8Björn Gustavsson
The default encoding for Erlang modules is now UTF-8, and the compilation would fail if a module contained byte sequences that are not valid UTF-8 sequences. In a large project with say many hundreds of Erlang modules with names of developers such as "Björn" or "Håkan" encoded in latin-1, that could mean that many hundreds of files would need to be modified just to get started testing OTP 17. As a temporary measure to ease the transition, automatically fall back to the latin-1 encoding with a warning for any module that contains invalid byte sequences and for which no encoding has been specified. The intention is to remove this workaround in OTP 18 or 19.
2014-03-18Properly collect variables in map expressions in v3_coreAnthony Ramine
Reported-by: José Valim
2014-03-17compiler: Transform M#{} to is_map(M)Björn-Egil Dahlberg
Core should not understand M#{} Instead transform M#{} to case _cor0 of <_cor1> when call 'erlang':'is_map' (_cor0) -> _cor1 ( <_cor2> when 'true' -> primop 'match_fail' ('badarg') -| ['compiler_generated'] ) end
2014-03-17compiler: Change #c_map{var} to #c_map{arg}Björn-Egil Dahlberg
Not only variables are allowed as arguments, the name should reflect that. Change cerl Map argument interface * cerl:map_arg/1 is more suitable then cerl:map_val/1 in this case.