Skip to content

Commit 4940d0f

Browse files
committed
Reduce state tracked in guard info
1 parent 7b22b8e commit 4940d0f

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

lib/elixir/lib/module/types/pattern.ex

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -892,14 +892,13 @@ defmodule Module.Types.Pattern do
892892
init_pattern_info(context, %{
893893
allow_empty?: false,
894894
parent_version: nil,
895-
precise?: true,
896895
vars: vars,
897896
changed: Map.from_keys(changed, [])
898897
})
899898

900-
{guard_precise?, context} = of_guards(guards, stack, context)
901-
{%{precise?: precise?, changed: changed}, context} = pop_pattern_info(context)
902-
{precise? and guard_precise?, of_changed(Map.keys(changed), stack, context)}
899+
{precise?, context} = of_guards(guards, stack, context)
900+
{%{vars: vars, changed: changed}, context} = pop_pattern_info(context)
901+
{is_map(vars) and precise?, of_changed(Map.keys(changed), stack, context)}
903902
end
904903

905904
defp of_guards([guard], stack, context) do
@@ -1035,18 +1034,14 @@ defmodule Module.Types.Pattern do
10351034
# and also when vars change, so we need to deal with all possibilities
10361035
# for pattern_info.
10371036
case context.pattern_info do
1038-
%{
1039-
allow_empty?: allow_empty?,
1040-
precise?: precise?,
1041-
vars: vars,
1042-
parent_version: parent_version,
1043-
changed: changed
1044-
} = pattern_info ->
1045-
precise? =
1046-
precise? and not is_map_key(vars, version) and not list_subpattern?(version, context)
1037+
%{allow_empty?: allow_empty?, vars: vars, parent_version: parent_version, changed: changed} =
1038+
pattern_info ->
1039+
vars =
1040+
is_map(vars) and not is_map_key(vars, version) and
1041+
not list_subpattern?(version, context) and vars
10471042

10481043
changed = Map.put(changed, version, [])
1049-
pattern_info = %{pattern_info | precise?: precise?, changed: changed}
1044+
pattern_info = %{pattern_info | vars: vars, changed: changed}
10501045
context = %{context | pattern_info: pattern_info}
10511046

10521047
context =
@@ -1173,13 +1168,13 @@ defmodule Module.Types.Pattern do
11731168

11741169
# We will be precise if all branches changed the same variable
11751170
context =
1176-
update_in(context.pattern_info.precise?, fn
1171+
update_in(context.pattern_info.vars, fn
11771172
false ->
11781173
false
11791174

1180-
true ->
1175+
vars ->
11811176
[{_, cond} | tail] = vars_conds
1182-
Enum.all?(tail, fn {_, tail_cond} -> cond == tail_cond end)
1177+
Enum.all?(tail, fn {_, tail_cond} -> cond == tail_cond end) and vars
11831178
end)
11841179

11851180
{type, Of.reduce_conditional_vars(vars_conds, call, stack, context)}

0 commit comments

Comments
 (0)