Skip to content
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

Use identity with the permissive instantation to detect nongenric instances and disable variance probing on nongeneric instances #29981

Merged

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Feb 20, 2019

Previously @ahejlsberg had mentioned disabling variance probing for generic mapped types - that's not good enough. In the examples given by, eg varianceProblingAndZeroOrderIndexSignatureRelationsAlign (which come from user code - see #29817), the mapped types are within something else which we're still doing variance calculations for. The real "heuristic" as it were, is simply that if we know we're not relating generic types, then we should compare structurally rather than with variances (since we know the structural comparison will yield the correct result and likely be more permissive than any pessimistic higher order relationship may have been). Since we can't directly check if a type still contains generics or not, I proxy the check by seeing if the permissive instantiation of the type and the type itself are identical. If they are, then either A. we're looking at a permissive instantiation of a type (which is by definition non-generic, since all generics have been mapped out), or B. we're looking at a type which is unaffected by instantiation of all generics in it (so contains no generics).

…stances and disable variance probing on nongeneric instances
@weswigham
Copy link
Member Author

weswigham commented Feb 25, 2019

cc @ahejlsberg this was the PR for the thing I was just talking to you about.

@microsoft microsoft deleted a comment from typescript-bot Feb 25, 2019
@microsoft microsoft deleted a comment from typescript-bot Feb 25, 2019
@microsoft microsoft deleted a comment from typescript-bot Feb 25, 2019
@microsoft microsoft deleted a comment from typescript-bot Feb 25, 2019
@sandersn
Copy link
Member

Note from DT: In its current state, this should fix the failure in @types/jasmine. (That's where the test case nongenericPartialInstantiationsRelatedInBothDirections.ts comes from.)

@weswigham
Copy link
Member Author

@typescript-bot test this & @typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 26, 2019

Heya @weswigham, I've started to run the Definitely Typed test suite on this PR at cd92006. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 26, 2019

Heya @weswigham, I've started to run the extended test suite on this PR at cd92006. You can monitor the build here. It should now contribute to this PR's status checks.

@weswigham
Copy link
Member Author

@typescript-bot test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 26, 2019

Heya @weswigham, I've started to run the extended test suite on this PR at bb250df. You can monitor the build here. It should now contribute to this PR's status checks.

@weswigham
Copy link
Member Author

This undoes the pair of RWC errors introduced by the merge of #29817, so the RWC diff looks pretty good to me.

@sandersn
Copy link
Member

I looked at the DT diff. Most of the ember errors are gone, so I guess that the ones remaining have strictFunctionTypes: true. Jasmine is also fixed. However, the process ran out of memory before finishing, so I'm not sure it finished yargs successfully.

Worse, mithril overflows the stack now. You should probably take a look.

@weswigham
Copy link
Member Author

@typescript-bot test this & @typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 26, 2019

Heya @weswigham, I've started to run the extended test suite on this PR at ba0720e. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 26, 2019

Heya @weswigham, I've started to run the Definitely Typed test suite on this PR at ba0720e. You can monitor the build here. It should now contribute to this PR's status checks.

@weswigham
Copy link
Member Author

Remaining DT changes just look to be some minor changes in ember that @sandersn already has a PR up on DT to fix, so this looks good now ❤️

@weswigham weswigham changed the title Use identity with the restrictive instantation to detect nongenric instances and disable variance probing on nongeneric instances Use identity with the permissive instantation to detect nongenric instances and disable variance probing on nongeneric instances Feb 27, 2019
@weswigham
Copy link
Member Author

After some soul searching on how to best fix the depth crash found via specced, i swapped from using the restrictive instantiation to the permissive instantiation as an identity target - both map all type parameters, but since permissive maps type parameters into wildcard, repeated instantiations don't chain (and the wildcard type often bails out of identity checking way faster than a type parameter when it doesn't match as an added bonus).

@weswigham
Copy link
Member Author

@typescript-bot test this & @typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 27, 2019

Heya @weswigham, I've started to run the extended test suite on this PR at 1565c97. You can monitor the build here. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 27, 2019

Heya @weswigham, I've started to run the Definitely Typed test suite on this PR at 1565c97. You can monitor the build here. It should now contribute to this PR's status checks.

@sandersn
Copy link
Member

The DT run is all clean except for the remaining ember failures, which I have a fix for, and another project URL change, which I just updated.

@weswigham
Copy link
Member Author

Is the project url failure just only reporting one failure at a time or something?

@sandersn
Copy link
Member

sandersn commented Feb 27, 2019

@weswigham That is unlikely because dtslint issues the error, and it's being run in parallel by dtslint-runner.

It's much more likely that of the 5200+ npm packages that DT tracks, one or two per day change their urls.

Edit: If that's the case, I'll look into an automated way to keep the urls up-to-date, because otherwise it'll constantly break the DT build.

@sandersn
Copy link
Member

Update from #30133: Reverting the invariance of conditional types shows that this PR still fixes errors in

  1. jasmine (which is a test case of this PR)
  2. ember and ember__object

I'm not sure of the exact cause of ember's problem, but it's still going through their UnwrapComputedPropertyGetters conditional type.

However, spected, mithril and yargs no longer error on master, so this PR doesn't need to address those errors.

@weswigham
Copy link
Member Author

@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 27, 2019

Heya @weswigham, I've started to run the Definitely Typed test suite on this PR at f8989af. You can monitor the build here. It should now contribute to this PR's status checks.

@weswigham weswigham merged commit 13c08ab into microsoft:master Feb 27, 2019
@weswigham weswigham deleted the disable-probing-for-nongeneric-instances branch February 27, 2019 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants