Return early on intrinsics in couldContainTypeVariables#54377
Return early on intrinsics in couldContainTypeVariables#54377jakebailey wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
@typescript-bot test this |
|
Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at b9aec28. You can monitor the build here. Update: The results are in! |
|
Heya @jakebailey, I've started to run the extended test suite on this PR at b9aec28. You can monitor the build here. |
|
Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at b9aec28. You can monitor the build here. Update: The results are in! |
|
Heya @jakebailey, I've started to run the diff-based user code test suite on this PR at b9aec28. You can monitor the build here. Update: The results are in! |
|
Heya @jakebailey, I've started to run the abridged perf test suite on this PR at b9aec28. You can monitor the build here. Update: The results are in! |
|
Heya @jakebailey, I've started to run the tarball bundle task on this PR at b9aec28. You can monitor the build here. |
|
Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build and an npm module you can use via |
|
@jakebailey Here are the results of running the user test suite comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
|
@jakebailey Here they are:Comparison Report - main..54377
System
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jakebailey Here are the results of running the top-repos suite comparing Everything looks good! |
|
Hey @jakebailey, the results of running the DT tests are ready. |
| // we perform type inference (i.e. a type parameter of a generic function). We cache | ||
| // results for union and intersection types for performance reasons. | ||
| function couldContainTypeVariables(type: Type): boolean { | ||
| if (type.flags & TypeFlags.Intrinsic) return false; |
There was a problem hiding this comment.
I'm not understanding how the function would previously return true for the wildcard type (which is a TypeFlags.Any)? What am I missing?
There was a problem hiding this comment.
The place I was referring to was inferTypes, which starts with a wildcard check, but if both sides are a wildcard we loop forever.
But, it checks for "could contain type var" before the wildcard logic.
There was a problem hiding this comment.
Right, but assuming both sides are wildcard types, how is it that we loop forever? That would require couldContainTypeVariables to return true for a TypeFlags.Any, and I'm not seeing how that happens.
There was a problem hiding this comment.
You're totally right that couldContainTypeVariables should already be returning false for wildcardType, and yet, in my example it appeared to be returning true in the debugger!
But now, on main, my test doesn't fail... reverse bisecting says that it was "fixed" by changing lib.d.ts. So, I think there's some really odd corruption happening. Sounds like a fun debugging challenge.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Traced this down to the new code in #53246, but it's absolutely bizarre. The flag is clearly there that says that "could contain type vars" is computed, and yet it still proceeds to overwrite it for no reason.
|
I have tested this on our codebase for @official-love-guru, where both 5.0.4 and 5.1.3 are crashing with and this PR fixes it! Please merge this. |
|
The real fix for this problem is definitely not going to be this PR, per above conversation. I am looking into the actual problem. |

Fixes #54348
The problem in the issue is that both source and target are the wildcard type, and so this recurses forever.
But, one thing that fixes this is to just bail early on intrinsics, as those can't actually contain type vars (which then does prevent the inference loop).
I could send a more targeted fix but I think this might actually help perf.
Needs a test.