Repository navigation
Prune disjoint positives when converting map and tuple BDDs to DNF - #16046
Merged
Merged
Conversation
Converting a map or tuple BDD to DNF expanded every path and only then
intersected the positive literals of each line, discarding the empty
ones. When a large type is refined by unions, such as a struct with a
negated guard intersected with `%{m: not :pp} or %{t: not :nn}`, most
paths have disjoint positives and the expansion dominates. In the
"from multiple defguard" test, 116 map key fetches expanded 100,834
lines, of which only 3,764 were non-empty.
We now intersect the positive literals as we traverse the BDD:
* `map_bdd_to_dnf/5` discards whole subtrees as soon as their
positive literals are disjoint, which is used by
`map_bdd_to_dnf_remove_empty/1` and `map_bdd_to_dnf_with_empty/1`
* `map_bdd_empty?/4` does the same for `map_empty?/2`, stopping as
soon as it finds a non-empty line, in the same order as before
* `tuple_bdd_to_dnf/4` and `tuple_bdd_empty?/4` do the same for
tuples, pruning on disjoint sizes, while the emptiness of the
elements is still checked once per line
The positive literals are now intersected from the root down, instead
of from the deepest literal up, which yields the same types.
This brings the "from multiple defguard" module from 660ms to 390ms
and is neutral on ts_bench projects.
Assisted-by: Claude Code:claude-opus-5-5
gldubc
approved these changes
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converting a map or tuple BDD to DNF expanded every path and only then intersected the positive literals of each line, discarding the empty ones. When a large type is refined by unions, such as a struct with a negated guard intersected with
%{m: not :pp} or %{t: not :nn}, most paths have disjoint positives and the expansion dominates. In the "from multiple defguard" test, 116 map key fetches expanded 100,834 lines, of which only 3,764 were non-empty.We now intersect the positive literals as we traverse the BDD:
map_bdd_to_dnf/5discards whole subtrees as soon as their positive literals are disjoint, which is used bymap_bdd_to_dnf_remove_empty/1andmap_bdd_to_dnf_with_empty/1map_bdd_empty?/4does the same formap_empty?/2, stopping as soon as it finds a non-empty line, in the same order as beforetuple_bdd_to_dnf/4andtuple_bdd_empty?/4do the same for tuples, pruning on disjoint sizes, while the emptiness of the elements is still checked once per lineThe positive literals are now intersected from the root down, instead of from the deepest literal up, which yields the same types.
This brings the "from multiple defguard" module from 660ms to 390ms and is neutral on ts_bench projects.
Assisted-by: Claude Code:claude-opus-5-5