> These document describes the release notes for older versions of the `compiler` application.

> ## Compiler 4.0

> ### Fixed errors and malfunctions

> - If records happened to be defined with initializers so that they included each other recursively, the compilation would eat up all memory and then crash. Now, an error message is given instead.
>   (Own Id: OTP-2677)

> - When using the `warn_unused_vars` option to the compiler, warnings could previously be incorrectly given for variables used within list comprehensions.
>   (Own Id: OTP-3412)

> - When using the option `warn_unused_vars` when compiling, unused variables introduced inside a `case`, `receive` or `if` were not always reported.
>   (Own Id: OTP-3729)

> ### Improvements and new features

> - The guard tests `list/1`, `atom/1` etc. now also have the names `is_list/1`, `is_atom/1`. All these guard tests are also BIFs that can be used in expression in function bodies, too.
>   (Own Id: OTP-3791)

> - There are more compiler optimisations. In particular, lists comprenhensions and record updates are faster.
>   (Own Id: OTP-4142)

> - Floating point operations are significantly faster if the compiler knows that floating point is involved. The guard bif `is_float/1` can be used ensure that the compiler knows the type.
>   (Own Id: OTP-4143)

> - To faciliate constructing records containing wildcards for functions such as `ets:match/2` and `mnesia:match_object/3`, a special field named `_` can now be assigned, meaning that all fields not explicitly assigned in the same record update will be assigned. Example: `#person{name = "Nisse", _ = '_'}`
>   (Own Id: OTP-4147)

> - New short-circuit versions of `and` and `or` called `andalso` and `orelse` have been added. They terminate evaluation of the boolean expression as soon as the truth value is known. The new operators cannot be used in guards.
>   (Own Id: OTP-4148)

> - The boolean operators `and`, `or`, and `not` can now be used in guards.
>   (Own Id: OTP-4149)

> - The compiler in R8 will issue a warnings when the atoms or functions `try` or `cond` are used, as these will be keywords in a future version of Erlang.
>   (Own Id: OTP-4150)

> - In the Open-Source release of Erlang/OTP, the HiPE (High Performance Erlang) extension can be enabled. (Using `./configure --enable-hipe` when building.) If the runtime-system is hipe-enabled, a module can be native-code compiled like this:

>   `c(Module, [native|OtherOptions])`.

>   Compiling in this way, the beam file will contain both standard beam byte-code and the native code. If loaded on a hipe-enabled system the native code will be loaded; otherwise the beam-code will be loaded.

>   HiPE is supported for Ultra Sparc and Intel Pentium.
>   (Own Id: OTP-4153)

> ## Compiler 3.0.1.2

> ### Fixed errors and malfunctions

> - The compiler would sometimes reorder bit syntax clauses causing them to be execute in the wrong order. This has been corrected.
>   Own Id: OTP-3748
>   Aux Id: Seq 4954
> - Modules containing long literals string concatenated with variables would take long time to compile and the beam module would be unecesserialy large. Both problems have been corrected.
>   Own Id: OTP-3831
>   Aux Id: Seq 5085
> - By default, debug information is no longer included in beam modules. Use the compiler option `debug_info` to include debug information.
>   Own Id: OTP-3885

> ## Compiler 3.0.1

> ### Improvements and new features

> - Several minor compiler bugs corncerning the bit syntax were corrected.
>   Own Id: OTP-3707

> ## Compiler 3.0

> ### Known problems

> - Use of recursively defined records causes the compiler to crash instead of reporting an error.
>   Own Id: OTP-2677

> ### Fixed errors and malfunctions

> - The Erlang compiler builds lists and tuples in a smarter way than previous compilers, meaning that literal lists and tuples practically any size can now be built.
>   Own Id: OTP-2388
>   Aux Id: seq 821
> - Using a literal atom in a call to atom_to_list/1 resulted in a compiled module that could not be loaded. This has been corrected.
>   Own Id: OTP-3438

> ### Improvements and new features

> - We have made several changes to the garbage collector and internal memory allocation routines to reduce memory consumption and memory fragmentation. Also, the compiler now makes sure that references to any data that will not be used again will be killed, so that the garbage collector can discard it as soon as possible. (Thanks to Claes Wickstrom at Bluetail who suggested most of the changes to the garbage collector.)
>   Own Id: OTP-2375
>   Aux Id: seq 816, HA81951
> - It is now allowed to use an expression within a pattern, if the expression uses only numeric or bitwise operators, and can be evaluated to a constant at compile-time. E.g., `case X of {1+2, T} -> T end.`
>   Own Id: OTP-3144
>   Aux Id: OTP-3143
> - There now exists syntax for constructing and matching binaries. For more infomation, see Extensions to Erlang. Also, the handling of small binaries (up to 64 bytes) has been optimised, as well as splitting of binaries.
>   Own Id: OTP-3376
> - The construction `??Arg` for an argument to a macro expands to a string containing the tokens of the argument, similar to the `#arg` stringifying construction in C.
>   Own Id: OTP-3425
> - The compiler now supports inlining within a module (see the compiler documentation). Numerous known problems and limitations have been corrected, and the optimisation is better (for instance, tuples used in cases for grouping are no longer built). The earlier compiler versions v1 (R5) and v2 (R6) have been discontinued because there are no longer any reason to use them.
>   Own Id: OTP-3672

> ## Compiler 2.1

> ### Improvements and new features

> - The old compiler from R5 is included as well as the new compiler. The new compiler (`v2`) is the default. The old compiler can be chosen by giving a `v1` option to the compiler. The compiler will also read default compiler options from the ERL_COMPILER_OPTIONS environment variables.

>   The `v2` compiler, which is default, generates smaller and faster code than the `v1` compiler, but in one case the compilation can be extremly slow: on pattern matching on long literal strings. The `v2` compiler in R6A also compiled huge list and/or tuple literals slowly. The `v2` compiler in R6B compiles these literals much faster.
>   Own Id: OTP-3363

> ## Compiler 2.0

> ### Known problems

> - Use of recursively defined records causes the compiler to crash instead of reporting an error.
>   Own Id: OTP-2677
> - All current versions of the Beam compiler (both the `v1` and the `v2` versions) have a hard limit on the size of list and tuple literals in Beam modules. This limit 1024, which is the number of registers in the Beam virtual machine. When building a list whose elements are not small integers or atoms, the compiler generates code that builds all list elements from left to right (as the Erlang standard prescribes) saving the built elements in registers. When all elements has been built, the list itself is built. This effectively limits the size of a literal list to 1024 elements.

>   This limitation will be removed in a future version of the compiler.

>   Note 1: This only applies to list literals in Beam modules, not to list literals read from data files by `file:consult/X` or other means, or lists built dynamically by Erlang code or BIFs. The only practial limit on the list size is the available memory.

>   Note 2: Literals list with elements that don't need to be built beforehand (such as numbers and atoms) can be of any length.

>   Note 3: The same rules apply to tuples.
>   Own Id: OTP-3367

> ### Fixed errors and malfunctions

> - In earlier Beam releases, the result of the match operator '=' in a function body was wrong. For instance, in '`io:format("~p\n", [[X]=[a]])`', the result of the match expression '`[X]=[a]`' should be '`[a]`', but in Beam it was '`a`'. This all means that multiple patterns in function bodies such as '`[X] = [Y] = [a]`' would fail with a badmatch exception in Beam releases before R6. This has been corrected in the new Beam compiler. Incorrect code like '`a = [X] = [a]`' which depended on the incorrect behaviour will now fail with a badmatch.
>   (*** POTENTIAL INCOMPATIBILITY ***)
>   Own Id: OTP-3176

> ### Improvements and new features

> - Where previously only one comma-separated sequence of guard tests was allowed, now a guard can be written as a disjunction of sequences, using `;` as separator. This is syntactic sugar which removes the bother of writing the same body after several guards.
>   Own Id: OTP-3182
> - The compiler has been entirely rewritten for this release. It generally generates smaller and faster code than the old compiler. The compiler itself, however, may be slower than the older compiler, depending on the input.
>   Own Id: OTP-3335

> ## Compiler 1.3

> ### Known problems

> - When the macro `?MACHINE` is encountered by the compiler, it is expanded to the machine which is running the compiler, not the machine for which the code is compiled. The latter is almost always more useful.
>   Own Id: OTP-2517
> - `c:c(File, 'P')` does produce a .P file, but yields an ugly error message in the process.
>   Own Id: OTP-3054

> ## Compiler 1.3

> ### Fixed errors and malfunctions

> - Use of macros with circular definitions now gives an error message, instead of causing the compiler (or `epp`) to hang or crash. (Checking is not done for macros which exploit the fact that macros may end in a lone '`?`' - use of this feature is not recommended.)
>   Own Id: OTP-1398
>   Aux Id: OTP-1103,OTP-1180
> - Some error conditions when compiling (for example, attempting to create a literal tuple with more than 256 elements in JAM) were not reported as errors, but only printed on the terminal, therefore making it appear as if the compilation succeeded. They are now reported properly.
>   Own Id: OTP-2620
> - BEAM only: the beam compiler generates wrong code when there is several function clauses with a common first part of a pattern and then a different second part of the pattern where this second part of the pattern is built on the heap. Examples of code that is generated wrong are:

>       -module(beamfel3).
>       -export([handle_cast/2]).
>       -record(state,{e1,e2}).

>       handle_cast({a,DpId},State) when State ==
>       #state{e1=true,
>       e2=a} ->
>       process_info(DpId);

>       handle_cast({a,DpId},State) when State ==
>       #state{e1=true,
>       e2=b} ->
>       process_info(DpId).

>   or like this:

>       -module(beamfel2).
>       -export([f/2]).

>       f({a,DpId},16#7fffffff) ->
>       process_info(DpId);

>       f({a,DpId},16#80000000) ->
>       process_info(DpId).

>   This codegeneration error could cause the Erlang emulator to terminate with the message "Overrun heap and stack ...". This is now corrected. This has also been corrected in patch erl_077 for OTP R4B.
>   Own Id: OTP-2821
>   Aux Id: Seq 1271
> - Failing parse transforms were confusing; now the error message is better.
>   Own Id: OTP-2839
> - BEAM only: If the '`<`' operator was used in a body context (`Bool = Expr1 < Expr`), the compiler could crasch or generate incorrect code. This has been corrected.
>   Own Id: OTP-2871
>   Aux Id: seq 1343

> ### Improvements and new features

> - Two functions have been added to the `compile` module: `compile:forms/1` and `compile:forms/2`, which are analogous to `compile:file/[1,2]`, but take a list of forms as their first argument (such as is returned by the function `epp:parse_file/3`). The option `binary` is implicit; i.e., a binary is produced, never an object code file. If a listing file is requested (e.g., using the option 'E'), the module name is taken as the file name.
>   Own Id: OTP-2621
>   Aux Id: seq 961
> - For two kinds of errors, error messages from the compiler/linter/scanner now report the errors at the line where they occurred instead of at the end of the file: unterminated atoms and strings; and undefined functions. (For unterminated atoms and strings, the line does not point out the start of the string, but the line where scanning of the current form or expression began.)
>   Own Id: OTP-2726
>   Aux Id: seq 1156
> - The compiler now evaluates expressions at compile-time when their values are known, also eliminating dead code from `if` and `case` expressions when only one branch can ever be selected.
>   Own Id: OTP-2820
>   Aux Id: OTP-2794 WP37
> - For a node A to be able to create a fun, send it to a node B and let it execute there, it used to be the case that the object code loaded in both nodes had to be produced by the same compilation. Now it is possible to use object code files produced from the same Erlang source file, but compiled on different occasions. The compiler attempts to ensure that a fun produced by one version of a module cannot be used with a different version of the module if the source code of the modules differ.
>   Own Id: OTP-2842
>   Aux Id: Seq 1233
> - A new construction has been added to the language: the match operator (i.e., the = operator) can now be used within patterns. For example, the following is now valid:

>       	f({'+',X,Y}=T) -> {X+Y,T}.

>   This often makes it possible to avoid rebuilding a term which is already present but has no name, since it was matched with a complex pattern. It also makes it possible to rewrite the construction

>       	f(X) when X == #rec{x=1, y=a} -> ...

>   as

>       	f(#rec{x=1, y=a} = X) -> ...

>   In the absence of optimization for the former case, the latter case is more efficient.
>   The new language feature uses no new addition to the virtual Erlang machine, which means that a compiled module using the new feature can be used in an old Erlang release, provided it is not incompatible for some other reason.
>   The abstract representation of Erlang source code has been augmented accordingly.
>   Own Id: OTP-2983
> - A new option `asm` expects the input file to be a previously produced Erlang assembler file (default file suffix ".S"). Note that the format of assembler files is not documented, and may change between releases - this option is primarily for internal debugging use. The `asm` option only works for BEAM.
>   Own Id: OTP-2988
> - The `export_all` compilation option no longer produces one warning for each function defined in a module; it produces one single warning (since `export_all` shouldn't be used in production code).
>   Own Id: OTP-3020
> - When compiling, warnings for functions which are not used are now given also for functions which call only themselves.
>   Own Id: OTP-3021
>   Aux Id: OTP-1007
> - New compiler options have been added for stopping compilation and outputting the code at certain points. 'E' still produces the last stage of Erlang code transformation. New options are `dexp` and `dpe`, which produce files with extension "`expand`" and "`parteval`", respectively. To pass these options to the compiler via `erlc`, prefix them with a '+'. For Beam, the new options `dcg` and `dopt` produce files with extension "`codegen`" and "`optimize`", respectively.
>   Own Id: OTP-3040
> - Due to an oversight, the following improvements were left out of the documentation in previous releases:

>   Two adjacent literal string tokens are concatenated into one string at compile-time (actually, by the parser). For example, `"abc" "def"` becomes `"abcdef"`.

>   The compiler directives `-include(File)` and `-include_lib(File)` are available for including header files.
>   Own Id: OTP-3051

> - A new construction is allowed in patterns, namely a literal string as the first operand of the ++ operator. Example:

>       	f("prefix" ++ L) -> ...

>   This is syntactic sugar for the equivalent, but harder to read

>       	f([$p,$r,$e,$f,$i,$x | L]) -> ...

>   Own Id: OTP-3069

> ## Compiler 1.2.1

> ### Fixed errors and malfunctions

> - An incorrect reference to `asm` is removed from the `compile` reference manual.
>   Own Id: OTP-2619

> ### Improvements and new features

> - It used to be the case that ?P and ?'P' (i.e., macro names starting with an uppercase letter) were references to different macros. This had the consequence that the form without quotes, which is the natural form to use, could not be set from outside the source file (for example, using the -D option to 'erlc'). Now, ?P and ?'P' have been made equivalent, so that "erl -DP=1" causes both ?P and ?'P' to expand to 1.
>   Own Id: OTP-2608

> ## Compiler 1.2

> ### Fixed errors and malfunctions

> - Giving floating points attributes in module attributes (like `-vsn(1.0)`) used to crash the Erlang compiler. This has been corrected.
>   Own Id: OTP-2141
>   Aux Id: seq 623, OTP-2302

> ### Improvements and new features

> - The `fast` option has been removed.
>   The object code format is partly documented (see the `compile` module). With the help of this documentation, tools can be written to inspect, change, delete, or add module attributes. Also, function call tracing can be enabled or disabled by changing a single bit in the header of the object code.
>   Own Id: OTP-2262
>   Aux Id: seq 718
> - The escape sequences \s in strings and $\s outside strings now give the ASCII code for space. It is recommended to use $\s instead of dollar followed by space, for readability reasons. Note that $\s in earlier releases was equivalent to $s.
>   Own Id: OTP-2522

> ## R3B02 (Compiler 1.1.5)

> ### Fixed errors and malfunctions

> - A `fun` could not be used in a record initializer.
>   Own Id: OTP-2173
>   Aux Id: seq 649
> - The compiler sometimes failed to compile modules where conditions were invariably false (e.g. `case 1 of [X] -> ...`).
>   Own Id: OTP-2330
>   Aux Id: seq 791
> - Using a literal atom as case expression and more than five matching atoms, the compiler would generate a module which cannot be loaded. This has been corrected.
>   Own Id: OTP-2380
>   Aux Id: seq 701,HA77209

> ## R3B (Compiler 1.1.4)

> ### Improvements and new features

> - The BEAM compiler will give a diagnostic if the trace and fast options are combined (earlier it silently ignored the trace flag, producing fast code which couldn't trace BIFs).
>   (*** POTENTIAL INCOMPATIBILITY ***)
>   Own Id: OTP-1954
>   Aux Id: seq 442

> ## R3A (Compiler 1.1.3)

> ### Fixed errors and malfunctions

> - An error in the beam-compiler which caused an internal error when compiling e.g. a list match like this:
>   `[H | T] = foo(),` where H is not used in the function is corrected.
>   Own Id: OTP-1476
> - In the Beam compiler, the calculation of heap usage for a `case` or `receive` statement was overly pessimistic in some cases, resulting in the allocation of unnecessary large process heaps or in the extreme case a load error for the module ("Error while loading -PASS 2-"). This has been corrected.
>   Own Id: OTP-1713
> - The beam-compiler is corrected regarding a catch inside a catch (in the same function). All exits ended up in the outermost catch, which was wrong.
>   Own Id: OTP-1834
>   Aux Id: SEQ 400

> ### Known problems

> - Giving floating points attributes in module attributes (like `-vsn(1.0)`) crashes the Erlang compiler.
>   Own Id: OTP-2141

> ## 2 Compiler 1.1.2

> ### 2.1 Incompatibilities with Compiler 1.1.1

> Due to corrections listed below, all BEAM code must be recompiled (see also release notes for ERTS).

> ### 2.2 Fixed bugs and malfunctions

> - Wrong restart of send at busy or garbage collect (BEAM, fast compiled code).
>   Own Id:OTP-1420
> - Bad arithmetic in guard fails instead of matching the next clause (BEAM).
>   Own Id:OTP-1422

> ### 2.3 Known bugs and problems

> - The BEAM compiler terminates with error `beam_asm_int: EXIT` when a list match is performed as in `[H| T] = foo()`, in case variable `T` is subsequently used, while `H` is not. The work-around is to write `T = tl(foo())` instead.
>   Own Id: OTP-1476

> ## 3 Compiler 1.1.1

> ### 3.1 Incompatibilities with Compiler 1.1

> Due to corrections listed below, all BEAM code must be recompiled (see also release notes for ERTS).

> ### 3.2 Fixed bugs and malfunctions

> - Correction of register allocation error in creation of tuples in guards in BEAM.
>   Own Id:OTP-1390
> - Correction of compiler error for BEAM which caused `ig` to generate erroneous code (error in nested case statements).
>   Own Id:OTP-1392
>   Aux Id:HA48119

> ## 4 Compiler 1.1

> ### 4.1 Improvements and new features

> - To simplify maintenance and cross compilations the two compiler directories, compiler_jam and compiler_beam, has been merged into a single compiler directory. Most modules names have been changed to avoid confusion and name collisions. The only user visible change is that the compilation target (jam or beam) can be specified in the list of arguments. E.g.

>       compile:file(foo, [beam, verbose, report]).

> ### 4.2 Incompatibilities with Compiler 1.0

> -

> ### 4.3 Fixed bugs and malfunctions

> - Compiler crashed on "silly" record update like this:

>       -record(bar, {hello}).

>       compilerCrash() ->
>            R1 = #bar{},
>            R2 = R1#bar{},   % <--- This causes the compiler to crash with the not_ok.

>   Own Id:OTP-1204,OTP-1208
> - The compiler does not check that record fields in a match are unique. Example:

>       -module(compiler_6_SUITE).

>       -record(foo, {bar}).

>       f() ->
>           #foo{bar = X,bar = Y} = x,
>           Y.

>       56> c(compiler_6_SUITE).
>       *** unset variable:'Y' in line:7

>   `bar` is repeated twice in the above example and the compiler does not detect that as an error which causes the assignment of `Y` to be silently ignored ...
>   Own Id:OTP-1231

> ## 5 Compiler 1.0.1

> ### 5.1 Improvements and new features

> -

> ### 5.2 Incompatibilities with Compiler 1.0

> -

> ### 5.3 Fixed bugs and malfunctions

> - The compiler no longer crashes on too long atoms (> 255).
>   Own Id: OTP-1012
> - The compiler `erl_lint` did earlier assume that some language constructs aways resided on the same line in the source code which caused a white space to be significant when determing an error or not. This is corrected.
>   Example:

>       -module(test).
>       -compile(export_all).
>       -record(test, {a,b}).
>       rectest(R) when record(R, test) ->
>           ok.
>       rectest2(R) when record(R,
>                               test) ->
>           ok.

>       (test@etxbc29)3> c(test).
>       ./test.erl:7: illegal guard expression

>   Own Id: OTP-1077
> - The compiler crashes on unsafe variable in nested case. This is corrected.
>   Own Id: OTP-1104

> ## 6 Compiler 1.0

> ### 6.1 Improvements and new features

> - A new include directive `-include_lib()` is introduced. Example:

>       -include_lib("mnesia/include/mnemosyne.hrl").

>   This instructs the compiler (preprocessor) to look for the directory where the application called `mnesia` is installed and then looks in the subdirectory `include` for the file `mnemosyne.hrl`. The preprocessor first looks in the orinary preprocessor search path to allow explicit overloading of the include files.
> - The new compiler options `{i, IncludeDir}` and {d, Def} are introduced.

> ### 6.2 Incompatibilities with Compiler P1C

> There are two new reserved words `let` and `query`.

> - `let` will be used in the future when a language construction similar to let in Lisp will be implemented.
> - `query` is used when making queries to Mnesia tables with the Mnemosyne query language.

> ### 6.3 Fixed bugs and malfunctions

> -

Copyright © 1991-99 Ericsson Utvecklings AB