[ty] Fix non-determinism in ConstraintSet.specialize_constrained by dcreager · Pull Request #21744 · astral-sh/ruff (original) (raw)
An internal refactor or improvement
Multi-file analysis & type inference
labels
Base automatically changed from dcreager/fire-display to main
- origin/main:
[ty] Improve
@override,@finaland Liskov checks in cases where there are multiple reachable definitions (#21767) [ty] Extendinvalid-explicit-overrideto also cover properties decorated with@overridethat do not override anything (#21756) [ty] Enable LRU collection for parsed module (#21749) [ty] Support typevar-specialized dynamic types in generic type aliases (#21730) Add token basedparenthesized_rangesimplementation (#21738) [ty] Default-specialization of generic type aliases (#21765) [ty] Suppress false positives whendataclasses.dataclass(...)(cls)is called imperatively (#21729) [syntax-error] Default type parameter followed by non-default type parameter (#21657) new module for parsing ranged suppressions (#21441) [ty]type[T]is assignable to an inferable typevar (#21766) Fix syntax error false positives forawaitoutside functions (#21763) [ty] Improve diagnostics for unsupported comparison operations (#21737) MoveToken,TokenKindandTokenstoruff-python-ast(#21760) [ty] Don't confuse multiple occurrences oftyping.Selfwhen binding bound methods (#21754) Use our org-wide Renovate preset (#21759) Deletemy-script.py(#21751) [ty] Moveall_members, and related types/routines, out ofide_support.rs(#21695)
dcreager deleted the dcreager/nondeterminism branch
dcreager added a commit that referenced this pull request
- origin/main:
[ty] Reachability constraints: minor documentation fixes (#21774)
[ty] Fix non-determinism in
ConstraintSet.specialize_constrained(#21744) [ty] Improve@override,@finaland Liskov checks in cases where there are multiple reachable definitions (#21767) [ty] Extendinvalid-explicit-overrideto also cover properties decorated with@overridethat do not override anything (#21756) [ty] Enable LRU collection for parsed module (#21749) [ty] Support typevar-specialized dynamic types in generic type aliases (#21730) Add token basedparenthesized_rangesimplementation (#21738) [ty] Default-specialization of generic type aliases (#21765) [ty] Suppress false positives whendataclasses.dataclass(...)(cls)is called imperatively (#21729) [syntax-error] Default type parameter followed by non-default type parameter (#21657)
dcreager added a commit that referenced this pull request
#21744 fixed some non-determinism in our constraint set implementation by switching our BDD representation from being "fully reduced" to being "quasi-reduced". We still deduplicate identical nodes (via salsa interning), but we removed the logic to prune redundant nodes (one with identical outgoing true and false edges). This ensures that the BDD "remembers" all of the individual constraints that it was created with.
However, that comes at the cost of creating larger BDDs, and on #21551
that was causing performance issues. scikit-learn was producing a
function signature with dozens of overloads, and we were trying to
create a constraint set that would map a return type typevar to any of
those overload's return types. This created a combinatorial explosion in
the BDD, with by far most of the BDD paths leading to the never
terminal.
This change updates the quasi-reduction logic to prune nodes that are
redundant because both edges lead to the never terminal. In this
case, we don't need to "remember" that constraint, since no assignment
to it can lead to a valid specialization. So we keep the "memory" of our
quasi-reduced structure, while still pruning large unneeded portions of
the BDD structure.
Pulling this out of #21551 for separate review.
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
[ Show hidden characters]({{ revealButtonHref }})