-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Properly propagate ObjectFlags.NonInferrableType, clean up non-inferrable code paths #49887
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
…g NonInferrableType, but breaks if it does
@@ -17196,6 +17191,7 @@ namespace ts { | |||
result.mapper = mapper; | |||
result.aliasSymbol = aliasSymbol || type.aliasSymbol; | |||
result.aliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper); | |||
result.objectFlags |= result.aliasTypeArguments ? getPropagatingFlagsOfTypes(result.aliasTypeArguments, /*excludeKinds*/ 0) : 0; |
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.
Huh, this is interesting because this is redundant for TypeReference
anonymous types (since those internally collect propagating flags from their type arguments), but required for any other anonymous object type with an alias. Go figure. I wonder if we should be propagating these object flags through conditional types, too... We already preserve them through intersections and unions. (We probably should be, since conditionals are "smart unions"...)
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.
Yes, I think they should. Right now I'm trying to go by hand to every createAnonymousType
, createObjectType
,... etc and see if there's anything missed, and it's a bit daunting because there's like 100 of them to verify, and nothing I've changed so far as actually changed any test.
I want to have something I can run while I'm debugging that'll observe each type during inference and walk down to see if there was a NonInferrableType
flag that was missed, but I get stuck in stack overflows, so I don't quite know how I can do my sanity check.
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.
I think for this PR, I'm inclined to not try and go everywhere and add some more flag propagation without a way for me to check these; I just don't trust that I'm getting it right, and I don't have any way to observe the result.
This PR at least improves the one case I can test, and has a good amount of cleanup, so I'm happy with it (but I'll rerun the testing since I changed the structure of this quite a bit).
@typescript-bot test this |
Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at dd6bdaf. You can monitor the build here. |
Heya @jakebailey, I've started to run the extended test suite on this PR at dd6bdaf. You can monitor the build here. |
Heya @jakebailey, I've started to run the diff-based user code test suite on this PR at dd6bdaf. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've started to run the perf test suite on this PR at dd6bdaf. You can monitor the build here. Update: The results are in! |
Heya @jakebailey, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here. |
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.
Assuming rwc and DT are good, this seems like a good consolidation.
@jakebailey Here they are:Comparison Report - main..refs/pull/49887/merge fp-ts2 of 4 projects failed to build with the old tsc dtslint/ts3.5/tsconfig.json
|
Hm, those fp-ts things seem relevant. I was hoping those would go away, but I guess not. |
Yeah, the actual fix in this PR breaks fp-ts's |
@jakebailey Here they are:
CompilerComparison Report - main..49887
System
Hosts
Scenarios
TSServerComparison Report - main..49887
System
Hosts
Scenarios
Developer Information: |
…lavent when the non-inferrable type was an any
Figured this out; we basically just needed to revert #26678, which worked around problems with non-inferrable types before the current non-inferrable flag and proper propagation was implemented. |
@typescript-bot test this |
Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at 9e831ec. You can monitor the build here. |
Heya @jakebailey, I've started to run the abridged perf test suite on this PR at 9e831ec. 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 9e831ec. 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 9e831ec. You can monitor the build here. |
@jakebailey Here they are:Comparison Report - main..49887
System
Hosts
Scenarios
Developer Information: |
@jakebailey |
All the tests look clean, phew. |
Fixes #43962
The original bug required two changes to fix:
NonInferrableType
flag needs to be propagated fromaliasTypeArguments
to the type they're used in, but this was missed in at least one place.silentNeverType
as its marker type to say "don't infer from this", but it only checked forsource === silentNeverType
, which doesn't work when you use that type in another type. So this needs to beNonInferrableType
too.The rest of the changes are cleanups and documentation improvements.
nonInferrableType
is redundant withsilentNeverType
, and there are other types likeanyFunctionType
,autoType
, andautoArrayType
which are also used as marker types for this same purpose. They all can just use the flag without any changes in behavior.nonInferrableAnyType
looks like it should beNonInferrableType
, but making it have that flag breaks things. It turns out that if you just useanyType
, nothing breaks.