-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Cache expression type when checking assertion #54224
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
Changes from all commits
1175676
c790579
372a1ab
bb14838
5b536d5
460c36b
bb2b5f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -34523,6 +34523,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
return getRegularTypeOfLiteralType(exprType); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
const links = getNodeLinks(node); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
and no changes in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So
Makes sense. |
||||||||||||||||||||||||||
links.assertionExpressionType = exprType; | ||||||||||||||||||||||||||
checkSourceElement(type); | ||||||||||||||||||||||||||
checkNodeDeferred(node); | ||||||||||||||||||||||||||
return getTypeFromTypeNode(type); | ||||||||||||||||||||||||||
|
@@ -34547,9 +34549,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
function checkAssertionDeferred(node: JSDocTypeAssertion | AssertionExpression) { | ||||||||||||||||||||||||||
const { type, expression } = getAssertionTypeAndExpression(node); | ||||||||||||||||||||||||||
const { type } = getAssertionTypeAndExpression(node); | ||||||||||||||||||||||||||
const errNode = isParenthesizedExpression(node) ? type : node; | ||||||||||||||||||||||||||
DanielRosenwasser marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
const exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(checkExpression(expression))); | ||||||||||||||||||||||||||
const links = getNodeLinks(node); | ||||||||||||||||||||||||||
Debug.assertIsDefined(links.assertionExpressionType); | ||||||||||||||||||||||||||
const exprType = getRegularTypeOfObjectLiteral(getBaseTypeOfLiteralType(links.assertionExpressionType)); | ||||||||||||||||||||||||||
const targetType = getTypeFromTypeNode(type); | ||||||||||||||||||||||||||
if (!isErrorType(targetType)) { | ||||||||||||||||||||||||||
addLazyDiagnostic(() => { | ||||||||||||||||||||||||||
|
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.
By moving the
checkExpression
for theas const
case into theif
, it's no longer used in the deferred-check case at all; so you shouldn't actually need to cache it like this (which is a tad unsafe, so if it's avoidable, I'd like to avoid it), since you'll either do it once early or once deferred.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.
So what're you thinking @weswigham? Place this in an explicit
else
?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.
Or I guess, keep it in the same as before, but then cache it on links unconditionally?
That makes sense, you're calling it twice in some cases anyway now, right?
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.
If I understand correctly, that's what I was doing in https://github.com/microsoft/TypeScript/pull/53261/files/45124b1447f2ff88bdf2f9e65f0e1766a80a70a3, and that's what caused
xstate
checking perf to increase by 10-13% (#53261 (comment)).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.
@gabritto but aren't you callingwhoops, duh, it's an early return.checkExpression
twice now?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 guess there's no "checking twice" but there's some code deduplication -
checkExpression
is going to happen anyway. I'd rather we got rid of that and go back to havingexprType
That said, I don't see why avoiding deferral is a problem in that case.
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 wouldn't. The
CheckMode
-independent unconditional cache is unsafe and could lead to weird inconsistencies between signature checking states, which can lead to odd editor/command line error inconsistencies. We do it in one or two other places for perf reasons, but it's to be avoided where possible.