aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler
AgeCommit message (Collapse)Author
2013-12-09Prepare releaseOTP_R16B03Erlang/OTP
2013-11-22Rename otp_8949_a/0 which common_test interprets as an info functionBjörn Gustavsson
Before running a test case named testcase/1, common_test will call testcase/0 (the info function). Exceptions and illegal return values would be silently ignored. In a planned update to common_test, errors will instead cause the test case to fail. The test case otp_8949_a/1 has a helper function called otp_8949_a/0. Rename it to do_otp_8949_a/0. While at it, also fix a copy and paste bug in the list of test cases. otp_8949_a was run twice; otp_8949_b was never run.
2013-11-01Typo fix ambigous -> ambiguousLeo Correa
2013-10-14Merge branch 'fenollp/treewide_remove_unexpected_0xff/OTP-11323' into maintFredrik Gustafsson
* fenollp/treewide_remove_unexpected_0xff/OTP-11323: Remove ^L characters hidden randomly in the code. Not those used in text files as delimiters.
2013-09-16Prepare releaseOTP_R16B02Erlang/OTP
2013-09-12Remove ^L characters hidden randomly in the code. Not those used in text ↵Pierre Fenoll
files as delimiters. While working on a tool that processes Erlang code and testing it against this repo, I found out about those little sneaky 0xff. I thought it may be of help to other people build such tools to remove non-conforming-to-standard characters.
2013-09-09core_lint: Correct the type error() to conform to the codeBjörn Gustavsson
Commit 60984ade updated the code, but not the type spec. Noticed-by: Kostis Sagonas
2013-09-09Merge branch 'bjorn/xml-encoding-fix/OTP-11310' into maintBjörn Gustavsson
* bjorn/xml-encoding-fix/OTP-11310: Change encoding of troublesome notes.xml files to utf-8 Convert some notes.xml files from latin-1 to utf-8
2013-09-06Change encoding of troublesome notes.xml files to utf-8Björn Gustavsson
Most notes.xml files will be updated in every release and cause the kind of the problems described in the previous commit.
2013-09-05compiler: Conform returned errors to the documented formatBjörn Gustavsson
ErrorInfo is documented to be: {ErrorLine,Module,ErrorDescriptor} but for some errors with line numbers it would look like: {Module,ErrorDescriptor} Ensure that all ErrorInfo tuples have three elements. Use 'none' instead of a line number: {none,Module,ErrorDescriptor} There already are errors that return 'none' when no line number is available, but that convention was not documented. Mention it in the documentation. Also make sure that the compiler will not print 'none' as a line number in error messages (if the 'report_errors' option is given) as that looks stupid. That is, when attempting to compile a non-existing module, the error message should be: non-existing.erl: no such file or directory and not: non-existing.erl:none: no such file or directory
2013-09-04genop.tab: Add documentation for many BEAM instructionsBjörn Gustavsson
By Erik Stenman (happi) with corrections by me.
2013-08-26Merge branch 'nox/match-context-return/OTP-11247' into maintFredrik Gustafsson
* nox/match-context-return/OTP-11247: Added primary bootstrap Forbid returning a match context in beam_validator
2013-08-15Fix compiler crash for 'B and B' guardBjörn Gustavsson
2013-08-01Forbid returning a match context in beam_validatorAnthony Ramine
If a match context is returned from a function without being converted back to a plain old binary, the whole VM will crash.
2013-07-29Merge branch 'nox/fix-comp-warnings/OTP-11212' into maintFredrik Gustafsson
* nox/fix-comp-warnings/OTP-11212: Bootstrap Silence a misleading warning with some comprehensions
2013-07-29Merge branch 'nox/fix-fname-inlining/OTP-11211' into maintFredrik Gustafsson
* nox/fix-fname-inlining/OTP-11211: Added primary bootstrap Restrict inlining of local fun references
2013-07-11Merge branch 'jw/fix-float-middle-endian/OTP-11201' into maintFredrik Gustafsson
* jw/fix-float-middle-endian/OTP-11201: Fix binary construction on floating point middle-endian machines Fix binary matching on floating point middle-endian machines Fix erlang:phash2() on floating point middle-endian machines Fix external term format BIFs on floating point middle-endian machines
2013-07-03Restrict inlining of local fun referencesAnthony Ramine
Local fun references look like plain old variables in the Core Erlang AST but should not be treated as such. Inlining of such expressions is now restricted to application contexts as a local fun reference should never occur in a guard. This is not perfect as it forbids inlining in some safe situations, but that is still better than a compiler crash.
2013-06-17Prepare releaseOTP_R16B01Erlang/OTP
2013-06-14Fix binary construction on floating point middle-endian machinesJohannes Weißl
This complements 933e701 (OTP-10209). Without this patch the test cases "in_guard/1" and "coerce_to_float/1" in bs_construct_SUITE fail. The added lines in bs_construct_SUITE cover all branches that were not covered before (small and big numbers if BIT_OFFSET(erts_bin_offset) != 0).
2013-06-12Update copyright yearsBjörn-Egil Dahlberg
2013-06-07Silence a misleading warning with some comprehensionsAnthony Ramine
When compiling comprehensions with generators which are foldable to 'true', a misleading warning is emitted by sys_core_fold because a clause resulting from the compilation of the comprehension to Core Erlang is not marked as generated by the compiler. An example of such a comprehension is [ true || true ].
2013-06-03Merge branch 'bjorn/compiler/fix-compiler-crash/OTP-11119' into maintBjörn Gustavsson
* bjorn/compiler/fix-compiler-crash/OTP-11119: compiler: Correct liveness optimization for wait/1
2013-05-29compiler: Correct liveness optimization for wait/1Björn Gustavsson
The live optimization in beam_utils:live_opt/4 did not take into account that the wait/1 instruction *never* falls through to the next instruction (it has the same effect on the control flow as the jump/1 instruction).
2013-05-28Fix renaming of bs_put_string instructionsAnthony Ramine
The clause was formerly commented-out because at this point in the code, no bs_put_string instruction has been generated yet when compiling from Erlang. If an Erlang module is compiled to BEAM assembly and the result contains a bs_put_string instruction, the output can't be compiled to binary anymore and the compiler crashes with the following error: $ erlc prs.S Function: compress/1 prs.S:none: internal error in beam_block; crash reason: {{case_clause, {'EXIT', {function_clause, [{beam_utils,live_opt, [[{bs_put_string,1,{string,[0]}}, {bs_init, {f,0}, {bs_append,0,8,{field_flags,[]}}, 0, [{integer,8},{x,0}], {x,1}}, {label,2}], 2, {1,{1,1,nil,nil}}, [{block, [{'%live',2}, {set,[{x,0}],[{x,1}],move}, {'%live',1}]}, return]], [{file,"beam_utils.erl"},{line,639}]}, {beam_utils,live_opt,1, [{file,"beam_utils.erl"},{line,205}]}, {beam_block,function,2, [{file,"beam_block.erl"},{line,38}]}, {lists,mapfoldl,3, [{file,"lists.erl"},{line,1329}]}, {beam_block,module,2, [{file,"beam_block.erl"},{line,29}]}, {compile,'-select_passes/2-anonymous-2-',2, [{file,"compile.erl"},{line,476}]}, {compile,'-internal_comp/4-anonymous-1-',2, [{file,"compile.erl"},{line,276}]}, {compile,fold_comp,3, [{file,"compile.erl"},{line,294}]}]}}}, [{compile,'-select_passes/2-anonymous-2-',2, [{file,"compile.erl"},{line,476}]}, {compile,'-internal_comp/4-anonymous-1-',2, [{file,"compile.erl"},{line,276}]}, {compile,fold_comp,3,[{file,"compile.erl"},{line,294}]}, {compile,internal_comp,4,[{file,"compile.erl"},{line,278}]}, {compile,'-do_compile/2-anonymous-0-',2, [{file,"compile.erl"},{line,152}]}]}
2013-05-20beam_lib, compile: Replace use of deprecated crypto functionsBjörn Gustavsson
Since both the STDLIB and compiler applications turn warnings into errors, we must stop using the old deprecated crypto functions. While we are at it, generalize the format of the key tuple returned by beam_lib:make_crypto_key/2 to facilitate introducing new crypto methods in the future. Change the format to: {Type,Key,IV,BlockSize} where Type, Key, and IV are the first three arguments for either crypto:block_encrypt4/ or crypto:block_decrypt/4, and BlockSize is the block size for the crypto algorithm (it is needed to properly pad the plaintext blocks before encryption).
2013-04-19Use a set to store ref registers in beam_receiveAnthony Ramine
In some circumstances, as when inlining code, when some optimization passes are disabled or with hand-written but semantically correct Core Erlang or BEAM assembly, a fresh reference may be live in more than one register: ... {allocate_zero,2,2}. ... {call_ext,0,{extfunc,erlang,make_ref,0}}. % Ref in [x0] ... {move,{x,0},{y,0}}. % Ref in [x0,y0] {move,{y,1},{x,0}}. % Ref in [y0] ... {move,{y,0},{x,0}}. % Ref in [x0,y0] {move,{x,0},{y,1}}. % Ref in [x0,y0,y1] {label,5}. {loop_rec,{f,6},{x,0}}. % Ref in [y0,y1] ... {loop_rec_end,{f,5}}. {label,6}. {wait,{f,5}}. ... Pass beam_receive expects a single live register for the ref when it encounters the loop_rec instruction and crashes with the following reason: $ erlc t.S ... crash reason: {{case_clause, {'EXIT', {{case_clause,[{y,1},{y,0}]}, [{beam_receive,opt_recv,5, [{file,"beam_receive.erl"},{line,154}]}, ...]}}}, ...} This commit teaches beam_receive how to use a set of registers instead of a single one when tracking fresh references, thus avoiding the crash.
2013-04-05Use erlang:demonitor(Ref, [flush]) where applicableLoïc Hoguin
2013-04-03Merge branch 'nox/fix-bc-optim/OTP-11005' into maintFredrik Gustafsson
* nox/fix-bc-optim/OTP-11005: Add a new option +clint0 to the compiler Fix optimization of some binary comprehensions
2013-03-28Add a new option +clint0 to the compilerAnthony Ramine
This option makes the compiler run the Core Erlang linting pass before any optimization pass, which can crash if the given code has unbound variables, something that is detected by core_lint.
2013-03-28Fix optimization of some binary comprehensionsAnthony Ramine
If a variable bound in a generator is used as the size of a segment in the comprehension body, v3_core uses this variable in the code generated to compute the initial size given to the `bs_init_writable` primop before the variable is actually bound, as in: << <<0:S>> || S <- Slist >> Reported-By: Peer Stritzinger
2013-03-19Fix slow compilation of complex guardsBjörn Gustavsson
beam_utils:is_not_used_at/3 could be very slow for complex guards, because the cached result for previously encountered labels were neither used nor updated within blocks. Reported-by: Magnus Müller
2013-02-25Prepare releaseOTP_R16BErlang/OTP
2013-02-22Update copyright yearsBjörn-Egil Dahlberg
2013-02-14Add float_to_binary and binary_to_floatLukas Larsson
2013-02-14Add new binary conversion bifsLukas Larsson
Added: binary_to_integer/1,2, integer_to_binary/1,2
2013-02-09Fix unsafe optimization of funsBjörn Gustavsson
Commits 53bd4974a101 and 726f6e4c7afe simplified the handling of match_fail (used to generated exceptions such as 'function_clause') by first rewriting them to a call to erlang/error{1,2} and later rewriting them to specialized BEAM instructions (to reduce the code size). There was one flaw, though, which only was exposed when more aggressive optimizations were added in c3b60f86c622. Here is an example to explain it: t(V) -> fun(get) -> V end. The following BEAM code will be initially generated for the fun: {function, '-t/1-fun-0-', 2, 5}. {label,1}. {line,[{location,"t.erl",5}]}. {func_info,{atom,t},{atom,'-t/1-fun-0-'},2}. {label,2}. {test,is_eq_exact,{f,2},[{x,0},{atom,get}]}. {move,{x,1},{x,0}}. return. {label,2}. {test_heap,2,1}. {put_list,{x,0},nil,{x,1}}. {move,{atom,function_clause},{x,0}}. {line,[{location,"t.erl",5}]}. {call_ext_only,2,{extfunc,erlang,error,2}}. Translating back to Erlang code, that would be roughly: '-t/1-fun-0-'(get, V) -> V; '-t/1-fun-0-'(Arg1, _) -> erlang:error(function_clause, [Arg1]). Note that the second argument (the free variable V) is not included in the call to erlang:error/2. The beam_except pass will simplify the code to: {function, '-t/1-fun-0-', 2, 8}. {label,1}. {line,[{location,"t.erl",5}]}. {func_info,{atom,t},{atom,'-t/1-fun-0-'},2}. {label,2}. {test,is_eq_exact,{f,1},[{x,0},{atom,get}]}. {move,{x,1},{x,0}}. return. The code has been shortened by jumping to the func_info/3 instruction. Translating back to Erlang: '-t/1-fun-0-'(get, V) -> V; '-t/1-fun-0-'(Arg1, Arg2) -> erlang:error(function_clause, [Arg1,Arg2]). it is clear that both arguments are now included in the 'function_clause' exception, even though the initially generated code only included the first argument. That is no problem in this particular case, but for some more complex funs, optimizing the first version based on variable usage could make the second version unsafe. I rejected the following potential solutions: - Including the free arguments in the call to erlang:error/2: '-t/1-fun-0-'(get, V) -> V; '-t/1-fun-0-'(Arg1, Arg2) -> erlang:error(function_clause, [Arg1,Arg2]). Unfortunately, that is tricky. The free variables are only known after the second pass in v3_kernel when variable usage has been calculated. We would need to add a third pass (only for funs) that would the free arguments to the second argument for erlang:error/2 *and* update the variable usage information. - Calling beam_except earlier, from within beam_block before any optimizations based on variable usages are done. But means that the problem could reappear in some other form in the future when other updates are done to the code generator and/or optimization passes. The solution I have chosen is to modify beam_except to only replace a call to erlang:error(function_class, Args) if the length of Args is the same as the arity in the func_info/3 instruction. The code will be slightly larger. Also, the free variables for funs and list comprehensions will no longer be included in the function_clause exception (that could be less confusing, but it also means less information during debugging).
2013-02-07Merge branch 'bjorn/compiler/dialyzer-warnings'Björn Gustavsson
* bjorn/compiler/dialyzer-warnings: compile: Eliminate warnings for unmatched return values beam_receive: Eliminate dialyzer warning for unmatched return beam_validator: Eliminate dialyzer warnings for unmatched returns
2013-02-06Merge branch 'nox/fix-seq-opt/OTP-10818'Fredrik Gustafsson
* nox/fix-seq-opt/OTP-10818: Add two tests for unused multiple values in effect context Forbid multiple values in Core Erlang sequence arguments
2013-02-06compile: Eliminate warnings for unmatched return valuesBjörn Gustavsson
2013-02-06beam_receive: Eliminate dialyzer warning for unmatched returnBjörn Gustavsson
2013-02-06beam_validator: Eliminate dialyzer warnings for unmatched returnsBjörn Gustavsson
The assert_fls/2 and assert_type/3 functions both return the Vst passed to them, but all callers ignore the return value. Given the name of the functions, they are not expected to return anything. Make it so by changing the return value to 'ok'. There are two calls to bsm_get_context/2 used only to validate that the match context is valid. Call bsm_validate_context/2 instead. In bsm_validate_context/2, explicitly match the return value of bsm_get_context/2 to '_' to make it clear that it is not used.
2013-02-04Add two tests for unused multiple values in effect contextAnthony Ramine
2013-02-04Merge branch 'bjorn/compiler/crash/OTP-10794'Björn Gustavsson
* bjorn/compiler/crash/OTP-10794: Test setelement(1, not_a_tuple, NewValue) Fix crash in the compiler when compiling element(2, not_a_tuple)
2013-02-03Forbid multiple values in Core Erlang sequence argumentsAnthony Ramine
It does not make sense to return multiple values from a sequence argument and the Kernel Erlang passes can't cope with it. The linting pass now knows how to detect this kind of defunct code and the Core code folding pass is changed to not generate code like that when optimizing away multiple-valued lets in effect mode. Reported-by: José Valim
2013-01-31beam_type: Convert integer to float at compile timeBjörn Gustavsson
In code such as: X / 2 the following code would be output from beam_type for the division: {fconv,{x,0},{fr,0}}. {fconv,{integer,2},{fr,1}}. fclearerror. {bif,fdiv,{f,0},[{fr,0},{fr,1}],{fr,0}}. That is, the integer 2 would be converted to the float 2.0 at run-time by "{fconv,{integer,2},{fr,1}}". Make sure that we do the conversion at compile time. Noticed-by: Richard O'Keefe
2013-01-31compiler: Use the literal pool for floating point constantsBjörn Gustavsson
The BEAM loader will put floating point constants into the literal pools for the module, but it will not check for duplicates. We can do much better by having the compiler use the literal pool for floating point constants.
2013-01-30Test setelement(1, not_a_tuple, NewValue)Björn Gustavsson
2013-01-30Fix crash in the compiler when compiling element(2, not_a_tuple)Björn Gustavsson
2013-01-29Prepare releaseOTP_R16A_RELEASE_CANDIDATEErlang/OTP