-
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
Remove redundant call to checkNodeDeferred
#22516
Conversation
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.
Provided nothing's been obviously broken, it seems fine - I'm pretty sure any context sensitive node that gets checked in SkipContextSensitive
will later on be checked in a context-sensitive way and use the following branches which also contain checkNodeDeferred
. That these supposedly-one time checks are getting registered during inference (which is inherently multi-pass and shouldn't persist state unless inference succeeds) at all is kinda odd, though. Do we not visit function expressions/object literal methods outside of inference? Given that the grammar checks done in this method which also does inference things, I guess not, but still... odd. It means we recheck the grammar during every every inference pass, which seems wasteful.
I wonder if it wouldn't impact performance to just move all the grammar checking out to its own tree walk -- would certainly make the code easier to read. |
@andy-ms We effectively already do js-only grammar checks in a separate tree walk in |
src/compiler/checker.ts
Outdated
@@ -21564,6 +21563,7 @@ namespace ts { | |||
|
|||
function registerForUnusedIdentifiersCheck(node: Node) { | |||
if (deferredUnusedIdentifierNodes) { | |||
Debug.assert(!contains(deferredUnusedIdentifierNodes, node), "Registering unused identifier twice"); |
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.
actually, isn't the contains call slow? I imagine the list gets long.
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.
Yeah contains
is a linear search - binarySearch
might be a bit better (since the list is probably effectively sorted by node id), but best would just be using a map instead.
Fixes #22491
If I have this right, we will always do one more check after all
SkipContextSensitive
checks.Before this PR, the assertion (also added in this PR) would have failed for most arrow functions in call expressions.
For posterity, a simple test case that failed was:
(we have lots of test cases like this already, so didn't see a need to add a new one.)