Skip to content

Commit 116f8f4

Browse files
committed
Also optimize bottoms in leaf bdd intersections
1 parent 9c1bd76 commit 116f8f4

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

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

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,6 +3069,20 @@ defmodule Module.Types.Descr do
30693069
end
30703070
end
30713071

3072+
defp map_bdd_intersection({bdd_leaf(:closed, _) = leaf, :bdd_bot, u, d}, bdd) do
3073+
case map_bdd_intersection(u, bdd) do
3074+
result when d == :bdd_bot -> result
3075+
result -> bdd_union(result, bdd_intersection(bdd, {leaf, :bdd_bot, :bdd_bot, d}))
3076+
end
3077+
end
3078+
3079+
defp map_bdd_intersection(bdd, {bdd_leaf(:closed, _) = leaf, :bdd_bot, u, d}) do
3080+
case map_bdd_intersection(u, bdd) do
3081+
result when d == :bdd_bot -> result
3082+
result -> bdd_union(result, bdd_intersection(bdd, {leaf, :bdd_bot, :bdd_bot, d}))
3083+
end
3084+
end
3085+
30723086
defp map_bdd_intersection(bdd1, bdd2) do
30733087
bdd_intersection(bdd1, bdd2)
30743088
end
@@ -6085,14 +6099,16 @@ defmodule Module.Types.Descr do
60856099
end
60866100

60876101
# Take two BDDs, B1 = {a1, C1, U2, D2} and B2.
6088-
# We can treat a1 as a leaf if C1 = :bdd_top.
6089-
# Then we have:
6102+
#
6103+
# When C1 = :bdd_top, we have:
60906104
#
60916105
# ((a1 and C1) or U2 or (not a1 and D2)) and B2
6106+
# (a1 and B2) or (B2 and U2) or (B2 and not a1 and D2)
60926107
#
6093-
# Which is equivalent to:
6108+
# When C1 = :bdd_bot, we have:
60946109
#
6095-
# (a1 and B2) or (B2 and U2) or (B2 and not a1 and D2)
6110+
# (U2 or (not a1 and D2)) and B2
6111+
# (B2 and U2) or (B2 and not a1 and D2)
60966112
defp bdd_intersection({leaf, :bdd_top, u, d}, bdd, leaf_intersection) do
60976113
bdd_leaf_intersection(leaf, bdd, leaf_intersection)
60986114
|> bdd_union(bdd_intersection(u, bdd, leaf_intersection))
@@ -6111,6 +6127,20 @@ defmodule Module.Types.Descr do
61116127
end
61126128
end
61136129

6130+
defp bdd_intersection({leaf, :bdd_bot, u, d}, bdd, leaf_intersection) do
6131+
case bdd_intersection(u, bdd, leaf_intersection) do
6132+
result when d == :bdd_bot -> result
6133+
result -> bdd_union(result, bdd_intersection(bdd, {leaf, :bdd_bot, :bdd_bot, d}))
6134+
end
6135+
end
6136+
6137+
defp bdd_intersection(bdd, {leaf, :bdd_bot, u, d}, leaf_intersection) do
6138+
case bdd_intersection(u, bdd, leaf_intersection) do
6139+
result when d == :bdd_bot -> result
6140+
result -> bdd_union(result, bdd_intersection(bdd, {leaf, :bdd_bot, :bdd_bot, d}))
6141+
end
6142+
end
6143+
61146144
defp bdd_intersection(bdd1, bdd2, _leaf_intersection) do
61156145
bdd_intersection(bdd1, bdd2)
61166146
end

0 commit comments

Comments
 (0)