Skip to content

Avoid infinite recursion with inferReverseMappedType #57837

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 5 commits into from
Apr 16, 2024
Merged

Conversation

gabritto
Copy link
Member

@gabritto gabritto commented Mar 18, 2024

Fixes #57786.

For reference, the test case reported in the issue loops until stack overflow with the following function calls repeating:

at resolveReverseMappedTypeMembers (src\compiler\checker.ts:13790:69)
at resolveStructuredTypeMembers (src\compiler\checker.ts:14103:21)
at C:\Users\gabrielaa\code\Typescript\src\compiler\checker.ts:17091:148
at some (src\compiler\core.ts:665:21)
at removeSubtypes (src\compiler\checker.ts:17091:50)
at getUnionTypeWorker (src\compiler\checker.ts:17314:27)
at getUnionType (src\compiler\checker.ts:17286:16)
at getTypeFromInference (src\compiler\checker.ts:25353:39)
at inferReverseMappedType (src\compiler\checker.ts:25307:16)

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

@typescript-bot run dt
@typescript-bot user test this
@typescript-bot test top400
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 18, 2024

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

Command Status Results
run dt ✅ Started ✅ Results
user test this ✅ Started ✅ Results
test top400 ✅ Started ✅ Results
perf test this ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

Hey @gabritto, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the user test suite comparing main and refs/pull/57837/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Unknown failure"

Otherwise...

Everything looks good!

@typescript-bot
Copy link
Collaborator

@gabritto
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
Angular - node (v18.15.0, x64)
Memory used 295,753k (± 0.00%) 295,761k (± 0.00%) ~ 295,744k 295,772k p=0.260 n=6
Parse Time 2.66s (± 0.15%) 2.66s (± 0.37%) ~ 2.65s 2.67s p=0.930 n=6
Bind Time 0.83s (± 0.49%) 0.83s (± 0.66%) ~ 0.82s 0.83s p=0.282 n=6
Check Time 8.18s (± 0.26%) 8.18s (± 0.21%) ~ 8.15s 8.20s p=0.870 n=6
Emit Time 7.12s (± 0.48%) 7.14s (± 0.17%) ~ 7.12s 7.15s p=0.293 n=6
Total Time 18.80s (± 0.22%) 18.80s (± 0.11%) ~ 18.77s 18.83s p=0.629 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,189k (± 0.91%) 193,863k (± 0.99%) ~ 191,885k 195,684k p=0.298 n=6
Parse Time 1.38s (± 1.33%) 1.36s (± 1.10%) ~ 1.34s 1.38s p=0.134 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.46s (± 0.74%) 9.54s (± 0.74%) ~ 9.44s 9.62s p=0.147 n=6
Emit Time 2.66s (± 0.39%) 2.66s (± 0.70%) ~ 2.63s 2.68s p=0.934 n=6
Total Time 14.21s (± 0.59%) 14.28s (± 0.45%) ~ 14.18s 14.35s p=0.109 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,387k (± 0.01%) 347,386k (± 0.01%) ~ 347,366k 347,417k p=1.000 n=6
Parse Time 2.48s (± 0.49%) 2.48s (± 0.49%) ~ 2.46s 2.49s p=0.406 n=6
Bind Time 0.93s (± 0.00%) 0.92s (± 0.59%) ~ 0.92s 0.93s p=0.071 n=6
Check Time 7.00s (± 0.49%) 7.03s (± 0.41%) ~ 6.98s 7.07s p=0.294 n=6
Emit Time 4.06s (± 0.50%) 4.05s (± 0.25%) ~ 4.03s 4.06s p=0.181 n=6
Total Time 14.48s (± 0.31%) 14.48s (± 0.27%) ~ 14.42s 14.54s p=0.686 n=6
TFS - node (v18.15.0, x64)
Memory used 302,718k (± 0.00%) 302,737k (± 0.01%) ~ 302,713k 302,775k p=0.173 n=6
Parse Time 2.01s (± 0.26%) 2.00s (± 1.48%) ~ 1.95s 2.04s p=0.209 n=6
Bind Time 1.00s (± 0.75%) 1.01s (± 1.16%) ~ 0.99s 1.02s p=0.279 n=6
Check Time 6.32s (± 0.23%) 6.29s (± 0.46%) ~ 6.26s 6.33s p=0.089 n=6
Emit Time 3.61s (± 0.37%) 3.62s (± 0.29%) ~ 3.60s 3.63s p=0.358 n=6
Total Time 12.94s (± 0.19%) 12.91s (± 0.22%) ~ 12.87s 12.95s p=0.106 n=6
material-ui - node (v18.15.0, x64)
Memory used 511,372k (± 0.00%) 511,356k (± 0.00%) ~ 511,327k 511,381k p=0.173 n=6
Parse Time 2.65s (± 0.55%) 2.65s (± 0.39%) ~ 2.64s 2.67s p=0.805 n=6
Bind Time 0.98s (± 1.58%) 0.98s (± 0.52%) ~ 0.98s 0.99s p=0.929 n=6
Check Time 17.37s (± 0.50%) 17.31s (± 0.51%) ~ 17.19s 17.42s p=0.298 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.00s (± 0.38%) 20.95s (± 0.44%) ~ 20.83s 21.08s p=0.261 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,719,111k (± 0.00%) 1,719,101k (± 0.00%) ~ 1,719,052k 1,719,152k p=0.936 n=6
Parse Time 6.50s (± 0.48%) 6.49s (± 0.53%) ~ 6.43s 6.53s p=1.000 n=6
Bind Time 2.36s (± 0.83%) 2.36s (± 0.32%) ~ 2.35s 2.37s p=1.000 n=6
Check Time 56.34s (± 0.14%) 56.28s (± 0.69%) ~ 55.90s 56.77s p=0.470 n=6
Emit Time 0.13s (± 3.10%) 0.13s (± 3.10%) ~ 0.13s 0.14s p=1.000 n=6
Total Time 65.34s (± 0.13%) 65.26s (± 0.62%) ~ 64.81s 65.75s p=0.688 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,395,521k (± 0.02%) 2,395,122k (± 0.03%) ~ 2,394,054k 2,395,827k p=0.230 n=6
Parse Time 5.01s (± 1.02%) 4.97s (± 1.44%) ~ 4.87s 5.05s p=0.521 n=6
Bind Time 1.89s (± 1.02%) 1.90s (± 0.91%) ~ 1.88s 1.92s p=0.557 n=6
Check Time 33.58s (± 0.35%) 33.66s (± 0.46%) ~ 33.45s 33.82s p=0.423 n=6
Emit Time 2.71s (± 0.89%) 2.74s (± 0.45%) +0.04s (+ 1.42%) 2.73s 2.76s p=0.022 n=6
Total Time 43.21s (± 0.36%) 43.29s (± 0.43%) ~ 43.08s 43.50s p=0.471 n=6
self-compiler - node (v18.15.0, x64)
Memory used 416,073k (± 0.01%) 416,134k (± 0.01%) +61k (+ 0.01%) 416,093k 416,190k p=0.013 n=6
Parse Time 2.86s (± 1.23%) 2.81s (± 1.38%) ~ 2.75s 2.86s p=0.122 n=6
Bind Time 1.06s (± 0.97%) 1.07s (± 0.70%) ~ 1.06s 1.08s p=0.351 n=6
Check Time 15.32s (± 0.29%) 15.28s (± 0.37%) ~ 15.19s 15.36s p=0.333 n=6
Emit Time 1.14s (± 1.43%) 1.15s (± 1.23%) ~ 1.13s 1.17s p=0.459 n=6
Total Time 20.38s (± 0.11%) 20.32s (± 0.18%) -0.06s (- 0.31%) 20.26s 20.37s p=0.016 n=6
vscode - node (v18.15.0, x64)
Memory used 2,883,061k (± 0.00%) 2,883,039k (± 0.00%) ~ 2,882,921k 2,883,145k p=0.575 n=6
Parse Time 10.82s (± 0.37%) 10.82s (± 0.43%) ~ 10.77s 10.88s p=0.936 n=6
Bind Time 3.47s (± 0.34%) 3.47s (± 0.24%) ~ 3.46s 3.48s p=1.000 n=6
Check Time 61.64s (± 0.54%) 61.59s (± 0.71%) ~ 61.06s 62.06s p=1.000 n=6
Emit Time 16.92s (± 8.12%) 17.62s (± 9.67%) ~ 16.32s 19.89s p=0.148 n=6
Total Time 92.85s (± 1.52%) 93.50s (± 2.23%) ~ 91.80s 96.19s p=1.000 n=6
webpack - node (v18.15.0, x64)
Memory used 407,994k (± 0.02%) 407,945k (± 0.01%) ~ 407,894k 408,008k p=0.378 n=6
Parse Time 3.22s (± 0.46%) 3.22s (± 0.38%) ~ 3.21s 3.24s p=0.934 n=6
Bind Time 1.38s (± 0.30%) 1.38s (± 1.29%) ~ 1.35s 1.40s p=0.548 n=6
Check Time 14.30s (± 0.32%) 14.29s (± 0.34%) ~ 14.22s 14.35s p=0.872 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.91s (± 0.25%) 18.89s (± 0.27%) ~ 18.82s 18.97s p=0.687 n=6
xstate - node (v18.15.0, x64)
Memory used 513,080k (± 0.02%) 513,059k (± 0.01%) ~ 512,984k 513,143k p=0.575 n=6
Parse Time 3.27s (± 0.43%) 3.28s (± 0.36%) ~ 3.27s 3.30s p=0.357 n=6
Bind Time 1.54s (± 0.67%) 1.54s (± 0.49%) ~ 1.53s 1.55s p=0.931 n=6
Check Time 2.86s (± 0.82%) 2.84s (± 0.47%) ~ 2.82s 2.86s p=0.418 n=6
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) ~ 0.07s 0.07s p=1.000 n=6
Total Time 7.74s (± 0.44%) 7.74s (± 0.22%) ~ 7.71s 7.76s p=0.747 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,351ms (± 0.66%) 2,355ms (± 0.49%) ~ 2,342ms 2,368ms p=0.872 n=6
Req 2 - geterr 5,779ms (± 0.53%) 5,772ms (± 0.38%) ~ 5,738ms 5,802ms p=0.688 n=6
Req 3 - references 325ms (± 1.11%) 325ms (± 0.89%) ~ 322ms 330ms p=0.934 n=6
Req 4 - navto 273ms (± 0.19%) 272ms (± 0.19%) ~ 272ms 273ms p=0.311 n=6
Req 5 - completionInfo count 1,357 (± 0.00%) 1,357 (± 0.00%) ~ 1,357 1,357 p=1.000 n=6
Req 5 - completionInfo 94ms (± 0.80%) 95ms (± 0.88%) ~ 93ms 95ms p=0.432 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,504ms (± 0.72%) 2,491ms (± 0.54%) ~ 2,478ms 2,517ms p=0.261 n=6
Req 2 - geterr 4,262ms (± 0.21%) 4,261ms (± 0.37%) ~ 4,242ms 4,288ms p=0.810 n=6
Req 3 - references 331ms (± 0.31%) 332ms (± 0.25%) ~ 331ms 333ms p=0.546 n=6
Req 4 - navto 284ms (± 0.37%) 284ms (± 0.56%) ~ 283ms 287ms p=0.615 n=6
Req 5 - completionInfo count 1,519 (± 0.00%) 1,519 (± 0.00%) ~ 1,519 1,519 p=1.000 n=6
Req 5 - completionInfo 78ms (± 0.66%) 78ms (± 1.04%) ~ 77ms 79ms p=0.140 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,620ms (± 0.19%) 2,618ms (± 0.44%) ~ 2,601ms 2,634ms p=0.688 n=6
Req 2 - geterr 1,719ms (± 1.78%) 1,722ms (± 2.50%) ~ 1,658ms 1,782ms p=1.000 n=6
Req 3 - references 121ms (± 8.29%) 122ms (± 8.14%) ~ 108ms 130ms p=0.935 n=6
Req 4 - navto 373ms (± 0.53%) 372ms (± 0.92%) ~ 369ms 378ms p=0.332 n=6
Req 5 - completionInfo count 2,079 (± 0.00%) 2,079 (± 0.00%) ~ 2,079 2,079 p=1.000 n=6
Req 5 - completionInfo 307ms (± 2.48%) 308ms (± 1.57%) ~ 302ms 315ms p=0.423 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 153.49ms (± 0.19%) 153.60ms (± 0.19%) +0.12ms (+ 0.08%) 152.56ms 157.44ms p=0.000 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 229.88ms (± 0.15%) 229.89ms (± 0.18%) ~ 228.34ms 236.39ms p=0.624 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 222.29ms (± 0.13%) 222.24ms (± 0.15%) ~ 220.70ms 229.06ms p=0.054 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 221.86ms (± 0.15%) 221.80ms (± 0.15%) ~ 220.39ms 225.21ms p=0.144 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the top-repos suite comparing main and refs/pull/57837/merge:

Everything looks good!

@gabritto
Copy link
Member Author

@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 18, 2024

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

Command Status Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

@gabritto
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
Angular - node (v18.15.0, x64)
Memory used 295,756k (± 0.01%) 295,754k (± 0.00%) ~ 295,733k 295,770k p=0.810 n=6
Parse Time 2.66s (± 0.15%) 2.66s (± 0.70%) ~ 2.63s 2.68s p=0.473 n=6
Bind Time 0.83s (± 0.62%) 0.83s (± 0.90%) ~ 0.82s 0.84s p=0.241 n=6
Check Time 8.20s (± 0.40%) 8.20s (± 0.32%) ~ 8.15s 8.22s p=0.746 n=6
Emit Time 7.12s (± 0.25%) 7.13s (± 0.32%) ~ 7.09s 7.15s p=0.463 n=6
Total Time 18.81s (± 0.30%) 18.82s (± 0.32%) ~ 18.71s 18.87s p=1.000 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 192,053k (± 0.09%) 192,189k (± 0.07%) ~ 191,915k 192,301k p=0.471 n=6
Parse Time 1.36s (± 1.42%) 1.35s (± 0.73%) ~ 1.33s 1.36s p=0.081 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.53s (± 0.57%) 9.52s (± 0.78%) ~ 9.40s 9.61s p=1.000 n=6
Emit Time 2.66s (± 0.62%) 2.65s (± 0.31%) ~ 2.64s 2.66s p=0.616 n=6
Total Time 14.27s (± 0.41%) 14.24s (± 0.55%) ~ 14.11s 14.34s p=0.936 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,383k (± 0.01%) 347,383k (± 0.01%) ~ 347,362k 347,419k p=0.936 n=6
Parse Time 2.48s (± 0.54%) 2.48s (± 0.40%) ~ 2.46s 2.49s p=0.934 n=6
Bind Time 0.93s (± 0.56%) 0.93s (± 0.00%) ~ 0.93s 0.93s p=0.174 n=6
Check Time 7.03s (± 0.56%) 7.03s (± 0.60%) ~ 6.95s 7.08s p=1.000 n=6
Emit Time 4.07s (± 0.29%) 4.06s (± 0.63%) ~ 4.04s 4.09s p=0.744 n=6
Total Time 14.51s (± 0.30%) 14.49s (± 0.26%) ~ 14.45s 14.54s p=0.520 n=6
TFS - node (v18.15.0, x64)
Memory used 302,730k (± 0.00%) 302,761k (± 0.01%) ~ 302,711k 302,803k p=0.108 n=6
Parse Time 2.01s (± 0.86%) 1.99s (± 0.53%) ~ 1.98s 2.01s p=0.086 n=6
Bind Time 1.01s (± 0.81%) 1.00s (± 1.22%) ~ 0.99s 1.02s p=0.730 n=6
Check Time 6.31s (± 0.16%) 6.32s (± 0.44%) ~ 6.28s 6.36s p=0.802 n=6
Emit Time 3.61s (± 0.62%) 3.62s (± 0.71%) ~ 3.57s 3.64s p=0.743 n=6
Total Time 12.94s (± 0.29%) 12.93s (± 0.33%) ~ 12.87s 12.97s p=1.000 n=6
material-ui - node (v18.15.0, x64)
Memory used 511,358k (± 0.00%) 511,377k (± 0.00%) ~ 511,366k 511,392k p=0.149 n=6
Parse Time 2.66s (± 0.79%) 2.65s (± 0.66%) ~ 2.63s 2.68s p=0.190 n=6
Bind Time 0.98s (± 1.06%) 0.99s (± 0.83%) ~ 0.98s 1.00s p=0.865 n=6
Check Time 17.32s (± 0.41%) 17.30s (± 0.42%) ~ 17.21s 17.43s p=0.629 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.97s (± 0.31%) 20.93s (± 0.35%) ~ 20.83s 21.05s p=0.332 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,719,093k (± 0.00%) 1,719,130k (± 0.00%) ~ 1,719,032k 1,719,175k p=0.128 n=6
Parse Time 6.51s (± 0.24%) 6.50s (± 0.64%) ~ 6.44s 6.55s p=0.685 n=6
Bind Time 2.36s (± 0.42%) 2.36s (± 0.32%) ~ 2.35s 2.37s p=1.000 n=6
Check Time 56.21s (± 0.51%) 56.42s (± 0.73%) ~ 55.77s 57.07s p=0.230 n=6
Emit Time 0.13s (± 0.00%) 0.13s (± 0.00%) ~ 0.13s 0.13s p=1.000 n=6
Total Time 65.22s (± 0.46%) 65.41s (± 0.64%) ~ 64.80s 66.11s p=0.298 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,395,474k (± 0.02%) 2,395,381k (± 0.02%) ~ 2,394,644k 2,395,892k p=0.810 n=6
Parse Time 4.99s (± 1.03%) 4.95s (± 1.04%) ~ 4.89s 5.01s p=0.230 n=6
Bind Time 1.91s (± 1.14%) 1.90s (± 0.90%) ~ 1.88s 1.92s p=0.805 n=6
Check Time 33.53s (± 0.32%) 33.56s (± 0.36%) ~ 33.39s 33.70s p=0.748 n=6
Emit Time 2.72s (± 0.68%) 2.73s (± 0.89%) ~ 2.68s 2.74s p=0.277 n=6
Total Time 43.15s (± 0.32%) 43.16s (± 0.37%) ~ 42.95s 43.35s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Memory used 416,067k (± 0.01%) 416,118k (± 0.01%) +51k (+ 0.01%) 416,062k 416,146k p=0.045 n=6
Parse Time 2.82s (± 1.12%) 2.81s (± 1.05%) ~ 2.76s 2.84s p=0.570 n=6
Bind Time 1.06s (± 0.60%) 1.07s (± 0.51%) ~ 1.06s 1.07s p=0.201 n=6
Check Time 15.32s (± 0.50%) 15.30s (± 0.18%) ~ 15.27s 15.35s p=0.226 n=6
Emit Time 1.14s (± 1.47%) 1.15s (± 0.55%) ~ 1.14s 1.16s p=0.323 n=6
Total Time 20.34s (± 0.41%) 20.33s (± 0.15%) ~ 20.27s 20.36s p=0.625 n=6
vscode - node (v18.15.0, x64)
Memory used 2,883,054k (± 0.00%) 2,883,078k (± 0.00%) ~ 2,882,966k 2,883,165k p=0.575 n=6
Parse Time 10.85s (± 0.34%) 10.81s (± 0.35%) ~ 10.78s 10.88s p=0.076 n=6
Bind Time 3.45s (± 0.98%) 3.48s (± 0.83%) ~ 3.45s 3.53s p=0.569 n=6
Check Time 61.52s (± 0.75%) 61.80s (± 0.50%) ~ 61.42s 62.32s p=0.173 n=6
Emit Time 16.96s (± 8.33%) 18.14s (±10.65%) ~ 16.30s 20.01s p=0.521 n=6
Total Time 92.79s (± 1.96%) 94.23s (± 2.31%) ~ 92.09s 96.51s p=0.230 n=6
webpack - node (v18.15.0, x64)
Memory used 407,998k (± 0.02%) 407,960k (± 0.02%) ~ 407,838k 408,102k p=0.471 n=6
Parse Time 3.23s (± 0.28%) 3.23s (± 0.46%) ~ 3.21s 3.25s p=0.804 n=6
Bind Time 1.38s (± 0.85%) 1.38s (± 0.46%) ~ 1.37s 1.39s p=1.000 n=6
Check Time 14.30s (± 0.32%) 14.30s (± 0.36%) ~ 14.22s 14.35s p=0.936 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.91s (± 0.29%) 18.91s (± 0.30%) ~ 18.81s 18.96s p=0.809 n=6
xstate - node (v18.15.0, x64)
Memory used 513,142k (± 0.01%) 513,060k (± 0.01%) ~ 513,002k 513,119k p=0.093 n=6
Parse Time 3.28s (± 0.31%) 3.27s (± 0.33%) ~ 3.26s 3.29s p=0.251 n=6
Bind Time 1.55s (± 0.53%) 1.54s (± 0.68%) ~ 1.53s 1.56s p=0.865 n=6
Check Time 2.85s (± 0.31%) 2.85s (± 0.59%) ~ 2.83s 2.87s p=0.934 n=6
Emit Time 0.07s (± 5.69%) 0.07s (± 7.03%) ~ 0.07s 0.08s p=0.595 n=6
Total Time 7.75s (± 0.15%) 7.74s (± 0.28%) ~ 7.72s 7.77s p=0.627 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@gabritto gabritto marked this pull request as ready for review March 19, 2024 01:18
@gabritto gabritto changed the title Avoid infinite recursion in inferReverseMappedType Avoid infinite recursion with inferReverseMappedType Mar 19, 2024
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

The less-broadly used inferTypeForHomomorphicMappedType has caching/circularity prevention mechanisms already, but I guess since we use this lazily to generate the types of properties of reverse mapped types (directly, in more places than just the aforementioned function), it's gotta get dedicated circularity guards. I'm just wondering if the fail case should be unknown, or if it should be the constraint of the target?

@gabritto
Copy link
Member Author

The less-broadly used inferTypeForHomomorphicMappedType has caching/circularity prevention mechanisms already, but I guess since we use this lazily to generate the types of properties of reverse mapped types (directly, in more places than just the aforementioned function), it's gotta get dedicated circularity guards.

What's the difference between calling inferTypeForHomomorphicMappedType and calling inferReverseMappedType directly?

I'm just wondering if the fail case should be unknown, or if it should be the constraint of the target?

I also have this same question. I'm returning unknown just because that's what inferReverseMappedType was already returning when inference failed (return getTypeFromInference(inference) || unknownType), but I don't know how we usually deal with failed inferences.

@weswigham
Copy link
Member

What's the difference between calling inferTypeForHomomorphicMappedType and calling inferReverseMappedType directly?

inferTypeForHomomorphicMappedType is used to create the outer object type with lazily inferred properties, while inferReverseMappedType is used to make the types for the properties of that type on demand.

but I don't know how we usually deal with failed inferences.

getInferredType usually falls back to the constraint of the type parameter. I dunno if we wanna change the reverse mapped type fallback behavior to match. Maybe that should be a separate followup PR.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

This seems fine - definitely an improvement. Just wondering if we should also be doing caching within this function, rather than relying on callers of it to cache the results somehow.

const typeParameter = getIndexedAccessType(constraint.type, getTypeParameterFromMappedType(target)) as TypeParameter;
const templateType = getTemplateTypeFromMappedType(target);
const inference = createInferenceInfo(typeParameter);
inferTypes([inference], sourceType, templateType);
return getTypeFromInference(inference) || unknownType;
}

function inferReverseMappedType(source: Type, target: MappedType, constraint: IndexType): Type {
Copy link
Member

Choose a reason for hiding this comment

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

Should we cache the results inside this, so we guarantee deeply nested results get cached? Of the callers of this function, only getTypeOfReverseMappedSymbol currently caches - the other uses don't (directly) cache the result, so could, in theory, witness different results for the same set of input types at different points. You can probably only easily trigger such a behavior with a reverse mapped type over an array...? Maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was adding the cache to inferReverseMappedType and looking at inferTypeForHomomorphicMappedType. I'm now wondering: could I do away with the recursion detection in inferTypeForHomomorphicMappedType (that uses homomorphicMappedTypeInferenceStack)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm pretty sure that we can, however this once again begs the question of what to return when we find a circularity. inferTypeForHomomorphicMappedType returns undefined in this case. I'll have to think some more about this, but I'm planning on removing that circularity detection code in inferTypeForHomomorphicMappedType.

@sandersn
Copy link
Member

I can't tell from the discussion if this is ready to merge. Do we want to investigate better caching before taking this? Do we need to figure out what happens in case of circularity?

@gabritto
Copy link
Member Author

I can't tell from the discussion if this is ready to merge. Do we want to investigate better caching before taking this? Do we need to figure out what happens in case of circularity?

I want to do two things still: 1. think about what to return in case of circularity 2. get rid of the circularity detection in inferTypeForHomomorphicMappedType as I think the one in this PR supersedes that one. I might not succeed and decide to merge as is, but if I change something I'll re-request reviews.

@Andarist
Copy link
Contributor

getInferredType usually falls back to the constraint of the type parameter. I dunno if we wanna change the reverse mapped type fallback behavior to match. Maybe that should be a separate followup PR.

I think that PR might already exist: #56300 ;p I need to take another look at it to see what is left to do there though

@gabritto
Copy link
Member Author

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 10, 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 @gabritto, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the user tests comparing main and refs/pull/57837/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@gabritto
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
Angular - node (v18.15.0, x64)
Memory used 295,913k (± 0.01%) 295,930k (± 0.01%) ~ 295,885k 295,965k p=0.575 n=6
Parse Time 2.65s (± 0.67%) 2.65s (± 0.56%) ~ 2.63s 2.66s p=0.868 n=6
Bind Time 0.82s (± 1.33%) 0.82s (± 1.33%) ~ 0.81s 0.83s p=1.000 n=6
Check Time 8.20s (± 0.47%) 8.20s (± 0.34%) ~ 8.17s 8.24s p=1.000 n=6
Emit Time 7.05s (± 0.45%) 7.06s (± 0.14%) ~ 7.05s 7.07s p=0.412 n=6
Total Time 18.72s (± 0.32%) 18.73s (± 0.19%) ~ 18.69s 18.78s p=1.000 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 192,279k (± 0.74%) 192,895k (± 1.01%) ~ 191,611k 195,423k p=0.575 n=6
Parse Time 2.02s (± 0.91%) 2.03s (± 1.69%) ~ 1.99s 2.07s p=0.572 n=6
Bind Time 1.07s (± 1.29%) 1.06s (± 1.39%) ~ 1.05s 1.08s p=0.734 n=6
Check Time 13.81s (± 0.35%) 13.79s (± 0.21%) ~ 13.75s 13.81s p=0.418 n=6
Emit Time 3.85s (± 0.66%) 3.86s (± 0.92%) ~ 3.80s 3.89s p=0.418 n=6
Total Time 20.74s (± 0.23%) 20.74s (± 0.21%) ~ 20.67s 20.79s p=0.936 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,714k (± 0.00%) 347,721k (± 0.01%) ~ 347,695k 347,773k p=1.000 n=6
Parse Time 3.68s (± 1.02%) 3.70s (± 1.17%) ~ 3.64s 3.76s p=0.334 n=6
Bind Time 1.32s (± 0.91%) 1.32s (± 0.75%) ~ 1.30s 1.33s p=0.557 n=6
Check Time 10.11s (± 0.57%) 10.14s (± 0.53%) ~ 10.08s 10.24s p=0.627 n=6
Emit Time 6.02s (± 0.30%) 6.03s (± 0.24%) ~ 6.01s 6.05s p=0.743 n=6
Total Time 21.14s (± 0.35%) 21.19s (± 0.36%) ~ 21.10s 21.28s p=0.260 n=6
TFS - node (v18.15.0, x64)
Memory used 302,567k (± 0.01%) 302,588k (± 0.01%) ~ 302,554k 302,645k p=0.298 n=6
Parse Time 2.42s (± 0.58%) 2.42s (± 1.34%) ~ 2.37s 2.47s p=0.871 n=6
Bind Time 1.16s (± 0.35%) 1.16s (± 0.45%) ~ 1.15s 1.16s p=0.114 n=6
Check Time 7.45s (± 0.27%) 7.47s (± 0.59%) ~ 7.41s 7.52s p=0.373 n=6
Emit Time 4.27s (± 0.78%) 4.27s (± 0.58%) ~ 4.24s 4.31s p=0.936 n=6
Total Time 15.30s (± 0.34%) 15.31s (± 0.26%) ~ 15.27s 15.36s p=0.747 n=6
material-ui - node (v18.15.0, x64)
Memory used 510,539k (± 0.01%) 510,568k (± 0.00%) ~ 510,544k 510,590k p=0.128 n=6
Parse Time 3.19s (± 0.38%) 3.19s (± 0.55%) ~ 3.16s 3.21s p=0.317 n=6
Bind Time 1.17s (± 0.94%) 1.17s (± 0.70%) ~ 1.16s 1.18s p=0.666 n=6
Check Time 20.40s (± 0.23%) 20.49s (± 0.31%) +0.09s (+ 0.45%) 20.42s 20.59s p=0.030 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 24.76s (± 0.24%) 24.86s (± 0.29%) +0.10s (+ 0.40%) 24.76s 24.95s p=0.045 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,742,646k (± 0.00%) 1,742,683k (± 0.00%) ~ 1,742,648k 1,742,737k p=0.109 n=6
Parse Time 9.72s (± 0.36%) 9.68s (± 0.57%) ~ 9.63s 9.79s p=0.162 n=6
Bind Time 3.39s (± 1.12%) 3.38s (± 1.01%) ~ 3.34s 3.44s p=0.748 n=6
Check Time 81.70s (± 0.52%) 81.33s (± 0.45%) ~ 80.93s 81.92s p=0.199 n=6
Emit Time 0.19s (± 2.67%) 0.19s (± 2.13%) ~ 0.19s 0.20s p=0.595 n=6
Total Time 95.00s (± 0.43%) 94.58s (± 0.37%) ~ 94.13s 95.14s p=0.149 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,302,220k (± 0.02%) 2,301,909k (± 0.03%) ~ 2,301,225k 2,302,612k p=0.230 n=6
Parse Time 6.04s (± 1.06%) 6.04s (± 0.82%) ~ 5.97s 6.10s p=0.687 n=6
Bind Time 2.23s (± 0.77%) 2.25s (± 1.11%) ~ 2.22s 2.28s p=0.090 n=6
Check Time 39.69s (± 0.22%) 39.65s (± 0.33%) ~ 39.44s 39.77s p=0.689 n=6
Emit Time 3.08s (± 2.11%) 3.13s (± 2.80%) ~ 3.04s 3.25s p=0.295 n=6
Total Time 51.06s (± 0.23%) 51.11s (± 0.39%) ~ 50.87s 51.41s p=0.423 n=6
self-build-src-public-api - node (v18.15.0, x64)
Memory used 2,376,728k (± 0.04%) 2,376,943k (± 0.03%) ~ 2,375,969k 2,377,891k p=0.936 n=6
Parse Time 6.21s (± 1.08%) 6.18s (± 0.98%) ~ 6.11s 6.27s p=0.471 n=6
Bind Time 2.04s (± 0.68%) 2.03s (± 0.91%) ~ 2.00s 2.05s p=0.935 n=6
Check Time 39.85s (± 0.39%) 39.78s (± 0.28%) ~ 39.69s 39.99s p=0.336 n=6
Emit Time 3.12s (± 2.90%) 3.09s (± 1.98%) ~ 3.01s 3.16s p=0.378 n=6
Total Time 51.22s (± 0.54%) 51.11s (± 0.39%) ~ 50.89s 51.46s p=0.423 n=6
self-compiler - node (v18.15.0, x64)
Memory used 418,302k (± 0.01%) 418,401k (± 0.01%) +99k (+ 0.02%) 418,337k 418,455k p=0.013 n=6
Parse Time 3.39s (± 0.80%) 3.38s (± 1.96%) ~ 3.25s 3.42s p=0.686 n=6
Bind Time 1.30s (± 1.57%) 1.32s (± 4.88%) ~ 1.28s 1.45s p=0.808 n=6
Check Time 17.84s (± 0.23%) 17.86s (± 0.29%) ~ 17.78s 17.92s p=0.687 n=6
Emit Time 1.36s (± 1.37%) 1.39s (± 1.56%) ~ 1.36s 1.42s p=0.169 n=6
Total Time 23.89s (± 0.25%) 23.94s (± 0.20%) ~ 23.89s 24.02s p=0.196 n=6
vscode - node (v18.15.0, x64)
Memory used 2,906,120k (± 0.00%) 2,906,119k (± 0.00%) ~ 2,906,049k 2,906,161k p=0.810 n=6
Parse Time 13.04s (± 0.35%) 12.96s (± 0.16%) -0.07s (- 0.56%) 12.94s 12.99s p=0.020 n=6
Bind Time 4.07s (± 0.25%) 4.07s (± 0.22%) ~ 4.06s 4.08s p=0.673 n=6
Check Time 71.42s (± 0.27%) 71.37s (± 0.26%) ~ 71.08s 71.58s p=0.689 n=6
Emit Time 19.39s (± 0.73%) 19.40s (± 0.64%) ~ 19.27s 19.59s p=0.688 n=6
Total Time 107.91s (± 0.26%) 107.81s (± 0.22%) ~ 107.36s 108.06s p=0.422 n=6
webpack - node (v18.15.0, x64)
Memory used 408,658k (± 0.02%) 408,644k (± 0.01%) ~ 408,584k 408,713k p=1.000 n=6
Parse Time 3.22s (± 0.20%) 3.21s (± 0.50%) ~ 3.19s 3.23s p=0.179 n=6
Bind Time 1.38s (± 1.09%) 1.38s (± 0.30%) ~ 1.38s 1.39s p=0.473 n=6
Check Time 14.14s (± 0.62%) 14.15s (± 0.21%) ~ 14.11s 14.19s p=1.000 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 18.75s (± 0.43%) 18.74s (± 0.20%) ~ 18.70s 18.79s p=1.000 n=6
xstate - node (v18.15.0, x64)
Memory used 670,758k (± 0.01%) 670,799k (± 0.02%) ~ 670,700k 671,006k p=0.936 n=6
Parse Time 3.32s (± 0.44%) 3.33s (± 0.23%) ~ 3.32s 3.34s p=0.117 n=6
Bind Time 1.56s (± 0.33%) 1.57s (± 0.35%) ~ 1.56s 1.57s p=0.640 n=6
Check Time 2.89s (± 0.84%) 2.88s (± 0.84%) ~ 2.85s 2.91s p=1.000 n=6
Emit Time 0.03s (±36.48%) 0.02s (± 0.00%) ~ 0.02s 0.02s p=0.071 n=6
Total Time 7.80s (± 0.51%) 7.81s (± 0.32%) ~ 7.78s 7.84s p=0.630 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - 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)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@gabritto
Copy link
Member Author

Latest changes: I got rid of the circularity detection that existed in inferTypeForHomomorphicMappedType, as every circularity of that function is also a circularity of inferReverseMappedType. To do that but keep the existing behavior where inferTypeForHomomorphicMappedType returns undefined in cases of circularity, I changed inferReverseMappedType to also return undefined when a circularity is detected, and so I had to update the callers of inferReverseMappedType to handle the undefined.
We may be able to get rid of those undefineds in the future in something like #56300, where when inference fails due to circularity, we default to the constraint of the type.

@gabritto gabritto requested a review from weswigham April 10, 2024 22:25
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.

Maximum call stack size exceeded with two mapped types
5 participants