You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds a (currently very conservative, based on design meeting feedback) limit on how large of a tuple type we will create through spread normalization.
On each recursion, checking T['length'] kicks off resolveObjectTypeMembers, which instantiates base types. Recall that an N-tuple is modeled something like
So in order to instantiate the base type, we have to pass along an array type mapper mapping T0...TN to the “type arguments,” or the element types of this particular tuple. So even though, in this case, every element type is any, the source side of the mapper is an N+1-length array filled with N unique type parameter identities (plus the this type parameter). When we instantiate each union constituent T0 | T1 | ... | TN, we have to search through that N-length array of sources, even though in this case we’ll always find any in the target side.
So you can imagine by the time we get to the 15th recursion or so, this is starting to take a while, and we’re creating quite a lot of type parameter identities. Pretty much all the time was being spent in this spiral of trying to instantiate the Array base type.
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this looks pretty reasonable. It's another limit someone may eventually come to us and say "but I need it higher for so and so reasons", but we can deal with that as it happens.
The reason will be displayed to describe this comment to others. Learn more.
I like having a limiter here, but I'm thinking 10,000 is a more reasonable threshold. Also, I think it is better to have only a single diagnostic, "Expression produces a tuple type...", instead of two. We only have a single diagnostic for the other limiters and it makes it easer to search for solutions on stack overflow, etc.
The first message I wrote was “Spread produces a tuple type...” but I wasn’t sure how I felt about it since the error could appear far from the actual spread via instantiation. I guess I can delete the “Type” variant, it just felt wrong to call a type an expression.
I agree that 10k would be fine as a limit. Will update.
@DanielRosenwasser if you’re concerned about this going into 4.2 as a breaking change at this point, I think it can wait until 4.3. But I think as breaking changes go, it’s not super likely to be observed, especially after I update the limit to 10k.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a (currently very conservative, based on design meeting feedback) limit on how large of a tuple type we will create through spread normalization.
On each recursion, checking
T['length']
kicks offresolveObjectTypeMembers
, which instantiates base types. Recall that an N-tuple is modeled something likeSo in order to instantiate the base type, we have to pass along an array type mapper mapping T0...TN to the “type arguments,” or the element types of this particular tuple. So even though, in this case, every element type is
any
, the source side of the mapper is an N+1-length array filled with N unique type parameter identities (plus thethis
type parameter). When we instantiate each union constituentT0 | T1 | ... | TN
, we have to search through that N-length array of sources, even though in this case we’ll always findany
in the target side.So you can imagine by the time we get to the 15th recursion or so, this is starting to take a while, and we’re creating quite a lot of type parameter identities. Pretty much all the time was being spent in this spiral of trying to instantiate the Array base type.
Fixes #41771