-
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
Smarter subtype reduction in union types #42353
Conversation
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at 439c9ad. You can monitor the build here. Update: The results are in! |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 439c9ad. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at 439c9ad. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 439c9ad. You can monitor the build here. |
@ahejlsberg Here they are:Comparison Report - master..42353
System
Hosts
Scenarios
|
@typescript-bot perf test this faster |
Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at aff7886. You can monitor the build here. Update: The results are in! |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
@ahejlsberg Here they are:Comparison Report - master..42353
System
Hosts
Scenarios
|
Tests all look good, performance is unaffected. I think this one is good to go. |
@typescript-bot pack this |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at b30b222. You can monitor the build here. |
Hey @DanielRosenwasser, 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 |
Tagging @brieb in case Airbnb wants to try this out. |
src/compiler/checker.ts
Outdated
@@ -28873,7 +28859,7 @@ namespace ts { | |||
if (returnType.flags & TypeFlags.ESSymbolLike && isSymbolOrSymbolForCall(node)) { | |||
return getESSymbolLikeTypeForNode(walkUpParenthesizedExpressions(node.parent)); | |||
} | |||
if (node.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.ExpressionStatement && | |||
if (node.kind === SyntaxKind.CallExpression && !node.questionDotToken && node.parent.kind === SyntaxKind.ExpressionStatement && |
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.
Was this supposed to be part of this change set? Or part of another PR?
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.
It's an intended change. We have some code in checkCallExpression
that attempts to issue errors when calls to assertion functions aren't actually processed as assertions (because, for example, they don't have targets that were declared with explicit type annotations). This code kicks in only with a function's return type is exactly void
. It would not kick in in cases where the return type was void | undefined
, but now that we reduce that to void
, it does kick in.
The core issue really is that we don't want the check when the call expression is a question-dot call because the assertion isn't know to have actually happened. So that's what this fixes.
@RyanCavanaugh I'd like to get this one merged, want to take a look? |
# Conflicts: # src/compiler/checker.ts
Wow, thank you so much for the fix!! Can you pack another version? Or I can wait for the nightly and report back. Happy to try it out on the original code that motivated the issue report. |
I can't pack from here, but the next nightly will have it. If you'd be able to pick that up, we'd appreciate it a ton! |
With this PR we improve our subtype reduction algorithm for union types to more efficiently handle primitive type constituents. Specifically, prior to performing subtype reduction we first perform the (much cheaper) literal type reduction pass. This allows us to almost always exclude primitive types from the subtype reduction pass and include them only when an empty object type is present.
With the PR the literal type reduction pass reduces away
undefined
when the type set includesvoid
. Previously we would only perform this reduction as part of subtype reduction. This minor change accounts for all but one of the baseline changes.Fixes #41615.