Skip to content

Commit 2acd094

Browse files
committed
Improvements to prune binding
1 parent 7996c0a commit 2acd094

File tree

4 files changed

+12
-19
lines changed

4 files changed

+12
-19
lines changed

lib/elixir/src/elixir.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,15 @@ eval_forms(Tree, Binding, OrigE, Opts) ->
272272
Prune = proplists:get_value(prune_binding, Opts, false),
273273
{ExVars, ErlVars, ErlBinding} = elixir_erl_var:load_binding(Binding),
274274
E = elixir_env:with_vars(OrigE, ExVars),
275-
ExS = elixir_env:env_to_ex(E, Prune),
275+
ExS = elixir_env:env_to_ex(E),
276276
ErlS = elixir_erl_var:from_env(E, ErlVars),
277277
{Erl, NewErlS, NewExS, NewE} = quoted_to_erl(Tree, ErlS, ExS, E),
278278

279279
case Erl of
280-
{Literal, _, Literal} when Literal == atom; Literal == float; Literal == integer ->
280+
{Literal, _, Value} when Literal == atom; Literal == float; Literal == integer ->
281281
if
282-
Prune -> {Literal, [], NewE};
283-
true -> {Literal, Binding, NewE}
282+
Prune -> {Value, [], NewE#{versioned_vars := #{}}};
283+
true -> {Value, Binding, NewE}
284284
end;
285285

286286
_ ->

lib/elixir/src/elixir_compiler.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ eval_or_compile(Forms, Args, E) ->
3737
(not elixir_config:is_bootstrap()) of
3838
true -> fast_compile(Forms, E);
3939
false -> compile(Forms, Args, E)
40-
end.
40+
end,
41+
ok.
4142

4243
compile(Quoted, ArgsList, E) ->
4344
{Expanded, SE, EE} = elixir_expand:expand(Quoted, elixir_env:env_to_ex(E), E),

lib/elixir/src/elixir_env.erl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-module(elixir_env).
22
-include("elixir.hrl").
33
-export([
4-
new/0, to_caller/1, with_vars/2, reset_vars/1, env_to_ex/1, env_to_ex/2,
4+
new/0, to_caller/1, with_vars/2, reset_vars/1, env_to_ex/1,
55
reset_unused_vars/1, check_unused_vars/2, merge_and_check_unused_vars/3,
66
trace/2, format_error/1,
77
reset_read/2, prepare_write/1, close_write/2
@@ -47,19 +47,11 @@ reset_vars(Env) ->
4747

4848
%% CONVERSIONS
4949

50-
env_to_ex(Env) ->
51-
env_to_ex(Env, false).
52-
53-
env_to_ex(#{context := match, versioned_vars := Vars}, Prune) ->
50+
env_to_ex(#{context := match, versioned_vars := Vars}) ->
5451
Counter = map_size(Vars),
55-
Unused = unused(Vars, Prune),
56-
#elixir_ex{prematch={Vars, Counter}, vars={Vars, false}, unused={Unused, Counter}};
57-
env_to_ex(#{versioned_vars := Vars}, Prune) ->
58-
Unused = unused(Vars, Prune),
59-
#elixir_ex{vars={Vars, false}, unused={Unused, map_size(Vars)}}.
60-
61-
unused(_Vars, false) -> #{};
62-
unused(Vars, true) -> maps:from_list([{K, {0, false}} || K <- maps:to_list(Vars)]).
52+
#elixir_ex{prematch={Vars, Counter}, vars={Vars, false}, unused={#{}, Counter}};
53+
env_to_ex(#{versioned_vars := Vars}) ->
54+
#elixir_ex{vars={Vars, false}, unused={#{}, map_size(Vars)}}.
6355

6456
%% VAR HANDLING
6557

lib/elixir/src/elixir_erl_var.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ dump_binding(Binding, ErlS, ExS, PruneBefore) ->
109109
%% If the variable is part of the pruning (usually the input binding)
110110
%% and is unused, we removed it from vars.
111111
(Pair, Version, {B, V})
112-
when Version < PruneBefore, map_get({Pair, Version}, Unused) /= false ->
112+
when Version < PruneBefore, not is_map_key({Pair, Version}, Unused) ->
113113
{B, maps:remove(Pair, V)};
114114

115115
({Var, Kind} = Pair, Version, {B, V}) when is_atom(Kind) ->

0 commit comments

Comments
 (0)