Skip to content

Commit 229be81

Browse files
committed
Move projections to use opt_ too
1 parent bce9ed8 commit 229be81

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

lib/elixir/lib/module/types/descr.ex

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,6 @@ defmodule Module.Types.Descr do
407407
defp pop_dynamic(:term), do: {:term, :term}
408408
defp pop_dynamic(descr), do: Map.pop(descr, :dynamic, descr)
409409

410-
@compile {:inline, maybe_opt_union: 2}
411-
defp maybe_opt_union(nil, _fun), do: nil
412-
defp maybe_opt_union(descr, fun), do: opt_union(descr, fun.())
413-
414410
@doc """
415411
Computes the union of two descrs.
416412
"""
@@ -2402,7 +2398,7 @@ defmodule Module.Types.Descr do
24022398
dynamic_value = list_hd_static(dynamic)
24032399

24042400
if non_empty_list_only?(static) and not empty?(dynamic_value) do
2405-
{:ok, bare_union(dynamic(dynamic_value), list_hd_static(static))}
2401+
{:ok, opt_union(dynamic(dynamic_value), list_hd_static(static))}
24062402
else
24072403
:badnonemptylist
24082404
end
@@ -2413,7 +2409,7 @@ defmodule Module.Types.Descr do
24132409

24142410
defp list_hd_static(%{list: bdd}) do
24152411
list_bdd_to_pos_dnf(bdd)
2416-
|> Enum.reduce(none(), fn {list, _last, _negs}, acc -> bare_union(acc, list) end)
2412+
|> Enum.reduce(none(), fn {list, _last, _negs}, acc -> opt_union(acc, list) end)
24172413
end
24182414

24192415
defp list_hd_static(%{}), do: none()
@@ -2442,7 +2438,7 @@ defmodule Module.Types.Descr do
24422438
dynamic_value = list_tl_static(dynamic)
24432439

24442440
if non_empty_list_only?(static) and not empty?(dynamic_value) do
2445-
{:ok, bare_union(dynamic(dynamic_value), list_tl_static(static))}
2441+
{:ok, opt_union(dynamic(dynamic_value), list_tl_static(static))}
24462442
else
24472443
:badnonemptylist
24482444
end
@@ -2462,7 +2458,7 @@ defmodule Module.Types.Descr do
24622458
end
24632459

24642460
list_bdd_to_pos_dnf(bdd)
2465-
|> Enum.reduce(initial, fn {_list, last, _negs}, acc -> bare_union(acc, last) end)
2461+
|> Enum.reduce(initial, fn {_list, last, _negs}, acc -> opt_union(acc, last) end)
24662462
end
24672463

24682464
defp list_tl_static(%{}), do: none()
@@ -3088,7 +3084,7 @@ defmodule Module.Types.Descr do
30883084
if static_optional? or empty?(dynamic_type) do
30893085
:badkey
30903086
else
3091-
{dynamic_optional?, bare_union(dynamic(dynamic_type), static_type)}
3087+
{dynamic_optional?, opt_union(dynamic(dynamic_type), static_type)}
30923088
end
30933089
else
30943090
:badmap
@@ -3120,9 +3116,9 @@ defmodule Module.Types.Descr do
31203116
# Optimization: if there are no negatives
31213117
{tag, fields, []}, acc ->
31223118
case fields_find(key, fields) do
3123-
{:ok, value} -> bare_union(value, acc)
3119+
{:ok, value} -> opt_union(value, acc)
31243120
:error when tag == :open -> throw(:open)
3125-
:error -> map_key_tag_to_type(tag) |> bare_union(acc)
3121+
:error -> map_key_tag_to_type(tag) |> opt_union(acc)
31263122
end
31273123

31283124
{tag, fields, negs}, acc ->
@@ -3139,10 +3135,10 @@ defmodule Module.Types.Descr do
31393135
else
31403136
negs
31413137
|> map_split_negative_key(key, value, bdd)
3142-
|> Enum.reduce(none(), fn {value, _}, acc -> bare_union(value, acc) end)
3138+
|> Enum.reduce(none(), fn {value, _}, acc -> opt_union(value, acc) end)
31433139
end
31443140

3145-
bare_union(value, acc)
3141+
opt_union(value, acc)
31463142
end
31473143
end)
31483144
catch
@@ -3278,7 +3274,7 @@ defmodule Module.Types.Descr do
32783274
with {:ok, dynamic_type} <- map_to_list_static(dynamic, fun) do
32793275
if descr_key?(static, :map) do
32803276
with {:ok, static_type} <- map_to_list_static(static, fun) do
3281-
{:ok, bare_union(static_type, dynamic(dynamic_type))}
3277+
{:ok, opt_union(static_type, dynamic(dynamic_type))}
32823278
end
32833279
else
32843280
{:ok, dynamic(dynamic_type)}
@@ -3345,7 +3341,7 @@ defmodule Module.Types.Descr do
33453341
if empty?(value) do
33463342
acc
33473343
else
3348-
bare_union(acc, fun.(domain_key_to_descr(domain_key), value))
3344+
opt_union(acc, fun.(domain_key_to_descr(domain_key), value))
33493345
end
33503346
end)
33513347

@@ -3369,7 +3365,7 @@ defmodule Module.Types.Descr do
33693365
if empty?(value) do
33703366
{seen, acc}
33713367
else
3372-
{seen, bare_union(acc, fun.(atom([key]), value))}
3368+
{seen, opt_union(acc, fun.(atom([key]), value))}
33733369
end
33743370
end
33753371
end)
@@ -3964,7 +3960,7 @@ defmodule Module.Types.Descr do
39643960
if empty?(dynamic_type) do
39653961
:error
39663962
else
3967-
{:ok, bare_union(dynamic(dynamic_type), static_type)}
3963+
{:ok, opt_union(dynamic(dynamic_type), static_type)}
39683964
end
39693965
else
39703966
:badmap
@@ -3993,7 +3989,7 @@ defmodule Module.Types.Descr do
39933989
defp map_get_keys(dnf, keys, acc) do
39943990
Enum.reduce(keys, acc, fn atom, acc ->
39953991
{_, value} = map_dnf_fetch_static(dnf, atom)
3996-
bare_union(value, acc)
3992+
opt_union(value, acc)
39973993
end)
39983994
end
39993995

@@ -4003,14 +3999,14 @@ defmodule Module.Types.Descr do
40033999
Enum.reduce(dnf, acc, fn
40044000
# Optimization: if there are no negatives, get the domain tag directly
40054001
{tag, _fields, []}, acc ->
4006-
map_domain_tag_to_type(tag, domain_key) |> bare_union(acc)
4002+
map_domain_tag_to_type(tag, domain_key) |> opt_union(acc)
40074003

40084004
{tag_or_domains, fields, negs}, acc ->
40094005
if init_map_line_empty?(tag_or_domains, fields, negs) do
40104006
acc
40114007
else
40124008
{_found, value, _bdd} = map_pop_domain_bdd(tag_or_domains, fields, domain_key)
4013-
bare_union(value, acc)
4009+
opt_union(value, acc)
40144010
end
40154011
end)
40164012
end
@@ -4934,8 +4930,7 @@ defmodule Module.Types.Descr do
49344930
if empty?(dynamic_type) do
49354931
:badindex
49364932
else
4937-
{static_optional? or dynamic_optional?,
4938-
bare_union(dynamic(dynamic_type), static_type)}
4933+
{static_optional? or dynamic_optional?, opt_union(dynamic(dynamic_type), static_type)}
49394934
end
49404935
else
49414936
:badtuple
@@ -4968,7 +4963,7 @@ defmodule Module.Types.Descr do
49684963
# Optimization: if there are no negatives
49694964
{tag, elements, []}, {acc_optional?, acc_descr} ->
49704965
{optional?, descr} = tuple_fetch_element(elements, index, tag)
4971-
{optional? or acc_optional?, bare_union(descr, acc_descr)}
4966+
{optional? or acc_optional?, opt_union(descr, acc_descr)}
49724967

49734968
{tag, elements, negs}, {acc_optional?, acc_descr} ->
49744969
{_, value, bdd} = tuple_take_element(elements, index, tag)
@@ -4984,11 +4979,11 @@ defmodule Module.Types.Descr do
49844979
else
49854980
negs
49864981
|> tuple_split_negative(index, value, bdd)
4987-
|> Enum.reduce(none(), fn {value, _}, acc -> bare_union(value, acc) end)
4982+
|> Enum.reduce(none(), fn {value, _}, acc -> opt_union(value, acc) end)
49884983
end
49894984

49904985
{optional?, descr} = pop_optional_static(value)
4991-
{optional? or acc_optional?, bare_union(descr, acc_descr)}
4986+
{optional? or acc_optional?, opt_union(descr, acc_descr)}
49924987
end
49934988
end)
49944989
catch
@@ -5123,7 +5118,7 @@ defmodule Module.Types.Descr do
51235118
end
51245119

51255120
dynamic(dynamic_value)
5126-
|> bare_union(process_tuples_values(Map.get(static, :tuple, :bdd_bot)))
5121+
|> opt_union(process_tuples_values(Map.get(static, :tuple, :bdd_bot)))
51275122
else
51285123
:badtuple
51295124
end
@@ -5136,9 +5131,9 @@ defmodule Module.Types.Descr do
51365131
cond do
51375132
Enum.any?(elements, &empty?/1) -> none()
51385133
tag == :open -> term()
5139-
tag == :closed -> Enum.reduce(elements, none(), &bare_union/2)
5134+
tag == :closed -> Enum.reduce(elements, none(), &opt_union/2)
51405135
end
5141-
|> bare_union(acc)
5136+
|> opt_union(acc)
51425137
end)
51435138
end
51445139

@@ -6156,6 +6151,10 @@ defmodule Module.Types.Descr do
61566151
def opt_negation(:term), do: none()
61576152
def opt_negation(%{} = descr), do: opt_difference(term(), descr)
61586153

6154+
@compile {:inline, maybe_opt_union: 2}
6155+
defp maybe_opt_union(nil, _fun), do: nil
6156+
defp maybe_opt_union(descr, fun), do: opt_union(descr, fun.())
6157+
61596158
defp opt_list_intersection(bdd_leaf(:term, :term), bdd), do: bdd
61606159
defp opt_list_intersection(bdd, bdd_leaf(:term, :term)), do: bdd
61616160

0 commit comments

Comments
 (0)