mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:49:50 +00:00
[red-knot] Use ternary decision diagrams (TDDs) for visibility constraints (#15861)
We now use ternary decision diagrams (TDDs) to represent visibility constraints. A TDD is just like a BDD ([_binary_ decision diagram](https://en.wikipedia.org/wiki/Binary_decision_diagram)), but with "ambiguous" as an additional allowed value. Unlike the previous representation, TDDs are strongly normalizing, so equivalent ternary formulas are represented by exactly the same graph node, and can be compared for equality in constant time. We currently have a slight 1-3% performance regression with this in place, according to local testing. However, we also have a _5× increase_ in performance for pathological cases, since we can now remove the recursion limit when we evaluate visibility constraints. As follow-on work, we are now closer to being able to remove the `simplify_visibility_constraint` calls in the semantic index builder. In the vast majority of cases, we now see (for instance) that the visibility constraint after an `if` statement, for bindings of symbols that weren't rebound in any branch, simplifies back to `true`. But there are still some cases we generate constraints that are cyclic. With fixed-point cycle support in salsa, or with some careful analysis of the still-failing cases, we might be able to remove those.
This commit is contained in:
parent
6bb32355ef
commit
444b055cec
4 changed files with 383 additions and 191 deletions
|
@ -3545,7 +3545,7 @@ impl From<Identifier> for Name {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq)]
|
||||
pub enum Singleton {
|
||||
None,
|
||||
True,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue