[ty] Fix simplification of T & ~T for non-fully-static types#20651
[ty] Fix simplification of T & ~T for non-fully-static types#20651AlexWaygood wants to merge 1 commit intomainfrom
T & ~T for non-fully-static types#20651Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
I agree
Which justification?
I don't think so? That's not even true for fully-static types. From my calculations,
|
3ea3541 to
e8ec64e
Compare
Apologies, I linked to this on Discord but should have put this in my PR description, and probably also have added better comments alongside the code changes in this PR. I was referring to @carljm's justification here:
In the same way, we can say that
The "intersect with
the conclusion here definitely seems correct to me. If Thinking through the formulation like that makes me wonder if we can simply say that
|
I like these sort of phrases as a justification after the fact, but I don't think they are good tools for a proof.
The key technique for any of these calculations is to write gradual types in the form But once we have this representation, we can start to do useful calculations. For example, we can rewrite And from this representation, we can extract that And finally we can rewrite this in the universal form What this type shows is that By the way, we could also compute |
That doesn't look correct. Take I think it should be |
e8ec64e to
3ef117e
Compare
Summary
(Stacked on top of #20650; review that PR first!)On
main, we simplifyAny & ~AnytoAny, but we simplifylist[Any] & ~list[Any]toNever. This is inconsistent! The justification for the first simplification applies to all non-fully-static types, so we should apply the same treatment to both.T & ~Tcannot simplify toNeverfor any non-fully-static typeT, but it can simplify toT. We cannot say thatlist[Any] & ~list[Any]is so small such that the only materialization of the type isNever, as the firstAnymight (for example) materialize tointwhile the second one might materialize tobool, andlist[int] & ~list[bool]is not equivalent toNever(it's equivalent tolist[int], since the two types are disjoint)Test Plan
Added mdtests that fail on
main