Commit 810cab3
authored
[ty] Use existential quantification to only consider inferable typevars (astral-sh#24383)
The `ConstraintSet::solutions` method returns a (set of) solutions for a
constraint set — assignments of specific types to each typevar in
question. astral-sh#23848 introduced two variants of this method. One of them
(`solutions_with_inferable`) would take in the set of `inferable`
typevars. This was used in a cycle check at the beginning of the method,
to make sure that we only considered the typevars we're actually solving
for when detecting a cyclic constraint set. More importantly, it was
also used to limit the result, so that we would only get solutions for
ther inferable typevars (i.e., the ones that we're using the constraint
set to solve for).
A cleaner approach is to use _extensional quantification_ to _remove_
the non-inferable typevars from the constraint set before calculating
solutions. We already had this available as a lower-level TDD method
(`abstract_one_inner`), which lets us provide an arbitrary
`should_remove` callback to determine which constraints to keep and
which to remove. We just need to add a new public API method that
provides a `should_remove` callback that keeps only the constraints
involving inferable typevars.
Given this change we can actually remove the cyclic checks completely,
since `SequentMap` and `PathAssignments` will already bottom out if they
encounter a cycle in the constraints. (Specifically, while we're walking
TDD paths, `PathAssignments` will only add constraints that aren't
already present in the current path.)1 parent 4add3b1 commit 810cab3
5 files changed
Lines changed: 141 additions & 187 deletions
File tree
- crates/ty_python_semantic
- resources/mdtest/regression
- src/types
- call
- infer
Lines changed: 52 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4340 | 4340 | | |
4341 | 4341 | | |
4342 | 4342 | | |
4343 | | - | |
| 4343 | + | |
| 4344 | + | |
| 4345 | + | |
4344 | 4346 | | |
4345 | 4347 | | |
4346 | 4348 | | |
4347 | 4349 | | |
4348 | 4350 | | |
4349 | | - | |
4350 | | - | |
4351 | | - | |
4352 | | - | |
4353 | | - | |
4354 | | - | |
4355 | | - | |
4356 | | - | |
4357 | | - | |
| 4351 | + | |
| 4352 | + | |
4358 | 4353 | | |
4359 | 4354 | | |
4360 | 4355 | | |
4361 | 4356 | | |
4362 | 4357 | | |
4363 | | - | |
4364 | | - | |
4365 | | - | |
| 4358 | + | |
| 4359 | + | |
4366 | 4360 | | |
4367 | 4361 | | |
4368 | 4362 | | |
| |||
0 commit comments