Skip to content

Commit

Permalink
Merge branch 'john/compiler/fix-local-fun-call-environment/GH-8316/OT…
Browse files Browse the repository at this point in the history
…P-19045' into maint-26

* john/compiler/fix-local-fun-call-environment/GH-8316/OTP-19045:
  fun_SUITE: Fix test snafu in fun_inline_SUITE variant
  beam_ssa_type: Fix environment check in local fun call optimization
  • Loading branch information
Erlang/OTP committed Apr 12, 2024
2 parents 9813e2a + 4f3cac2 commit b530af0
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
Expand Up @@ -330,7 +330,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 @@ -670,7 +670,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
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, {_, [1, flurb]}}, _}} = catch F(1, flurb),
ok.

id(I) ->
I.

0 comments on commit b530af0

Please sign in to comment.