[ty] Use a simpler ordering for BDD variables#22777
Merged
Conversation
Typing conformance resultsNo changes detected ✅ |
|
MichaReiser
approved these changes
Jan 20, 2026
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
2 | 2 | 4 |
invalid-await |
0 | 2 | 6 |
invalid-assignment |
0 | 0 | 5 |
invalid-return-type |
1 | 0 | 3 |
possibly-missing-attribute |
0 | 3 | 1 |
unused-ignore-comment |
1 | 2 | 0 |
unresolved-attribute |
0 | 0 | 2 |
unsupported-operator |
0 | 0 | 2 |
| Total | 4 | 9 | 23 |
ibraheemdev
approved these changes
Jan 21, 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.
This PR updates the ordering that we use for the BDD variables in our constraint set representation. If we only care about correctness, we can choose any ordering that we want, as long as it's consistent. However, different orderings can have very different performance characteristics. Many BDD libraries attempt to reorder variables on the fly while building and working with BDDs. We don't do that, but we have tried to make some simple choices that have clear wins.
In particular, we now use the IDs that salsa assigns to each constraint as it is created. This tends to ensure that constraints that are close to each other in the source are also close to each other in the BDD structure.
As an optimization, we also reverse this ordering, so that constraints that appear earlier in the source appear "lower" (closer to the terminal nodes) in the BDD. Since we build up BDDs by combining smaller BDDs (which will have been constructed from expressions earlier in the source), this tends to minimize the amount of "node shuffling" that we have to do when combining BDDs.
Previously, we tried to be more clever — for instance, by comparing the typevars of each constraint first, in an attempt to keep all of the constraints for a single typevar adjacent in the BDD structure. However, this proved to be counterproductive; we've found empirically that we get smaller BDDs with an ordering that is more aligned with source order.