Skip to content
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

Merged
2 commits merged into from
Mar 13, 2018
Merged

Remove redundant call to checkNodeDeferred #22516

2 commits merged into from
Mar 13, 2018

Conversation

ghost
Copy link

@ghost ghost commented Mar 13, 2018

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:

// @noUnusedLocals: true
// @noUnusedParameters: true
declare function f<T>(a: (s: string) => T): void;
f(s => s);

(we have lots of test cases like this already, so didn't see a need to add a new one.)

@ghost ghost requested review from sandersn and weswigham March 13, 2018 21:30
Copy link
Member

@weswigham weswigham left a 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.

@ghost
Copy link
Author

ghost commented Mar 13, 2018

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.

@weswigham
Copy link
Member

weswigham commented Mar 13, 2018

@andy-ms We effectively already do js-only grammar checks in a separate tree walk in program.ts, so it can't be that bad.

@@ -21564,6 +21563,7 @@ namespace ts {

function registerForUnusedIdentifiersCheck(node: Node) {
if (deferredUnusedIdentifierNodes) {
Debug.assert(!contains(deferredUnusedIdentifierNodes, node), "Registering unused identifier twice");
Copy link
Member

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.

Copy link
Member

@weswigham weswigham Mar 13, 2018

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.

@ghost ghost merged commit 23a64fe into master Mar 13, 2018
@ghost ghost deleted the checkNodeDeferred branch March 13, 2018 22:46
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants