-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
@typescript-bot test this |
@typescript-bot pack this |
@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.) |
Hey @amcasey, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running There is also a playground for this build. |
The error I'm now seeing in the compiler is:
Looks good to me :) |
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. |
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. 😄 |
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 |
@ahejlsberg pointed out that we probably want different limits for primitive and non-primitive unions/intersections. I'll try to work some out empirically. |
@typescript-bot test this |
RWC shows no instances of the new error text. |
@typescript-bot pack this |
@@ -0,0 +1,8018 @@ | |||
tests/cases/compiler/conditionalTypeDiscriminatingLargeUnionRegularTypeFetchingSpeedReasonable.ts(8011,26): error TS2797: Expression requires comparison of excessively large union or intersection types. |
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'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.
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.
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
8f33b9d
to
833a268
Compare
Force pushed a rebase, so that feedback-driven changes would show up cleanly in subsequent commits. |
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.
👍 tracepoint
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