Skip to content

Extract function types from function and arrow expressions. - #60234

Merged
Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
bloomberg:isolated-declarations-function-types
Nov 11, 2024
Merged

Extract function types from function and arrow expressions.#60234
Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
bloomberg:isolated-declarations-function-types

Conversation

@dragomirtitian

Copy link
Copy Markdown
Contributor

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

@typescript-botTypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 15, 2024
@typescript-bot

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/compiler/checker.ts Outdated
@jakebailey

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) test it

@typescript-bot

TypeScript Bot (typescript-bot) commented Oct 25, 2024

Copy link
Copy Markdown
Contributor

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

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

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@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
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors3131~~~p=1.000 n=6
Symbols62,34062,340~~~p=1.000 n=6
Types50,37950,379~~~p=1.000 n=6
Memory used192,861k (± 0.06%)193,971k (± 0.93%)~192,784k196,309kp=0.689 n=6
Parse Time1.32s (± 0.48%)1.31s (± 0.48%)-0.01s (- 0.76%)1.30s1.32sp=0.031 n=6
Bind Time0.72s0.72s~~~p=1.000 n=6
Check Time9.73s (± 0.36%)9.73s (± 0.24%)~9.70s9.77sp=1.000 n=6
Emit Time2.72s (± 0.36%)2.73s (± 0.38%)~2.72s2.74sp=0.557 n=6
Total Time14.49s (± 0.20%)14.49s (± 0.20%)~14.44s14.52sp=0.935 n=6
angular-1 - node (v18.15.0, x64)
Errors3333~~~p=1.000 n=6
Symbols947,886947,886~~~p=1.000 n=6
Types410,840410,840~~~p=1.000 n=6
Memory used1,224,631k (± 0.00%)1,224,538k (± 0.00%)-93k (- 0.01%)1,224,504k1,224,603kp=0.008 n=6
Parse Time6.65s (± 0.66%)6.64s (± 0.69%)~6.58s6.71sp=0.628 n=6
Bind Time1.88s (± 0.34%)1.88s (± 0.43%)~1.87s1.89sp=0.432 n=6
Check Time31.87s (± 0.56%)31.81s (± 0.58%)~31.61s32.05sp=0.378 n=6
Emit Time15.23s (± 0.51%)15.23s (± 0.30%)~15.16s15.27sp=1.000 n=6
Total Time55.63s (± 0.38%)55.56s (± 0.32%)~55.30s55.79sp=0.630 n=6
mui-docs - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols2,494,5002,494,500~~~p=1.000 n=6
Types908,298908,298~~~p=1.000 n=6
Memory used2,307,127k (± 0.00%)2,307,056k (± 0.00%)-71k (- 0.00%)2,307,014k2,307,101kp=0.031 n=6
Parse Time9.34s (± 0.37%)9.31s (± 0.25%)~9.28s9.35sp=0.217 n=6
Bind Time2.15s (± 0.35%)2.13s (± 0.26%)-0.01s (- 0.62%)2.13s2.14sp=0.015 n=6
Check Time75.10s (± 0.40%)74.97s (± 0.65%)~74.13s75.57sp=0.936 n=6
Emit Time0.28s (± 3.04%)0.28s (± 3.91%)~0.27s0.29sp=0.465 n=6
Total Time86.85s (± 0.37%)86.70s (± 0.54%)~85.87s87.27sp=0.748 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,258,0441,258,045+1 (+ 0.00%)~~p=0.001 n=6
Types266,229266,229~~~p=1.000 n=6
Memory used2,422,307k (± 0.03%)2,422,555k (± 0.02%)~2,422,050k2,423,069kp=0.575 n=6
Parse Time5.17s (± 0.83%)5.22s (± 1.06%)~5.15s5.29sp=0.128 n=6
Bind Time1.93s (± 0.51%)1.93s (± 0.33%)~1.92s1.94sp=0.733 n=6
Check Time35.55s (± 0.36%)35.50s (± 0.39%)~35.36s35.74sp=0.378 n=6
Emit Time3.09s (± 5.47%)3.00s (± 1.61%)~2.94s3.08sp=0.199 n=6
Total Time45.74s (± 0.54%)45.65s (± 0.26%)~45.50s45.80sp=0.689 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,258,0441,258,045+1 (+ 0.00%)~~p=0.001 n=6
Types266,229266,229~~~p=1.000 n=6
Memory used2,619,089k (±11.20%)2,499,028k (± 0.03%)~2,497,849k2,500,129kp=0.575 n=6
Parse Time6.64s (± 2.54%)6.56s (± 0.79%)~6.51s6.63sp=0.423 n=6
Bind Time2.16s (± 2.21%)2.14s (± 1.86%)~2.11s2.22sp=0.574 n=6
Check Time43.30s (± 0.60%)43.45s (± 0.57%)~43.16s43.91sp=0.229 n=6
Emit Time3.60s (± 2.81%)3.57s (± 2.72%)~3.44s3.72sp=0.471 n=6
Total Time55.69s (± 0.56%)55.73s (± 0.51%)~55.42s56.27sp=0.575 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols261,754261,755+1 (+ 0.00%)~~p=0.001 n=6
Types106,477106,477~~~p=1.000 n=6
Memory used438,854k (± 0.01%)438,781k (± 0.02%)-74k (- 0.02%)438,634k438,843kp=0.013 n=6
Parse Time3.54s (± 0.73%)3.54s (± 0.73%)~3.50s3.57sp=0.809 n=6
Bind Time1.30s (± 1.43%)1.30s (± 1.26%)~1.28s1.32sp=1.000 n=6
Check Time18.89s (± 0.62%)18.84s (± 0.41%)~18.78s18.98sp=0.470 n=6
Emit Time1.54s (± 0.82%)1.53s (± 1.41%)~1.50s1.56sp=0.677 n=6
Total Time25.28s (± 0.33%)25.21s (± 0.35%)~25.14s25.38sp=0.092 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors6868~~~p=1.000 n=6
Symbols225,919225,919~~~p=1.000 n=6
Types94,41594,415~~~p=1.000 n=6
Memory used371,092k (± 0.01%)371,084k (± 0.01%)~371,015k371,128kp=1.000 n=6
Parse Time2.89s (± 1.11%)2.89s (± 1.50%)~2.83s2.95sp=1.000 n=6
Bind Time1.58s (± 0.95%)1.60s (± 1.02%)~1.57s1.61sp=0.069 n=6
Check Time16.38s (± 0.19%)16.41s (± 0.38%)~16.33s16.49sp=0.332 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time20.85s (± 0.09%)20.89s (± 0.49%)~20.75s21.06sp=0.170 n=6
vscode - node (v18.15.0, x64)
Errors33~~~p=1.000 n=6
Symbols3,127,9923,127,992~~~p=1.000 n=6
Types1,078,2451,078,245~~~p=1.000 n=6
Memory used3,220,297k (± 0.01%)3,220,271k (± 0.02%)~3,219,491k3,220,844kp=0.936 n=6
Parse Time14.15s (± 0.54%)14.13s (± 0.57%)~14.02s14.26sp=0.809 n=6
Bind Time4.46s (± 0.27%)4.45s (± 0.54%)~4.42s4.48sp=0.253 n=6
Check Time86.96s (± 3.43%)85.67s (± 1.65%)~84.54s88.50sp=0.471 n=6
Emit Time26.53s (± 6.88%)27.53s (± 1.70%)~27.00s28.29sp=0.230 n=6
Total Time132.11s (± 1.44%)131.78s (± 0.94%)~130.39s133.98sp=1.000 n=6
webpack - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols286,866286,866~~~p=1.000 n=6
Types116,245116,245~~~p=1.000 n=6
Memory used437,881k (± 0.04%)437,812k (± 0.03%)~437,690k438,055kp=0.575 n=6
Parse Time4.99s (± 0.24%)4.99s (± 0.54%)~4.95s5.03sp=0.803 n=6
Bind Time2.17s (± 0.86%)2.16s (± 0.99%)~2.12s2.18sp=0.746 n=6
Check Time23.10s (± 1.66%)22.95s (± 0.65%)~22.79s23.20sp=0.810 n=6
Emit Time0.00s (±244.70%)0.00s~~~p=0.405 n=6
Total Time30.25s (± 1.28%)30.11s (± 0.52%)~29.93s30.35sp=0.810 n=6
xstate-main - node (v18.15.0, x64)
Errors33~~~p=1.000 n=6
Symbols543,130543,130~~~p=1.000 n=6
Types181,889181,889~~~p=1.000 n=6
Memory used485,484k (± 0.03%)485,537k (± 0.01%)~485,507k485,599kp=1.000 n=6
Parse Time4.17s (± 0.64%)4.18s (± 0.71%)~4.14s4.22sp=0.809 n=6
Bind Time1.46s (± 0.84%)1.45s (± 0.94%)~1.44s1.47sp=0.798 n=6
Check Time23.84s (± 0.90%)23.78s (± 0.46%)~23.65s23.91sp=0.746 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time29.47s (± 0.77%)29.41s (± 0.49%)~29.24s29.57sp=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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

@dragomirtitianTitian Cernicova-Dragomir (dragomirtitian)Oct 29, 2024

Copy link
Copy Markdown
ContributorAuthor

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

@jakebaileyJake Bailey (jakebailey) left a comment

Copy link
Copy Markdown
Member

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. Wesley Wigham (@weswigham)Daniel Rosenwasser (@DanielRosenwasser) do you have an opinion here?

@jakebailey

Copy link
Copy Markdown
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.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dragomirtitian@typescript-bot@jakebailey@sandersn