Skip to content

Try subtype reducing call expression types if type argument arity checks will fail #60036

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

Conversation

weswigham
Copy link
Member

We basically peek into a cheap part of overload resolution and see if we're destined to report an error on a union's list of signatures, and, if so, try subtype reducing the union and then doing the arity checks. If we can find a matching signature in the reduced union, we proceed with that, instead, and avoid the error.

Note that, per the comment in the code, right now I only do this for call expressions, and not other call-like expressions (decorators, tagged templates, jsx tags), because of where this logic needs to sit in the call resolution stack. If we like it, I can make the logic a bit more generic and insert it into all the call resolution codepaths (it's an interesting bit of logic since it needs both expression type information and signature level information - and the core resolveCall only operates on the later).

Fixes #60006

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 23, 2024
@weswigham
Copy link
Member Author

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 23, 2024

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 @weswigham, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

@weswigham
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 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,153 62,153 ~ ~ ~ p=1.000 n=6
Types 50,242 50,242 ~ ~ ~ p=1.000 n=6
Memory used 192,473k (± 0.02%) 194,335k (± 0.99%) ~ 192,402k 196,262k p=0.092 n=6
Parse Time 1.31s (± 0.31%) 1.30s (± 0.76%) ~ 1.29s 1.31s p=0.071 n=6
Bind Time 0.71s 0.71s ~ ~ ~ p=1.000 n=6
Check Time 9.58s (± 0.25%) 9.59s (± 0.61%) ~ 9.52s 9.67s p=0.936 n=6
Emit Time 2.73s (± 0.56%) 2.70s (± 1.74%) ~ 2.61s 2.74s p=0.413 n=6
Total Time 14.32s (± 0.21%) 14.30s (± 0.39%) ~ 14.26s 14.41s p=0.257 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 7 ~ ~ ~ p=1.000 n=6
Symbols 945,734 945,734 ~ ~ ~ p=1.000 n=6
Types 410,049 410,049 ~ ~ ~ p=1.000 n=6
Memory used 1,222,786k (± 0.00%) 1,222,791k (± 0.00%) ~ 1,222,767k 1,222,826k p=1.000 n=6
Parse Time 6.66s (± 0.66%) 6.68s (± 0.77%) ~ 6.62s 6.77s p=0.418 n=6
Bind Time 1.86s (± 0.53%) 1.86s (± 0.34%) ~ 1.85s 1.87s p=1.000 n=6
Check Time 31.24s (± 0.29%) 31.30s (± 0.29%) ~ 31.17s 31.41s p=0.225 n=6
Emit Time 15.07s (± 0.29%) 15.04s (± 0.29%) ~ 14.97s 15.08s p=0.261 n=6
Total Time 54.83s (± 0.21%) 54.87s (± 0.20%) ~ 54.71s 54.97s p=0.521 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,521,513 2,521,513 ~ ~ ~ p=1.000 n=6
Types 936,002 936,002 ~ ~ ~ p=1.000 n=6
Memory used 2,351,486k (± 0.00%) 2,351,479k (± 0.00%) ~ 2,351,472k 2,351,491k p=0.471 n=6
Parse Time 9.28s (± 0.25%) 9.28s (± 0.19%) ~ 9.25s 9.30s p=0.936 n=6
Bind Time 2.14s (± 0.48%) 2.13s (± 0.46%) -0.02s (- 0.70%) 2.11s 2.14s p=0.028 n=6
Check Time 73.23s (± 0.24%) 73.14s (± 0.27%) ~ 72.89s 73.45s p=0.378 n=6
Emit Time 0.28s (± 2.67%) 0.28s (± 3.53%) ~ 0.26s 0.29s p=0.652 n=6
Total Time 84.93s (± 0.21%) 84.83s (± 0.24%) ~ 84.57s 85.13s p=0.521 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,246,933 1,246,938 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Types 264,605 264,606 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,399,865k (± 0.02%) 2,399,994k (± 0.01%) ~ 2,399,785k 2,400,271k p=1.000 n=6
Parse Time 5.07s (± 0.46%) 5.08s (± 0.57%) ~ 5.03s 5.12s p=0.575 n=6
Bind Time 1.92s (± 0.33%) 1.91s (± 0.61%) ~ 1.89s 1.92s p=0.177 n=6
Check Time 34.89s (± 0.72%) 35.01s (± 0.79%) ~ 34.78s 35.55s p=0.748 n=6
Emit Time 2.97s (± 0.46%) 2.96s (± 0.59%) ~ 2.94s 2.99s p=0.934 n=6
Total Time 44.87s (± 0.56%) 44.98s (± 0.62%) ~ 44.73s 45.52s p=0.810 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,246,933 1,246,938 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Types 264,605 264,606 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,474,180k (± 0.04%) 2,474,637k (± 0.02%) ~ 2,474,206k 2,475,844k p=0.230 n=6
Parse Time 6.32s (± 1.02%) 6.34s (± 0.68%) ~ 6.29s 6.41s p=0.873 n=6
Bind Time 2.06s (± 1.01%) 2.05s (± 0.44%) ~ 2.04s 2.06s p=0.806 n=6
Check Time 41.92s (± 0.37%) 41.91s (± 0.80%) ~ 41.44s 42.29s p=1.000 n=6
Emit Time 3.59s (± 1.24%) 3.56s (± 1.55%) ~ 3.47s 3.62s p=0.230 n=6
Total Time 53.91s (± 0.35%) 53.87s (± 0.75%) ~ 53.30s 54.28s p=1.000 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 260,157 260,162 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Types 106,293 106,294 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 436,154k (± 0.04%) 436,069k (± 0.03%) ~ 435,926k 436,324k p=0.298 n=6
Parse Time 3.44s (± 0.85%) 3.43s (± 0.63%) ~ 3.40s 3.46s p=0.331 n=6
Bind Time 1.29s (± 0.85%) 1.29s (± 1.16%) ~ 1.27s 1.31s p=0.663 n=6
Check Time 18.15s (± 0.41%) 18.07s (± 0.24%) ~ 18.01s 18.13s p=0.090 n=6
Emit Time 1.52s (± 2.24%) 1.53s (± 1.22%) ~ 1.51s 1.56s p=0.625 n=6
Total Time 24.40s (± 0.34%) 24.32s (± 0.33%) ~ 24.21s 24.40s p=0.213 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,018 225,018 ~ ~ ~ p=1.000 n=6
Types 94,249 94,249 ~ ~ ~ p=1.000 n=6
Memory used 370,285k (± 0.02%) 370,294k (± 0.01%) ~ 370,242k 370,358k p=0.936 n=6
Parse Time 2.75s (± 0.50%) 2.77s (± 0.78%) ~ 2.75s 2.81s p=0.076 n=6
Bind Time 1.56s (± 0.70%) 1.56s (± 0.57%) ~ 1.55s 1.57s p=0.932 n=6
Check Time 15.72s (± 0.35%) 15.71s (± 0.52%) ~ 15.65s 15.86s p=0.686 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.03s (± 0.27%) 20.04s (± 0.43%) ~ 19.96s 20.18s p=1.000 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,094,697 3,094,697 ~ ~ ~ p=1.000 n=6
Types 1,066,781 1,066,781 ~ ~ ~ p=1.000 n=6
Memory used 3,192,582k (± 0.00%) 3,192,544k (± 0.00%) ~ 3,192,444k 3,192,616k p=0.336 n=6
Parse Time 17.20s (± 0.26%) 17.21s (± 0.46%) ~ 17.08s 17.31s p=0.688 n=6
Bind Time 5.40s (± 2.11%) 5.39s (± 2.33%) ~ 5.30s 5.61s p=0.809 n=6
Check Time 100.00s (± 0.41%) 99.93s (± 0.25%) ~ 99.68s 100.27s p=0.936 n=6
Emit Time 27.30s (± 0.14%) 27.25s (± 0.25%) ~ 27.16s 27.33s p=0.142 n=6
Total Time 149.90s (± 0.28%) 149.77s (± 0.17%) ~ 149.54s 150.11s p=0.471 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 277,129 277,129 ~ ~ ~ p=1.000 n=6
Types 113,106 113,106 ~ ~ ~ p=1.000 n=6
Memory used 427,005k (± 0.01%) 426,976k (± 0.02%) ~ 426,901k 427,071k p=0.575 n=6
Parse Time 3.95s (± 0.41%) 3.95s (± 0.38%) ~ 3.93s 3.97s p=0.935 n=6
Bind Time 1.72s (± 0.96%) 1.71s (± 0.48%) ~ 1.70s 1.72s p=0.323 n=6
Check Time 17.61s (± 0.21%) 17.56s (± 0.42%) ~ 17.45s 17.62s p=0.257 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 23.28s (± 0.17%) 23.22s (± 0.34%) ~ 23.10s 23.31s p=0.260 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 539,981 539,981 ~ ~ ~ p=1.000 n=6
Types 181,270 181,270 ~ ~ ~ p=1.000 n=6
Memory used 483,378k (± 0.01%) 483,386k (± 0.02%) ~ 483,276k 483,574k p=0.936 n=6
Parse Time 3.23s (± 0.66%) 3.26s (± 0.43%) +0.03s (+ 0.98%) 3.24s 3.28s p=0.023 n=6
Bind Time 1.16s (± 0.35%) 1.16s (± 0.85%) ~ 1.15s 1.17s p=0.487 n=6
Check Time 18.61s (± 0.58%) 18.56s (± 0.53%) ~ 18.40s 18.68s p=0.230 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 23.00s (± 0.48%) 22.98s (± 0.48%) ~ 22.79s 23.11s p=0.630 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

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@weswigham
Copy link
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 24, 2024

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

Command Status Results
pack this ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 24, 2024

Hey @weswigham, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/163678/artifacts?artifactName=tgz&fileId=1764C8FADAAE7E5D00AD2DA8F1ABBDC2E5359205EA31222B43802ECE65FF68EC02&fileName=/typescript-5.7.0-insiders.20240924.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.7.0-pr-60036-8".;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing overload method on union types
2 participants