[ty] Fix loop-header reachability cycles in conditional unpacking#24006
[ty] Fix loop-header reachability cycles in conditional unpacking#24006charliermarsh merged 1 commit intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 85.38%. The percentage of expected errors that received a diagnostic held steady at 78.70%. The number of fully passing files held steady at 64/132. |
Memory usage reportMemory usage unchanged ✅ |
|
4142971 to
a214e78
Compare
|
|
||
| LoopHeaderReachability { | ||
| has_defined_bindings: self.has_defined_bindings, | ||
| deleted_reachability: self.deleted_reachability, |
There was a problem hiding this comment.
I suppose it would be equivalent to change this to self.has_defined_bindings || previous.has_defined_bindings? Do we also need to update deleted_reachability here?
There was a problem hiding this comment.
I think we don't want to do that because it would over-estimate unboundness, though I can't come up with a test impacted by changing that.
There was a problem hiding this comment.
With this diff:
- deleted_reachability: self.deleted_reachability,
+ deleted_reachability: self.deleted_reachability.or(previous.deleted_reachability),The following example emits a warning:
x = 1
# warning[possibly-unresolved-reference]:
while x < 10:
# warning[possibly-unresolved-reference]:
if x == 4:
del xSo I think leaving it is correct (though it is possible it may prevent cycle convergence in some cases, but if we don't have a reproduction we can leave it for now). As @carljm points out, I think this means that your change also has the same problem of over-estimating the definedness of bindings within the loop, but I think it's fine to land for now to fix the cycle panics.
There was a problem hiding this comment.
Added both tests, thank you!
|
This might be the unavoidable cost of fixing these cycles (I'd have to think harder about what else we could do to avoid it), but Codex observes that this branch means we now infer Of course, no other type checker is able to reveal |
|
I'll need to dig deeper to figure out if there's a fix that would retain the current behavior, but we might want to err on the side of merging this since we now have two panic reports. |
ibraheemdev
left a comment
There was a problem hiding this comment.
Happy to land this for now to fix the panics, but it would be helpful to add @carljm's example as a regression test.
a214e78 to
f489564
Compare
Summary
Closes astral-sh/ty#3057.
Closes astral-sh/ty#3104.