Skip to content

Commit 663c4ab

Browse files
committed
Make type of map_bdd_to_dnf conversion explicit
1 parent 0dbdada commit 663c4ab

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ defmodule Module.Types.Descr do
685685
end
686686

687687
defp each_singleton?(:map, bdd) do
688-
case map_bdd_to_dnf(bdd) do
688+
case map_bdd_to_dnf_no_negations(bdd) do
689689
[] ->
690690
:empty
691691

@@ -3157,10 +3157,7 @@ defmodule Module.Types.Descr do
31573157
if empty?(type), do: throw(:empty), else: type
31583158
end
31593159

3160-
# Takes all the lines from the root to the leaves finishing with a 1,
3161-
# and compile into tuples of positive and negative nodes. Positive nodes are
3162-
# those followed by a left path, negative nodes are those followed by a right path.
3163-
defp map_bdd_to_dnf(bdd) do
3160+
defp map_bdd_to_dnf_no_negations(bdd) do
31643161
bdd_to_dnf(bdd)
31653162
|> Enum.reduce([], fn {pos, negs}, acc ->
31663163
case non_empty_map_literals_intersection(pos) do
@@ -3177,6 +3174,16 @@ defmodule Module.Types.Descr do
31773174
end)
31783175
end
31793176

3177+
defp map_bdd_to_dnf_with_negations(bdd) do
3178+
bdd_to_dnf(bdd)
3179+
|> Enum.reduce([], fn {pos, negs}, acc ->
3180+
case non_empty_map_literals_intersection(pos) do
3181+
:empty -> acc
3182+
{tag, fields} -> [{tag, fields, negs} | acc]
3183+
end
3184+
end)
3185+
end
3186+
31803187
## Map key functions
31813188

31823189
@doc """
@@ -3235,7 +3242,7 @@ defmodule Module.Types.Descr do
32353242
end
32363243

32373244
defp map_fetch_key_static(%{map: bdd}, key) do
3238-
bdd |> map_bdd_to_dnf() |> map_dnf_fetch_static(key)
3245+
bdd |> map_bdd_to_dnf_with_negations() |> map_dnf_fetch_static(key)
32393246
end
32403247

32413248
defp map_fetch_key_static(%{}, _key), do: {false, none()}
@@ -3370,7 +3377,7 @@ defmodule Module.Types.Descr do
33703377
end
33713378

33723379
defp map_to_list_static(%{map: bdd}, fun) do
3373-
case map_bdd_to_dnf(bdd) do
3380+
case map_bdd_to_dnf_no_negations(bdd) do
33743381
[] ->
33753382
:badmap
33763383

@@ -3414,7 +3421,7 @@ defmodule Module.Types.Descr do
34143421
case tag_or_domains do
34153422
:open ->
34163423
# A negation cannot make an open map closed without cancelling it completely,
3417-
# which is filtered by `map_bdd_to_dnf/1`.
3424+
# which is filtered by `map_bdd_to_dnf_*/1`.
34183425
throw(:open)
34193426

34203427
domains = %{} ->
@@ -3565,7 +3572,7 @@ defmodule Module.Types.Descr do
35653572
{required_keys, optional_keys, maybe_negated_set, required_domains, optional_domains} =
35663573
split_keys
35673574

3568-
dnf = map_bdd_to_dnf(bdd)
3575+
dnf = map_bdd_to_dnf_with_negations(bdd)
35693576
bdd = map_update_put_negated(bdd, maybe_negated_set, type_fun)
35703577

35713578
{found?, value, domains, errors} =
@@ -3633,7 +3640,7 @@ defmodule Module.Types.Descr do
36333640
{term(), open_map(), [], true}
36343641
else
36353642
acc = {none(), none(), [], false}
3636-
dnf = map_bdd_to_dnf(@map_top)
3643+
dnf = map_bdd_to_dnf_with_negations(@map_top)
36373644
map_update_keys_static(dnf, required_keys, optional_keys, type_fun, force?, static?, acc)
36383645
end
36393646
end
@@ -3942,7 +3949,7 @@ defmodule Module.Types.Descr do
39423949
domains -> map_update_put_domains(bdd, domains, type_fun)
39433950
end
39443951

3945-
dnf = map_bdd_to_dnf(bdd)
3952+
dnf = map_bdd_to_dnf_with_negations(bdd)
39463953
map_put_keys_static(dnf, required_keys ++ optional_keys, type, descr)
39473954
end
39483955

@@ -3960,7 +3967,7 @@ defmodule Module.Types.Descr do
39603967
if required_domains != [] or optional_domains != [] do
39613968
open_map()
39623969
else
3963-
dnf = map_bdd_to_dnf(@map_top)
3970+
dnf = map_bdd_to_dnf_with_negations(@map_top)
39643971
map_put_keys_static(dnf, required_keys ++ optional_keys, type, none())
39653972
end
39663973
end
@@ -4020,7 +4027,7 @@ defmodule Module.Types.Descr do
40204027
{required_keys, optional_keys, maybe_negated_set, required_domains, optional_domains} =
40214028
split_keys
40224029

4023-
dnf = map_bdd_to_dnf(bdd)
4030+
dnf = map_bdd_to_dnf_with_negations(bdd)
40244031

40254032
acc = none()
40264033
acc = map_get_keys(dnf, required_keys, acc)
@@ -4408,7 +4415,7 @@ defmodule Module.Types.Descr do
44084415

44094416
defp map_to_quoted(bdd, opts) do
44104417
bdd
4411-
|> map_bdd_to_dnf()
4418+
|> map_bdd_to_dnf_no_negations()
44124419
|> Enum.map(fn {tag, fields, negs} ->
44134420
map_eliminate_while_negs_decrease(tag, fields, negs)
44144421
end)

0 commit comments

Comments
 (0)