These document describes the release notes for older versions of the
compiler
application.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 av1
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 thev1
compiler, but in one case the compilation can be extremly slow: on pattern matching on long literal strings. Thev2
compiler in R6A also compiled huge list and/or tuple literals slowly. Thev2
compiler in R6B compiles these literals much faster.
Own Id: OTP-3363Compiler 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 thev2
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-3367Fixed 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-3176Improvements 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-3335Compiler 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-2517c:c(File, 'P')
does produce a .P file, but yields an ugly error message in the process.
Own Id: OTP-3054Compiler 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}).or like this:
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).
-module(beamfel2). -export([f/2]).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.
f({a,DpId},16#7fffffff) -> process_info(DpId);
f({a,DpId},16#80000000) -> process_info(DpId).
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 1343Improvements and new features
- Two functions have been added to the
compile
module:compile:forms/1
andcompile:forms/2
, which are analogous tocompile:file/[1,2]
, but take a list of forms as their first argument (such as is returned by the functionepp:parse_file/3
). The optionbinary
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
andcase
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 constructionf(X) when X == #rec{x=1, y=a} -> ...asf(#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. Theasm
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 (sinceexport_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
anddpe
, which produce files with extension "expand
" and "parteval
", respectively. To pass these options to the compiler viaerlc
, prefix them with a '+'. For Beam, the new optionsdcg
anddopt
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 readf([$p,$r,$e,$f,$i,$x | L]) -> ...
Own Id: OTP-3069Compiler 1.2.1
Fixed errors and malfunctions
- An incorrect reference to
asm
is removed from thecompile
reference manual.
Own Id: OTP-2619Improvements 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-2608Compiler 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-2302Improvements and new features
- The
fast
option has been removed.
The object code format is partly documented (see thecompile
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-2522R3B02 (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,HA77209R3B (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 442R3A (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
orreceive
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 400Known problems
- Giving floating points attributes in module attributes (like
-vsn(1.0) ) crashes the Erlang compiler.
Own Id: OTP-21412 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 variableT
is subsequently used, whileH
is not. The work-around is to writeT = 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:7bar
is repeated twice in the above example and the compiler does not detect that as an error which causes the assignment ofY
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 expressionOwn 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 calledmnesia
is installed and then looks in the subdirectoryinclude
for the filemnemosyne.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
andquery
.
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
-