Skip to content

Defer union and intersection type reduction #26848

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

Merged
merged 2 commits into from
Sep 5, 2018

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Sep 2, 2018

When constructing union and intersection types, we eagerly remove duplicate function types that originate in function or method declarations. This eager reduction can be very expensive when resolving the members of unions of a large number of array or tuple types. We used to rely on the eager reduction, but it is no longer necessary because a similar and more efficient reduction happens later (and in a deferred manner) when we compute the signature lists of union and intersection types.

With this PR we remove the unnecessary eager reduction. This makes our behavior more consistent since the eager reduction was never done for other types.

One example that directly benefits is this code in #26756. When requesting statement completion:

function sendCommand<C extends keyof Commands>(method: C, ...params: Commands[C]['paramsType']) {
    params.  // Statement completion here
}

we currently spend 5-6 seconds grinding away before bringing up a completion list. With this PR the completion time drops to less than half a second.

Only one RWC project, fp-ts, is affected by this. Upon inspection the new errors in fp-ts look correct, and with the latest code here https://github.com/gcanti/fp-ts the errors are no longer present. I suspect the errors were not reported before because the eager reduction uses type parameter erasure which can lead to false positives.

@ahejlsberg ahejlsberg merged commit 695aae7 into master Sep 5, 2018
@ahejlsberg ahejlsberg deleted the deferUnionIntersectionReduction branch September 5, 2018 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants