aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test
AgeCommit message (Collapse)Author
2019-06-17Create a shared wrapper function for all occurrences of 'fun F/A'Björn Gustavsson
If the `fun F/A` syntax is used multiple times with the same `F/A`, (for examle, `fun foo/2`), there would a wrapper function and fun entry generated for each occurrence. Using the new support in the OTP 23 runtime system, generate a single wrapper function and fun entry for each `F/A`. Since there is only one wrapper function, it can be named based on the name of the function it calls to faciliate debugging, not based on the function that defines the fun. For example, the wrapper function for `fun foo/0` will now be named `-fun.foo/0-'.
2019-06-12beam_validator: Replace old type representation with beam_typesJohn Högberg
2019-06-12compiler: Move "known functions" to beam_typesJohn Högberg
2019-06-12compiler: Break out SSA/beam type definitions into a separate moduleJohn Högberg
2019-06-11Merge branch 'maint'John Högberg
* maint: erts: Fix bad loader optimization of get_tuple_element beam_ssa_type: Fix incorrect bitstring unit determination
2019-06-11Merge branch 'john/erts/fix-bad-get_tuple_element-opt/OTP-15871/ERIERL-374' ↵John Högberg
into maint * john/erts/fix-bad-get_tuple_element-opt/OTP-15871/ERIERL-374: erts: Fix bad loader optimization of get_tuple_element
2019-06-11Merge branch 'john/compiler/fix-bad-bitstring-type-opt/OTP-15872' into maintJohn Högberg
* john/compiler/fix-bad-bitstring-type-opt/OTP-15872: beam_ssa_type: Fix incorrect bitstring unit determination
2019-06-10erts: Fix bad loader optimization of get_tuple_elementJohn Högberg
The following sequence would be wrongly optimized into a i_get_tuple_element2 instruction, reading an element from the wrong tuple: {get_tuple_element,{x,0},1,{x,0}}. {get_tuple_element,{x,0},2,{x,1}}.
2019-06-10beam_ssa_type: Fix incorrect bitstring unit determinationJohn Högberg
The compiler would treat the "Unit" of bs_init instructions as the unit of the result instead of the required unit of the input, causing is_binary checks to be wrongly optimized away.
2019-05-29Merge branch 'bjorn/compiler/fix-beam_ssa_dead-patch/OTP-15845' into maint-22Erlang/OTP
* bjorn/compiler/fix-beam_ssa_dead-patch/OTP-15845: Fix unsafe optimizations where guard tests could be removed
2019-05-29Merge branch ↵Erlang/OTP
'bjorng_ghub/bjorn/compiler/fix-beam_ssa_dead-crash/ERL-956/OTP-15848' into maint-22 * bjorng_ghub/bjorn/compiler/fix-beam_ssa_dead-crash/ERL-956/OTP-15848: Eliminate crash in the beam_ssa_dead compiler pass
2019-05-29Merge branch 'bjorn/compiler/fix-unloadable-code-patch/ERL-955/OTP-15846' ↵Erlang/OTP
into maint-22 * bjorn/compiler/fix-unloadable-code-patch/ERL-955/OTP-15846: Fix loading of Core Erlang code for extracting a map element
2019-05-29Merge branch 'bjorn/compiler/fix-beam_except/ERL-954/OTP-15839' into maint-22Erlang/OTP
* bjorn/compiler/fix-beam_except/ERL-954/OTP-15839: Fix compiler crash in beam_except
2019-05-29Merge branch 'john/compiler/list_append_type/OTP-15841' into maint-22Erlang/OTP
* john/compiler/list_append_type/OTP-15841: compiler: Fix broken type for erlang:'++'/2
2019-05-29Merge branch 'bjorn/compiler/fix-receive-patch/ERL-950/OTP-15832' into maint-22Erlang/OTP
* bjorn/compiler/fix-receive-patch/ERL-950/OTP-15832: Eliminate compiler crash when compiling complex receive statements
2019-05-29Merge branch 'maint'Björn Gustavsson
* maint: Eliminate crash in the beam_ssa_dead compiler pass
2019-05-29Merge pull request #2263 from ↵Björn Gustavsson
bjorng/bjorn/compiler/fix-beam_ssa_dead-crash/ERL-956/OTP-15848 Eliminate crash in the beam_ssa_dead compiler pass
2019-05-28Merge branch 'maint'John Högberg
2019-05-28Merge branch 'john/compiler/list_append_type/OTP-15841' into maintJohn Högberg
2019-05-28Fix unsafe optimizations where guard tests could be removedBjörn Gustavsson
A repeated test could be optimized away. Example: bar(A) -> if is_bitstring(A) -> if is_binary(A) -> binary; true -> bitstring end; true -> other end. In the example, the `is_binary/1` test would be optimized away, basically turning the example into: bar(A) -> if is_bitstring(A) -> bitstring; true -> other end. Thanks user Marcus Kruse in the Elixir forum for noticing this bug.
2019-05-28Eliminate crash in the beam_ssa_dead compiler passBjörn Gustavsson
The compiler could crash in the beam_ssa_dead pass while compiling complex nested `case` expressions. See the added test case for an example and explanation. https://bugs.erlang.org/browse/ERL-956
2019-05-27Merge branch 'maint'Björn Gustavsson
* maint: Fix loading of Core Erlang code for extracting a map element Fix unsafe optimizations where guard tests could be removed
2019-05-27Merge branch 'bjorn/compiler/fix-unloadable-code-patch/ERL-955/OTP-15846' ↵Björn Gustavsson
into maint * bjorn/compiler/fix-unloadable-code-patch/ERL-955/OTP-15846: Fix loading of Core Erlang code for extracting a map element
2019-05-27Merge branch 'bjorn/compiler/fix-beam_ssa_dead-patch/OTP-15845' into maintBjörn Gustavsson
* bjorn/compiler/fix-beam_ssa_dead-patch/OTP-15845: Fix unsafe optimizations where guard tests could be removed
2019-05-27Merge branch 'maint'Björn Gustavsson
* maint: Fix compiler crash in beam_except
2019-05-27Merge branch 'bjorn/compiler/fix-beam_except/ERL-954/OTP-15839' into maintBjörn Gustavsson
* bjorn/compiler/fix-beam_except/ERL-954/OTP-15839: Fix compiler crash in beam_except
2019-05-27Fix compiler crash in beam_exceptBjörn Gustavsson
The compiler would crash in `beam_except` while compiling this function: bar(Req) -> ok = case Req of "POST" -> {error, <<"BAD METHOD ", Req/binary>>, Req}; _ -> ok end. https://bugs.erlang.org/browse/ERL-954
2019-05-27compiler: Fix broken type for erlang:'++'/2John Högberg
2019-05-27Fix loading of Core Erlang code for extracting a map elementBjörn Gustavsson
The following Core Erlang code could not be loaded: 'f'/1 = fun (_1) -> case <_1> of <~{'foo':='foo'}~> when 'true' -> _1 end Loading would fail with the following message: beam/beam_load.c(2314): Error loading function example:f/1: op i_get_map_element_hash p x a u x: no specific operation found https://bugs.erlang.org/browse/ERL-955
2019-05-25Fix unsafe optimizations where guard tests could be removedBjörn Gustavsson
A repeated test could be optimized away. Example: bar(A) -> if is_bitstring(A) -> if is_binary(A) -> binary; true -> bitstring end; true -> other end. In the example, the `is_binary/1` test would be optimized away, basically turning the example into: bar(A) -> if is_bitstring(A) -> bitstring; true -> other end. Thanks user Marcus Kruse in the Elixir forum for noticing this bug.
2019-05-23Merge branch 'maint'Björn Gustavsson
* maint: Eliminate compiler crash when compiling complex receive statements
2019-05-23Merge branch 'bjorn/compiler/fix-receive-patch/ERL-950/OTP-15832' into maintBjörn Gustavsson
* bjorn/compiler/fix-receive-patch/ERL-950/OTP-15832: Eliminate compiler crash when compiling complex receive statements
2019-05-22Merge branch 'maint'Björn Gustavsson
* maint: Fix non-terminating compilation Fix compiler crash when funs were matched
2019-05-22Merge branch 'bjorn/compiler/fix-freeze/ERL-948/OTP-15828' into maintBjörn Gustavsson
* bjorn/compiler/fix-freeze/ERL-948/OTP-15828: Fix non-terminating compilation
2019-05-22Merge pull request #2243 from bjorng/bjorn/compiler/fix-redundant-testsBjörn Gustavsson
Improve optimization of redundant tests
2019-05-22Merge pull request #2242 from bjorng/bjorn/add-swap-instructionBjörn Gustavsson
Make the swap instruction known to the compiler
2019-05-22Make the swap instruction known to the compilerBjörn Gustavsson
BEAM has had a `swap` instruction for several releases, but it was not known to the compiler. The loader would translate a sequence of three `move` instructions to the `swap` instructions, but only when it was possible to determine that it would be safe. By making `swap` known to the compiler, it can be applied in more situations since it is easier for the compiler than for the loader to ensure that the usage is safe, and the loader shenanigans can be eliminated.
2019-05-21Eliminate compiler crash when compiling complex receive statementsBjörn Gustavsson
Certain complex receive statements would result in an internal compiler failure. That would happen when the compiler would fail to find the common exit block following a receive. See the added test case for an example. https://bugs.erlang.org/browse/ERL-950
2019-05-20Improve optimization of redundant testsBjörn Gustavsson
The `beam_ssa_dead` pass is supposed to eliminate tests that are determined to be redundant based on the outcome of a previous test. For example, in the following example that repeats a guard test, the second clause can never be executed: foo(A) when A >= 42 -> one; foo(A) when A >= 42 -> two; foo(_) -> three. `beam_ssa_dead` should have eliminated the second clause, but didn't: {test,is_ge,{f,5},[{x,0},{integer,42}]}. {move,{atom,one},{x,0}}. return. {label,5}. {test,is_ge,{f,6},[{x,0},{integer,42}]}. {move,{atom,two},{x,0}}. return. {label,6}. {move,{atom,three},{x,0}}. return. Correct the optimization of four different combinations of relational operations that were too conservate. To ensure the correctness of the optimization, also add an exahaustive test of all combinations of relational operations with one variable and one literal. (Also remove the weak and now redundant coverage tests in `beam_ssa_SUITE`.) With this correction, the following code will be generated for the example: {test,is_ge,{f,5},[{x,0},{integer,42}]}. {move,{atom,one},{x,0}}. return. {label,5}. {move,{atom,three},{x,0}}. return. Thanks to Dániel Szoboszlay (@dszoboszlay), whose talk at Code BEAM STO 2019 made me aware of this missed opportunity for optimization.
2019-05-20Fix non-terminating compilationBjörn Gustavsson
The compiler would not terminate while compiling the following code: foo(<<N:32>>, Tuple, NewValue) -> _ = element(N, Tuple), setelement(N, Tuple, NewValue). The type analysis pass would attempt to construct a huge list when attempting analyse the type of `Tuple` after the call to `setelement/3`. https://bugs.erlang.org/browse/ERL-948
2019-05-14Eliminate the beam_except passBjörn Gustavsson
The beam_except pass rewrites certain calls `erlang:error/{1,2}` to use specialized instructions for common exceptions such as `{badmatch,Term}`. Move this optimization to `beam_ssa_pre_codegen` and `beam_ssa_codegen`. The main reason for this change is that optimization passes operating on SSA code are easier to maintain than optimization passes working on BEAM code.
2019-05-14Fix compiler crash when funs were matchedBjörn Gustavsson
Code such as the following would crash the compiler in OTP 22: [some_atom = fun some_function/1] The reason is that the fun would be copied (used both in the match operation and as a value in the list), and the copy of the fun would create two wrapper functions with the same name for calling some_function/1. In OTP 21, the duplicate functions happened not to cause any harm (one of the wrappers functions would be unused and ultimately be removed by beam_clean). In OTP 22, the new beam_ssa_type pass would be confused by the multiple definitions of the wrapper function.
2019-04-30Merge branch 'john/compiler/fix-missing-match-reposition/ERL-923'John Högberg
* john/compiler/fix-missing-match-reposition/ERL-923: compiler: Propagate match context position on fail path
2019-04-29compiler: Propagate match context position on fail pathJohn Högberg
2019-04-23beam_validator: Don't infer types for dead valuesJohn Högberg
2019-03-28Merge branch 'bjorn/compiler/cuddle-with-tests'Björn Gustavsson
* bjorn/compiler/cuddle-with-tests: Verify the highest opcode for the r21 test suites Add test_lib:highest_opcode/1 sys_core_fold: Simplify case_expand_var/2 beam_validator: Remove uncovered lines in lists_mod_return_type/3 Cover return type determination of lists functions
2019-03-26compiler: Fully disable no_return optimizations in try blocksJohn Högberg
Validation could fail when a function that never returned was used in a try block (see attached test case). It's possible to solve this without disabling the optimization as the generated code is sound, but I'm not comfortable making such a large change this close to the OTP 22 release.
2019-03-25Verify the highest opcode for the r21 test suitesBjörn Gustavsson
2019-03-25Add test_lib:highest_opcode/1Björn Gustavsson
2019-03-25Cover return type determination of lists functionsBjörn Gustavsson