Skip to content

Properly account for type parameters introduced by contextual types #59516

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

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

ahejlsberg
Copy link
Member

Fixes #59450.

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

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 2, 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 @ahejlsberg, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

@ahejlsberg
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 193,542k (± 0.95%) 193,007k (± 0.73%) ~ 192,322k 195,885k p=1.000 n=6
Parse Time 1.30s (± 1.34%) 1.30s (± 1.41%) ~ 1.28s 1.33s p=0.803 n=6
Bind Time 0.71s (± 0.58%) 0.71s ~ ~ ~ p=0.405 n=6
Check Time 9.57s (± 0.42%) 9.55s (± 0.34%) ~ 9.50s 9.59s p=0.374 n=6
Emit Time 2.73s (± 1.55%) 2.75s (± 0.71%) ~ 2.72s 2.77s p=0.375 n=6
Total Time 14.31s (± 0.21%) 14.30s (± 0.23%) ~ 14.27s 14.35s p=0.629 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 7 ~ ~ ~ p=1.000 n=6
Symbols 945,537 945,537 ~ ~ ~ p=1.000 n=6
Types 409,512 409,512 ~ ~ ~ p=1.000 n=6
Memory used 1,222,258k (± 0.01%) 1,222,275k (± 0.00%) ~ 1,222,229k 1,222,314k p=0.936 n=6
Parse Time 6.60s (± 0.87%) 6.61s (± 0.76%) ~ 6.58s 6.70s p=0.466 n=6
Bind Time 1.86s (± 0.56%) 1.86s (± 0.28%) ~ 1.86s 1.87s p=0.794 n=6
Check Time 31.22s (± 0.27%) 31.17s (± 0.34%) ~ 31.06s 31.31s p=0.377 n=6
Emit Time 15.12s (± 1.16%) 14.96s (± 0.65%) ~ 14.86s 15.12s p=0.108 n=6
Total Time 54.80s (± 0.46%) 54.61s (± 0.42%) ~ 54.40s 54.96s p=0.229 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,483,478 2,483,478 ~ ~ ~ p=1.000 n=6
Types 1,012,731 1,012,731 ~ ~ ~ p=1.000 n=6
Memory used 2,475,367k (± 0.00%) 2,475,412k (± 0.00%) ~ 2,475,404k 2,475,421k p=0.066 n=6
Parse Time 8.79s (± 0.56%) 8.79s (± 0.54%) ~ 8.74s 8.85s p=1.000 n=6
Bind Time 2.18s (± 0.45%) 2.17s (± 0.38%) ~ 2.16s 2.18s p=0.282 n=6
Check Time 75.42s (± 0.46%) 75.98s (± 1.43%) ~ 74.88s 78.05s p=0.298 n=6
Emit Time 0.28s (± 2.70%) 0.28s (± 3.53%) ~ 0.27s 0.29s p=1.000 n=6
Total Time 86.67s (± 0.45%) 87.23s (± 1.22%) ~ 86.09s 89.22s p=0.298 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,919 1,227,921 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 265,192 265,194 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,406,351k (± 6.00%) 2,346,843k (± 0.02%) ~ 2,346,306k 2,347,541k p=0.173 n=6
Parse Time 4.97s (± 0.80%) 4.92s (± 1.03%) -0.05s (- 1.11%) 4.82s 4.95s p=0.044 n=6
Bind Time 1.89s (± 0.43%) 1.90s (± 0.40%) ~ 1.89s 1.91s p=0.120 n=6
Check Time 34.56s (± 0.38%) 34.61s (± 0.26%) ~ 34.48s 34.72s p=0.470 n=6
Emit Time 3.28s (± 1.38%) 3.30s (± 0.89%) ~ 3.26s 3.33s p=0.628 n=6
Total Time 44.73s (± 0.26%) 44.75s (± 0.20%) ~ 44.64s 44.90s p=0.936 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,919 1,227,921 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 265,192 265,194 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,420,903k (± 0.02%) 2,421,695k (± 0.03%) ~ 2,420,231k 2,422,438k p=0.093 n=6
Parse Time 7.71s (± 0.62%) 7.71s (± 0.66%) ~ 7.61s 7.76s p=0.936 n=6
Bind Time 2.50s (± 0.53%) 2.51s (± 1.22%) ~ 2.47s 2.56s p=0.628 n=6
Check Time 50.88s (± 0.57%) 50.97s (± 0.56%) ~ 50.75s 51.51s p=0.689 n=6
Emit Time 5.09s (± 3.81%) 5.05s (± 3.73%) ~ 4.91s 5.42s p=0.810 n=6
Total Time 66.21s (± 0.49%) 66.26s (± 0.53%) ~ 65.86s 66.84s p=1.000 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 256,031 256,033 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 104,976 104,978 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 428,033k (± 0.05%) 428,094k (± 0.06%) ~ 427,835k 428,398k p=0.936 n=6
Parse Time 3.36s (± 0.83%) 3.35s (± 0.33%) ~ 3.33s 3.36s p=0.681 n=6
Bind Time 1.31s (± 1.15%) 1.31s (± 1.15%) ~ 1.29s 1.32s p=0.437 n=6
Check Time 17.99s (± 0.23%) 18.05s (± 0.25%) ~ 17.98s 18.10s p=0.076 n=6
Emit Time 1.64s (± 1.66%) 1.64s (± 1.37%) ~ 1.62s 1.68s p=1.000 n=6
Total Time 24.31s (± 0.25%) 24.35s (± 0.28%) ~ 24.23s 24.43s p=0.375 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,931 224,931 ~ ~ ~ p=1.000 n=6
Types 94,146 94,146 ~ ~ ~ p=1.000 n=6
Memory used 370,236k (± 0.05%) 370,132k (± 0.04%) ~ 369,942k 370,333k p=0.378 n=6
Parse Time 2.77s (± 0.40%) 2.75s (± 1.06%) ~ 2.71s 2.78s p=0.452 n=6
Bind Time 1.58s (± 1.33%) 1.58s (± 0.67%) ~ 1.56s 1.59s p=1.000 n=6
Check Time 15.62s (± 0.33%) 15.69s (± 0.46%) ~ 15.57s 15.76s p=0.148 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 19.97s (± 0.16%) 20.01s (± 0.29%) ~ 19.91s 20.09s p=0.090 n=6
vscode - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,990,805 2,990,805 ~ ~ ~ p=1.000 n=6
Types 1,029,115 1,029,118 +3 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 3,116,010k (± 0.00%) 3,116,056k (± 0.00%) ~ 3,115,920k 3,116,205k p=0.471 n=6
Parse Time 17.01s (± 0.58%) 16.98s (± 0.42%) ~ 16.87s 17.05s p=0.748 n=6
Bind Time 5.30s (± 2.53%) 5.31s (± 2.58%) ~ 5.19s 5.49s p=0.683 n=6
Check Time 96.46s (± 0.49%) 96.25s (± 0.31%) ~ 95.82s 96.70s p=0.336 n=6
Emit Time 25.07s (± 0.36%) 25.04s (± 0.55%) ~ 24.84s 25.23s p=0.810 n=6
Total Time 143.83s (± 0.34%) 143.59s (± 0.31%) ~ 143.08s 144.22s p=0.471 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 268,265 268,265 ~ ~ ~ p=1.000 n=6
Types 109,187 109,187 ~ ~ ~ p=1.000 n=6
Memory used 413,065k (± 0.01%) 413,116k (± 0.01%) +50k (+ 0.01%) 413,077k 413,185k p=0.045 n=6
Parse Time 3.81s (± 0.54%) 3.81s (± 0.43%) ~ 3.79s 3.83s p=0.935 n=6
Bind Time 1.71s (± 0.95%) 1.71s (± 0.68%) ~ 1.69s 1.72s p=0.445 n=6
Check Time 16.79s (± 0.34%) 16.79s (± 0.28%) ~ 16.73s 16.86s p=1.000 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.31s (± 0.38%) 22.31s (± 0.26%) ~ 22.24s 22.39s p=0.936 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 538,543 538,543 ~ ~ ~ p=1.000 n=6
Types 176,469 176,469 ~ ~ ~ p=1.000 n=6
Memory used 481,329k (± 0.02%) 481,372k (± 0.01%) ~ 481,301k 481,447k p=0.521 n=6
Parse Time 3.42s (± 1.24%) 3.43s (± 0.75%) ~ 3.39s 3.45s p=0.808 n=6
Bind Time 1.26s (± 0.93%) 1.25s (± 0.67%) ~ 1.24s 1.26s p=0.547 n=6
Check Time 17.99s (± 0.36%) 18.04s (± 0.16%) ~ 17.99s 18.07s p=0.229 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.67s (± 0.40%) 22.72s (± 0.24%) ~ 22.62s 22.76s p=0.148 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

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

Something interesting changed - please have a look.

Details

honojs/hono

5 of 6 projects failed to build with the old tsc and were ignored

tsconfig.json

@ahejlsberg
Copy link
Member Author

Performance is unaffected. One new error in honojs/hono, a top 400 repo. The new error is correct, but wasn't previously detected because instantiations of the type of { data } object literal weren't correctly resolved for the contextually injected TData type parameter. So, I think this is good to merge.

@m-shaka
Copy link

m-shaka commented Aug 3, 2024

Yeah, it's me who added this test of hono.js and I expected the failure. You can go forward

if ((kind === SyntaxKind.FunctionExpression || kind === SyntaxKind.ArrowFunction || isObjectLiteralMethod(node)) && isContextSensitive(node as Expression | MethodDeclaration)) {
const signature = firstOrUndefined(getSignaturesOfType(getTypeOfSymbol(getSymbolOfDeclaration(node as FunctionLikeDeclaration)), SignatureKind.Call));
if (signature && signature.typeParameters) {
return [...(outerTypeParameters || emptyArray), ...signature.typeParameters];
Copy link
Member

@jakebailey jakebailey Aug 3, 2024

Choose a reason for hiding this comment

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

Should this be concatenate like the other cases? (Should also get rid of the empty array since I think it accepts undefined)

Copy link
Member Author

Choose a reason for hiding this comment

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

We are required to return a mutable array, and concatenate only returns a mutable array when both arguments are mutable arrays. In this case, signature.typeParameters is read-only.

Can't get rid of the empty array, spreading undefined causes an exception.

Copy link
Member

Choose a reason for hiding this comment

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

I meant more that concatenate can accept undefined so you don't have to || things, but, yeah, it doesn't return a copy.

Though it's sort of confusing given all of the surrounding code uses append / concatenate

@ahejlsberg ahejlsberg merged commit 278cb94 into main Aug 8, 2024
32 checks passed
@ahejlsberg ahejlsberg deleted the fix59450 branch August 8, 2024 20:38
@sandersn sandersn removed this from PR Backlog Apr 22, 2025
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.

Conditional type evaluation not deferred when it depends on an implicitly-present type parameter
4 participants