Detect comparisons between large unions or intersections - #41574
Conversation
|
TypeScript Bot (@typescript-bot) test this |
|
TypeScript Bot (@typescript-bot) pack this |
|
Heya Andrew Casey (@amcasey), I've started to run the tarball bundle task on this PR at 935e27a. You can monitor the build here. |
|
Heya Andrew Casey (@amcasey), I've started to run the extended test suite on this PR at 935e27a. You can monitor the build here. |
|
Tom Gardiner (@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 Andrew Casey (@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 |
|
Anders Hejlsberg (@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 (@typescript-bot) test this |
|
Heya Andrew Casey (@amcasey), I've started to run the extended test suite on this PR at 64a1229. You can monitor the build here. |
|
RWC shows no instances of the new error text. |
|
TypeScript Bot (@typescript-bot) pack this |
|
Heya Andrew Casey (@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. | |||
There was a problem hiding this comment.
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.
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. |
Wesley Wigham (weswigham)
left a comment
There was a problem hiding this comment.
👍 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