Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Use ternary decision diagrams (TDDs) for visibility constraints #15861

Merged
merged 27 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5c2d731
Add TDD implementation
dcreager Jan 31, 2025
1116336
Replace the old implementation with the new TDD one!
dcreager Jan 31, 2025
5b6bce5
Remove NodeKind
dcreager Feb 1, 2025
48fce26
Check cache second
dcreager Feb 1, 2025
3e4058c
Add additional comments
dcreager Feb 3, 2025
eaec377
Remove recursion depth limit test
dcreager Feb 3, 2025
dd03d79
clippy
dcreager Feb 3, 2025
2c2aba4
easy on the inline
dcreager Feb 3, 2025
f76824c
Reduce C && !C to false (etc) correctly
dcreager Feb 3, 2025
2c98b82
Remove simplify calls!!!
dcreager Feb 3, 2025
0fa1015
Skip calculating ambiguous branch if it's not needed
dcreager Feb 3, 2025
6fb24c6
Revert "Remove simplify calls!!!"
dcreager Feb 3, 2025
6e47aa9
Reapply "Remove simplify calls!!!"
dcreager Feb 3, 2025
61b2335
Add .pyi xfail for RET503
dcreager Feb 3, 2025
bd5ebf7
Use IndexVec
dcreager Feb 3, 2025
d7f070c
Handle two-terminal case in cmp_atoms
dcreager Feb 3, 2025
7eb1f2b
Remove unneeded clippy allows
dcreager Feb 3, 2025
cf6b269
Custom Idx impl for Atom
dcreager Feb 4, 2025
a387636
Add custom Idx impl for ScopedVisibilityConstraintId
dcreager Feb 4, 2025
ff472b7
Go back to Vec I guess
dcreager Feb 4, 2025
977da30
Revert "Go back to Vec I guess"
dcreager Feb 4, 2025
086bb58
Revert "Remove simplify calls!!!"
dcreager Feb 3, 2025
20ada6a
Move finish calls
dcreager Feb 4, 2025
82e8e3e
Add module docs describing TDDs
dcreager Feb 4, 2025
7e286a7
Make SMALLEST_TERMINAL an id
dcreager Feb 4, 2025
3377315
Document copy number better
dcreager Feb 4, 2025
ec35dcf
Document format_args usage
dcreager Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1489,37 +1489,6 @@ if True:
from module import symbol
```

## Known limitations

We currently have a limitation in the complexity (depth) of the visibility constraints that are
supported. This is to avoid pathological cases that would require us to recurse deeply.

```py
x = 1

False or False or False or False or \
False or False or False or False or \
False or False or False or False or \
False or False or False or False or \
False or False or False or False or \
False or False or (x := 2) # fmt: skip

# This still works fine:
reveal_type(x) # revealed: Literal[2]

y = 1

False or False or False or False or \
False or False or False or False or \
False or False or False or False or \
False or False or False or False or \
False or False or False or False or \
False or False or False or (y := 2) # fmt: skip

# TODO: This should ideally be `Literal[2]` as well:
reveal_type(y) # revealed: Literal[1, 2]
```

## Unsupported features

We do not support full unreachable code analysis yet. We also raise diagnostics from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ use crate::db::Db;
use crate::semantic_index::expression::Expression;
use crate::semantic_index::symbol::{FileScopeId, ScopeId};

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub(crate) struct Constraint<'db> {
pub(crate) node: ConstraintNode<'db>,
pub(crate) is_positive: bool,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub(crate) enum ConstraintNode<'db> {
Expression(Expression<'db>),
Pattern(PatternConstraint<'db>),
}

/// Pattern kinds for which we support type narrowing and/or static visibility analysis.
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, Hash, PartialEq)]
pub(crate) enum PatternConstraintKind<'db> {
Singleton(Singleton, Option<Expression<'db>>),
Value(Expression<'db>, Option<Expression<'db>>),
Expand Down
Loading
Loading