Skip to content

Detect comparisons between large unions or intersections #41574

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 6 commits into from
Dec 10, 2020

Conversation

amcasey
Copy link
Member

@amcasey amcasey commented Nov 18, 2020

If their multiplied size is greater than 1E7 (chosen based on the repro
in #41517), then we'll expend a large amount of time and memory
comparing them, so alert the user instead.

Fixes #41517

@amcasey
Copy link
Member Author

amcasey commented Nov 18, 2020

@typescript-bot test this

@amcasey
Copy link
Member Author

amcasey commented Nov 18, 2020

@typescript-bot pack this

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Nov 18, 2020
@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 18, 2020

Heya @amcasey, I've started to run the tarball bundle task on this PR at 935e27a. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 18, 2020

Heya @amcasey, I've started to run the extended test suite on this PR at 935e27a. You can monitor the build here.

@amcasey
Copy link
Member Author

amcasey commented Nov 18, 2020

@NoPhaseNoKill the bot should post a link to a private build shortly. If you have a minute, can you please confirm that this change correctly flags the problematic expression in your real code? (I've already confirmed that it works in the toy repro.)

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 18, 2020

Hey @amcasey, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/89455/artifacts?artifactName=tgz&fileId=618CA2EA1F4B47196F4BF57EC3167658E429AB9FDB6380D977C766FBCFB1546F02&fileName=/typescript-4.2.0-insiders.20201118.tgz"
    }
}

and then running npm install.


There is also a playground for this build.

@NoPhaseNoKill
Copy link

NoPhaseNoKill commented Nov 18, 2020

The error I'm now seeing in the compiler is:

ERROR in /[redacted]src/IconButton.tsx
ERROR in /[redacted]/src/IconButton.tsx(23,17):
TS2769: No overload matches this call.
  Overload 1 of 2, '(props: Readonly<IconProps>): Icon', gave the following error.
    Expression requires comparison of excessively large unions or intersections.
  Overload 2 of 2, '(props: IconProps, context?: any): Icon', gave the following error.
    Expression requires comparison of excessively large unions or intersections.

Looks good to me :)

@NoPhaseNoKill
Copy link

Are there any places I can lodge/put in feedback for the help you've given me? I just want to say what an excellent experience this has been for me.

Normally, dealing with large companies/significant repo's it's an absolute nightmare. So thank you very much for all your help, you deserve to be recognised formally.

@amcasey
Copy link
Member Author

amcasey commented Nov 18, 2020

Thanks for confirming! I'm glad we could get that sorted out for you. And, no, there won't be a satisfaction survey - if you're happy, I'm happy. 😄

@NoPhaseNoKill
Copy link

Sounds good man, thanks for the help again. I'll reach out if we find any unusual behaviour in the future. Keep in touch, Tom

@amcasey
Copy link
Member Author

amcasey commented Nov 18, 2020

@ahejlsberg pointed out that we probably want different limits for primitive and non-primitive unions/intersections. I'll try to work some out empirically.

@amcasey
Copy link
Member Author

amcasey commented Nov 19, 2020

@typescript-bot test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 19, 2020

Heya @amcasey, I've started to run the extended test suite on this PR at 64a1229. You can monitor the build here.

@amcasey
Copy link
Member Author

amcasey commented Nov 20, 2020

RWC shows no instances of the new error text.

@amcasey amcasey requested a review from ahejlsberg November 24, 2020 22:31
@amcasey
Copy link
Member Author

amcasey commented Dec 9, 2020

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 9, 2020

Heya @amcasey, I've started to run the tarball bundle task on this PR at 8f33b9d. You can monitor the build here.

@@ -0,0 +1,8018 @@
tests/cases/compiler/conditionalTypeDiscriminatingLargeUnionRegularTypeFetchingSpeedReasonable.ts(8011,26): error TS2797: Expression requires comparison of excessively large union or intersection types.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure adding an error into this test kinda invalidates it, since it was here to test that we could do a thing without timing out - not being able to do it at all is kinda strictly worse (and, moreover, means we're no longer testing for a timeout). Is it just a matter of the limit being too low? #37749 made it so this is actually quite cheap for us (and this is just a simplified form of a common reactish pattern), so we shouldn't have an error here.

Copy link
Member

@weswigham weswigham Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, regarding the limit, these kinda of errors are "hard blocks" in scenarios which may otherwise work, so we should ensure we only ever issue them them in cases where we'd either time out, stack out, or OOM without the error. If we can process the comparison without one of those three things occurring, we shouldn't be erroring, IMO.

If their multiplied size is greater than 1E7 (chosen based on the repro
in microsoft#41517), then we'll expend a large amount of time and memory
comparing them, so alert the user instead.

Fixes microsoft#41517
@amcasey
Copy link
Member Author

amcasey commented Dec 10, 2020

Force pushed a rebase, so that feedback-driven changes would show up cleanly in subsequent commits.

@amcasey amcasey requested a review from weswigham December 10, 2020 18:52
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.

👍 tracepoint

@amcasey amcasey merged commit 3e72526 into microsoft:master Dec 10, 2020
@amcasey amcasey deleted the UnionCompLimit branch December 10, 2020 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Slow compilation issues (40-50s) - --skipLibCheck not working
5 participants