diff options
author | Björn Gustavsson <[email protected]> | 2018-10-30 06:25:40 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2018-10-30 09:40:37 +0100 |
commit | d9470c07acc8d9b5f18676d852a0ff1707788e9e (patch) | |
tree | 9f64e1c12a8ae77537600904ea587ce08ba9c0e2 /lib/compiler/test | |
parent | b36b359d4cb9988c0c24130023cf89e92b6577a4 (diff) | |
download | otp-d9470c07acc8d9b5f18676d852a0ff1707788e9e.tar.gz otp-d9470c07acc8d9b5f18676d852a0ff1707788e9e.tar.bz2 otp-d9470c07acc8d9b5f18676d852a0ff1707788e9e.zip |
beam_except: Generalize translation to func_info instructions
The `beam_except` pass replaces some calls to `erlang:error/1` or
`erlang:error/2` with specialized instructions in order to reduce the
size of the BEAM code.
In functions that do binary matching, `beam_except` would fail to
translate the instructions that generate a `function_clause`
exception. Here is an example:
bsum(<<H:16,T/binary>>, Acc) ->
bsum(T, Acc+H);
bsum(<<>>, Acc) ->
Acc.
The BEAM code that generates the `function_clause` exception looks
like this:
{label,4}.
{test_heap,2,3}.
{put_list,{x,1},nil,{x,1}}.
%% The following two instructions prevents the translation.
{bs_set_position,{x,2},{x,0}}.
{bs_get_tail,{x,2},{x,0},3}.
{test_heap,2,2}.
{put_list,{x,0},{x,1},{x,1}}.
{move,{atom,function_clause},{x,0}}.
{line,...}.
{call_ext,2,{extfunc,erlang,error,2}}.
Make the translation of `function_clause` exceptions smarter, so
that the following code will be produced:
{label,4}.
{bs_set_position,{x,2},{x,0}}.
{bs_get_tail,{x,2},{x,0},3}.
{jump,{f,1}}. %Jump to `func_info` instruction.
(This issue was noticed when looking at the code generated by
https://github.com/tomas-abrahamsson/gpb.)
Diffstat (limited to 'lib/compiler/test')
-rw-r--r-- | lib/compiler/test/beam_except_SUITE.erl | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/compiler/test/beam_except_SUITE.erl b/lib/compiler/test/beam_except_SUITE.erl index 2b4a780899..da61931136 100644 --- a/lib/compiler/test/beam_except_SUITE.erl +++ b/lib/compiler/test/beam_except_SUITE.erl @@ -83,6 +83,11 @@ coverage(_) -> (catch bar(x)), {'EXIT',{{case_clause,{1}},[{?MODULE,bar,1,[File,{line,9}]}|_]}} = (catch bar(0)), + + Self = self(), + {'EXIT',{{strange,Self},[{?MODULE,foo,[any],[File,{line,14}]}|_]}} = + (catch foo(any)), + ok. -file("fake.erl", 1). @@ -96,3 +101,6 @@ bar(X) -> %Line 8 case {X+1} of %Line 9 1 -> ok %Line 10 end. %Line 11 +%% Cover collection code for function_clause exceptions. +foo(A) -> %Line 13 + error({strange,self()}, [A]). %Line 14 |