Skip to content

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

Closed
Max Stoumen (mxsdev) wants to merge 3 commits into
microsoft:mainfrom
mxsdev:fix-50858
Closed

fix(50858): parameters in function signatures inferred from default generic types sometimes not assigned instantiated types#50960
Max Stoumen (mxsdev) wants to merge 3 commits into
microsoft:mainfrom
mxsdev:fix-50858

Conversation

@mxsdev

@mxsdevMax Stoumen (mxsdev) commented Sep 27, 2022

Copy link
Copy Markdown

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:

typeType={a: (e: string)=>void,b: (e: number)=>void,}functionf1<TextendskeyofType='a'>(props: Type[T]): any{returnnull}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.

@mxsdev

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@Andarist

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/compiler/checker.ts Outdated
@RyanCavanaugh

Copy link
Copy Markdown
Member

@typescript-bot

TypeScript Bot (typescript-bot) commented Sep 28, 2022

Copy link
Copy Markdown
Contributor

Heya Ryan Cavanaugh (@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

TypeScript Bot (typescript-bot) commented Sep 28, 2022

Copy link
Copy Markdown
Contributor

Heya Ryan Cavanaugh (@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
Copy Markdown
Contributor

Ryan Cavanaugh (@RyanCavanaugh)
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - main..50960
Metricmain50960DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used362,505k (± 0.02%)362,449k (± 0.02%)-56k (- 0.02%)362,300k362,626k
Parse Time2.08s (± 0.62%)2.08s (± 0.45%)-0.00s (- 0.14%)2.06s2.10s
Bind Time0.79s (± 1.19%)0.78s (± 0.67%)-0.01s (- 1.39%)0.77s0.79s
Check Time6.21s (± 0.56%)6.20s (± 0.49%)-0.01s (- 0.14%)6.10s6.26s
Emit Time6.05s (± 0.46%)6.04s (± 0.79%)-0.01s (- 0.17%)5.96s6.14s
Total Time15.14s (± 0.45%)15.11s (± 0.24%)-0.03s (- 0.20%)15.01s15.19s
Compiler-Unions - node (v10.16.3, x64)
Memory used206,064k (± 0.28%)206,015k (± 0.30%)-50k (- 0.02%)203,561k206,408k
Parse Time0.85s (± 0.53%)0.84s (± 0.40%)-0.01s (- 0.94%)0.83s0.85s
Bind Time0.47s (± 1.18%)0.46s (± 0.74%)-0.01s (- 1.91%)0.46s0.47s
Check Time8.52s (± 0.69%)8.42s (± 0.97%)-0.10s (- 1.16%)8.29s8.66s
Emit Time2.47s (± 1.41%)2.45s (± 0.90%)-0.02s (- 0.81%)2.41s2.50s
Total Time12.31s (± 0.69%)12.18s (± 0.70%)-0.13s (- 1.07%)12.04s12.40s
Monaco - node (v10.16.3, x64)
Memory used344,783k (± 0.02%)344,776k (± 0.02%)-6k (- 0.00%)344,555k344,892k
Parse Time1.61s (± 0.54%)1.60s (± 0.95%)-0.01s (- 0.50%)1.57s1.65s
Bind Time0.70s (± 0.88%)0.70s (± 1.16%)-0.00s (- 0.14%)0.69s0.73s
Check Time6.23s (± 0.64%)6.22s (± 0.44%)-0.00s (- 0.03%)6.17s6.29s
Emit Time3.26s (± 0.90%)3.24s (± 0.42%)-0.02s (- 0.49%)3.21s3.27s
Total Time11.79s (± 0.28%)11.77s (± 0.26%)-0.02s (- 0.19%)11.70s11.84s
TFS - node (v10.16.3, x64)
Memory used306,046k (± 0.02%)306,059k (± 0.02%)+13k (+ 0.00%)305,955k306,178k
Parse Time1.30s (± 0.77%)1.28s (± 0.65%)-0.01s (- 0.93%)1.27s1.31s
Bind Time0.67s (± 0.83%)0.67s (± 0.67%)0.00s ( 0.00%)0.66s0.68s
Check Time5.52s (± 0.49%)5.49s (± 0.44%)-0.03s (- 0.49%)5.44s5.56s
Emit Time3.45s (± 1.17%)3.42s (± 1.18%)-0.03s (- 0.87%)3.33s3.55s
Total Time10.93s (± 0.57%)10.86s (± 0.42%)-0.06s (- 0.59%)10.76s10.98s
material-ui - node (v10.16.3, x64)
Memory used458,146k (± 0.02%)458,188k (± 0.01%)+42k (+ 0.01%)458,073k458,266k
Parse Time1.83s (± 0.48%)1.84s (± 0.71%)+0.01s (+ 0.27%)1.81s1.85s
Bind Time0.58s (± 1.91%)0.57s (± 2.31%)-0.00s (- 0.87%)0.55s0.60s
Check Time15.64s (± 0.75%)15.60s (± 0.77%)-0.04s (- 0.26%)15.44s15.95s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time18.05s (± 0.67%)18.01s (± 0.67%)-0.04s (- 0.23%)17.86s18.37s
xstate - node (v10.16.3, x64)
Memory used587,405k (± 1.62%)580,964k (± 0.01%)-6,441k (- 1.10%)580,823k581,144k
Parse Time2.60s (± 0.53%)2.60s (± 0.36%)-0.01s (- 0.23%)2.58s2.62s
Bind Time0.90s (± 0.64%)0.90s (± 0.49%)-0.00s (- 0.11%)0.89s0.91s
Check Time1.61s (± 0.51%)1.59s (± 0.51%)-0.01s (- 0.87%)1.58s1.61s
Emit Time0.07s (± 4.66%)0.07s (± 3.14%)-0.00s (- 2.74%)0.07s0.08s
Total Time5.19s (± 0.40%)5.16s (± 0.28%)-0.03s (- 0.52%)5.13s5.19s
Angular - node (v12.1.0, x64)
Memory used340,065k (± 0.03%)339,996k (± 0.02%)-69k (- 0.02%)339,858k340,206k
Parse Time2.09s (± 0.83%)2.09s (± 0.48%)-0.01s (- 0.33%)2.07s2.12s
Bind Time0.77s (± 1.20%)0.77s (± 0.91%)-0.00s (- 0.39%)0.75s0.78s
Check Time5.89s (± 0.52%)5.85s (± 0.45%)-0.04s (- 0.68%)5.81s5.91s
Emit Time6.36s (± 0.64%)6.28s (± 0.53%)-0.09s (- 1.38%)6.22s6.34s
Total Time15.12s (± 0.38%)14.98s (± 0.41%)-0.14s (- 0.91%)14.89s15.12s
Compiler-Unions - node (v12.1.0, x64)
Memory used193,709k (± 0.32%)193,695k (± 0.32%)-14k (- 0.01%)191,395k194,269k
Parse Time0.83s (± 0.71%)0.83s (± 1.14%)0.00s ( 0.00%)0.82s0.86s
Bind Time0.48s (± 1.25%)0.47s (± 1.01%)-0.00s (- 0.63%)0.46s0.48s
Check Time6.76s (± 0.47%)6.72s (± 0.71%)-0.04s (- 0.59%)6.60s6.83s
Emit Time2.47s (± 1.45%)2.47s (± 1.30%)-0.00s (- 0.12%)2.41s2.53s
Total Time10.54s (± 0.47%)10.49s (± 0.58%)-0.05s (- 0.43%)10.33s10.62s
Monaco - node (v12.1.0, x64)
Memory used327,722k (± 0.02%)327,789k (± 0.02%)+66k (+ 0.02%)327,631k327,957k
Parse Time1.58s (± 0.79%)1.59s (± 0.84%)+0.00s (+ 0.19%)1.55s1.61s
Bind Time0.70s (± 0.98%)0.70s (± 1.07%)+0.00s (+ 0.14%)0.68s0.72s
Check Time5.86s (± 0.53%)5.83s (± 0.41%)-0.03s (- 0.50%)5.78s5.88s
Emit Time3.33s (± 0.75%)3.32s (± 0.77%)-0.00s (- 0.09%)3.29s3.40s
Total Time11.46s (± 0.38%)11.43s (± 0.30%)-0.03s (- 0.25%)11.37s11.49s
TFS - node (v12.1.0, x64)
Memory used290,679k (± 0.01%)290,553k (± 0.06%)-126k (- 0.04%)289,865k290,738k
Parse Time1.30s (± 0.63%)1.30s (± 0.81%)-0.01s (- 0.54%)1.27s1.32s
Bind Time0.68s (± 0.87%)0.68s (± 1.22%)-0.01s (- 1.31%)0.66s0.70s
Check Time5.42s (± 0.40%)5.42s (± 0.46%)-0.01s (- 0.13%)5.37s5.48s
Emit Time3.52s (± 1.29%)3.53s (± 1.39%)+0.01s (+ 0.37%)3.45s3.68s
Total Time10.93s (± 0.44%)10.91s (± 0.70%)-0.01s (- 0.10%)10.78s11.16s
material-ui - node (v12.1.0, x64)
Memory used437,278k (± 0.06%)437,469k (± 0.01%)+191k (+ 0.04%)437,343k437,630k
Parse Time1.83s (± 0.74%)1.83s (± 0.53%)-0.00s (- 0.05%)1.81s1.86s
Bind Time0.55s (± 0.62%)0.55s (± 0.73%)-0.00s (- 0.36%)0.54s0.56s
Check Time12.85s (± 0.93%)12.76s (± 0.47%)-0.09s (- 0.70%)12.66s12.93s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.23s (± 0.81%)15.14s (± 0.40%)-0.09s (- 0.61%)15.06s15.30s
xstate - node (v12.1.0, x64)
Memory used549,467k (± 1.28%)546,243k (± 0.01%)-3,224k (- 0.59%)546,147k546,426k
Parse Time2.55s (± 0.54%)2.55s (± 0.49%)-0.00s (- 0.08%)2.51s2.57s
Bind Time0.89s (± 0.54%)0.88s (± 0.45%)-0.01s (- 0.90%)0.87s0.89s
Check Time1.49s (± 0.59%)1.49s (± 0.68%)-0.00s (- 0.34%)1.47s1.50s
Emit Time0.07s (± 0.00%)0.07s (± 0.00%)0.00s ( 0.00%)0.07s0.07s
Total Time5.00s (± 0.38%)4.98s (± 0.37%)-0.01s (- 0.24%)4.94s5.03s
Angular - node (v14.15.1, x64)
Memory used338,105k (± 0.01%)338,086k (± 0.01%)-19k (- 0.01%)338,015k338,157k
Parse Time2.07s (± 0.71%)2.06s (± 1.14%)-0.01s (- 0.48%)2.04s2.15s
Bind Time0.80s (± 0.60%)0.79s (± 0.75%)-0.00s (- 0.38%)0.78s0.81s
Check Time5.88s (± 0.29%)5.87s (± 0.30%)-0.02s (- 0.31%)5.82s5.90s
Emit Time6.27s (± 0.62%)6.24s (± 0.52%)-0.03s (- 0.45%)6.17s6.31s
Total Time15.02s (± 0.37%)14.96s (± 0.32%)-0.06s (- 0.38%)14.84s15.07s
Compiler-Unions - node (v14.15.1, x64)
Memory used190,782k (± 0.67%)190,204k (± 0.02%)-579k (- 0.30%)190,144k190,273k
Parse Time0.86s (± 0.90%)0.86s (± 0.55%)-0.00s (- 0.23%)0.85s0.87s
Bind Time0.49s (± 0.45%)0.49s (± 1.19%)-0.00s (- 0.81%)0.48s0.50s
Check Time6.76s (± 0.53%)6.77s (± 0.65%)+0.01s (+ 0.22%)6.69s6.88s
Emit Time2.41s (± 0.91%)2.40s (± 1.04%)-0.01s (- 0.50%)2.35s2.46s
Total Time10.52s (± 0.48%)10.52s (± 0.58%)-0.00s (- 0.01%)10.38s10.65s
Monaco - node (v14.15.1, x64)
Memory used326,565k (± 0.01%)326,556k (± 0.01%)-9k (- 0.00%)326,509k326,620k
Parse Time1.58s (± 0.41%)1.59s (± 1.03%)+0.01s (+ 0.32%)1.57s1.64s
Bind Time0.73s (± 0.80%)0.73s (± 1.16%)+0.00s (+ 0.28%)0.72s0.75s
Check Time5.70s (± 0.51%)5.72s (± 0.40%)+0.02s (+ 0.44%)5.67s5.75s
Emit Time3.38s (± 0.86%)3.37s (± 0.82%)-0.01s (- 0.35%)3.33s3.44s
Total Time11.39s (± 0.35%)11.41s (± 0.51%)+0.02s (+ 0.18%)11.31s11.57s
TFS - node (v14.15.1, x64)
Memory used289,693k (± 0.01%)289,673k (± 0.01%)-20k (- 0.01%)289,613k289,734k
Parse Time1.30s (± 0.53%)1.30s (± 0.94%)+0.01s (+ 0.39%)1.28s1.33s
Bind Time0.79s (± 0.56%)0.79s (± 1.72%)0.00s ( 0.00%)0.74s0.81s
Check Time5.38s (± 0.47%)5.38s (± 0.45%)0.00s ( 0.00%)5.34s5.45s
Emit Time3.60s (± 0.89%)3.60s (± 0.67%)-0.01s (- 0.14%)3.52s3.65s
Total Time11.07s (± 0.43%)11.07s (± 0.45%)-0.00s (- 0.03%)10.91s11.16s
material-ui - node (v14.15.1, x64)
Memory used435,600k (± 0.01%)435,475k (± 0.06%)-125k (- 0.03%)434,421k435,650k
Parse Time1.88s (± 0.55%)1.88s (± 0.80%)-0.00s (- 0.16%)1.86s1.93s
Bind Time0.58s (± 0.38%)0.58s (± 0.57%)+0.00s (+ 0.17%)0.57s0.59s
Check Time12.87s (± 0.56%)12.89s (± 0.65%)+0.02s (+ 0.16%)12.76s13.09s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.33s (± 0.47%)15.35s (± 0.58%)+0.02s (+ 0.14%)15.21s15.54s
xstate - node (v14.15.1, x64)
Memory used544,051k (± 0.01%)544,057k (± 0.00%)+6k (+ 0.00%)544,009k544,106k
Parse Time2.61s (± 0.48%)2.62s (± 0.46%)+0.00s (+ 0.15%)2.60s2.66s
Bind Time0.98s (± 1.23%)0.99s (± 1.18%)+0.01s (+ 0.92%)0.96s1.01s
Check Time1.52s (± 0.50%)1.52s (± 0.54%)+0.00s (+ 0.13%)1.50s1.53s
Emit Time0.07s (± 0.00%)0.07s (± 3.14%)+0.00s (+ 1.43%)0.07s0.08s
Total Time5.18s (± 0.41%)5.20s (± 0.33%)+0.01s (+ 0.25%)5.16s5.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)
BenchmarkNameIterations
Current5096010
Baselinemain10

TSServer

Comparison Report - main..50960
Metricmain50960DeltaBestWorst
Compiler-UnionsTSServer - node (v10.16.3, x64)
Req 1 - updateOpen1,407ms (± 0.57%)1,402ms (± 0.49%)-5ms (- 0.33%)1,392ms1,420ms
Req 2 - geterr4,126ms (± 0.76%)4,081ms (± 0.61%)-46ms (- 1.11%)4,015ms4,136ms
Req 3 - references231ms (± 0.59%)229ms (± 0.58%)-1ms (- 0.56%)227ms232ms
Req 4 - navto172ms (± 0.84%)172ms (± 1.44%)-1ms (- 0.46%)167ms180ms
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)0 ( 0.00%)1,3561,356
Req 5 - completionInfo96ms (± 3.43%)92ms (± 3.45%)🟩-4ms (- 3.86%)86ms98ms
CompilerTSServer - node (v10.16.3, x64)
Req 1 - updateOpen1,509ms (± 0.54%)1,497ms (± 0.52%)-12ms (- 0.81%)1,480ms1,521ms
Req 2 - geterr2,256ms (± 0.40%)2,264ms (± 0.66%)+8ms (+ 0.34%)2,234ms2,304ms
Req 3 - references243ms (± 0.63%)245ms (± 0.45%)+2ms (+ 0.95%)243ms248ms
Req 4 - navto186ms (± 1.04%)184ms (± 1.26%)-2ms (- 1.24%)178ms189ms
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)0 ( 0.00%)1,5181,518
Req 5 - completionInfo61ms (± 1.88%)61ms (± 1.84%)+0ms (+ 0.49%)59ms65ms
xstateTSServer - node (v10.16.3, x64)
Req 1 - updateOpen2,092ms (± 0.54%)2,089ms (± 0.52%)-3ms (- 0.15%)2,068ms2,111ms
Req 2 - geterr799ms (± 0.31%)796ms (± 0.83%)-2ms (- 0.30%)786ms818ms
Req 3 - references101ms (± 2.30%)100ms (± 2.27%)-1ms (- 0.89%)96ms107ms
Req 4 - navto236ms (± 1.07%)233ms (± 1.30%)-3ms (- 1.36%)226ms240ms
Req 5 - completionInfo count3,205 (± 0.00%)3,205 (± 0.00%)0 ( 0.00%)3,2053,205
Req 5 - completionInfo276ms (± 1.33%)273ms (± 1.27%)-3ms (- 0.98%)264ms279ms
Compiler-UnionsTSServer - node (v12.1.0, x64)
Req 1 - updateOpen1,423ms (± 0.93%)1,410ms (± 1.07%)-13ms (- 0.93%)1,373ms1,443ms
Req 2 - geterr3,401ms (± 0.55%)3,387ms (± 0.67%)-14ms (- 0.41%)3,339ms3,432ms
Req 3 - references222ms (± 0.37%)220ms (± 0.76%)-3ms (- 1.17%)217ms223ms
Req 4 - navto161ms (± 0.74%)161ms (± 1.20%)-0ms (- 0.25%)155ms163ms
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)0 ( 0.00%)1,3561,356
Req 5 - completionInfo61ms (± 4.30%)59ms (± 5.01%)-1ms (- 1.82%)55ms67ms
CompilerTSServer - node (v12.1.0, x64)
Req 1 - updateOpen1,512ms (± 0.62%)1,500ms (± 0.54%)-12ms (- 0.81%)1,487ms1,520ms
Req 2 - geterr2,185ms (± 0.60%)2,180ms (± 0.26%)-5ms (- 0.21%)2,169ms2,190ms
Req 3 - references236ms (± 0.80%)235ms (± 0.69%)-1ms (- 0.30%)231ms239ms
Req 4 - navto172ms (± 1.39%)171ms (± 0.97%)-1ms (- 0.70%)167ms174ms
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)0 ( 0.00%)1,5181,518
Req 5 - completionInfo59ms (± 2.32%)58ms (± 2.78%)-1ms (- 1.86%)55ms63ms
xstateTSServer - node (v12.1.0, x64)
Req 1 - updateOpen2,048ms (± 0.65%)2,035ms (± 0.68%)-14ms (- 0.67%)2,007ms2,069ms
Req 2 - geterr755ms (± 0.96%)748ms (± 0.50%)-7ms (- 0.93%)741ms757ms
Req 3 - references68ms (± 1.18%)68ms (± 4.40%)+1ms (+ 0.74%)65ms80ms
Req 4 - navto224ms (± 1.12%)224ms (± 0.47%)+0ms (+ 0.13%)222ms226ms
Req 5 - completionInfo count3,205 (± 0.00%)3,205 (± 0.00%)0 ( 0.00%)3,2053,205
Req 5 - completionInfo269ms (± 1.25%)268ms (± 0.75%)-1ms (- 0.48%)263ms272ms
Compiler-UnionsTSServer - node (v14.15.1, x64)
Req 1 - updateOpen1,458ms (± 0.63%)1,455ms (± 0.74%)-4ms (- 0.26%)1,430ms1,480ms
Req 2 - geterr3,527ms (± 0.38%)3,515ms (± 0.69%)-12ms (- 0.34%)3,459ms3,591ms
Req 3 - references233ms (± 0.66%)230ms (± 0.58%)-3ms (- 1.12%)227ms233ms
Req 4 - navto170ms (± 0.92%)169ms (± 0.74%)-1ms (- 0.59%)166ms172ms
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)0 ( 0.00%)1,3561,356
Req 5 - completionInfo55ms (± 0.94%)59ms (± 7.40%)+4ms (+ 6.72%)54ms68ms
CompilerTSServer - node (v14.15.1, x64)
Req 1 - updateOpen1,540ms (± 0.56%)1,522ms (± 0.44%)-18ms (- 1.19%)1,509ms1,538ms
Req 2 - geterr2,332ms (± 0.41%)2,317ms (± 0.44%)-15ms (- 0.64%)2,290ms2,334ms
Req 3 - references244ms (± 0.56%)242ms (± 0.41%)-2ms (- 0.62%)241ms245ms
Req 4 - navto179ms (± 0.70%)178ms (± 0.67%)-1ms (- 0.61%)175ms180ms
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)0 ( 0.00%)1,5181,518
Req 5 - completionInfo55ms (± 1.35%)55ms (± 1.06%)-1ms (- 1.08%)53ms56ms
xstateTSServer - node (v14.15.1, x64)
Req 1 - updateOpen2,159ms (± 0.87%)2,160ms (± 0.76%)+1ms (+ 0.04%)2,126ms2,197ms
Req 2 - geterr768ms (± 0.37%)768ms (± 0.36%)+1ms (+ 0.09%)764ms774ms
Req 3 - references68ms (± 1.88%)68ms (± 1.75%)0ms ( 0.00%)64ms70ms
Req 4 - navto227ms (± 0.55%)226ms (± 0.64%)-1ms (- 0.26%)224ms230ms
Req 5 - completionInfo count3,205 (± 0.00%)3,205 (± 0.00%)0 ( 0.00%)3,2053,205
Req 5 - completionInfo274ms (± 1.22%)271ms (± 1.17%)-4ms (- 1.31%)267ms281ms
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)
BenchmarkNameIterations
Current5096010
Baselinemain10

Developer Information:

Download Benchmark

@typescript-bot

Copy link
Copy Markdown
Contributor

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

Everything looks good!

@mxsdev

Copy link
Copy Markdown
Author

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
Copy Markdown
Contributor

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

Max Stoumen (@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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
elseif((apparentType.flags&TypeFlags.Union)){
elseif((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
Copy Markdown
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
Copy Markdown
Member

Max Stoumen (@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 freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Backlog BugPRs 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

@mxsdev@Andarist@RyanCavanaugh@typescript-bot@ahejlsberg