Skip to content

Reuse single errored signature candidate as resolved signature #61787

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

fixes #61500

@Copilot Copilot AI review requested due to automatic review settings May 30, 2025 19:53
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog May 30, 2025
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label May 30, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances overload resolution by reusing a single errored signature candidate as the resolved signature and updates tests and baselines accordingly.

  • Adjust overload failure logic in checker.ts to prefer a lone errored candidate
  • Add new fourslash tests for failed inference in context-sensitive arguments
  • Update numerous baseline reference files to reflect the new signature resolution behavior

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/compiler/checker.ts Adjust candidate selection to reuse a single errored signature
tests/cases/fourslash/quickInfoFailedInferenceWithContextSensitiveArg2.ts Add quickInfo test for second context-sensitive failure scenario
tests/cases/fourslash/quickInfoFailedInferenceWithContextSensitiveArg1.ts Add quickInfo test for first context-sensitive failure scenario
tests/cases/fourslash/completionsFailedInferenceWithContextSensitiveArg1.ts Add completion test for context-sensitive inference failure
tests/cases/conformance/types/typeRelationships/typeInference/contextualSignatureInstantiation.ts Update test to use baz signature reuse with explicit b2
tests/baselines/reference/promiseTry.types Update expected return type for Promise.try
tests/baselines/reference/promisePermutations3.types Update expected IPromise chaining result
tests/baselines/reference/partiallyAnnotatedFunctionInferenceError.types Revise expected inference error outputs
tests/baselines/reference/genericCallWithFunctionTypedArguments5.types Correct expected return type from function-typed argument calls
tests/baselines/reference/generatorTypeCheck62.types Update expected strategy generator signature
tests/baselines/reference/contextualSignatureInstantiation.types Reflect new baz return types and renamed b2
tests/baselines/reference/contextualSignatureInstantiation.symbols Update symbol declarations for b2 and d vars
tests/baselines/reference/contextualSignatureInstantiation.js Adjust JS baseline for b2 and d variable initializations
tests/baselines/reference/contextualSignatureInstantiation.errors.txt Update error messages and variable names from b to b2

@Andarist Andarist marked this pull request as draft May 30, 2025 20:54
@Andarist Andarist marked this pull request as ready for review May 31, 2025 08:27
@@ -33,8 +33,8 @@ declare function testError<T extends C>(a: (t: T, t1: T) => void): T

// more args
testError((t1: D, t2, t3) => {})
>testError((t1: D, t2, t3) => {}) : C
> : ^
>testError((t1: D, t2, t3) => {}) : any
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks bad but this call errors so I think it's a fair game that the returned type changes - as it doesn't quite matter anyway.

The reason it got changed is simple - this got inferred from the implicit any assigned to t2 and t3. The same was always inferred here internally. It's just the final assigned signature was the one computed by inferSignatureInstantiationForOverloadFailure and that ignores context--sensitive arguments.

All of the changes in baselines can be attributed to the same thing. It's just any here is, of course, extra suspicious.

Maybe this could be "improved" but given this callback has more parameters than the contextual signature - the contextual signature is not selected so it can't assign "better" types to t2 and t3. This gets ignored in getContextualCallSignature based on the isAritySmaller check.

Comment on lines +23 to +24
var b2: number | string;
var b2 = baz(b2, b2, g); // Should be number | string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why the change here? it's because now the previous calls are able to change the assigned type to b (by not ignoring generic functions we infer string/number instead of unknown). So the contextual return type here changed from string | number to string and that introduced the error. But that never was the intention of this test case anyway - so I just separated this to decouple this from CFA type changes

@Mateusnasciment
Copy link

would it make sense to emit a warning when any is inferred in these partially annotated functions, to help catch unintended inference?

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 6, 2025

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests with tsc comparing main and refs/pull/61787/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 34 34 ~ ~ ~ p=1.000 n=6
Symbols 62,390 62,390 ~ ~ ~ p=1.000 n=6
Types 50,395 50,395 ~ ~ ~ p=1.000 n=6
Memory used 196,572k (± 0.08%) 196,086k (± 0.78%) ~ 192,977k 196,729k p=0.298 n=6
Parse Time 1.59s (± 1.23%) 1.59s (± 1.24%) ~ 1.55s 1.60s p=0.357 n=6
Bind Time 0.88s (± 0.96%) 0.88s (± 1.61%) ~ 0.86s 0.90s p=0.548 n=6
Check Time 11.83s (± 0.69%) 11.81s (± 0.84%) ~ 11.70s 11.97s p=0.748 n=6
Emit Time 3.39s (± 3.47%) 3.37s (± 2.59%) ~ 3.29s 3.54s p=1.000 n=6
Total Time 17.69s (± 0.51%) 17.64s (± 0.74%) ~ 17.45s 17.82s p=0.748 n=6
angular-1 - node (v18.15.0, x64)
Errors 56 56 ~ ~ ~ p=1.000 n=6
Symbols 949,240 949,228 -12 (- 0.00%) ~ ~ p=0.001 n=6
Types 411,065 411,065 ~ ~ ~ p=1.000 n=6
Memory used 1,225,316k (± 0.01%) 1,225,320k (± 0.00%) ~ 1,225,242k 1,225,396k p=0.810 n=6
Parse Time 8.03s (± 0.75%) 8.01s (± 0.62%) ~ 7.96s 8.08s p=0.748 n=6
Bind Time 2.29s (± 0.51%) 2.30s (± 0.98%) ~ 2.28s 2.33s p=0.730 n=6
Check Time 38.10s (± 0.39%) 38.19s (± 0.29%) ~ 38.00s 38.29s p=0.298 n=6
Emit Time 17.90s (± 0.66%) 17.95s (± 0.69%) ~ 17.77s 18.14s p=0.521 n=6
Total Time 66.32s (± 0.32%) 66.45s (± 0.13%) ~ 66.33s 66.53s p=0.229 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,577,125 2,576,904 -221 (- 0.01%) ~ ~ p=0.001 n=6
Types 892,437 892,364 -73 (- 0.01%) ~ ~ p=0.001 n=6
Memory used 2,857,483k (± 0.00%) 2,857,350k (± 0.00%) ~ 2,857,116k 2,857,497k p=0.066 n=6
Parse Time 11.00s (± 0.49%) 10.99s (± 0.25%) ~ 10.97s 11.04s p=0.422 n=6
Bind Time 2.82s (± 0.32%) 2.80s (± 0.93%) ~ 2.78s 2.85s p=0.063 n=6
Check Time 106.36s (± 1.58%) 106.36s (± 1.84%) ~ 104.53s 109.87s p=0.936 n=6
Emit Time 0.38s (± 2.23%) 0.38s (± 2.23%) ~ 0.37s 0.39s p=0.796 n=6
Total Time 120.56s (± 1.37%) 120.53s (± 1.61%) ~ 118.69s 124.02s p=0.936 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,228,872 1,228,874 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 267,514 267,514 ~ ~ ~ p=1.000 n=6
Memory used 2,731,011k (±14.66%) 2,852,990k (±13.27%) ~ 2,363,451k 3,099,145k p=0.810 n=6
Parse Time 6.61s (± 1.38%) 6.63s (± 1.27%) ~ 6.51s 6.71s p=0.872 n=6
Bind Time 2.16s (± 0.94%) 2.16s (± 1.30%) ~ 2.11s 2.19s p=0.935 n=6
Check Time 42.88s (± 0.56%) 42.97s (± 0.38%) ~ 42.70s 43.13s p=0.689 n=6
Emit Time 3.52s (± 3.73%) 3.55s (± 4.14%) ~ 3.39s 3.78s p=0.809 n=6
Total Time 55.17s (± 0.71%) 55.31s (± 0.36%) ~ 54.93s 55.46s p=0.689 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,228,872 1,228,874 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 267,514 267,514 ~ ~ ~ p=1.000 n=6
Memory used 2,919,449k (±12.86%) 2,919,117k (±12.89%) ~ 2,432,409k 3,163,015k p=0.936 n=6
Parse Time 6.84s (± 1.81%) 6.83s (± 1.28%) ~ 6.70s 6.94s p=0.810 n=6
Bind Time 2.17s (± 1.11%) 2.20s (± 2.42%) ~ 2.14s 2.28s p=0.520 n=6
Check Time 43.01s (± 0.69%) 42.99s (± 0.57%) ~ 42.71s 43.34s p=0.810 n=6
Emit Time 3.49s (± 3.07%) 3.50s (± 2.96%) ~ 3.41s 3.68s p=0.936 n=6
Total Time 55.50s (± 0.65%) 55.52s (± 0.47%) ~ 55.11s 55.84s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 263,510 263,512 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 107,227 107,227 ~ ~ ~ p=1.000 n=6
Memory used 442,143k (± 0.01%) 442,144k (± 0.03%) ~ 442,006k 442,356k p=0.575 n=6
Parse Time 3.57s (± 1.19%) 3.52s (± 0.83%) ~ 3.49s 3.56s p=0.091 n=6
Bind Time 1.32s (± 1.55%) 1.32s (± 0.78%) ~ 1.31s 1.34s p=0.565 n=6
Check Time 18.94s (± 0.39%) 18.95s (± 0.36%) ~ 18.82s 19.00s p=0.470 n=6
Emit Time 1.52s (± 0.93%) 1.53s (± 0.64%) ~ 1.51s 1.54s p=0.278 n=6
Total Time 25.34s (± 0.34%) 25.32s (± 0.35%) ~ 25.17s 25.41s p=0.810 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 71 71 ~ ~ ~ p=1.000 n=6
Symbols 225,981 225,981 ~ ~ ~ p=1.000 n=6
Types 94,356 94,356 ~ ~ ~ p=1.000 n=6
Memory used 371,358k (± 0.04%) 371,344k (± 0.04%) ~ 371,188k 371,601k p=0.936 n=6
Parse Time 3.60s (± 0.58%) 3.57s (± 1.13%) ~ 3.54s 3.64s p=0.228 n=6
Bind Time 1.97s (± 0.76%) 1.96s (± 0.72%) ~ 1.94s 1.98s p=0.560 n=6
Check Time 20.48s (± 0.41%) 20.46s (± 0.36%) ~ 20.41s 20.59s p=0.628 n=6
Emit Time 0.00s 0.00s (±244.70%) ~ 0.00s 0.01s p=0.405 n=6
Total Time 26.05s (± 0.26%) 26.00s (± 0.28%) ~ 25.91s 26.12s p=0.149 n=6
vscode - node (v18.15.0, x64)
Errors 38 38 ~ ~ ~ p=1.000 n=6
Symbols 3,495,364 3,495,358 -6 (- 0.00%) ~ ~ p=0.001 n=6
Types 1,180,160 1,180,160 ~ ~ ~ p=1.000 n=6
Memory used 3,536,942k (± 0.00%) 3,536,976k (± 0.00%) ~ 3,536,780k 3,537,098k p=0.575 n=6
Parse Time 12.25s (± 0.41%) 12.25s (± 0.36%) ~ 12.21s 12.33s p=1.000 n=6
Bind Time 3.99s (± 0.40%) 3.99s (± 0.22%) ~ 3.98s 4.00s p=0.933 n=6
Check Time 80.28s (± 0.53%) 80.26s (± 0.34%) ~ 79.95s 80.60s p=0.936 n=6
Emit Time 24.96s (± 0.94%) 24.82s (± 0.44%) ~ 24.65s 24.98s p=0.199 n=6
Total Time 121.47s (± 0.55%) 121.32s (± 0.27%) ~ 120.79s 121.62s p=0.936 n=6
webpack - node (v18.15.0, x64)
Errors 2 2 ~ ~ ~ p=1.000 n=6
Symbols 320,086 320,086 ~ ~ ~ p=1.000 n=6
Types 140,412 140,412 ~ ~ ~ p=1.000 n=6
Memory used 474,279k (± 0.01%) 474,312k (± 0.02%) ~ 474,156k 474,395k p=0.298 n=6
Parse Time 4.31s (± 0.92%) 4.34s (± 0.58%) ~ 4.31s 4.38s p=0.086 n=6
Bind Time 1.76s (± 1.37%) 1.76s (± 1.29%) ~ 1.73s 1.79s p=0.519 n=6
Check Time 20.72s (± 0.53%) 20.74s (± 0.51%) ~ 20.57s 20.83s p=0.810 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 26.80s (± 0.40%) 26.83s (± 0.44%) ~ 26.64s 26.98s p=0.630 n=6
xstate-main - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 571,458 570,465 -993 (- 0.17%) ~ ~ p=0.001 n=6
Types 191,798 191,234 -564 (- 0.29%) ~ ~ p=0.001 n=6
Memory used 503,354k (± 0.04%) 502,869k (± 0.01%) -485k (- 0.10%) 502,797k 502,991k p=0.005 n=6
Parse Time 3.45s (± 0.83%) 3.44s (± 0.65%) ~ 3.41s 3.47s p=0.418 n=6
Bind Time 1.24s (± 1.33%) 1.24s (± 1.18%) ~ 1.22s 1.26s p=0.514 n=6
Check Time 19.98s (± 3.07%) 19.59s (± 0.23%) ~ 19.54s 19.65s p=0.128 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.67s (± 2.41%) 24.27s (± 0.23%) ~ 24.19s 24.36s p=0.092 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

> : ^^^^^^^^^^^^^^^^^^^^
>_.map<number, string, Date>(c2, (x, y) => { return x.toFixed() }) : Collection<any, any>
> : ^^^^^^^^^^^^^^^^^^^^
>r5a : Collection<number, Date>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the previous result was already somewhat bizzare here as it came from the overloaded signature with 2 type parameters but 3 are applied here - taking that into consideration, the new one makes much more sense to the user (it comes from the signature with 3 type parameters)

Comment on lines +36707 to +36708
// for the time being only do this when there is a single candidate as the origin index of the `candidatesForArgumentError` is not known
// and it could be different from the selected `bestIndex` here
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd consider revisiting this in Corsa where CallState is already inroduced and improving upon this would likely be slightly easier thanks to that

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos with tsc comparing main and refs/pull/61787/merge:

Everything looks good!

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
Status: Not started
Development

Successfully merging this pull request may close these issues.

Broken Autocomplete and Type Display For Parameters Dependent on Transitively Contextually Typed Return Type
4 participants