Skip to content

fix(50858): parameters in function signatures inferred from default generic types sometimes not assigned instantiated types #50960

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

Closed
wants to merge 3 commits into from

Conversation

mxsdev
Copy link

@mxsdev mxsdev commented Sep 27, 2022

Fixes #50858

This issue is specifically about functions within the arguments of generic-inferring call expressions. Early in the execution flow, the internal function's signature will only be instantiated with types when some inferences have already been made about them, but this misses the case where those generics have default values. Instead of taking default values, the signature falls back to a base type. If that base type is a union of incompatible signatures or any, then the signature's parameters will be set to any.

Later in the execution flow, the signature is properly instantiated; however by that time diagnostics have already been created and the signature's symbol type may already have been set to any.

See below for a more in-depth look at the call stack.

Example

Consider the following test:

type Type = {
    a: (e: string) => void,
    b: (e: number) => void,
}
  
function f1<T extends keyof Type = 'a'>(props: Type[T]): any {
    return null
}

f1((event) => { })

The function call f1 should take a default type parameter of "a" for type parameter T, and so we expect event to take its contextual type of string. However, due to this issue, it is of type any and throws a noImplicitAny diagnostic.

Call Stack

Call Stack Analysis of Example (in checker.ts)
  • resolveCallExpression on call expression f1((event) => { }) -> resolveCall -> chooseOverload
    • chooseOverload: No typeParameters are specified, so inferTypeArguments is called twice. The first call skips context sensitive parameters (such as (event) => {}), so we are interested in the second call
      • inferTypeArguments: calls checkExpressionWithContextualType to get the type of each argument before making any type inferences
        • checkExpressionWithContextualType -> ... -> contextuallyCheckFunctionExpressionOrObjectLiteralMethod
          • contextuallyCheckFunctionExpressionOrObjectLiteralMethod: Gets contextual signature of argument by calling getContextualSignature
            • getContextualSignature: Gets type from getApparentTypeOfContextualType
              • getApparentTypeOfContextualType: contextualType is the type Type[T] of kind IndexedAccess. We then try and instantiate that type by calling instantiateContextualType
                • instantiateContextualType: Since no inferences have been made, the type is not instantiated, and the contextualType is returned
              • The return of instantiateContextualType does nothing, so we find the apparent type of Type[T], which in this case is the base type, which is (e: string) => void|(e: number) => void
            • A union of incompatible function signatures cannot be flattened into one, so undefined is returned
          • Since the contextual signature is undefined, the parameter type is assigned with assignNonContextualParameterTypes
            • assignNonContextualParameterTypes: Calls assignParameterType with undefined type on each parameter
              • The parameter type being undefined, another attempt is made to infer it contextually, which ultimately hits getContextualSignature again which like before returns undefined
                • -> ... -> widenTypeForVariableLikeDeclaration: Type is undefined so anyType is returned and a diagnostic is thrown
      • inferTypes is now called, which makes type inferences
    • The signature is now properly instantiated with getSignatureInstantiation, and the resulting signature is correct (has (event: string) => void as a parameter)
    • ...
    • getSignatureApplicabilityError is called, which flows through the same call stack as before with the instantiated signature, until contextuallyCheckFunctionExpressionOrObjectLiteralMethod because the previous execution stack already "checked the context" and set NodeCheckFlags.ContextChecked.

This issue is caused by instantiateContextualType, which is in the call stack of inferTypeArguments in chooseOverload. There is a cyclic dependency: the result of inferTypeArguments is necessary to fully instantiate the signature with getSignatureInstantiation, but (it would seem) a fully instantiated signature is expected by the return result of instantiateContextualType within getApparentTypeOfContextualType, which is in the call stack of inferTypeArguments.

Solution

The solution presented is to instantiate from within instantiateContextualType whenever the apparent type of contextualType is "degenerate" - that is, when it is either any or a union of incompatible signatures - since, in this case, essentially no further information on the parameters of the signature can be gleamed if we return it. So, in the worst case, we get back another degenerate type from instantiation, but in the best case, we get more type information.

In cases like the previous example, the call stack off of inferTypeArguments will generate the correct signature, and the correct parameter type will be assigned.

Further thoughts

I doubt this fixes every single possible instance of this bug, but it fixes the linked issue and many others. But I presume the types of the function parameters should be set after or during the instantiation of the signature, not during inferTypeArguments. It is indeed rather strange as well that a function named "assignNonContextualParameterTypes" ends up trying to infer a lot of contextual information. But my familiarity with the codebase is not excellent, so if somebody can clear that up, please do!

One more potential concern I had was that instantiateContextualType may now end up inferring "too much" - perhaps returning a non-any type where an any type is required. All of the tests pass, however, so this doesn't seem likely.

My original assumption was that inferTypeArguments should have a flag to never result in a call of assignParameterType, however I wasn't able to get this to work without destroying generic inference; it seems that many instances of type inference require types to be set from the call to inferTypeArguments, and not from the call to getSignatureApplicabilityError with the instantiated signature.

Another thought was to allow getSignatureApplicabilityError to set the type by resetting NodeCheckFlags.ContextChecked on the arguments. This does not work, however, since assignParameterType prevents setting the parameter type to one different than was cached; moreover, the diagnostic errors have already been thrown.

Note that removing the check in instantiateContextualType that "no inferences have been made" understandably breaks the codebase as well, since this will (I assume) instantiate preemptively in many cases.

If anyone has any ideas on how to make the previous approaches work, please respond, since I think they're significantly more elegant solutions to the problem than the one presented.

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Sep 27, 2022
@mxsdev
Copy link
Author

mxsdev commented Sep 27, 2022

@microsoft-github-policy-service agree

@Andarist
Copy link
Contributor

As a bystander - I applaud the description of this PR 👏

@RyanCavanaugh
Copy link
Member

@typescript-bot perf test this
@typescript-bot test top100

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 28, 2022

Heya @RyanCavanaugh, I've started to run the perf test suite on this PR at 92631fe. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 28, 2022

Heya @RyanCavanaugh, I've started to run the diff-based top-repos suite on this PR at 92631fe. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@RyanCavanaugh
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - main..50960
Metric main 50960 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 362,505k (± 0.02%) 362,449k (± 0.02%) -56k (- 0.02%) 362,300k 362,626k
Parse Time 2.08s (± 0.62%) 2.08s (± 0.45%) -0.00s (- 0.14%) 2.06s 2.10s
Bind Time 0.79s (± 1.19%) 0.78s (± 0.67%) -0.01s (- 1.39%) 0.77s 0.79s
Check Time 6.21s (± 0.56%) 6.20s (± 0.49%) -0.01s (- 0.14%) 6.10s 6.26s
Emit Time 6.05s (± 0.46%) 6.04s (± 0.79%) -0.01s (- 0.17%) 5.96s 6.14s
Total Time 15.14s (± 0.45%) 15.11s (± 0.24%) -0.03s (- 0.20%) 15.01s 15.19s
Compiler-Unions - node (v10.16.3, x64)
Memory used 206,064k (± 0.28%) 206,015k (± 0.30%) -50k (- 0.02%) 203,561k 206,408k
Parse Time 0.85s (± 0.53%) 0.84s (± 0.40%) -0.01s (- 0.94%) 0.83s 0.85s
Bind Time 0.47s (± 1.18%) 0.46s (± 0.74%) -0.01s (- 1.91%) 0.46s 0.47s
Check Time 8.52s (± 0.69%) 8.42s (± 0.97%) -0.10s (- 1.16%) 8.29s 8.66s
Emit Time 2.47s (± 1.41%) 2.45s (± 0.90%) -0.02s (- 0.81%) 2.41s 2.50s
Total Time 12.31s (± 0.69%) 12.18s (± 0.70%) -0.13s (- 1.07%) 12.04s 12.40s
Monaco - node (v10.16.3, x64)
Memory used 344,783k (± 0.02%) 344,776k (± 0.02%) -6k (- 0.00%) 344,555k 344,892k
Parse Time 1.61s (± 0.54%) 1.60s (± 0.95%) -0.01s (- 0.50%) 1.57s 1.65s
Bind Time 0.70s (± 0.88%) 0.70s (± 1.16%) -0.00s (- 0.14%) 0.69s 0.73s
Check Time 6.23s (± 0.64%) 6.22s (± 0.44%) -0.00s (- 0.03%) 6.17s 6.29s
Emit Time 3.26s (± 0.90%) 3.24s (± 0.42%) -0.02s (- 0.49%) 3.21s 3.27s
Total Time 11.79s (± 0.28%) 11.77s (± 0.26%) -0.02s (- 0.19%) 11.70s 11.84s
TFS - node (v10.16.3, x64)
Memory used 306,046k (± 0.02%) 306,059k (± 0.02%) +13k (+ 0.00%) 305,955k 306,178k
Parse Time 1.30s (± 0.77%) 1.28s (± 0.65%) -0.01s (- 0.93%) 1.27s 1.31s
Bind Time 0.67s (± 0.83%) 0.67s (± 0.67%) 0.00s ( 0.00%) 0.66s 0.68s
Check Time 5.52s (± 0.49%) 5.49s (± 0.44%) -0.03s (- 0.49%) 5.44s 5.56s
Emit Time 3.45s (± 1.17%) 3.42s (± 1.18%) -0.03s (- 0.87%) 3.33s 3.55s
Total Time 10.93s (± 0.57%) 10.86s (± 0.42%) -0.06s (- 0.59%) 10.76s 10.98s
material-ui - node (v10.16.3, x64)
Memory used 458,146k (± 0.02%) 458,188k (± 0.01%) +42k (+ 0.01%) 458,073k 458,266k
Parse Time 1.83s (± 0.48%) 1.84s (± 0.71%) +0.01s (+ 0.27%) 1.81s 1.85s
Bind Time 0.58s (± 1.91%) 0.57s (± 2.31%) -0.00s (- 0.87%) 0.55s 0.60s
Check Time 15.64s (± 0.75%) 15.60s (± 0.77%) -0.04s (- 0.26%) 15.44s 15.95s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 18.05s (± 0.67%) 18.01s (± 0.67%) -0.04s (- 0.23%) 17.86s 18.37s
xstate - node (v10.16.3, x64)
Memory used 587,405k (± 1.62%) 580,964k (± 0.01%) -6,441k (- 1.10%) 580,823k 581,144k
Parse Time 2.60s (± 0.53%) 2.60s (± 0.36%) -0.01s (- 0.23%) 2.58s 2.62s
Bind Time 0.90s (± 0.64%) 0.90s (± 0.49%) -0.00s (- 0.11%) 0.89s 0.91s
Check Time 1.61s (± 0.51%) 1.59s (± 0.51%) -0.01s (- 0.87%) 1.58s 1.61s
Emit Time 0.07s (± 4.66%) 0.07s (± 3.14%) -0.00s (- 2.74%) 0.07s 0.08s
Total Time 5.19s (± 0.40%) 5.16s (± 0.28%) -0.03s (- 0.52%) 5.13s 5.19s
Angular - node (v12.1.0, x64)
Memory used 340,065k (± 0.03%) 339,996k (± 0.02%) -69k (- 0.02%) 339,858k 340,206k
Parse Time 2.09s (± 0.83%) 2.09s (± 0.48%) -0.01s (- 0.33%) 2.07s 2.12s
Bind Time 0.77s (± 1.20%) 0.77s (± 0.91%) -0.00s (- 0.39%) 0.75s 0.78s
Check Time 5.89s (± 0.52%) 5.85s (± 0.45%) -0.04s (- 0.68%) 5.81s 5.91s
Emit Time 6.36s (± 0.64%) 6.28s (± 0.53%) -0.09s (- 1.38%) 6.22s 6.34s
Total Time 15.12s (± 0.38%) 14.98s (± 0.41%) -0.14s (- 0.91%) 14.89s 15.12s
Compiler-Unions - node (v12.1.0, x64)
Memory used 193,709k (± 0.32%) 193,695k (± 0.32%) -14k (- 0.01%) 191,395k 194,269k
Parse Time 0.83s (± 0.71%) 0.83s (± 1.14%) 0.00s ( 0.00%) 0.82s 0.86s
Bind Time 0.48s (± 1.25%) 0.47s (± 1.01%) -0.00s (- 0.63%) 0.46s 0.48s
Check Time 6.76s (± 0.47%) 6.72s (± 0.71%) -0.04s (- 0.59%) 6.60s 6.83s
Emit Time 2.47s (± 1.45%) 2.47s (± 1.30%) -0.00s (- 0.12%) 2.41s 2.53s
Total Time 10.54s (± 0.47%) 10.49s (± 0.58%) -0.05s (- 0.43%) 10.33s 10.62s
Monaco - node (v12.1.0, x64)
Memory used 327,722k (± 0.02%) 327,789k (± 0.02%) +66k (+ 0.02%) 327,631k 327,957k
Parse Time 1.58s (± 0.79%) 1.59s (± 0.84%) +0.00s (+ 0.19%) 1.55s 1.61s
Bind Time 0.70s (± 0.98%) 0.70s (± 1.07%) +0.00s (+ 0.14%) 0.68s 0.72s
Check Time 5.86s (± 0.53%) 5.83s (± 0.41%) -0.03s (- 0.50%) 5.78s 5.88s
Emit Time 3.33s (± 0.75%) 3.32s (± 0.77%) -0.00s (- 0.09%) 3.29s 3.40s
Total Time 11.46s (± 0.38%) 11.43s (± 0.30%) -0.03s (- 0.25%) 11.37s 11.49s
TFS - node (v12.1.0, x64)
Memory used 290,679k (± 0.01%) 290,553k (± 0.06%) -126k (- 0.04%) 289,865k 290,738k
Parse Time 1.30s (± 0.63%) 1.30s (± 0.81%) -0.01s (- 0.54%) 1.27s 1.32s
Bind Time 0.68s (± 0.87%) 0.68s (± 1.22%) -0.01s (- 1.31%) 0.66s 0.70s
Check Time 5.42s (± 0.40%) 5.42s (± 0.46%) -0.01s (- 0.13%) 5.37s 5.48s
Emit Time 3.52s (± 1.29%) 3.53s (± 1.39%) +0.01s (+ 0.37%) 3.45s 3.68s
Total Time 10.93s (± 0.44%) 10.91s (± 0.70%) -0.01s (- 0.10%) 10.78s 11.16s
material-ui - node (v12.1.0, x64)
Memory used 437,278k (± 0.06%) 437,469k (± 0.01%) +191k (+ 0.04%) 437,343k 437,630k
Parse Time 1.83s (± 0.74%) 1.83s (± 0.53%) -0.00s (- 0.05%) 1.81s 1.86s
Bind Time 0.55s (± 0.62%) 0.55s (± 0.73%) -0.00s (- 0.36%) 0.54s 0.56s
Check Time 12.85s (± 0.93%) 12.76s (± 0.47%) -0.09s (- 0.70%) 12.66s 12.93s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.23s (± 0.81%) 15.14s (± 0.40%) -0.09s (- 0.61%) 15.06s 15.30s
xstate - node (v12.1.0, x64)
Memory used 549,467k (± 1.28%) 546,243k (± 0.01%) -3,224k (- 0.59%) 546,147k 546,426k
Parse Time 2.55s (± 0.54%) 2.55s (± 0.49%) -0.00s (- 0.08%) 2.51s 2.57s
Bind Time 0.89s (± 0.54%) 0.88s (± 0.45%) -0.01s (- 0.90%) 0.87s 0.89s
Check Time 1.49s (± 0.59%) 1.49s (± 0.68%) -0.00s (- 0.34%) 1.47s 1.50s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.00s (± 0.38%) 4.98s (± 0.37%) -0.01s (- 0.24%) 4.94s 5.03s
Angular - node (v14.15.1, x64)
Memory used 338,105k (± 0.01%) 338,086k (± 0.01%) -19k (- 0.01%) 338,015k 338,157k
Parse Time 2.07s (± 0.71%) 2.06s (± 1.14%) -0.01s (- 0.48%) 2.04s 2.15s
Bind Time 0.80s (± 0.60%) 0.79s (± 0.75%) -0.00s (- 0.38%) 0.78s 0.81s
Check Time 5.88s (± 0.29%) 5.87s (± 0.30%) -0.02s (- 0.31%) 5.82s 5.90s
Emit Time 6.27s (± 0.62%) 6.24s (± 0.52%) -0.03s (- 0.45%) 6.17s 6.31s
Total Time 15.02s (± 0.37%) 14.96s (± 0.32%) -0.06s (- 0.38%) 14.84s 15.07s
Compiler-Unions - node (v14.15.1, x64)
Memory used 190,782k (± 0.67%) 190,204k (± 0.02%) -579k (- 0.30%) 190,144k 190,273k
Parse Time 0.86s (± 0.90%) 0.86s (± 0.55%) -0.00s (- 0.23%) 0.85s 0.87s
Bind Time 0.49s (± 0.45%) 0.49s (± 1.19%) -0.00s (- 0.81%) 0.48s 0.50s
Check Time 6.76s (± 0.53%) 6.77s (± 0.65%) +0.01s (+ 0.22%) 6.69s 6.88s
Emit Time 2.41s (± 0.91%) 2.40s (± 1.04%) -0.01s (- 0.50%) 2.35s 2.46s
Total Time 10.52s (± 0.48%) 10.52s (± 0.58%) -0.00s (- 0.01%) 10.38s 10.65s
Monaco - node (v14.15.1, x64)
Memory used 326,565k (± 0.01%) 326,556k (± 0.01%) -9k (- 0.00%) 326,509k 326,620k
Parse Time 1.58s (± 0.41%) 1.59s (± 1.03%) +0.01s (+ 0.32%) 1.57s 1.64s
Bind Time 0.73s (± 0.80%) 0.73s (± 1.16%) +0.00s (+ 0.28%) 0.72s 0.75s
Check Time 5.70s (± 0.51%) 5.72s (± 0.40%) +0.02s (+ 0.44%) 5.67s 5.75s
Emit Time 3.38s (± 0.86%) 3.37s (± 0.82%) -0.01s (- 0.35%) 3.33s 3.44s
Total Time 11.39s (± 0.35%) 11.41s (± 0.51%) +0.02s (+ 0.18%) 11.31s 11.57s
TFS - node (v14.15.1, x64)
Memory used 289,693k (± 0.01%) 289,673k (± 0.01%) -20k (- 0.01%) 289,613k 289,734k
Parse Time 1.30s (± 0.53%) 1.30s (± 0.94%) +0.01s (+ 0.39%) 1.28s 1.33s
Bind Time 0.79s (± 0.56%) 0.79s (± 1.72%) 0.00s ( 0.00%) 0.74s 0.81s
Check Time 5.38s (± 0.47%) 5.38s (± 0.45%) 0.00s ( 0.00%) 5.34s 5.45s
Emit Time 3.60s (± 0.89%) 3.60s (± 0.67%) -0.01s (- 0.14%) 3.52s 3.65s
Total Time 11.07s (± 0.43%) 11.07s (± 0.45%) -0.00s (- 0.03%) 10.91s 11.16s
material-ui - node (v14.15.1, x64)
Memory used 435,600k (± 0.01%) 435,475k (± 0.06%) -125k (- 0.03%) 434,421k 435,650k
Parse Time 1.88s (± 0.55%) 1.88s (± 0.80%) -0.00s (- 0.16%) 1.86s 1.93s
Bind Time 0.58s (± 0.38%) 0.58s (± 0.57%) +0.00s (+ 0.17%) 0.57s 0.59s
Check Time 12.87s (± 0.56%) 12.89s (± 0.65%) +0.02s (+ 0.16%) 12.76s 13.09s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.33s (± 0.47%) 15.35s (± 0.58%) +0.02s (+ 0.14%) 15.21s 15.54s
xstate - node (v14.15.1, x64)
Memory used 544,051k (± 0.01%) 544,057k (± 0.00%) +6k (+ 0.00%) 544,009k 544,106k
Parse Time 2.61s (± 0.48%) 2.62s (± 0.46%) +0.00s (+ 0.15%) 2.60s 2.66s
Bind Time 0.98s (± 1.23%) 0.99s (± 1.18%) +0.01s (+ 0.92%) 0.96s 1.01s
Check Time 1.52s (± 0.50%) 1.52s (± 0.54%) +0.00s (+ 0.13%) 1.50s 1.53s
Emit Time 0.07s (± 0.00%) 0.07s (± 3.14%) +0.00s (+ 1.43%) 0.07s 0.08s
Total Time 5.18s (± 0.41%) 5.20s (± 0.33%) +0.01s (+ 0.25%) 5.16s 5.25s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v10.16.3, x64)
  • xstate - node (v12.1.0, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 50960 10
Baseline main 10

TSServer

Comparison Report - main..50960
Metric main 50960 Delta Best Worst
Compiler-UnionsTSServer - node (v10.16.3, x64)
Req 1 - updateOpen 1,407ms (± 0.57%) 1,402ms (± 0.49%) -5ms (- 0.33%) 1,392ms 1,420ms
Req 2 - geterr 4,126ms (± 0.76%) 4,081ms (± 0.61%) -46ms (- 1.11%) 4,015ms 4,136ms
Req 3 - references 231ms (± 0.59%) 229ms (± 0.58%) -1ms (- 0.56%) 227ms 232ms
Req 4 - navto 172ms (± 0.84%) 172ms (± 1.44%) -1ms (- 0.46%) 167ms 180ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 96ms (± 3.43%) 92ms (± 3.45%) 🟩-4ms (- 3.86%) 86ms 98ms
CompilerTSServer - node (v10.16.3, x64)
Req 1 - updateOpen 1,509ms (± 0.54%) 1,497ms (± 0.52%) -12ms (- 0.81%) 1,480ms 1,521ms
Req 2 - geterr 2,256ms (± 0.40%) 2,264ms (± 0.66%) +8ms (+ 0.34%) 2,234ms 2,304ms
Req 3 - references 243ms (± 0.63%) 245ms (± 0.45%) +2ms (+ 0.95%) 243ms 248ms
Req 4 - navto 186ms (± 1.04%) 184ms (± 1.26%) -2ms (- 1.24%) 178ms 189ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 61ms (± 1.88%) 61ms (± 1.84%) +0ms (+ 0.49%) 59ms 65ms
xstateTSServer - node (v10.16.3, x64)
Req 1 - updateOpen 2,092ms (± 0.54%) 2,089ms (± 0.52%) -3ms (- 0.15%) 2,068ms 2,111ms
Req 2 - geterr 799ms (± 0.31%) 796ms (± 0.83%) -2ms (- 0.30%) 786ms 818ms
Req 3 - references 101ms (± 2.30%) 100ms (± 2.27%) -1ms (- 0.89%) 96ms 107ms
Req 4 - navto 236ms (± 1.07%) 233ms (± 1.30%) -3ms (- 1.36%) 226ms 240ms
Req 5 - completionInfo count 3,205 (± 0.00%) 3,205 (± 0.00%) 0 ( 0.00%) 3,205 3,205
Req 5 - completionInfo 276ms (± 1.33%) 273ms (± 1.27%) -3ms (- 0.98%) 264ms 279ms
Compiler-UnionsTSServer - node (v12.1.0, x64)
Req 1 - updateOpen 1,423ms (± 0.93%) 1,410ms (± 1.07%) -13ms (- 0.93%) 1,373ms 1,443ms
Req 2 - geterr 3,401ms (± 0.55%) 3,387ms (± 0.67%) -14ms (- 0.41%) 3,339ms 3,432ms
Req 3 - references 222ms (± 0.37%) 220ms (± 0.76%) -3ms (- 1.17%) 217ms 223ms
Req 4 - navto 161ms (± 0.74%) 161ms (± 1.20%) -0ms (- 0.25%) 155ms 163ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 61ms (± 4.30%) 59ms (± 5.01%) -1ms (- 1.82%) 55ms 67ms
CompilerTSServer - node (v12.1.0, x64)
Req 1 - updateOpen 1,512ms (± 0.62%) 1,500ms (± 0.54%) -12ms (- 0.81%) 1,487ms 1,520ms
Req 2 - geterr 2,185ms (± 0.60%) 2,180ms (± 0.26%) -5ms (- 0.21%) 2,169ms 2,190ms
Req 3 - references 236ms (± 0.80%) 235ms (± 0.69%) -1ms (- 0.30%) 231ms 239ms
Req 4 - navto 172ms (± 1.39%) 171ms (± 0.97%) -1ms (- 0.70%) 167ms 174ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 59ms (± 2.32%) 58ms (± 2.78%) -1ms (- 1.86%) 55ms 63ms
xstateTSServer - node (v12.1.0, x64)
Req 1 - updateOpen 2,048ms (± 0.65%) 2,035ms (± 0.68%) -14ms (- 0.67%) 2,007ms 2,069ms
Req 2 - geterr 755ms (± 0.96%) 748ms (± 0.50%) -7ms (- 0.93%) 741ms 757ms
Req 3 - references 68ms (± 1.18%) 68ms (± 4.40%) +1ms (+ 0.74%) 65ms 80ms
Req 4 - navto 224ms (± 1.12%) 224ms (± 0.47%) +0ms (+ 0.13%) 222ms 226ms
Req 5 - completionInfo count 3,205 (± 0.00%) 3,205 (± 0.00%) 0 ( 0.00%) 3,205 3,205
Req 5 - completionInfo 269ms (± 1.25%) 268ms (± 0.75%) -1ms (- 0.48%) 263ms 272ms
Compiler-UnionsTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 1,458ms (± 0.63%) 1,455ms (± 0.74%) -4ms (- 0.26%) 1,430ms 1,480ms
Req 2 - geterr 3,527ms (± 0.38%) 3,515ms (± 0.69%) -12ms (- 0.34%) 3,459ms 3,591ms
Req 3 - references 233ms (± 0.66%) 230ms (± 0.58%) -3ms (- 1.12%) 227ms 233ms
Req 4 - navto 170ms (± 0.92%) 169ms (± 0.74%) -1ms (- 0.59%) 166ms 172ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 55ms (± 0.94%) 59ms (± 7.40%) +4ms (+ 6.72%) 54ms 68ms
CompilerTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 1,540ms (± 0.56%) 1,522ms (± 0.44%) -18ms (- 1.19%) 1,509ms 1,538ms
Req 2 - geterr 2,332ms (± 0.41%) 2,317ms (± 0.44%) -15ms (- 0.64%) 2,290ms 2,334ms
Req 3 - references 244ms (± 0.56%) 242ms (± 0.41%) -2ms (- 0.62%) 241ms 245ms
Req 4 - navto 179ms (± 0.70%) 178ms (± 0.67%) -1ms (- 0.61%) 175ms 180ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 55ms (± 1.35%) 55ms (± 1.06%) -1ms (- 1.08%) 53ms 56ms
xstateTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 2,159ms (± 0.87%) 2,160ms (± 0.76%) +1ms (+ 0.04%) 2,126ms 2,197ms
Req 2 - geterr 768ms (± 0.37%) 768ms (± 0.36%) +1ms (+ 0.09%) 764ms 774ms
Req 3 - references 68ms (± 1.88%) 68ms (± 1.75%) 0ms ( 0.00%) 64ms 70ms
Req 4 - navto 227ms (± 0.55%) 226ms (± 0.64%) -1ms (- 0.26%) 224ms 230ms
Req 5 - completionInfo count 3,205 (± 0.00%) 3,205 (± 0.00%) 0 ( 0.00%) 3,205 3,205
Req 5 - completionInfo 274ms (± 1.22%) 271ms (± 1.17%) -4ms (- 1.31%) 267ms 281ms
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v10.16.3, x64)
  • Compiler-UnionsTSServer - node (v12.1.0, x64)
  • Compiler-UnionsTSServer - node (v14.15.1, x64)
  • CompilerTSServer - node (v10.16.3, x64)
  • CompilerTSServer - node (v12.1.0, x64)
  • CompilerTSServer - node (v14.15.1, x64)
  • xstateTSServer - node (v10.16.3, x64)
  • xstateTSServer - node (v12.1.0, x64)
  • xstateTSServer - node (v14.15.1, x64)
Benchmark Name Iterations
Current 50960 10
Baseline main 10

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

@RyanCavanaugh Here are the results of running the top-repos suite comparing main and refs/pull/50960/merge:

Everything looks good!

@mxsdev
Copy link
Author

mxsdev commented Sep 29, 2022

As a bystander - I applaud the description of this PR 👏

Ha, thanks! I hope it helps the reviewers more than it confuses them 😅

@Andarist
Copy link
Contributor

This PR would also fix #46310 and thus it would supersed my PR attempting to fix that issue: #48823

@mxsdev could you add a test case from my PR here?

Comment on lines +27546 to +27550
// If the apparent type is any, we cannot lose any information by instantiating,
// so we might as well try and possibly get a useful type
if (apparentType === anyType) {
return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In what cases this is helpful? It's not totally clear to me what exactly the apparent type is but if I take into account the comment above the getApparentType then it should return the base constraint for type parameters.

Given that this PR introduces only tests that have a base constraint that is not any - I wonder, what existing test cases does this branch satisfy?

if (apparentType === anyType) {
return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper);
}
else if((apparentType.flags & TypeFlags.Union)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
else if((apparentType.flags & TypeFlags.Union)) {
else if ((apparentType.flags & TypeFlags.Union)) {


if (!signatureList) {
// At this point, the signature type is guaranteed to eventually collapse into any
// because it is a union of incompatible function signatures
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// because it is a union of incompatible function signatures
// because it is a union of incompatible function signatures or there is no signature at all

@ahejlsberg
Copy link
Member

@mxsdev I think it is a good idea to fix this issue, but I think there's a much simpler way to implement it. I will put up a PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default type in generic react component not inherited in callbacks
5 participants