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

Preserve type parameter constraint in emitted mapped types while preserving their distributivity #54759

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Jun 23, 2023

fixes #54560
fixes #55049

The idea behind this PR is that:

  • a different emit has to be done when a homomorphic mapped type has a non-homomorphic instantiation because distributivity has to be preserved
  • the mappedType.target is the homomorphic one so it feels like it can be used to create a proper instantiation
  • we only need to create type params for both K and T and instantiate the target's template type with them properly

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jun 23, 2023
@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.

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jun 23, 2023
@sandersn sandersn requested review from weswigham and gabritto July 19, 2023 20:50
@gabritto

This comment was marked as duplicate.

@gabritto
Copy link
Member

@typescript-bot test this
@typescript-bot run DT
@typescript-bot user test this
@typescript-bot test top100
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 20, 2023

Heya @gabritto, I've started to run the diff-based user code test suite on this PR at bfdd0d9. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 20, 2023

Heya @gabritto, I've started to run the extended test suite on this PR at bfdd0d9. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 20, 2023

Heya @gabritto, I've started to run the diff-based top-repos suite on this PR at bfdd0d9. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 20, 2023

Heya @gabritto, I've started to run the perf test suite on this PR at bfdd0d9. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 20, 2023

Heya @gabritto, I've started to run the parallelized Definitely Typed test suite on this PR at bfdd0d9. You can monitor the build here.

Update: The results are in!

@gabritto
Copy link
Member

This looks ok to me, but I don't fully understand the code, so I'll defer to @weswigham.

@typescript-bot
Copy link
Collaborator

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

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Unknown failure"
  • 1 instance of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

rxjs-src

/mnt/ts_downloads/rxjs-src/build.sh

  • [NEW] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54759/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
  • [MISSING] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)

@typescript-bot
Copy link
Collaborator

@gabritto
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - main..54759
Metric main 54759 Delta Best Worst p-value
Angular - node (v18.10.0, x64)
Memory used 366,813k (± 0.01%) 366,811k (± 0.00%) ~ 366,792k 366,828k p=0.810 n=6
Parse Time 3.39s (± 0.58%) 3.39s (± 0.44%) ~ 3.37s 3.41s p=0.934 n=6
Bind Time 1.12s (± 0.67%) 1.12s (± 0.46%) ~ 1.11s 1.12s p=0.784 n=6
Check Time 8.89s (± 0.28%) 8.91s (± 0.49%) ~ 8.83s 8.96s p=0.222 n=6
Emit Time 7.47s (± 0.26%) 7.55s (± 0.98%) +0.07s (+ 0.98%) 7.46s 7.66s p=0.036 n=6
Total Time 20.87s (± 0.15%) 20.96s (± 0.45%) ~ 20.79s 21.07s p=0.065 n=6
Compiler-Unions - node (v18.10.0, x64)
Memory used 192,100k (± 1.19%) 193,064k (± 1.52%) ~ 191,148k 197,062k p=0.936 n=6
Parse Time 1.52s (± 1.13%) 1.50s (± 0.80%) ~ 1.49s 1.52s p=0.166 n=6
Bind Time 0.78s (± 1.05%) 0.77s (± 0.53%) ~ 0.77s 0.78s p=0.248 n=6
Check Time 9.51s (± 0.79%) 9.49s (± 0.55%) ~ 9.42s 9.55s p=0.873 n=6
Emit Time 2.77s (± 0.88%) 2.74s (± 0.50%) ~ 2.72s 2.75s p=0.089 n=6
Total Time 14.57s (± 0.79%) 14.51s (± 0.44%) ~ 14.44s 14.57s p=0.294 n=6
Monaco - node (v18.10.0, x64)
Memory used 346,872k (± 0.01%) 346,843k (± 0.01%) ~ 346,825k 346,866k p=0.108 n=6
Parse Time 2.63s (± 0.88%) 2.61s (± 0.58%) ~ 2.59s 2.63s p=0.121 n=6
Bind Time 1.01s (± 0.82%) 1.01s (± 0.88%) ~ 1.00s 1.02s p=0.339 n=6
Check Time 7.29s (± 0.53%) 7.29s (± 0.60%) ~ 7.21s 7.33s p=0.745 n=6
Emit Time 4.26s (± 0.71%) 4.25s (± 0.95%) ~ 4.19s 4.30s p=1.000 n=6
Total Time 15.19s (± 0.30%) 15.16s (± 0.46%) ~ 15.08s 15.24s p=0.748 n=6
TFS - node (v18.10.0, x64)
Memory used 300,899k (± 0.01%) 300,909k (± 0.00%) ~ 300,900k 300,920k p=0.297 n=6
Parse Time 2.11s (± 1.10%) 2.09s (± 1.58%) ~ 2.05s 2.14s p=0.334 n=6
Bind Time 1.13s (± 0.66%) 1.13s (± 0.72%) ~ 1.12s 1.14s p=0.306 n=6
Check Time 6.65s (± 0.48%) 6.64s (± 0.59%) ~ 6.60s 6.71s p=0.936 n=6
Emit Time 3.86s (± 0.51%) 3.86s (± 1.32%) ~ 3.79s 3.94s p=0.747 n=6
Total Time 13.74s (± 0.32%) 13.73s (± 0.77%) ~ 13.64s 13.92s p=0.422 n=6
material-ui - node (v18.10.0, x64)
Memory used 482,390k (± 0.01%) 482,385k (± 0.01%) ~ 482,326k 482,495k p=0.575 n=6
Parse Time 3.12s (± 0.61%) 3.12s (± 0.43%) ~ 3.11s 3.14s p=0.675 n=6
Bind Time 0.93s (± 1.11%) 0.92s (± 0.56%) ~ 0.91s 0.92s p=0.077 n=6
Check Time 17.33s (± 0.49%) 17.28s (± 0.77%) ~ 17.14s 17.47s p=0.471 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.38s (± 0.37%) 21.32s (± 0.64%) ~ 21.17s 21.49s p=0.471 n=6
xstate - node (v18.10.0, x64)
Memory used 563,550k (± 0.01%) 563,608k (± 0.02%) ~ 563,500k 563,739k p=0.471 n=6
Parse Time 3.84s (± 0.46%) 3.84s (± 0.38%) ~ 3.82s 3.86s p=0.871 n=6
Bind Time 1.65s (± 1.04%) 1.66s (± 0.62%) ~ 1.64s 1.67s p=0.622 n=6
Check Time 2.79s (± 0.43%) 2.80s (± 1.06%) ~ 2.76s 2.83s p=0.567 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 8.36s (± 0.28%) 8.38s (± 0.49%) ~ 8.33s 8.45s p=0.466 n=6
Angular - node (v16.17.1, x64)
Memory used 366,202k (± 0.01%) 366,194k (± 0.01%) ~ 366,147k 366,220k p=1.000 n=6
Parse Time 3.55s (± 0.63%) 3.56s (± 0.52%) ~ 3.55s 3.60s p=1.000 n=6
Bind Time 1.19s (± 0.98%) 1.18s (± 0.69%) ~ 1.17s 1.19s p=0.666 n=6
Check Time 9.70s (± 0.39%) 9.69s (± 0.70%) ~ 9.60s 9.77s p=0.748 n=6
Emit Time 7.98s (± 0.27%) 7.96s (± 0.57%) ~ 7.92s 8.04s p=0.259 n=6
Total Time 22.42s (± 0.25%) 22.39s (± 0.41%) ~ 22.28s 22.53s p=0.630 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,923k (± 0.03%) 192,948k (± 0.01%) ~ 192,918k 192,973k p=0.688 n=6
Parse Time 1.57s (± 1.12%) 1.59s (± 0.66%) ~ 1.58s 1.61s p=0.071 n=6
Bind Time 0.82s (± 1.42%) 0.83s (± 0.66%) ~ 0.82s 0.83s p=0.498 n=6
Check Time 10.15s (± 1.19%) 10.16s (± 0.79%) ~ 10.07s 10.28s p=0.748 n=6
Emit Time 3.02s (± 0.88%) 3.01s (± 1.63%) ~ 2.96s 3.08s p=0.372 n=6
Total Time 15.56s (± 1.05%) 15.59s (± 0.51%) ~ 15.48s 15.72s p=0.629 n=6
Monaco - node (v16.17.1, x64)
Memory used 346,187k (± 0.01%) 346,188k (± 0.00%) ~ 346,164k 346,201k p=0.471 n=6
Parse Time 2.76s (± 0.37%) 2.78s (± 0.86%) ~ 2.76s 2.81s p=0.231 n=6
Bind Time 1.08s (± 0.48%) 1.07s (± 0.48%) ~ 1.07s 1.08s p=0.311 n=6
Check Time 7.98s (± 0.56%) 7.98s (± 0.47%) ~ 7.94s 8.03s p=1.000 n=6
Emit Time 4.45s (± 0.72%) 4.46s (± 0.65%) ~ 4.41s 4.48s p=0.746 n=6
Total Time 16.28s (± 0.42%) 16.29s (± 0.46%) ~ 16.19s 16.38s p=0.808 n=6
TFS - node (v16.17.1, x64)
Memory used 300,238k (± 0.01%) 300,242k (± 0.01%) ~ 300,213k 300,268k p=1.000 n=6
Parse Time 2.20s (± 0.70%) 2.20s (± 0.41%) ~ 2.19s 2.21s p=0.672 n=6
Bind Time 1.20s (± 1.22%) 1.22s (± 0.99%) ~ 1.20s 1.23s p=0.119 n=6
Check Time 7.31s (± 0.44%) 7.31s (± 0.32%) ~ 7.28s 7.34s p=0.871 n=6
Emit Time 4.33s (± 0.94%) 4.32s (± 0.83%) ~ 4.25s 4.35s p=0.806 n=6
Total Time 15.05s (± 0.48%) 15.05s (± 0.32%) ~ 14.97s 15.11s p=0.808 n=6
material-ui - node (v16.17.1, x64)
Memory used 481,671k (± 0.01%) 481,628k (± 0.01%) ~ 481,557k 481,672k p=0.173 n=6
Parse Time 3.26s (± 0.45%) 3.24s (± 0.16%) ~ 3.24s 3.25s p=0.052 n=6
Bind Time 0.96s (± 0.85%) 0.95s (± 0.57%) ~ 0.95s 0.96s p=0.859 n=6
Check Time 18.37s (± 0.29%) 18.32s (± 0.58%) ~ 18.20s 18.45s p=0.687 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.58s (± 0.25%) 22.52s (± 0.46%) ~ 22.41s 22.64s p=0.373 n=6
xstate - node (v16.17.1, x64)
Memory used 561,276k (± 0.03%) 561,361k (± 0.03%) ~ 561,097k 561,525k p=0.575 n=6
Parse Time 4.00s (± 0.26%) 4.00s (± 0.56%) ~ 3.98s 4.04s p=0.935 n=6
Bind Time 1.69s (± 5.74%) 1.67s (± 6.67%) ~ 1.59s 1.81s p=0.806 n=6
Check Time 3.14s (± 2.95%) 3.21s (± 3.54%) ~ 3.06s 3.29s p=0.126 n=6
Emit Time 0.09s (± 4.45%) 0.09s (± 8.51%) ~ 0.08s 0.10s p=0.389 n=6
Total Time 8.92s (± 0.46%) 8.96s (± 0.25%) ~ 8.94s 9.00s p=0.090 n=6
Angular - node (v14.21.3, x64)
Memory used 360,169k (± 0.01%) 360,193k (± 0.01%) ~ 360,158k 360,219k p=0.575 n=6
Parse Time 3.72s (± 0.33%) 3.73s (± 0.71%) ~ 3.71s 3.78s p=0.739 n=6
Bind Time 1.22s (± 0.68%) 1.22s (± 0.33%) ~ 1.22s 1.23s p=0.527 n=6
Check Time 10.11s (± 0.39%) 10.10s (± 0.19%) ~ 10.07s 10.12s p=0.572 n=6
Emit Time 8.33s (± 0.55%) 8.31s (± 0.45%) ~ 8.25s 8.35s p=0.258 n=6
Total Time 23.39s (± 0.29%) 23.36s (± 0.22%) ~ 23.29s 23.44s p=0.520 n=6
Compiler-Unions - node (v14.21.3, x64)
Memory used 188,196k (± 0.01%) 188,161k (± 0.02%) ~ 188,092k 188,192k p=0.066 n=6
Parse Time 1.61s (± 0.51%) 1.61s (± 0.72%) ~ 1.60s 1.63s p=0.720 n=6
Bind Time 0.85s (± 0.89%) 0.85s (± 0.48%) ~ 0.84s 0.85s p=1.000 n=6
Check Time 10.29s (± 0.42%) 10.30s (± 0.35%) ~ 10.25s 10.36s p=0.334 n=6
Emit Time 3.15s (± 1.51%) 3.12s (± 0.90%) ~ 3.09s 3.17s p=0.469 n=6
Total Time 15.90s (± 0.61%) 15.89s (± 0.34%) ~ 15.79s 15.94s p=0.687 n=6
Monaco - node (v14.21.3, x64)
Memory used 341,188k (± 0.00%) 341,181k (± 0.01%) ~ 341,153k 341,233k p=0.378 n=6
Parse Time 2.81s (± 0.37%) 2.80s (± 0.27%) -0.02s (- 0.59%) 2.79s 2.81s p=0.021 n=6
Bind Time 1.10s (± 0.94%) 1.09s (± 0.50%) ~ 1.09s 1.10s p=1.000 n=6
Check Time 8.27s (± 0.61%) 8.26s (± 0.37%) ~ 8.22s 8.31s p=0.872 n=6
Emit Time 4.67s (± 0.86%) 4.66s (± 0.54%) ~ 4.61s 4.68s p=0.746 n=6
Total Time 16.85s (± 0.45%) 16.82s (± 0.10%) ~ 16.80s 16.84s p=0.747 n=6
TFS - node (v14.21.3, x64)
Memory used 295,321k (± 0.00%) 295,321k (± 0.00%) ~ 295,305k 295,338k p=0.936 n=6
Parse Time 2.43s (± 0.95%) 2.42s (± 0.68%) ~ 2.40s 2.45s p=0.935 n=6
Bind Time 1.08s (± 0.75%) 1.08s (± 0.50%) ~ 1.08s 1.09s p=0.859 n=6
Check Time 7.65s (± 0.60%) 7.63s (± 0.24%) ~ 7.61s 7.66s p=0.870 n=6
Emit Time 4.31s (± 0.96%) 4.29s (± 0.79%) ~ 4.23s 4.33s p=0.627 n=6
Total Time 15.47s (± 0.35%) 15.43s (± 0.28%) ~ 15.36s 15.48s p=0.226 n=6
material-ui - node (v14.21.3, x64)
Memory used 477,160k (± 0.00%) 477,168k (± 0.00%) ~ 477,148k 477,185k p=0.630 n=6
Parse Time 3.32s (± 0.59%) 3.31s (± 0.44%) ~ 3.29s 3.33s p=0.193 n=6
Bind Time 0.99s (± 0.00%) 0.99s (± 0.52%) ~ 0.98s 0.99s p=0.174 n=6
Check Time 19.18s (± 0.33%) 19.19s (± 0.19%) ~ 19.15s 19.25s p=0.628 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 23.49s (± 0.33%) 23.48s (± 0.20%) ~ 23.44s 23.56s p=1.000 n=6
xstate - node (v14.21.3, x64)
Memory used 550,047k (± 0.00%) 550,063k (± 0.01%) ~ 550,028k 550,104k p=0.689 n=6
Parse Time 4.22s (± 0.45%) 4.24s (± 0.48%) ~ 4.22s 4.26s p=0.141 n=6
Bind Time 1.69s (± 1.06%) 1.68s (± 0.90%) ~ 1.67s 1.71s p=0.570 n=6
Check Time 3.14s (± 0.65%) 3.14s (± 0.80%) ~ 3.11s 3.17s p=0.809 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 9.14s (± 0.35%) 9.16s (± 0.25%) ~ 9.12s 9.18s p=0.258 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.21.3, x64)
Scenarios
  • Angular - node (v18.10.0, x64)
  • Angular - node (v16.17.1, x64)
  • Angular - node (v14.21.3, x64)
  • Compiler-Unions - node (v18.10.0, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Compiler-Unions - node (v14.21.3, x64)
  • Monaco - node (v18.10.0, x64)
  • Monaco - node (v16.17.1, x64)
  • Monaco - node (v14.21.3, x64)
  • TFS - node (v18.10.0, x64)
  • TFS - node (v16.17.1, x64)
  • TFS - node (v14.21.3, x64)
  • material-ui - node (v18.10.0, x64)
  • material-ui - node (v16.17.1, x64)
  • material-ui - node (v14.21.3, x64)
  • xstate - node (v18.10.0, x64)
  • xstate - node (v16.17.1, x64)
  • xstate - node (v14.21.3, x64)
Benchmark Name Iterations
Current 54759 6
Baseline main 6

TSServer

Comparison Report - main..54759
Metric main 54759 Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,535ms (± 0.39%) 2,531ms (± 0.33%) ~ 2,521ms 2,540ms p=1.000 n=6
Req 2 - geterr 5,387ms (± 0.67%) 5,376ms (± 0.42%) ~ 5,340ms 5,404ms p=0.689 n=6
Req 3 - references 339ms (± 0.47%) 340ms (± 0.55%) ~ 338ms 343ms p=1.000 n=6
Req 4 - navto 289ms (± 0.53%) 288ms (± 0.77%) ~ 286ms 292ms p=0.684 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 91ms (± 3.51%) 89ms (± 3.29%) ~ 86ms 92ms p=0.622 n=6
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,620ms (± 1.08%) 2,616ms (± 0.56%) ~ 2,593ms 2,637ms p=1.000 n=6
Req 2 - geterr 4,101ms (± 0.23%) 4,108ms (± 0.45%) ~ 4,078ms 4,135ms p=0.377 n=6
Req 3 - references 348ms (± 1.00%) 349ms (± 0.79%) ~ 344ms 352ms p=1.000 n=6
Req 4 - navto 290ms (± 0.77%) 289ms (± 0.53%) ~ 287ms 291ms p=0.325 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 75ms (± 6.66%) 77ms (± 6.47%) ~ 71ms 85ms p=0.373 n=6
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 3,076ms (± 0.59%) 3,085ms (± 0.61%) ~ 3,064ms 3,112ms p=0.470 n=6
Req 2 - geterr 1,598ms (± 0.49%) 1,596ms (± 1.03%) ~ 1,575ms 1,617ms p=0.810 n=6
Req 3 - references 112ms (± 2.00%) 113ms (± 0.56%) ~ 112ms 114ms p=0.367 n=6
Req 4 - navto 370ms (± 0.33%) 370ms (± 0.51%) ~ 367ms 372ms p=1.000 n=6
Req 5 - completionInfo count 2,872 (± 0.00%) 2,872 (± 0.00%) ~ 2,872 2,872 p=1.000 n=6
Req 5 - completionInfo 383ms (± 0.87%) 382ms (± 1.81%) ~ 371ms 392ms p=0.936 n=6
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,618ms (± 0.42%) 2,653ms (± 1.33%) +35ms (+ 1.32%) 2,631ms 2,723ms p=0.024 n=6
Req 2 - geterr 6,048ms (± 0.42%) 5,969ms (± 1.48%) -80ms (- 1.32%) 5,801ms 6,048ms p=0.031 n=6
Req 3 - references 355ms (± 0.48%) 355ms (± 0.48%) ~ 353ms 358ms p=1.000 n=6
Req 4 - navto 287ms (± 1.39%) 289ms (± 1.50%) ~ 285ms 296ms p=0.260 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 100ms (± 0.98%) 96ms (± 7.81%) ~ 81ms 100ms p=0.143 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,791ms (± 0.83%) 2,798ms (± 0.47%) ~ 2,786ms 2,822ms p=0.936 n=6
Req 2 - geterr 4,647ms (± 0.31%) 4,665ms (± 0.23%) ~ 4,646ms 4,677ms p=0.054 n=6
Req 3 - references 365ms (± 0.75%) 364ms (± 0.79%) ~ 360ms 367ms p=0.871 n=6
Req 4 - navto 281ms (± 1.08%) 282ms (± 0.53%) ~ 280ms 283ms p=0.806 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 76ms (± 0.99%) 76ms (± 1.08%) ~ 75ms 77ms p=0.306 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 3,218ms (± 0.16%) 3,214ms (± 0.24%) ~ 3,206ms 3,226ms p=0.230 n=6
Req 2 - geterr 1,742ms (± 0.73%) 1,737ms (± 1.34%) ~ 1,715ms 1,768ms p=0.873 n=6
Req 3 - references 123ms (± 0.61%) 126ms (± 6.69%) ~ 121ms 143ms p=0.742 n=6
Req 4 - navto 353ms (± 0.64%) 353ms (± 0.49%) ~ 351ms 356ms p=0.454 n=6
Req 5 - completionInfo count 2,872 (± 0.00%) 2,872 (± 0.00%) ~ 2,872 2,872 p=1.000 n=6
Req 5 - completionInfo 410ms (± 1.52%) 414ms (± 2.14%) ~ 404ms 426ms p=0.423 n=6
Compiler-UnionsTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 2,772ms (± 0.60%) 2,769ms (± 0.30%) ~ 2,756ms 2,778ms p=0.575 n=6
Req 2 - geterr 6,174ms (± 0.53%) 6,188ms (± 0.64%) ~ 6,149ms 6,257ms p=0.575 n=6
Req 3 - references 361ms (± 0.76%) 365ms (± 1.02%) ~ 360ms 370ms p=0.088 n=6
Req 4 - navto 293ms (± 1.46%) 291ms (± 0.51%) ~ 289ms 293ms p=0.567 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 109ms (± 4.99%) 110ms (± 3.57%) ~ 102ms 112ms p=0.806 n=6
CompilerTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 2,926ms (± 0.74%) 2,949ms (± 1.03%) ~ 2,902ms 2,985ms p=0.261 n=6
Req 2 - geterr 4,559ms (± 0.60%) 4,560ms (± 0.42%) ~ 4,528ms 4,575ms p=1.000 n=6
Req 3 - references 381ms (± 0.77%) 383ms (± 1.36%) ~ 375ms 387ms p=0.375 n=6
Req 4 - navto 297ms (± 0.82%) 297ms (± 0.30%) ~ 296ms 298ms p=1.000 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 83ms (± 1.97%) 83ms (± 1.45%) ~ 81ms 84ms p=0.503 n=6
xstateTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 3,509ms (± 0.28%) 3,493ms (± 1.72%) ~ 3,413ms 3,544ms p=0.378 n=6
Req 2 - geterr 1,858ms (± 0.53%) 1,856ms (± 0.68%) ~ 1,838ms 1,867ms p=0.809 n=6
Req 3 - references 139ms (± 7.58%) 139ms (± 8.04%) ~ 130ms 154ms p=1.000 n=6
Req 4 - navto 387ms (± 0.41%) 388ms (± 1.04%) ~ 385ms 394ms p=0.864 n=6
Req 5 - completionInfo count 2,872 (± 0.00%) 2,872 (± 0.00%) ~ 2,872 2,872 p=1.000 n=6
Req 5 - completionInfo 421ms (± 0.76%) 424ms (± 0.75%) ~ 420ms 428ms p=0.124 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.21.3, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v18.10.0, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v14.21.3, x64)
  • CompilerTSServer - node (v18.10.0, x64)
  • CompilerTSServer - node (v16.17.1, x64)
  • CompilerTSServer - node (v14.21.3, x64)
  • xstateTSServer - node (v18.10.0, x64)
  • xstateTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v14.21.3, x64)
Benchmark Name Iterations
Current 54759 6
Baseline main 6

Startup

Comparison Report - main..54759
Metric main 54759 Delta Best Worst p-value
tsc-startup - node (v16.17.1, x64)
Execution time 142.90ms (± 0.19%) 142.88ms (± 0.18%) ~ 142.17ms 145.44ms p=0.518 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 222.44ms (± 0.15%) 222.40ms (± 0.14%) ~ 221.51ms 228.05ms p=0.252 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 223.77ms (± 0.14%) 223.85ms (± 0.18%) +0.08ms (+ 0.04%) 222.99ms 234.22ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 205.69ms (± 0.15%) 205.69ms (± 0.14%) ~ 204.93ms 208.94ms p=0.582 n=600
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • tsc-startup - node (v16.17.1, x64)
  • tsserver-startup - node (v16.17.1, x64)
  • tsserverlibrary-startup - node (v16.17.1, x64)
  • typescript-startup - node (v16.17.1, x64)
Benchmark Name Iterations
Current 54759 6
Baseline main 6

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@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.

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.

I think this may need to be conflict-resolved with #55054 now that that's in (maybe there's another test-case for modifier-preserving non-homomorphic types here, too), but this largely looks good. I'd like to see the name (or preferably the whole type parameter) reused for the key type parameter, though.

const newParam = createTypeParameter(createSymbol(SymbolFlags.TypeParameter, "T" as __String));
const name = typeParameterToName(newParam, context);
const newConstraintParam = createTypeParameter(createSymbol(SymbolFlags.TypeParameter, "T" as __String));
const newTypeParam = createTypeParameter(createSymbol(SymbolFlags.TypeParameter, "K" as __String));
Copy link
Member

Choose a reason for hiding this comment

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

Ideally, this should reuse the symbol name of the existing key type, rather than always using K, just in case.

Copy link
Member

Choose a reason for hiding this comment

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

Also, it would definitely be better just to reuse the existing mapped type's key type parameter wholesale; I can't really think of why we'd need a unique copy here, and it's usually better to keep type identities minimal where possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've applied the first suggestion (reusing the symbol). I'm not exactly sure what's the expected result that I'm supposed to get here but I think I might be somewhat close using this extra diff:

git diff
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index dfbcd01413..33bbc22259 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -6642,7 +6642,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
                 let appropriateConstraintTypeNode: TypeNode;
                 let newTypeVariable: TypeReferenceNode | undefined;
                 let templateType = getTemplateTypeFromMappedType(type);
-                let typeParameter = getTypeParameterFromMappedType(type);
+                const typeParameter = getTypeParameterFromMappedType(type);
                 // If the mapped type isn't `keyof` constraint-declared, _but_ still has modifiers preserved, and its naive instantiation won't preserve modifiers because its constraint isn't `keyof` constrained, we have work to do
                 const needsModifierPreservingWrapper = !isMappedTypeWithKeyofConstraintDeclaration(type)
                     && !(getModifiersTypeFromMappedType(type).flags & TypeFlags.Unknown)
@@ -6653,14 +6653,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
                     // We do this to ensure we retain the toplevel keyof-ness of the type which may be lost due to keyof distribution during `getConstraintTypeFromMappedType`
                     if (isHomomorphicMappedTypeWithNonHomomorphicInstantiation(type) && context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams) {
                         const newConstraintParam = createTypeParameter(createSymbol(SymbolFlags.TypeParameter, "T" as __String));
-                        const newTypeParam = createTypeParameter(typeParameter.symbol);
                         const name = typeParameterToName(newConstraintParam, context);
                         const target = type.target as MappedType;
-                        typeParameter = newTypeParam;
                         newTypeVariable = factory.createTypeReferenceNode(name);
                         templateType = instantiateType(
                             getTemplateTypeFromMappedType(target),
-                            makeArrayTypeMapper([getTypeParameterFromMappedType(target), getModifiersTypeFromMappedType(target)], [newTypeParam, newConstraintParam])
+                            makeArrayTypeMapper([getTypeParameterFromMappedType(target), getModifiersTypeFromMappedType(target)], [typeParameter, newConstraintParam])
                         );
                     }
                     appropriateConstraintTypeNode = factory.createTypeOperatorNode(SyntaxKind.KeyOfKeyword, newTypeVariable || typeToTypeNodeHelper(getModifiersTypeFromMappedType(type), context));

but the typeParameterToName in typeParameterToDeclarationWithConstraint still uses NodeBuilderFlags.GenerateNamesForShadowedTypeParams. Even if I save those flags on the side and generate this without this generation for shadowed type params then I get the same problem with templateTypeNode.

Am I even on the right track here? Or did I misunderstand your suggestion? It might be worthwhile to take a look at the diff here to see how it behaves with the latest patch that I pushed out.

Copy link
Member

Choose a reason for hiding this comment

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

Or did I misunderstand your suggestion?

No, that diff is it, it's just unfortunate that we're manufacturing new type identities basically to work around a shortcoming in scope tracking in the type parameter name serializer. I think the issue as-is that the type parameter isn't "visible" to the serializer because the context.enclosingDeclaration is too broad - maybe if, in addition to the patch you linked, you also temporarily override context.enclosingDeclaration with a fake scope, as in signatureToSignatureDeclarationHelper it'd work. In fact, mapped types are basically signature scopes (with only a type parameter) - that's almost certainly what's missing, and what manufacturing a new type is just a kludge covering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To get it right:

  • I should stop reassigning typeParameter here (like in the short git diff posted above in the hidden details)
  • and I should reuse the fake scope strategy used by signatureToSignatureDeclarationHelper

The second thing... doesn't look completely straightforward so tbh this might take me a longer while especially since I have some more pressing reviews to address right now.

const newConstraintParam = createTypeParameter(createSymbol(SymbolFlags.TypeParameter, "T" as __String));
const newTypeParam = createTypeParameter(createSymbol(SymbolFlags.TypeParameter, "K" as __String));
const name = typeParameterToName(newConstraintParam, context);
const target = type.target as MappedType;
Copy link
Member

Choose a reason for hiding this comment

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

...This is probably more elegant than using a prependTypeMapping call on the existing mapper.

@EdwardDrapkin
Copy link

Any motion on this?

@Andarist Andarist force-pushed the fix/mapped-type-dts-emit-type-param-constraint branch from 0c140e9 to b618196 Compare December 12, 2023 22:43
src/compiler/checker.ts Outdated Show resolved Hide resolved
@JCMais
Copy link

JCMais commented Oct 31, 2024

is this still planned to be shipped with 5.7?

@gabritto
Copy link
Member

is this still planned to be shipped with 5.7?

No. I believe this PR is stalled for the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Status: Waiting on author
6 participants