Skip to content

Commit 2137e07

Browse files
committed
Apply further fn optimizations
1 parent 824fc3b commit 2137e07

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,45 +1496,44 @@ defmodule Module.Types.Descr do
14961496
# Create cache key from function arguments
14971497
cache_key = {args, {b, ret}, [{arguments, return} | rest_positive]}
14981498

1499-
case Map.get(cache, cache_key) do
1500-
nil ->
1499+
case cache do
1500+
%{^cache_key => value} ->
1501+
value
1502+
1503+
%{} ->
15011504
# Compute result and cache it
15021505
{result1, cache} = phi(args, {true, intersection(ret, return)}, rest_positive, cache)
15031506

15041507
if not result1 do
1505-
# Store false result in cache
15061508
cache = Map.put(cache, cache_key, false)
15071509
{false, cache}
15081510
else
1509-
# This doesn't stop if one intermediate result is false?
1510-
{result2, cache} =
1511-
Enum.with_index(arguments)
1512-
|> Enum.reduce_while({true, cache}, fn {type, index}, {acc_result, acc_cache} ->
1513-
{new_result, new_cache} =
1514-
List.update_at(args, index, fn {_, arg} -> {true, difference(arg, type)} end)
1515-
|> phi({b, ret}, rest_positive, acc_cache)
1516-
1517-
if new_result do
1518-
{:cont, {acc_result and new_result, new_cache}}
1519-
else
1520-
{:halt, {false, new_cache}}
1521-
end
1511+
{_index, result2, cache} =
1512+
Enum.reduce_while(arguments, {0, true, cache}, fn
1513+
type, {index, acc_result, acc_cache} ->
1514+
{new_result, new_cache} =
1515+
args
1516+
|> List.update_at(index, fn {_, arg} -> {true, difference(arg, type)} end)
1517+
|> phi({b, ret}, rest_positive, acc_cache)
1518+
1519+
if new_result do
1520+
{:cont, {index + 1, acc_result and new_result, new_cache}}
1521+
else
1522+
{:halt, {index + 1, false, new_cache}}
1523+
end
15221524
end)
15231525

15241526
result = result1 and result2
1525-
# Store result in cache
15261527
cache = Map.put(cache, cache_key, result)
15271528
{result, cache}
15281529
end
1529-
1530-
cached_result ->
1531-
# Return cached result
1532-
{cached_result, cache}
15331530
end
15341531
end
15351532

15361533
defp all_non_empty_domains?(positives) do
1537-
Enum.all?(positives, fn {args, _ret} -> not empty?(args_to_domain(args)) end)
1534+
Enum.all?(positives, fn {args, _ret} ->
1535+
Enum.all?(args, fn arg -> not empty?(arg) end)
1536+
end)
15381537
end
15391538

15401539
defp fun_union(bdd1, bdd2) do

0 commit comments

Comments
 (0)