aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
AgeCommit message (Collapse)Author
2016-09-05Merge branch 'bjorn/floor-ceiling/OTP-13692'Björn Gustavsson
* bjorn/floor-ceiling/OTP-13692: Add math:floor/1 and math:ceil/1 Implement the new ceil/1 and floor/1 guard BIFs
2016-09-05Add math:floor/1 and math:ceil/1Björn Gustavsson
Add math:floor/1 and math:ceil/1 to avoid unnecessary conversions in floating point expressions. That is, instead of having to write float(floor(X)) as part of a floating point expressions, we can write simply math:floor(X).
2016-09-05Implement the new ceil/1 and floor/1 guard BIFsBjörn Gustavsson
Implement as ceil/1 and floor/1 as new guard BIFs (essentially part of Erlang language). They are guard BIFs because trunc/1 is a guard BIF. It would be strange to have trunc/1 as a part of the language, but not ceil/1 and floor/1.
2016-09-02Fix overridden BIFsBjörn Gustavsson
The filters in a list comprehension can be guard expressions or an ordinary expressions. If a guard expression is used as a filter, an exception will basically mean the same as 'false': t() -> L = [{some_tag,42},an_atom], [X || X <- L, element(1, X) =:= some_tag] %% Returns [{some_tag,42}] On the other hand, if an ordinary expression is used as a filter, there will be an exception: my_element(N, T) -> element(N, T). t() -> L = [{some_tag,42},an_atom], [X || X <- L, my_element(1, X) =:= some_tag] %% Causes a 'badarg' exception when element(1, an_atom) is evaluated It has been allowed for several releases to override a BIF with a local function. Thus, if we define a function called element/2, it will be called instead of the BIF element/2 within the module. We must use the "erlang:" prefix to call the BIF. Therefore, the following code is expected to work the same way as in our second example above: -compile({no_auto_import,[element/2]}). element(N, T) -> erlang:element(N, T). t() -> L = [{some_tag,42},an_atom], [X || X <- L, element(1, X) =:= some_tag]. %% Causes a 'badarg' exception when element(1, an_atom) is evaluated But the compiler refuses to compile the code with the following diagnostic: call to local/imported function element/2 is illegal in guard
2016-09-02Merge branch 'bjorn/eliminate-sys_pre_expand/OTP-13856'Björn Gustavsson
* bjorn/eliminate-sys_pre_expand/OTP-13856: Remove sys_pre_expand xref: Eliminate use of sys_pre_expand debugger: Eliminate use of sys_pre_expand compiler: Eliminate use of sys_pre_expand shell_SUITE: Eliminate references to sys_pre_expand in comments qlc_pt: Simplify code because of updated erl_expand_records Teach erl_expand_records to translate module-less calls erl_internal: Add add_predefined_functions/1 cover: Remove always stale comment
2016-09-02Merge branch 'maint'Hans Bolinder
* maint: doc: Correct errors introduced by Editorial changes
2016-09-01Remove sys_pre_expandBjörn Gustavsson
The previous commits have made sys_pre_expand superfluous. Since sys_pre_expand is undocumented and unsupported it can be removed in a major release without prior deprecation. Also remove code in erl_parse that handles abstract code that has passed through sys_pre_expand. We considered deprecating sys_pre_expand just in case, but decided against it for the following reasons: - Anyone brave and knowledgeable enough to use sys_pre_expand should be able to cope with sys_pre_expand being removed. - If we kept it, but didn't test it anywhere in OTP, it could potentially stop working. So we would probably have to add some test cases.
2016-09-01compiler: Eliminate use of sys_pre_expandBjörn Gustavsson
sys_pre_expand previously did a lot more work, for example, translating records and funs, but now is merely a grab bag of small transformations. Move those transformations to v3_core.
2016-09-01doc: Correct errors introduced by Editorial changesHans Bolinder
Fix some older errors as well.
2016-08-19Reinstate optimization of binary literal matchingBjörn Gustavsson
105c5b0071 was reverted in dd1162846e because clauses that were supposed to match would not match. (See 8b83bc0b.) Reintroduce the optimization, but make sure that we only shortcut bs_context_to_binary instructions and not bs_start_match2 instructions.
2016-08-19Strengthen test case added in 8b83bc0bBjörn Gustavsson
Don't only test the case that failed; test it exhaustively.
2016-08-12Merge branch 'maint'Björn Gustavsson
* maint: asn1_test_lib: Compile ASN.1 modules in parallel Support 'make -j' when compiling ASN.1 modules [ERL-209] Fix ambiguous_catch_try_state inconsistency error
2016-08-11[ERL-209] Fix ambiguous_catch_try_state inconsistency errorBjörn Gustavsson
It is not safe to share code between 'catch' blocks.
2016-08-10Merge branch 'josevalim/large-binary-strings/PR-1131/OTP-13794'Björn Gustavsson
* josevalim/large-binary-strings/PR-1131/OTP-13794: Move expansion of strings in binaries to v3_core
2016-08-05Merge branch 'maint'Björn Gustavsson
* maint: Update primary bootstrap beam_block: Fix potentially unsafe optimization in move_allocates/1
2016-08-05beam_block: Fix potentially unsafe optimization in move_allocates/1Björn Gustavsson
beam_block has an optimization that only is safe when it is applied immediately after code generation. That is pointed out in a comment: NOTE: Moving allocation instructions is only safe because it is done immediately after code generation so that we KNOW that if {x,X} is initialized, all x registers with lower numbers are also initialized. That assumption may not be true after other optimizations, such as the beam_utils:live_opt/1 optimization. The new beam_reorder pass added in OTP 19 runs before beam_block. Therefore, the optimization is potentially unsafe. The optimization is also unsafe if compilation is started from assembly code in a .S file. Rewrite the optimization to make it safe. See the newly added comment for details. ERL-202
2016-08-04Move expansion of strings in binaries to v3_coreJosé Valim
This speeds up the compilation of binary literals with string values in them. For example, compiling a file with a ~340kB binary would yield the following times by the compiler: Compiling "foo" parse_module : 0.130 s 5327.6 kB transform_module : 0.000 s 5327.6 kB lint_module : 0.011 s 5327.8 kB expand_module : 0.508 s 71881.2 kB v3_core : 0.463 s 11.5 kB Notice the increase in memory and processing time in expand_module and v3_core. This happened because expand_module would expand the string in binaries into chars. For example, the binary <<"foo">>, which is represented as {bin, 1, [ {bin_element, 1, {string, 1, "foo"}, default, default} ]} would be converted to {bin, 1, [ {bin_element, 1, {char, 1, $f}, default, default}, {bin_element, 1, {char, 1, $o}, default, default}, {bin_element, 1, {char, 1, $o}, default, default} ]} However, v3_core would then traverse all of those characters and convert it into an actual binary, as it is a literal value. This patch addresses this issue by moving the expansion of string into chars to v3_core and only if a literal value cannot not be built. This reduces the compilation time of the file mentioned above to the values below: Compiling "bar" parse_module : 0.134 s 5327.6 kB transform_module : 0.000 s 5327.6 kB lint_module : 0.005 s 5327.8 kB expand_module : 0.000 s 5328.7 kB v3_core : 0.013 s 11.2 kB
2016-07-15Merge branch 'maint'Björn-Egil Dahlberg
Conflicts: OTP_VERSION
2016-07-15Merge branch 'maint-19' into maintBjörn-Egil Dahlberg
2016-07-14Prepare releaseErlang/OTP
2016-07-12Revert "beam_dead: Improve optimization of literal binary matching"Björn-Egil Dahlberg
This reverts commit 105c5b0071056dc062797e58772e098d2a3a4627.
2016-07-12compiler: Test literal binary matchingBjörn-Egil Dahlberg
The following regression was introduced in 19.0: foo(bar, <<"x">>) -> 1; foo(_, <<"x">>) -> 2; foo(_, <<"y">>) -> 3; foo(_, _) -> fail. The call foo(bar,<<"y">>) would errorneous return 'fail' instead of 3. A testcase in match_SUITE has been added to verify this.
2016-06-30Merge branch 'maint'Björn Gustavsson
* maint: Fix spec of compile:(noenv_)forms/2
2016-06-30Merge branch 'aronisstav/compiler/fix-compile-forms-spec/PR-1109' into maintBjörn Gustavsson
* aronisstav/compiler/fix-compile-forms-spec/PR-1109: Fix spec of compile:(noenv_)forms/2
2016-06-29Merge branch 'bjorn/gc-bifs'Björn Gustavsson
* bjorn/gc-bifs: compiler: Eliminate num_bif_SUITE erl_internal: Eliminate duplication of guard tests beam_debug: Improve the disassembly of gc_bif instructions Simplify creation of new GC BIFs make_tables: Remove broken automatic BIF aliasing
2016-06-29compiler: Eliminate num_bif_SUITEBjörn Gustavsson
num_bif_SUITE.erl was originally copied from the emulator test suite. It does not test much of the compiler. Therefore, remove num_bif_SUITE. Add a new test to bif_SUITE to test trunc/1 and round/1 in contexts that could be tricky for the compiler to handle correctly. Note that there is no need to test abs/1 in bif_SUITE, since it is tested in many other places (e.g. in guard_SUITE).
2016-06-23Fix try-catch when writing makefileMagnus Henoch
Any exceptions at this point would be of class error, not exit.
2016-06-22Show error reason when compiler cannot write fileMagnus Henoch
When the compiler fails to write an output file, it used to just print "error writing file". With this change, it also prints the error reason: $ echo "-module(foo)." > foo.erl $ chmod -w . $ erlc foo.erl /tmp/bar/foo.bea#: error writing file: permission denied
2016-06-21Prepare releaseErlang/OTP
2016-06-20Fix spec of compile:(noenv_)forms/2Stavros Aronis
The input for a call to compile:(noenv_)forms/2 can also be a cerl module (useful e.g. to resume with 'from_core' after a 'to_core' compilation). Internal representations used for 'from_asm' and 'from_beam' compilation can also be valid, but have no relevant types defined.
2016-06-08compile.xml: Eliminate unsightly space before periodBjörn Gustavsson
2016-06-07Compiler: new function env_compiler_options/0alisdair sullivan
retrieve the value of the environment variable ERL_COMPILER_OPTIONS in the same manner as used by file/2, forms/2 and output_generated/2
2016-06-03Merge branch 'bjorn/compiler/misc'Björn Gustavsson
* bjorn/compiler/misc: misc_SUITE: Cover the remaining lines in beam_peep Avoid the dreaded "no_file" in warnings Eliminate crash for map updates in guards beam_block: Eliminate crash in beam_utils
2016-06-03Merge branch 'jv/compiler/mapsify-rec_env/PR-1082/OTP-13646'Björn-Egil Dahlberg
* jv/compiler/mapsify-rec_env/PR-1082/OTP-13646: Convert dict() to map() in rec_env.erl
2016-06-03misc_SUITE: Cover the remaining lines in beam_peepBjörn Gustavsson
2016-06-02Avoid the dreaded "no_file" in warningsBjörn Gustavsson
Add more filename/line number annotations while translating to Core Erlang in v3_core, and ensure that sys_core_fold retains existing annotations. The goal is to avoid that sys_core_fold generate warnings with "no_file" instead of a filename.
2016-06-02Eliminate crash for map updates in guardsBjörn Gustavsson
beam_validator would complain that x(1) is uninitialized in a test_heap instruction when attempting to compile the following code with sys_core_fold turned off: foo(M) when not (M#{true := 0}); [M] -> ok. Simplified, the generated BEAM assembly code looked like this: test is_map BadMap x(0) put_map_exact Fail x(0) => x(1) ... jump BooleanStuff BadMap: move ok => x(1) jump Fail BooleanStuff: ... move Boolean => x(2) jump Build Fail: move false => x(2) Build: test_heap 2 3 %% x(0), x(1), x(2) must be live. ... That is, if put_map_exact failed, control would transfer to the label Fail without initializing x(1). Fix that by making sure that x(1) is initilized even if put_map_exact fails: test is_map BadMap x(0) put_map_exact BadLbl x(0) => x(1) ... jump OkLbl BadLbl: move ok => x(1) jump Fail OkLbl: jump BooleanStuff BadMap: move ok => x(1) jump Fail BooleanStuff: ... move Boolean => x(2) jump Build Fail: move false => x(2) Build: test_heap 2 3 %% x(0), x(1), x(2) must be live. ... Note that this situation is rare, and that other optimization passes (beam_dead and beam_jump in particular) will clean up this mess.
2016-06-02Revert "Prepare release"Erlang/OTP
This reverts commit e020f75c10410a6943cd055bfa072a2641eab7da.
2016-06-02Prepare releaseErlang/OTP
2016-06-01Convert dict() to map() in rec_env.erlJosé Valim
2016-06-01beam_block: Eliminate crash in beam_utilsBjörn Gustavsson
Somewhat simplified, beam_block would rewrite the target for the first instruction in this code sequence: move x(0) => y(1) gc_bif '+' 1 x(0) => y(0) move y(1) => x(1) move nil => x(0) call 2 local_function/2 The resulting code would be: move x(0) => x(1) %% Changed target. gc_bif '+' 1 x(0) => y(0) move x(1) => y(1) %% Operands swapped (see 02d6135813). move nil => x(0) call 2 local_function/2 The resulting code is not safe because the x(1) will be killed by the gc_bif instruction. 7a47b20c3a cleaned up move optimizations and would reject the optimization if the target was an X register and an allocating instruction was found. To avoid this bug, the optimization must be rejected even if the target is a Y register.
2016-05-31Add additional coverage and smoke test of beam_validatorBjörn Gustavsson
2016-05-31beam_validator: Strengthen validation of match statesBjörn Gustavsson
We want to find bugs in the compiler during compilation. Validation of match contexts was weak, which could allow serious bugs in the generated code to slip through.
2016-05-31beam_validator: Use a record representing the match contextBjörn Gustavsson
Using a record will make it much easier to add additional information.
2016-05-31Merge branch 'bjorn/compiler/misc'Björn Gustavsson
* bjorn/compiler/misc: Eliminate unsafe use of Y registers beam_validator: Add is_bitstring/1 as a safe BIF beam_validator: Remove uncovered line Teach beam_utils:is_pure_test/1 to handle is_bitstr and is_function2 beam_utils: Simplify handling of 'return' to eliminate uncovered line beam_jump: Clean up handling of labels before func_info beam_expect: Correctly handle blocks with multiple allocs v3_codegen: Don't confuse beam_validator v3_codegen: Correct code generation for an error/1 call in a guard beam_receive: Don't crash when encountering nonsensical code
2016-05-30Eliminate unsafe use of Y registersBjörn Gustavsson
If the Core Erlang optimization were turned off (using no_copt), the optimization passes for Beam assembly could generate unsafe code that did not initialize all Y registers before (for example) a call instruction. To fix this, beam_dead should not attempt to remove stores to Y registers. That is not safe if there is an exception-generating instruction inside a try...catch block.
2016-05-30beam_validator: Add is_bitstring/1 as a safe BIFBjörn Gustavsson
beam_validator wrongly complained that the following was not safe because it didn't know that is_bitstring/1 is safe: food(Curriculum) -> [try is_bitstring(functions) catch _ -> 0 end, Curriculum]. While we are it, also add a new bif_SUITE test suite to cover some more code in beam_validator.
2016-05-30beam_validator: Remove uncovered lineBjörn Gustavsson
The raise/3 instruction is specially handled, thus there is no need for bif_type/3 to handle raise/3 (also, the number of arguments was incorrect, so it could never have matched).
2016-05-30Teach beam_utils:is_pure_test/1 to handle is_bitstr and is_function2Björn Gustavsson
The 'is_bitstr' and 'is_function2' tests are pure. The corresponding BIFs have different names; thus the default call to erl_internal:new_type_test/2 is not sufficient.
2016-05-27Declare the type of function entry pointsKostis Sagonas
This shuts off compiler warnings and will allow to enable stronger compiler checks files that include beam_disasm.hrl in the hipe application. While doing that, also modified a comment in the header file and turned a case statement into effectively an assertion: there should not really be any beam files where functions do not have a label as entry point, right?