Skip to content
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

Extract function types from function and arrow expressions. #60234

Merged

Conversation

dragomirtitian
Copy link
Contributor

This PR brings TS emit closer to what an external tool could emit without type information.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 15, 2024
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 25, 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

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

Everything looks good!

@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
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 31 31 ~ ~ ~ p=1.000 n=6
Symbols 62,340 62,340 ~ ~ ~ p=1.000 n=6
Types 50,379 50,379 ~ ~ ~ p=1.000 n=6
Memory used 192,861k (± 0.06%) 193,971k (± 0.93%) ~ 192,784k 196,309k p=0.689 n=6
Parse Time 1.32s (± 0.48%) 1.31s (± 0.48%) -0.01s (- 0.76%) 1.30s 1.32s p=0.031 n=6
Bind Time 0.72s 0.72s ~ ~ ~ p=1.000 n=6
Check Time 9.73s (± 0.36%) 9.73s (± 0.24%) ~ 9.70s 9.77s p=1.000 n=6
Emit Time 2.72s (± 0.36%) 2.73s (± 0.38%) ~ 2.72s 2.74s p=0.557 n=6
Total Time 14.49s (± 0.20%) 14.49s (± 0.20%) ~ 14.44s 14.52s p=0.935 n=6
angular-1 - node (v18.15.0, x64)
Errors 33 33 ~ ~ ~ p=1.000 n=6
Symbols 947,886 947,886 ~ ~ ~ p=1.000 n=6
Types 410,840 410,840 ~ ~ ~ p=1.000 n=6
Memory used 1,224,631k (± 0.00%) 1,224,538k (± 0.00%) -93k (- 0.01%) 1,224,504k 1,224,603k p=0.008 n=6
Parse Time 6.65s (± 0.66%) 6.64s (± 0.69%) ~ 6.58s 6.71s p=0.628 n=6
Bind Time 1.88s (± 0.34%) 1.88s (± 0.43%) ~ 1.87s 1.89s p=0.432 n=6
Check Time 31.87s (± 0.56%) 31.81s (± 0.58%) ~ 31.61s 32.05s p=0.378 n=6
Emit Time 15.23s (± 0.51%) 15.23s (± 0.30%) ~ 15.16s 15.27s p=1.000 n=6
Total Time 55.63s (± 0.38%) 55.56s (± 0.32%) ~ 55.30s 55.79s p=0.630 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,494,500 2,494,500 ~ ~ ~ p=1.000 n=6
Types 908,298 908,298 ~ ~ ~ p=1.000 n=6
Memory used 2,307,127k (± 0.00%) 2,307,056k (± 0.00%) -71k (- 0.00%) 2,307,014k 2,307,101k p=0.031 n=6
Parse Time 9.34s (± 0.37%) 9.31s (± 0.25%) ~ 9.28s 9.35s p=0.217 n=6
Bind Time 2.15s (± 0.35%) 2.13s (± 0.26%) -0.01s (- 0.62%) 2.13s 2.14s p=0.015 n=6
Check Time 75.10s (± 0.40%) 74.97s (± 0.65%) ~ 74.13s 75.57s p=0.936 n=6
Emit Time 0.28s (± 3.04%) 0.28s (± 3.91%) ~ 0.27s 0.29s p=0.465 n=6
Total Time 86.85s (± 0.37%) 86.70s (± 0.54%) ~ 85.87s 87.27s p=0.748 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,258,044 1,258,045 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 266,229 266,229 ~ ~ ~ p=1.000 n=6
Memory used 2,422,307k (± 0.03%) 2,422,555k (± 0.02%) ~ 2,422,050k 2,423,069k p=0.575 n=6
Parse Time 5.17s (± 0.83%) 5.22s (± 1.06%) ~ 5.15s 5.29s p=0.128 n=6
Bind Time 1.93s (± 0.51%) 1.93s (± 0.33%) ~ 1.92s 1.94s p=0.733 n=6
Check Time 35.55s (± 0.36%) 35.50s (± 0.39%) ~ 35.36s 35.74s p=0.378 n=6
Emit Time 3.09s (± 5.47%) 3.00s (± 1.61%) ~ 2.94s 3.08s p=0.199 n=6
Total Time 45.74s (± 0.54%) 45.65s (± 0.26%) ~ 45.50s 45.80s 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,258,044 1,258,045 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 266,229 266,229 ~ ~ ~ p=1.000 n=6
Memory used 2,619,089k (±11.20%) 2,499,028k (± 0.03%) ~ 2,497,849k 2,500,129k p=0.575 n=6
Parse Time 6.64s (± 2.54%) 6.56s (± 0.79%) ~ 6.51s 6.63s p=0.423 n=6
Bind Time 2.16s (± 2.21%) 2.14s (± 1.86%) ~ 2.11s 2.22s p=0.574 n=6
Check Time 43.30s (± 0.60%) 43.45s (± 0.57%) ~ 43.16s 43.91s p=0.229 n=6
Emit Time 3.60s (± 2.81%) 3.57s (± 2.72%) ~ 3.44s 3.72s p=0.471 n=6
Total Time 55.69s (± 0.56%) 55.73s (± 0.51%) ~ 55.42s 56.27s p=0.575 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 261,754 261,755 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 106,477 106,477 ~ ~ ~ p=1.000 n=6
Memory used 438,854k (± 0.01%) 438,781k (± 0.02%) -74k (- 0.02%) 438,634k 438,843k p=0.013 n=6
Parse Time 3.54s (± 0.73%) 3.54s (± 0.73%) ~ 3.50s 3.57s p=0.809 n=6
Bind Time 1.30s (± 1.43%) 1.30s (± 1.26%) ~ 1.28s 1.32s p=1.000 n=6
Check Time 18.89s (± 0.62%) 18.84s (± 0.41%) ~ 18.78s 18.98s p=0.470 n=6
Emit Time 1.54s (± 0.82%) 1.53s (± 1.41%) ~ 1.50s 1.56s p=0.677 n=6
Total Time 25.28s (± 0.33%) 25.21s (± 0.35%) ~ 25.14s 25.38s p=0.092 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,919 225,919 ~ ~ ~ p=1.000 n=6
Types 94,415 94,415 ~ ~ ~ p=1.000 n=6
Memory used 371,092k (± 0.01%) 371,084k (± 0.01%) ~ 371,015k 371,128k p=1.000 n=6
Parse Time 2.89s (± 1.11%) 2.89s (± 1.50%) ~ 2.83s 2.95s p=1.000 n=6
Bind Time 1.58s (± 0.95%) 1.60s (± 1.02%) ~ 1.57s 1.61s p=0.069 n=6
Check Time 16.38s (± 0.19%) 16.41s (± 0.38%) ~ 16.33s 16.49s p=0.332 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.85s (± 0.09%) 20.89s (± 0.49%) ~ 20.75s 21.06s p=0.170 n=6
vscode - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 3,127,992 3,127,992 ~ ~ ~ p=1.000 n=6
Types 1,078,245 1,078,245 ~ ~ ~ p=1.000 n=6
Memory used 3,220,297k (± 0.01%) 3,220,271k (± 0.02%) ~ 3,219,491k 3,220,844k p=0.936 n=6
Parse Time 14.15s (± 0.54%) 14.13s (± 0.57%) ~ 14.02s 14.26s p=0.809 n=6
Bind Time 4.46s (± 0.27%) 4.45s (± 0.54%) ~ 4.42s 4.48s p=0.253 n=6
Check Time 86.96s (± 3.43%) 85.67s (± 1.65%) ~ 84.54s 88.50s p=0.471 n=6
Emit Time 26.53s (± 6.88%) 27.53s (± 1.70%) ~ 27.00s 28.29s p=0.230 n=6
Total Time 132.11s (± 1.44%) 131.78s (± 0.94%) ~ 130.39s 133.98s p=1.000 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 286,866 286,866 ~ ~ ~ p=1.000 n=6
Types 116,245 116,245 ~ ~ ~ p=1.000 n=6
Memory used 437,881k (± 0.04%) 437,812k (± 0.03%) ~ 437,690k 438,055k p=0.575 n=6
Parse Time 4.99s (± 0.24%) 4.99s (± 0.54%) ~ 4.95s 5.03s p=0.803 n=6
Bind Time 2.17s (± 0.86%) 2.16s (± 0.99%) ~ 2.12s 2.18s p=0.746 n=6
Check Time 23.10s (± 1.66%) 22.95s (± 0.65%) ~ 22.79s 23.20s p=0.810 n=6
Emit Time 0.00s (±244.70%) 0.00s ~ ~ ~ p=0.405 n=6
Total Time 30.25s (± 1.28%) 30.11s (± 0.52%) ~ 29.93s 30.35s p=0.810 n=6
xstate-main - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 543,130 543,130 ~ ~ ~ p=1.000 n=6
Types 181,889 181,889 ~ ~ ~ p=1.000 n=6
Memory used 485,484k (± 0.03%) 485,537k (± 0.01%) ~ 485,507k 485,599k p=1.000 n=6
Parse Time 4.17s (± 0.64%) 4.18s (± 0.71%) ~ 4.14s 4.22s p=0.809 n=6
Bind Time 1.46s (± 0.84%) 1.45s (± 0.94%) ~ 1.44s 1.47s p=0.798 n=6
Check Time 23.84s (± 0.90%) 23.78s (± 0.46%) ~ 23.65s 23.91s p=0.746 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 29.47s (± 0.77%) 29.41s (± 0.49%) ~ 29.24s 29.57s p=0.936 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

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

Everything looks good!

Comment on lines +73 to +74
declare var foo3: () => () => /*elided*/ any;
declare var x: () => () => /*elided*/ any;
Copy link
Member

Choose a reason for hiding this comment

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

Do you know why this is changing? It seems a little awkward for this self referential type to be printed one level deep like this rather than the single elided any (which would cause fewer downstream errors)

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 base cause is that at the root level syntactic printing is now always given a try. And in this case the parameter list can be copied, it's just the return type that needs to fallback on type printing. I think I can revert this behavior.

Copy link
Contributor Author

@dragomirtitian dragomirtitian Oct 29, 2024

Choose a reason for hiding this comment

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

I looked into it and I don't think I can easily revert to the old behavior. The type checked printer only knows a type is too recursive to represent when it tries to print it. So when I see the function expression, I try to reuse types from the expression. When doing so, I discover the missing return type and fallback to type checker printing which then discovers the type is recursive.

What specifically is the worry in this case ? () => any and () => () => any are both bad, they both allow calling the function, so I don't really think the types are worse.

Copy link
Member

Choose a reason for hiding this comment

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

Moreso if someone actually calls it and uses the result, that result will not be any and may cause follow-on errors. But I think this particular case is exceeding rare and weird anyway. Like, the function is clearly returning a function, so maybe that safety is better.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

In general, this seems fine to me, though I am unsure if we want to sneak this in before the 5.7 RC. @weswigham @DanielRosenwasser do you have an opinion here?

@jakebailey
Copy link
Member

5.7 is cut, main is open for 5.8; I'm just going to merge this now. I don't think we need this for 5.7 or anything.

@jakebailey jakebailey merged commit b58ac4a into microsoft:main Nov 11, 2024
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants