-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Improve variance measurement #36261
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
Improve variance measurement #36261
Conversation
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at b453606. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at b453606. You can monitor the build here. It should now contribute to this PR's status checks. |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at b453606. You can monitor the build here. It should now contribute to this PR's status checks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems straightforward to me.
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
Community test failures appear to be preexisting conditions. Other tests are clean. |
This PR improves variance measurement for generic types. Previously we'd default to covariance for recursive references to the same type during variance measurement. Now we instead assume recursive references to be "possibly related" (signaled using
Ternary.Maybe
), similarly to what happens when we hit the recursion depth limiter. This effectively means we measure variance only from type parameter occurrences that aren't nested in recursive instantiations of the generic type.Previously, a type like the following:
would be measured as invariant in
T
: We would correctly measure the reference toT
in thef
property as contravariant, but then the recursive reference toFoo
in theg
property would default to covariance and we'd end up with a combined invariant result. We now correctly measure the type as contravariant inT
:We furthermore now correctly measure unwitnessed type parameters in recursive references as independent:
We could potentially further improve variance measurement by structurally exploring recursive references to some depth other than zero, but we already know that the limit of 5 imposed by the recursion depth limiter is too high to prevent runaway recursion in some of our test suites.
Fixes #35805.