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

Only resolve source return type when actually needed during inference #58650

Merged
merged 4 commits into from
May 28, 2024

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented May 24, 2024

Fixes #58616. Also fixes an unnecessary circularity in one of our existing tests.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels May 24, 2024
# Conflicts:
#	tests/baselines/reference/circularReferenceInReturnType.types
@ahejlsberg
Copy link
Member Author

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 24, 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 comparing main and refs/pull/58650/merge:

Something interesting changed - please have a look.

Details

webpack

tsconfig.types.json

  • [NEW] error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.

@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,154 62,153 -1 (- 0.00%) ~ ~ p=0.001 n=6
Types 50,248 50,242 -6 (- 0.01%) ~ ~ p=0.001 n=6
Memory used 192,864k (± 0.78%) 192,278k (± 0.07%) ~ 192,194k 192,563k p=0.689 n=6
Parse Time 1.55s (± 1.40%) 1.56s (± 1.26%) ~ 1.53s 1.58s p=0.467 n=6
Bind Time 0.86s (± 0.97%) 0.86s (± 1.59%) ~ 0.85s 0.88s p=1.000 n=6
Check Time 11.33s (± 0.29%) 11.31s (± 0.36%) ~ 11.26s 11.37s p=0.571 n=6
Emit Time 3.13s (± 1.26%) 3.14s (± 0.16%) ~ 3.14s 3.15s p=0.560 n=6
Total Time 16.87s (± 0.39%) 16.88s (± 0.16%) ~ 16.84s 16.92s p=0.687 n=6
angular-1 - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 944,110 944,105 -5 (- 0.00%) ~ ~ p=0.001 n=6
Types 407,140 407,032 -108 (- 0.03%) ~ ~ p=0.001 n=6
Memory used 1,222,010k (± 0.00%) 1,222,031k (± 0.01%) ~ 1,221,879k 1,222,127k p=0.298 n=6
Parse Time 8.10s (± 0.47%) 8.12s (± 0.52%) ~ 8.06s 8.17s p=0.466 n=6
Bind Time 2.24s (± 0.67%) 2.25s (± 0.79%) ~ 2.23s 2.28s p=0.190 n=6
Check Time 36.61s (± 0.52%) 36.54s (± 0.64%) ~ 36.30s 36.88s p=0.378 n=6
Emit Time 17.54s (± 0.79%) 17.57s (± 0.76%) ~ 17.40s 17.76s p=0.748 n=6
Total Time 64.48s (± 0.25%) 64.47s (± 0.41%) ~ 64.25s 64.92s p=0.575 n=6
mui-docs - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 1,982,501 1,982,496 -5 (- 0.00%) ~ ~ p=0.001 n=6
Types 882,099 882,085 -14 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 1,886,154k (± 0.00%) 1,886,053k (± 0.00%) -101k (- 0.01%) 1,886,025k 1,886,073k p=0.005 n=6
Parse Time 6.79s (± 0.25%) 6.80s (± 0.50%) ~ 6.77s 6.85s p=0.685 n=6
Bind Time 2.30s (± 0.93%) 2.30s (± 0.80%) ~ 2.28s 2.33s p=0.867 n=6
Check Time 60.56s (± 0.29%) 60.56s (± 0.37%) ~ 60.25s 60.80s p=0.936 n=6
Emit Time 0.14s (± 4.05%) 0.14s ~ ~ ~ p=0.071 n=6
Total Time 69.78s (± 0.27%) 69.79s (± 0.36%) ~ 69.45s 70.08s p=1.000 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,225,780 1,225,756 -24 (- 0.00%) ~ ~ p=0.001 n=6
Types 260,772 260,634 -138 (- 0.05%) ~ ~ p=0.001 n=6
Memory used 2,343,388k (± 0.07%) 2,343,249k (± 0.03%) ~ 2,342,377k 2,344,432k p=0.689 n=6
Parse Time 7.50s (± 1.30%) 7.39s (± 1.05%) ~ 7.30s 7.49s p=0.077 n=6
Bind Time 2.80s (± 0.37%) 2.79s (± 0.73%) ~ 2.76s 2.81s p=0.627 n=6
Check Time 49.43s (± 0.72%) 49.29s (± 0.27%) ~ 49.08s 49.44s p=0.689 n=6
Emit Time 3.75s (± 4.02%) 3.82s (± 5.72%) ~ 3.65s 4.24s p=0.470 n=6
Total Time 63.49s (± 0.93%) 63.31s (± 0.50%) ~ 62.97s 63.84s 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,225,780 1,225,756 -24 (- 0.00%) ~ ~ p=0.001 n=6
Types 260,772 260,634 -138 (- 0.05%) ~ ~ p=0.001 n=6
Memory used 2,454,143k (± 2.46%) 2,468,547k (± 3.16%) ~ 2,416,964k 2,569,375k p=0.810 n=6
Parse Time 6.26s (± 1.04%) 6.22s (± 0.90%) ~ 6.13s 6.28s p=0.378 n=6
Bind Time 2.04s (± 0.20%) 2.04s (± 0.67%) ~ 2.02s 2.06s p=0.667 n=6
Check Time 40.25s (± 0.43%) 40.37s (± 0.61%) ~ 40.12s 40.80s p=0.471 n=6
Emit Time 3.12s (± 7.47%) 3.10s (± 3.84%) ~ 2.94s 3.21s p=0.936 n=6
Total Time 51.69s (± 0.72%) 51.73s (± 0.59%) ~ 51.39s 52.28s p=0.575 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 258,042 258,030 -12 (- 0.00%) ~ ~ p=0.001 n=6
Types 104,983 104,903 -80 (- 0.08%) ~ ~ p=0.001 n=6
Memory used 426,861k (± 0.02%) 426,797k (± 0.01%) ~ 426,720k 426,828k p=0.078 n=6
Parse Time 4.17s (± 0.47%) 4.16s (± 0.71%) ~ 4.12s 4.19s p=0.627 n=6
Bind Time 1.62s (± 0.65%) 1.63s (± 0.63%) ~ 1.61s 1.64s p=0.098 n=6
Check Time 22.25s (± 0.52%) 22.25s (± 0.60%) ~ 22.09s 22.39s p=0.936 n=6
Emit Time 1.65s (± 1.65%) 1.70s (± 0.89%) +0.04s (+ 2.42%) 1.68s 1.72s p=0.023 n=6
Total Time 29.69s (± 0.37%) 29.72s (± 0.50%) ~ 29.55s 29.91s p=0.872 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,575 224,565 -10 (- 0.00%) ~ ~ p=0.001 n=6
Types 93,785 93,734 -51 (- 0.05%) ~ ~ p=0.001 n=6
Memory used 369,783k (± 0.02%) 369,851k (± 0.02%) ~ 369,746k 369,964k p=0.173 n=6
Parse Time 3.50s (± 0.93%) 3.49s (± 1.08%) ~ 3.44s 3.53s p=0.688 n=6
Bind Time 1.93s (± 1.16%) 1.92s (± 1.11%) ~ 1.90s 1.95s p=0.370 n=6
Check Time 19.37s (± 0.29%) 19.35s (± 0.45%) ~ 19.26s 19.50s p=0.574 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.81s (± 0.29%) 24.76s (± 0.38%) ~ 24.60s 24.88s p=0.421 n=6
vscode - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,836,660 2,836,658 -2 (- 0.00%) ~ ~ p=0.001 n=6
Types 961,296 960,774 -522 (- 0.05%) ~ ~ p=0.001 n=6
Memory used 3,009,142k (± 0.00%) 3,008,946k (± 0.00%) -196k (- 0.01%) 3,008,894k 3,008,978k p=0.005 n=6
Parse Time 13.82s (± 0.23%) 13.83s (± 0.25%) ~ 13.79s 13.88s p=0.872 n=6
Bind Time 4.16s (± 0.29%) 4.16s (± 0.39%) ~ 4.14s 4.19s p=0.319 n=6
Check Time 74.78s (± 2.78%) 74.10s (± 2.09%) ~ 73.36s 77.25s p=0.810 n=6
Emit Time 22.27s (± 9.00%) 23.06s (± 6.89%) ~ 19.83s 23.95s p=0.149 n=6
Total Time 115.03s (± 0.19%) 115.15s (± 0.26%) ~ 114.93s 115.74s p=0.810 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 266,087 266,048 -39 (- 0.01%) ~ ~ p=0.001 n=6
Types 108,518 108,470 -48 (- 0.04%) ~ ~ p=0.001 n=6
Memory used 410,989k (± 0.03%) 410,812k (± 0.02%) -176k (- 0.04%) 410,739k 410,919k p=0.045 n=6
Parse Time 3.86s (± 1.21%) 3.82s (± 1.20%) ~ 3.75s 3.89s p=0.226 n=6
Bind Time 1.66s (± 0.59%) 1.66s (± 0.38%) ~ 1.65s 1.67s p=0.733 n=6
Check Time 17.01s (± 0.55%) 17.02s (± 0.48%) ~ 16.90s 17.10s p=0.936 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.53s (± 0.54%) 22.50s (± 0.42%) ~ 22.35s 22.59s p=0.871 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 535,745 535,743 -2 (- 0.00%) ~ ~ p=0.001 n=6
Types 182,753 182,738 -15 (- 0.01%) ~ ~ p=0.001 n=6
Memory used 470,420k (± 0.01%) 470,404k (± 0.01%) ~ 470,335k 470,460k p=0.575 n=6
Parse Time 3.17s (± 0.83%) 3.16s (± 0.24%) ~ 3.15s 3.17s p=0.279 n=6
Bind Time 1.20s (± 0.97%) 1.20s (± 0.43%) ~ 1.19s 1.20s p=0.542 n=6
Check Time 18.36s (± 0.31%) 18.33s (± 0.38%) ~ 18.25s 18.45s p=0.423 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.72s (± 0.18%) 22.69s (± 0.31%) ~ 22.61s 22.81s p=0.261 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

@@ -3,7 +3,7 @@
=== Performance Stats ===
Assignability cache: 10,000
Type Count: 50,000
Instantiation count: 250,000
Instantiation count: 100,000
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@@ -28,7 +28,7 @@ flatArrayNoExcessiveStackDepth.ts(20,5): error TS2322: Type 'FlatArray<Arr, any>
~
!!! error TS2322: Type 'FlatArray<Arr, any>' is not assignable to type 'FlatArray<Arr, D>'.
!!! error TS2322: Type 'Arr' is not assignable to type 'FlatArray<Arr, D>'.
!!! error TS2322: Type 'Arr' is not assignable to type '(Arr extends readonly (infer InnerArr)[] ? FlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][D]> : Arr) & Arr'.
!!! error TS2322: Type 'Arr' is not assignable to type 'Arr & (Arr extends readonly (infer InnerArr)[] ? FlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][D]> : Arr)'.
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing that because a return type was not eagerly calculated at some step, one of these types was created later than the other.

Copy link
Member

@DanielRosenwasser DanielRosenwasser May 24, 2024

Choose a reason for hiding this comment

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

Though we don't sort type IDs in intersections, so that's not it.

Copy link
Member Author

@ahejlsberg ahejlsberg May 24, 2024

Choose a reason for hiding this comment

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

I'm sure it's a case of a distributing over a union type and turning it into an intersection type in a write-position. We do that in several places in type simplification and type relations. For example, an indexed access type T[K], where K is a union type, occurring in a write-position.

@DanielRosenwasser
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 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 May 24, 2024

Hey @DanielRosenwasser, 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/161926/artifacts?artifactName=tgz&fileId=7C4C88D3CC0BAE62E2E916143B8B1846083A315541F261C3DA38959E4EF3190402&fileName=/typescript-5.5.0-insiders.20240524.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/[email protected]".;

@typescript-bot
Copy link
Collaborator

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

Something interesting changed - please have a look.

Details

tinacms/tinacms

11 of 24 projects failed to build with the old tsc and were ignored

packages/@tinacms/cli/tsconfig.json

@DanielRosenwasser
Copy link
Member

The Webpack change is that there are now two implicit any errors instead of just one.

@ahejlsberg
Copy link
Member Author

The Webpack change is that there are now two implicit any errors instead of just one.

Looks to me like we now get a bit deeper in type resolution before detecting the circularity in here, and thus we report an error in one more place (because the resolution stack is one level deeper). This actually improves the error reporting because it makes it easier to see what causes the circularity.

@ahejlsberg
Copy link
Member Author

ahejlsberg commented May 26, 2024

The new errors in the tinacms repo result from the absence of circularities that previously caused arrow functions to have implicit any return types. The repo has noImplicitAny turned off, so those circularities would simply go unreported and the types would become very permissive. With this PR, the circularities are gone, the types are actually what they should be, and appropriate errors are reported.

@ahejlsberg
Copy link
Member Author

I think this is ready to merge. Performance is unaffected and the new test suite errors in are all desirable and correct.

@ahejlsberg ahejlsberg merged commit 1d026a9 into main May 28, 2024
28 checks passed
@ahejlsberg ahejlsberg deleted the fix58616 branch May 28, 2024 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More flexible handling of circular types with "typeof function" inference
4 participants