-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Measure variance of aliased conditional types using variance markers #27804
Measure variance of aliased conditional types using variance markers #27804
Conversation
Interesting that it has no effect on test and RWC baselines. However, I'm definitely concerned about the fact that the presence or absence of alias symbols now has a semantic effect. As I mentioned, in a worst case scenario, your code might stop compiling just because interned type (such as a unit type) was materialized without an alias symbol instead of with an alias symbol. |
It already affects inference, which in turn affects assignability via |
I'm only checking for alias symbols on conditional types for now, so this will not be the case. Unless we start interning conditionals or something. |
For the record: The reason this fixes the linked issue is that when we're computing variances, we have a circularity guard that gets triggered while computing weather |
@ahejlsberg like we spoke about in person, I've swapped to just do variance probing for all type aliases - this doesn't seem to adversely impact any RWC tests at all. I'll try it out on DT; but that's going to take a wee bit to run. |
@ahejlsberg This PR causes no change to RWC, user, or DT baselines. By all the things we can test, this optimization has no effect on any code we know of (except, ofc, the new test case in this PR that it fixes!). 😄 |
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.
Approved with fixes.
|
||
function getAliasVariances(symbol: Symbol) { | ||
const links = getSymbolLinks(symbol); | ||
return getVariancesWorker(links.typeParameters, links, (_links, param, marker) => getTypeAliasInstantiation(symbol, instantiateTypes(links.typeParameters!, makeUnaryTypeMapper(param, marker)))); |
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.
Just set the marker boolean here.
return type === markerSuperType || type === markerSubType || type === markerOtherType; | ||
} | ||
|
||
function getAliasArgumentsContainsMarker(type: Type) { |
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.
Can get rid of this function if you eagerly set the marker property.
Fixes #26681
We do this for interface references already, and extending it to type aliases wasn't too difficult. Doing this provides an easy fast-path bailout when comparing different instantiations of the same (type-aliased) conditional.
This PR has no impact on either RWC or user suite baselines, I checked 😄