Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* maint:
  beam_ssa_type: Fix environment check in local fun call optimization
  • Loading branch information
jhogberg committed Mar 28, 2024
2 parents ab43b55 + 1d1f3ad commit 447964c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/compiler/src/beam_ssa_type.erl
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ sig_fun_call(I0, Args, Ts, Ds, Fdb, Sub, State0) ->
CallArgs = CallArgs0 ++ simplify_args(Env, Ts, Sub),
I = I0#b_set{args=[Callee | CallArgs]},
sig_local_call(I, Callee, CallArgs, Ts, Fdb, State0);
{#t_fun{target={Name,Arity}}, _} ->
{#t_fun{arity=Arity,target={Name,Arity}}, _} ->
%% When a fun lacks free variables, we can make a direct call even
%% when we don't know where it was defined.
Callee = #b_local{name=#b_literal{val=Name},
Expand Down Expand Up @@ -683,7 +683,7 @@ opt_fun_call(#b_set{dst=Dst}=I0, [Fun | CallArgs0], Ts, Ds, Fdb, Sub, Meta) ->
CallArgs = CallArgs0 ++ simplify_args(Env, Ts, Sub),
I = I0#b_set{args=[Callee | CallArgs]},
opt_local_call(I, Callee, CallArgs, Dst, Ts, Fdb, Meta);
{#t_fun{target={Name,Arity}}, _} ->
{#t_fun{arity=Arity,target={Name,Arity}}, _} ->
%% When a fun lacks free variables, we can make a direct call even
%% when we don't know where it was defined.
Callee = #b_local{name=#b_literal{val=Name},
Expand Down
10 changes: 8 additions & 2 deletions lib/compiler/test/fun_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
test1/1,overwritten_fun/1,otp_7202/1,bif_fun/1,
external/1,eep37/1,badarity/1,badfun/1,
duplicated_fun/1,unused_fun/1,parallel_scopes/1,
coverage/1]).
coverage/1,leaky_environment/1]).

%% Internal exports.
-export([call_me/1,dup1/0,dup2/0]).
Expand All @@ -41,7 +41,7 @@ groups() ->
[test1,overwritten_fun,otp_7202,bif_fun,external,eep37,
badarity,badfun,duplicated_fun,unused_fun,
parallel_scopes,
coverage]}].
coverage,leaky_environment]}].

init_per_suite(Config) ->
test_lib:recompile(?MODULE),
Expand Down Expand Up @@ -590,5 +590,11 @@ coverage_2(List) ->
coverage_3({[], A}) ->
{id(42), fun() -> A end}.

leaky_environment(_Config) ->
G = fun(X, Y) -> X + Y end,
F = fun(A) -> G(A, 0) end,
{'EXIT', {{badarity, {F, [1, flurb]}}, _}} = catch F(1, flurb),
ok.

id(I) ->
I.

0 comments on commit 447964c

Please sign in to comment.