Skip to content

Commit a4f98b1

Browse files
committed
Optimize DNFs to avoid negations when possible
1 parent 5b2f9c9 commit a4f98b1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2756,7 +2756,7 @@ defmodule Module.Types.Descr do
27562756
# Takes all the lines from the root to the leaves finishing with a 1,
27572757
# and compile into tuples of positive and negative nodes. Positive nodes are
27582758
# those followed by a left path, negative nodes are those followed by a right path.
2759-
def map_bdd_to_dnf(bdd) do
2759+
defp map_bdd_to_dnf(bdd) do
27602760
bdd_to_dnf(bdd)
27612761
|> Enum.reduce([], fn {pos, negs}, acc ->
27622762
case non_empty_map_literals_intersection(pos) do
@@ -4591,6 +4591,9 @@ defmodule Module.Types.Descr do
45914591
:bdd_top ->
45924592
[{pos, neg} | acc]
45934593

4594+
{fun, :bdd_top, right} ->
4595+
bdd_to_dnf([{[fun | pos], neg} | acc], pos, neg, right)
4596+
45944597
{fun, left, right} ->
45954598
bdd_to_dnf(bdd_to_dnf(acc, [fun | pos], neg, left), pos, [fun | neg], right)
45964599
end

lib/elixir/test/elixir/module/types/descr_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ defmodule Module.Types.DescrTest do
23522352
)
23532353
|> union(difference(open_map(x: atom()), open_map(x: boolean())))
23542354
|> to_quoted_string() ==
2355-
"%{..., x: atom() and not boolean()} or\n (%{..., a: integer(), b: atom(), c: boolean()} and not %{..., x: atom() and not boolean()})"
2355+
"%{..., a: integer(), b: atom(), c: boolean()} or %{..., x: atom() and not boolean()}"
23562356

23572357
assert closed_map(a: number(), b: atom(), c: pid())
23582358
|> difference(closed_map(a: integer(), b: atom(), c: pid()))

0 commit comments

Comments
 (0)