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

Require at least a single match when defining discriminable properties #53654

Closed
wants to merge 4 commits into from

Conversation

MariaSolOs
Copy link
Contributor

Fixes #53165

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Apr 3, 2023
src/compiler/checker.ts Outdated Show resolved Hide resolved
@MariaSolOs MariaSolOs marked this pull request as draft April 4, 2023 16:12
src/compiler/checker.ts Outdated Show resolved Hide resolved
tests/cases/fourslash/completionsUnionProperty.ts Outdated Show resolved Hide resolved
@MariaSolOs MariaSolOs changed the title Don't consider empty literals as discriminant values Require at least a single match when defining discriminable properties Apr 4, 2023
@MariaSolOs MariaSolOs requested a review from sandersn April 4, 2023 20:56
}
else {
discriminable[i] = false;
if (discriminable[i] === undefined) {
Copy link
Contributor Author

@MariaSolOs MariaSolOs Apr 4, 2023

Choose a reason for hiding this comment

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

To explain this change: This line says that "discriminated types stop at 'true'", but the code is overwriting a potentially true discriminable[i] to false if one of the union variants has a property with a type that's unrelated to the target type (which is what's happening when the property's value is an incomplete string literal).

Comment on lines -9 to -12
Type 'S' is not assignable to type '{ a: N; b: N; c: 2; }'.
Types of property 'c' are incompatible.
Type 'N' is not assignable to type '2'.
Type '0' is not assignable to type '2'.
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'm not a fan of these errors not being included anymore and I'll try to keep them, but IMO the diagnostic changes in the other files do make sense.

Copy link
Contributor Author

@MariaSolOs MariaSolOs Apr 6, 2023

Choose a reason for hiding this comment

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

@DanielRosenwasser @ahejlsberg Wait I think that those errors are a bug (?). The example says that s should be assignable to t (and if you look at it, it is), but it errors because of the number of combinations being too complex. The diagnostics are incorrect, and so I actually prefer them going away.

@MariaSolOs MariaSolOs marked this pull request as ready for review April 4, 2023 21:17
@RyanCavanaugh
Copy link
Member

@typescript-bot test this
@typescript-bot test top100
@typescript-bot user test this
@typescript-bot user test tsserver
@typescript-bot test tsserver top100
@typescript-bot run dt
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 4, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 4, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 4, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 4, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 4, 2023

Heya @RyanCavanaugh, I've started to run the diff-based user code test suite (tsserver) on this PR at 86295fb. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 4, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 4, 2023

Heya @RyanCavanaugh, I've started to run the diff-based top-repos suite (tsserver) on this PR at 86295fb. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Package install failed"

Otherwise...

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - main..53654
Metric main 53654 Delta Best Worst p-value
Angular - node (v18.10.0, x64)
Memory used 365,442k (± 0.01%) 365,431k (± 0.01%) ~ 365,386k 365,460k p=0.810 n=6
Parse Time 3.38s (± 0.25%) 3.40s (± 0.86%) ~ 3.37s 3.45s p=0.359 n=6
Bind Time 1.12s (± 0.36%) 1.13s (± 0.49%) ~ 1.12s 1.13s p=0.054 n=6
Check Time 8.73s (± 0.44%) 8.72s (± 0.61%) ~ 8.65s 8.81s p=0.809 n=6
Emit Time 7.48s (± 0.47%) 7.50s (± 1.08%) ~ 7.42s 7.64s p=0.872 n=6
Total Time 20.71s (± 0.26%) 20.74s (± 0.55%) ~ 20.66s 20.97s p=0.809 n=6
Compiler-Unions - node (v18.10.0, x64)
Memory used 191,793k (± 1.22%) 192,674k (± 1.50%) ~ 190,791k 196,413k p=0.521 n=6
Parse Time 1.49s (± 1.77%) 1.49s (± 0.78%) ~ 1.48s 1.51s p=0.461 n=6
Bind Time 0.77s (± 0.67%) 0.77s (± 0.53%) ~ 0.77s 0.78s p=0.114 n=6
Check Time 9.61s (± 0.47%) 9.66s (± 0.67%) ~ 9.57s 9.76s p=0.419 n=6
Emit Time 2.75s (± 2.06%) 2.74s (± 1.38%) ~ 2.69s 2.80s p=1.000 n=6
Total Time 14.63s (± 0.64%) 14.66s (± 0.26%) ~ 14.62s 14.71s p=0.468 n=6
Monaco - node (v18.10.0, x64)
Memory used 346,405k (± 0.01%) 346,434k (± 0.01%) ~ 346,382k 346,485k p=0.378 n=6
Parse Time 2.57s (± 0.67%) 2.56s (± 0.73%) ~ 2.54s 2.59s p=0.808 n=6
Bind Time 1.00s (± 1.17%) 1.01s (± 0.97%) ~ 1.00s 1.02s p=0.209 n=6
Check Time 7.07s (± 0.50%) 7.12s (± 0.37%) +0.05s (+ 0.73%) 7.09s 7.15s p=0.027 n=6
Emit Time 4.21s (± 0.29%) 4.21s (± 0.65%) ~ 4.17s 4.25s p=0.462 n=6
Total Time 14.85s (± 0.28%) 14.91s (± 0.27%) +0.06s (+ 0.43%) 14.84s 14.95s p=0.036 n=6
TFS - node (v18.10.0, x64)
Memory used 300,713k (± 0.01%) 300,707k (± 0.00%) ~ 300,696k 300,725k p=0.575 n=6
Parse Time 2.05s (± 1.30%) 2.05s (± 0.82%) ~ 2.02s 2.07s p=1.000 n=6
Bind Time 1.14s (± 0.66%) 1.13s (± 0.74%) ~ 1.12s 1.14s p=0.652 n=6
Check Time 6.55s (± 0.64%) 6.55s (± 0.50%) ~ 6.51s 6.59s p=1.000 n=6
Emit Time 3.84s (± 0.33%) 3.82s (± 0.49%) ~ 3.80s 3.85s p=0.118 n=6
Total Time 13.58s (± 0.41%) 13.56s (± 0.26%) ~ 13.52s 13.60s p=0.748 n=6
material-ui - node (v18.10.0, x64)
Memory used 480,167k (± 0.00%) 479,992k (± 0.01%) -175k (- 0.04%) 479,942k 480,028k p=0.005 n=6
Parse Time 3.08s (± 0.65%) 3.09s (± 1.14%) ~ 3.04s 3.13s p=0.506 n=6
Bind Time 0.91s (± 0.90%) 0.91s (± 0.83%) ~ 0.90s 0.92s p=0.729 n=6
Check Time 17.13s (± 0.25%) 17.21s (± 0.73%) ~ 17.05s 17.42s p=0.148 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.12s (± 0.26%) 21.21s (± 0.71%) ~ 21.02s 21.46s p=0.229 n=6
xstate - node (v18.10.0, x64)
Memory used 562,088k (± 0.03%) 562,185k (± 0.01%) ~ 562,093k 562,272k p=0.378 n=6
Parse Time 3.79s (± 0.72%) 3.82s (± 0.69%) +0.04s (+ 0.92%) 3.77s 3.84s p=0.048 n=6
Bind Time 1.65s (± 0.51%) 1.65s (± 0.71%) ~ 1.64s 1.67s p=0.615 n=6
Check Time 2.85s (± 1.17%) 2.85s (± 0.72%) ~ 2.82s 2.88s p=0.810 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 8.37s (± 0.52%) 8.41s (± 0.37%) ~ 8.36s 8.44s p=0.126 n=6
Angular - node (v16.17.1, x64)
Memory used 364,816k (± 0.00%) 364,796k (± 0.02%) ~ 364,707k 364,872k p=1.000 n=6
Parse Time 3.54s (± 0.91%) 3.53s (± 0.77%) ~ 3.51s 3.58s p=0.515 n=6
Bind Time 1.18s (± 1.03%) 1.18s (± 0.76%) ~ 1.17s 1.19s p=0.676 n=6
Check Time 9.53s (± 0.18%) 9.55s (± 0.56%) ~ 9.50s 9.62s p=1.000 n=6
Emit Time 7.97s (± 0.34%) 7.95s (± 0.41%) ~ 7.90s 7.99s p=0.416 n=6
Total Time 22.22s (± 0.29%) 22.20s (± 0.30%) ~ 22.10s 22.27s p=0.936 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,553k (± 0.03%) 193,709k (± 0.92%) ~ 192,545k 196,018k p=0.128 n=6
Parse Time 1.59s (± 0.76%) 1.59s (± 0.40%) ~ 1.58s 1.60s p=0.673 n=6
Bind Time 0.82s (± 0.50%) 0.82s (± 0.63%) ~ 0.82s 0.83s p=0.595 n=6
Check Time 10.38s (± 0.93%) 10.32s (± 0.70%) ~ 10.19s 10.39s p=0.573 n=6
Emit Time 3.00s (± 0.49%) 2.99s (± 0.86%) ~ 2.95s 3.02s p=1.000 n=6
Total Time 15.78s (± 0.64%) 15.73s (± 0.59%) ~ 15.56s 15.82s p=0.810 n=6
Monaco - node (v16.17.1, x64)
Memory used 345,677k (± 0.01%) 345,681k (± 0.00%) ~ 345,665k 345,699k p=0.748 n=6
Parse Time 2.71s (± 0.69%) 2.73s (± 0.55%) ~ 2.71s 2.75s p=0.326 n=6
Bind Time 1.08s (± 0.48%) 1.09s (± 0.47%) ~ 1.08s 1.09s p=0.311 n=6
Check Time 7.77s (± 0.33%) 7.81s (± 0.36%) +0.04s (+ 0.49%) 7.77s 7.84s p=0.037 n=6
Emit Time 4.47s (± 0.74%) 4.46s (± 0.50%) ~ 4.44s 4.50s p=0.624 n=6
Total Time 16.04s (± 0.17%) 16.09s (± 0.27%) ~ 16.02s 16.15s p=0.077 n=6
TFS - node (v16.17.1, x64)
Memory used 300,052k (± 0.00%) 300,042k (± 0.01%) ~ 300,016k 300,077k p=0.378 n=6
Parse Time 2.16s (± 0.19%) 2.17s (± 0.57%) ~ 2.16s 2.19s p=0.218 n=6
Bind Time 1.23s (± 0.80%) 1.22s (± 0.67%) ~ 1.21s 1.23s p=0.498 n=6
Check Time 7.22s (± 0.29%) 7.23s (± 0.52%) ~ 7.19s 7.27s p=0.746 n=6
Emit Time 4.33s (± 0.43%) 4.33s (± 0.53%) ~ 4.29s 4.36s p=0.808 n=6
Total Time 14.93s (± 0.15%) 14.95s (± 0.40%) ~ 14.85s 15.00s p=0.376 n=6
material-ui - node (v16.17.1, x64)
Memory used 479,408k (± 0.01%) 479,280k (± 0.01%) -128k (- 0.03%) 479,245k 479,309k p=0.005 n=6
Parse Time 3.24s (± 0.30%) 3.24s (± 0.57%) ~ 3.21s 3.26s p=0.621 n=6
Bind Time 0.95s (± 0.67%) 0.96s (± 0.93%) ~ 0.95s 0.97s p=0.070 n=6
Check Time 18.20s (± 0.21%) 18.20s (± 0.47%) ~ 18.11s 18.32s 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 22.39s (± 0.16%) 22.41s (± 0.37%) ~ 22.30s 22.51s p=0.936 n=6
xstate - node (v16.17.1, x64)
Memory used 559,726k (± 0.01%) 559,660k (± 0.02%) ~ 559,520k 559,784k p=0.378 n=6
Parse Time 3.98s (± 0.34%) 3.99s (± 0.44%) ~ 3.96s 4.01s p=0.294 n=6
Bind Time 1.74s (± 0.57%) 1.74s (± 0.47%) ~ 1.73s 1.75s p=0.383 n=6
Check Time 3.07s (± 0.34%) 3.08s (± 0.39%) ~ 3.07s 3.10s p=0.164 n=6
Emit Time 0.09s (± 5.53%) 0.09s (± 4.45%) ~ 0.09s 0.10s p=0.595 n=6
Total Time 8.88s (± 0.30%) 8.91s (± 0.41%) ~ 8.86s 8.95s p=0.147 n=6
Angular - node (v14.15.1, x64)
Memory used 358,585k (± 0.01%) 358,599k (± 0.00%) ~ 358,584k 358,612k p=0.230 n=6
Parse Time 3.64s (± 1.21%) 3.63s (± 0.52%) ~ 3.60s 3.65s p=0.572 n=6
Bind Time 1.22s (± 1.37%) 1.22s (± 0.42%) ~ 1.21s 1.22s p=0.277 n=6
Check Time 9.93s (± 0.33%) 9.94s (± 0.55%) ~ 9.85s 10.00s p=0.628 n=6
Emit Time 8.27s (± 0.66%) 8.28s (± 0.51%) ~ 8.23s 8.35s p=0.687 n=6
Total Time 23.06s (± 0.37%) 23.06s (± 0.45%) ~ 22.90s 23.20s p=1.000 n=6
Compiler-Unions - node (v14.15.1, x64)
Memory used 187,806k (± 0.01%) 187,829k (± 0.02%) ~ 187,799k 187,886k p=0.128 n=6
Parse Time 1.59s (± 0.40%) 1.59s (± 0.86%) ~ 1.57s 1.61s p=0.438 n=6
Bind Time 0.85s (± 0.89%) 0.85s (± 0.48%) ~ 0.84s 0.85s p=1.000 n=6
Check Time 10.46s (± 0.67%) 10.52s (± 0.30%) ~ 10.48s 10.57s p=0.199 n=6
Emit Time 3.13s (± 0.75%) 3.16s (± 0.89%) ~ 3.13s 3.20s p=0.090 n=6
Total Time 16.04s (± 0.65%) 16.12s (± 0.31%) ~ 16.05s 16.18s p=0.128 n=6
Monaco - node (v14.15.1, x64)
Memory used 340,676k (± 0.00%) 340,663k (± 0.01%) ~ 340,612k 340,684k p=0.521 n=6
Parse Time 2.83s (± 0.52%) 2.83s (± 0.50%) ~ 2.81s 2.85s p=0.870 n=6
Bind Time 1.10s (± 1.06%) 1.10s (± 0.57%) ~ 1.09s 1.11s p=1.000 n=6
Check Time 8.13s (± 0.25%) 8.14s (± 0.57%) ~ 8.10s 8.21s p=0.807 n=6
Emit Time 4.68s (± 0.99%) 4.70s (± 1.15%) ~ 4.65s 4.79s p=0.571 n=6
Total Time 16.75s (± 0.33%) 16.78s (± 0.42%) ~ 16.70s 16.88s p=0.518 n=6
TFS - node (v14.15.1, x64)
Memory used 295,129k (± 0.00%) 295,111k (± 0.00%) -18k (- 0.01%) 295,096k 295,132k p=0.031 n=6
Parse Time 2.38s (± 0.90%) 2.40s (± 0.22%) ~ 2.39s 2.40s p=0.084 n=6
Bind Time 1.06s (± 0.00%) 1.06s (± 1.25%) ~ 1.04s 1.08s p=0.599 n=6
Check Time 7.54s (± 0.61%) 7.57s (± 0.44%) ~ 7.52s 7.60s p=0.253 n=6
Emit Time 4.30s (± 0.69%) 4.30s (± 1.12%) ~ 4.27s 4.40s p=0.571 n=6
Total Time 15.28s (± 0.34%) 15.33s (± 0.40%) ~ 15.25s 15.41s p=0.149 n=6
material-ui - node (v14.15.1, x64)
Memory used 474,951k (± 0.01%) 474,799k (± 0.00%) -151k (- 0.03%) 474,766k 474,822k p=0.005 n=6
Parse Time 3.38s (± 0.52%) 3.38s (± 0.49%) ~ 3.35s 3.40s p=0.288 n=6
Bind Time 1.00s (± 0.41%) 1.00s (± 0.41%) ~ 1.00s 1.01s p=0.218 n=6
Check Time 19.21s (± 1.08%) 19.14s (± 0.87%) ~ 18.98s 19.38s p=0.630 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 23.60s (± 0.89%) 23.52s (± 0.76%) ~ 23.33s 23.77s p=0.575 n=6
xstate - node (v14.15.1, x64)
Memory used 548,246k (± 0.00%) 548,252k (± 0.00%) ~ 548,237k 548,274k p=0.629 n=6
Parse Time 4.30s (± 1.79%) 4.26s (± 0.66%) ~ 4.23s 4.31s p=0.327 n=6
Bind Time 1.61s (± 4.25%) 1.66s (± 1.36%) ~ 1.61s 1.67s p=0.123 n=6
Check Time 3.18s (± 0.75%) 3.16s (± 0.55%) ~ 3.15s 3.19s p=0.315 n=6
Emit Time 0.09s (± 5.53%) 0.09s (± 4.45%) ~ 0.09s 0.10s p=0.595 n=6
Total Time 9.19s (± 0.28%) 9.17s (± 0.39%) ~ 9.12s 9.21s p=0.376 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-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.15.1, x64)
Scenarios
  • Angular - node (v18.10.0, x64)
  • Angular - node (v16.17.1, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v18.10.0, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v18.10.0, x64)
  • Monaco - node (v16.17.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v18.10.0, x64)
  • TFS - node (v16.17.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v18.10.0, x64)
  • material-ui - node (v16.17.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v18.10.0, x64)
  • xstate - node (v16.17.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 53654 6
Baseline main 6

TSServer

Comparison Report - main..53654
Metric main 53654 Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,393ms (± 0.29%) 2,393ms (± 0.30%) ~ 2,384ms 2,403ms p=1.000 n=6
Req 2 - geterr 5,737ms (± 0.33%) 5,691ms (± 1.20%) ~ 5,557ms 5,747ms p=0.109 n=6
Req 3 - references 335ms (± 0.86%) 334ms (± 0.68%) ~ 331ms 337ms p=0.571 n=6
Req 4 - navto 279ms (± 0.54%) 281ms (± 1.09%) ~ 277ms 285ms p=0.277 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 85ms (± 0.96%) 84ms (± 1.22%) ~ 83ms 86ms p=0.546 n=6
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,509ms (± 1.08%) 2,514ms (± 0.53%) ~ 2,490ms 2,526ms p=0.810 n=6
Req 2 - geterr 4,224ms (± 2.00%) 4,276ms (± 0.41%) ~ 4,251ms 4,301ms p=0.298 n=6
Req 3 - references 344ms (± 0.73%) 343ms (± 0.73%) ~ 340ms 347ms p=0.935 n=6
Req 4 - navto 287ms (± 0.78%) 288ms (± 0.81%) ~ 284ms 291ms p=0.625 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 65ms (± 5.61%) 63ms (± 0.88%) ~ 62ms 63ms p=0.675 n=6
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 3,002ms (± 0.63%) 3,005ms (± 0.78%) ~ 2,983ms 3,048ms p=0.936 n=6
Req 2 - geterr 1,625ms (± 1.25%) 1,627ms (± 1.25%) ~ 1,600ms 1,650ms p=0.810 n=6
Req 3 - references 107ms (± 1.29%) 106ms (± 0.97%) ~ 105ms 107ms p=0.788 n=6
Req 4 - navto 362ms (± 0.28%) 365ms (± 0.15%) +2ms (+ 0.60%) 364ms 365ms p=0.008 n=6
Req 5 - completionInfo count 2,862 (± 0.00%) 2,862 (± 0.00%) ~ 2,862 2,862 p=1.000 n=6
Req 5 - completionInfo 370ms (± 0.92%) 368ms (± 1.97%) ~ 355ms 377ms p=0.748 n=6
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,506ms (± 0.86%) 2,491ms (± 0.55%) ~ 2,472ms 2,512ms p=0.230 n=6
Req 2 - geterr 6,181ms (± 0.52%) 6,179ms (± 0.57%) ~ 6,133ms 6,223ms p=1.000 n=6
Req 3 - references 349ms (± 0.42%) 349ms (± 0.26%) ~ 348ms 350ms p=1.000 n=6
Req 4 - navto 279ms (± 1.28%) 279ms (± 1.25%) ~ 276ms 284ms p=0.935 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 (± 0.82%) 90ms (± 0.90%) ~ 89ms 91ms p=0.120 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,666ms (± 0.59%) 2,672ms (± 0.94%) ~ 2,635ms 2,699ms p=0.630 n=6
Req 2 - geterr 4,628ms (± 0.53%) 4,658ms (± 0.40%) +31ms (+ 0.67%) 4,634ms 4,684ms p=0.045 n=6
Req 3 - references 357ms (± 0.57%) 358ms (± 0.52%) ~ 356ms 361ms p=0.933 n=6
Req 4 - navto 282ms (± 1.07%) 283ms (± 1.12%) ~ 279ms 288ms p=0.629 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 68ms (± 0.60%) 68ms (± 1.11%) ~ 67ms 69ms p=1.000 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 3,163ms (± 0.35%) 3,175ms (± 0.37%) ~ 3,157ms 3,189ms p=0.128 n=6
Req 2 - geterr 1,765ms (± 0.94%) 1,784ms (± 1.14%) ~ 1,758ms 1,804ms p=0.173 n=6
Req 3 - references 114ms (± 1.11%) 114ms (± 1.33%) ~ 112ms 116ms p=0.512 n=6
Req 4 - navto 350ms (± 0.21%) 352ms (± 0.61%) ~ 349ms 354ms p=0.058 n=6
Req 5 - completionInfo count 2,862 (± 0.00%) 2,862 (± 0.00%) ~ 2,862 2,862 p=1.000 n=6
Req 5 - completionInfo 385ms (± 1.72%) 386ms (± 1.73%) ~ 374ms 393ms p=0.873 n=6
Compiler-UnionsTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 2,600ms (± 0.47%) 2,618ms (± 0.45%) +18ms (+ 0.71%) 2,606ms 2,636ms p=0.045 n=6
Req 2 - geterr 6,423ms (± 2.01%) 6,457ms (± 1.98%) ~ 6,280ms 6,571ms p=0.298 n=6
Req 3 - references 372ms (± 5.36%) 373ms (± 5.16%) ~ 363ms 412ms p=0.466 n=6
Req 4 - navto 281ms (± 1.28%) 281ms (± 0.61%) ~ 278ms 283ms p=0.256 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 97ms (± 8.42%) 97ms (± 5.22%) ~ 89ms 103ms p=1.000 n=6
CompilerTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 2,803ms (± 0.45%) 2,814ms (± 0.35%) ~ 2,803ms 2,828ms p=0.173 n=6
Req 2 - geterr 4,775ms (± 0.45%) 4,761ms (± 0.41%) ~ 4,734ms 4,792ms p=0.298 n=6
Req 3 - references 367ms (± 0.92%) 368ms (± 0.58%) ~ 366ms 371ms p=0.288 n=6
Req 4 - navto 293ms (± 0.85%) 295ms (± 0.46%) ~ 293ms 296ms p=0.121 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 89ms (± 8.55%) 92ms (± 2.17%) ~ 88ms 93ms p=0.849 n=6
xstateTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 3,423ms (± 0.35%) 3,424ms (± 0.50%) ~ 3,404ms 3,451ms p=0.873 n=6
Req 2 - geterr 1,883ms (± 0.91%) 1,878ms (± 0.78%) ~ 1,860ms 1,896ms p=0.575 n=6
Req 3 - references 128ms (± 2.41%) 125ms (± 0.88%) ~ 123ms 126ms p=0.164 n=6
Req 4 - navto 371ms (± 0.56%) 376ms (± 1.46%) ~ 371ms 383ms p=0.195 n=6
Req 5 - completionInfo count 2,862 (± 0.00%) 2,862 (± 0.00%) ~ 2,862 2,862 p=1.000 n=6
Req 5 - completionInfo 417ms (± 1.85%) 410ms (± 0.86%) ~ 407ms 416ms p=0.148 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-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.15.1, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v18.10.0, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v14.15.1, x64)
  • CompilerTSServer - node (v18.10.0, x64)
  • CompilerTSServer - node (v16.17.1, x64)
  • CompilerTSServer - node (v14.15.1, x64)
  • xstateTSServer - node (v18.10.0, x64)
  • xstateTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v14.15.1, x64)
Benchmark Name Iterations
Current 53654 6
Baseline main 6

Startup

Comparison Report - main..53654
Metric main 53654 Delta Best Worst p-value
tsc-startup - node (v16.17.1, x64)
Execution time 141.48ms (± 0.20%) 141.98ms (± 0.18%) +0.49ms (+ 0.35%) 141.27ms 145.13ms p=0.000 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 219.28ms (± 0.16%) 220.91ms (± 0.30%) +1.63ms (+ 0.74%) 219.13ms 226.48ms p=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 220.80ms (± 0.15%) 222.77ms (± 0.34%) +1.98ms (+ 0.90%) 220.50ms 231.23ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 203.03ms (± 0.17%) 204.37ms (± 0.26%) +1.33ms (+ 0.66%) 202.68ms 210.37ms p=0.000 n=600
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-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 53654 6
Baseline main 6

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

@typescript-bot
Copy link
Collaborator

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

Something interesting changed - please have a look.

Details

backstage/backstage

Server exited prematurely with code unknown and signal SIGABRT

That is a filtered view of the text. To see the raw error text, go to RepoResults4/backstage.backstage.rawError.txt in the artifact folder

Last few requests

{"seq":3457,"type":"request","command":"updateOpen","arguments":{"changedFiles":[{"fileName":"@PROJECT_ROOT@/packages/integration/src/gerrit/index.ts","textChanges":[{"newText":" //comment","start":{"line":1,"offset":3},"end":{"line":1,"offset":3}}]}],"closedFiles":[],"openFiles":[]}}
{"seq":3458,"type":"request","command":"definitionAndBoundSpan","arguments":{"file":"@PROJECT_ROOT@/packages/integration/src/gerrit/index.ts","line":11,"offset":25}}
{"seq":3459,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":["@PROJECT_ROOT@/packages/integration/src/bitbucketServer/BitbucketServerIntegration.ts"],"openFiles":[]}}
{"seq":3460,"type":"request","command":"updateOpen","arguments":{"changedFiles":[],"closedFiles":[],"openFiles":[{"file":"@PROJECT_ROOT@/packages/integration/src/gitea/core.test.ts","projectRootPath":"@PROJECT_ROOT@"}]}}

Repro Steps

  1. git clone https://github.com/backstage/backstage --recurse-submodules
  2. In dir backstage, run git reset --hard 0d07f9cbefac9e9f30f4c88dfd4980786898953a
  3. Install packages (exact steps are below, but it might be easier to follow the repo readme)
    1. In dir backstage/cypress, run yarn install --no-immutable --mode=skip-build
    2. In dir backstage/microsite, run yarn install --no-immutable --mode=skip-build
    3. In dir backstage, run yarn install --no-immutable --mode=skip-build
    4. In dir backstage/storybook, run yarn install --no-immutable --mode=skip-build
  4. Back in the initial folder, download RepoResults4/backstage.backstage.replay.txt from the artifact folder
  5. npm install --no-save @typescript/server-replay
  6. npx tsreplay ./backstage ./backstage.backstage.replay.txt path/to/tsserver.js
  7. npx tsreplay --help to learn about helpful switches for debugging, logging, etc

@MariaSolOs
Copy link
Contributor Author

@RyanCavanaugh Ryan Cavanaugh FTE Here are the results of running the top-repos suite comparing main and refs/pull/53654/merge:

Something interesting changed - please have a look.

Details

Ehhh this looks unrelated to this change... right?

@DanielRosenwasser
Copy link
Member

Ehhh this looks unrelated to this change... right?

I think so.

Comment on lines 22631 to 22632
if (discriminable[i] === undefined) {
discriminable[i] = !!(targetType && related(getDiscriminatingType(), targetType));
Copy link
Member

@DanielRosenwasser DanielRosenwasser Apr 5, 2023

Choose a reason for hiding this comment

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

What happens if you switch this to check discriminable[i] !== true so that as long as some type has a successful discriminant, the property is discriminable?

Or alternatively,

for (const type of target.types) {
    const targetType = getTypeOfPropertyOfType(type, propertyName);

    const targetIsDiscriminable = discriminable[i] = !!(targetType && related(getDiscriminatingType(), targetType));
    if (targetIsDiscriminable) {
        break;
    }

    i++
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That doesn't change the logic though, it just optimizes the looping a bit.

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 do like your suggestion BTW, just making sure I'm not missing something.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't it?

In the original version, a single false takes precedence over everything else.

With your change, the first result takes precedence over every other (which sounds suspicious - this doesn't even need to be a loop anymore).

In my suggestion, a single true takes precedence over any other result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, that makes sense. Boolean logic gets tricky with truthy and falsy stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, with my change the first result doesn't always take precedence, because the objects in the union could potentially contain different items and so the writes to discriminable could differ between iterations.

Copy link
Contributor Author

@MariaSolOs MariaSolOs Apr 5, 2023

Choose a reason for hiding this comment

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

@DanielRosenwasser your suggested change breaks this test (among other suspicious diagnostic changes).

foo2({
  type2: 'y',
  ~~~~~
!!! error TS2345: Argument of type '{ type2: string; value: string; method(): void; }' is not assignable to parameter of type 'X2 | Y2'.
!!! error TS2345:   Object literal may only specify known properties, but 'type2' does not exist in type 'X2'. Did you mean to write 'type1'?
  value: 'done',
  method() {
    this;
    this.value;
  }
});

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

I have some other ideas for error recovery here, but I believe this is an improvement that doesn't have to wait on that.

@jakebailey
Copy link
Member

@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 7, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..53654

Metric main 53654 Delta Best Worst p-value
Angular - node (v16.17.1, x64)
Memory used 364,779k (± 0.01%) 364,761k (± 0.01%) ~ 364,723k 364,782k p=0.261 n=6
Parse Time 3.57s (± 0.60%) 3.58s (± 0.78%) ~ 3.55s 3.62s p=0.686 n=6
Bind Time 1.18s (± 0.69%) 1.19s (± 0.83%) ~ 1.17s 1.20s p=0.282 n=6
Check Time 9.54s (± 0.48%) 9.55s (± 0.22%) ~ 9.52s 9.58s p=0.872 n=6
Emit Time 8.01s (± 0.70%) 7.97s (± 1.09%) ~ 7.88s 8.10s p=0.421 n=6
Total Time 22.31s (± 0.42%) 22.28s (± 0.50%) ~ 22.19s 22.44s p=0.748 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,543k (± 0.02%) 192,516k (± 0.04%) ~ 192,436k 192,633k p=0.298 n=6
Parse Time 1.60s (± 0.65%) 1.60s (± 1.35%) ~ 1.57s 1.63s p=0.935 n=6
Bind Time 0.83s (± 0.62%) 0.83s (± 0.49%) ~ 0.82s 0.83s p=0.595 n=6
Check Time 10.32s (± 0.60%) 10.37s (± 1.08%) ~ 10.18s 10.49s p=0.261 n=6
Emit Time 3.01s (± 0.62%) 2.99s (± 0.25%) ~ 2.98s 3.00s p=0.217 n=6
Total Time 15.75s (± 0.46%) 15.78s (± 0.72%) ~ 15.60s 15.88s p=0.629 n=6
Monaco - node (v16.17.1, x64)
Memory used 345,748k (± 0.00%) 345,745k (± 0.00%) ~ 345,740k 345,753k p=0.297 n=6
Parse Time 2.73s (± 0.95%) 2.72s (± 0.30%) ~ 2.71s 2.73s p=0.683 n=6
Bind Time 1.09s (± 0.47%) 1.09s (± 0.75%) ~ 1.08s 1.10s p=0.140 n=6
Check Time 7.82s (± 0.38%) 7.85s (± 0.59%) ~ 7.79s 7.91s p=0.227 n=6
Emit Time 4.47s (± 0.46%) 4.47s (± 0.79%) ~ 4.44s 4.53s p=0.809 n=6
Total Time 16.10s (± 0.35%) 16.14s (± 0.46%) ~ 16.04s 16.25s p=0.518 n=6
TFS - node (v16.17.1, x64)
Memory used 300,052k (± 0.01%) 300,047k (± 0.01%) ~ 300,019k 300,085k p=0.575 n=6
Parse Time 2.15s (± 0.63%) 2.18s (± 0.54%) +0.02s (+ 1.16%) 2.17s 2.20s p=0.009 n=6
Bind Time 1.23s (± 0.95%) 1.24s (± 0.79%) ~ 1.23s 1.25s p=0.314 n=6
Check Time 7.21s (± 0.25%) 7.25s (± 0.48%) ~ 7.19s 7.29s p=0.073 n=6
Emit Time 4.34s (± 0.76%) 4.34s (± 0.55%) ~ 4.30s 4.36s p=1.000 n=6
Total Time 14.93s (± 0.34%) 15.00s (± 0.34%) +0.07s (+ 0.46%) 14.91s 15.06s p=0.037 n=6
material-ui - node (v16.17.1, x64)
Memory used 479,430k (± 0.00%) 479,286k (± 0.01%) -144k (- 0.03%) 479,237k 479,382k p=0.005 n=6
Parse Time 3.25s (± 0.54%) 3.24s (± 0.92%) ~ 3.19s 3.27s p=1.000 n=6
Bind Time 0.96s (± 0.43%) 0.96s (± 1.42%) ~ 0.95s 0.99s p=0.673 n=6
Check Time 18.25s (± 0.35%) 18.22s (± 0.31%) ~ 18.15s 18.32s p=0.521 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.45s (± 0.28%) 22.43s (± 0.27%) ~ 22.38s 22.55s p=0.806 n=6
xstate - node (v16.17.1, x64)
Memory used 559,737k (± 0.02%) 559,752k (± 0.02%) ~ 559,594k 559,851k p=0.378 n=6
Parse Time 3.98s (± 0.29%) 4.00s (± 0.51%) ~ 3.97s 4.02s p=0.117 n=6
Bind Time 1.74s (± 0.86%) 1.76s (± 0.59%) ~ 1.74s 1.77s p=0.131 n=6
Check Time 3.04s (± 0.70%) 3.07s (± 0.13%) ~ 3.06s 3.07s p=0.056 n=6
Emit Time 0.09s (± 4.45%) 0.10s (± 4.15%) +0.01s (+ 7.27%) 0.09s 0.10s p=0.034 n=6
Total Time 8.86s (± 0.38%) 8.92s (± 0.28%) +0.06s (+ 0.68%) 8.89s 8.95s p=0.013 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-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
  • Angular - node (v16.17.1, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Monaco - node (v16.17.1, x64)
  • TFS - node (v16.17.1, x64)
  • material-ui - node (v16.17.1, x64)
  • xstate - node (v16.17.1, x64)
Benchmark Name Iterations
Current 53654 6
Baseline main 6

Developer Information:

Download Benchmark

@ahejlsberg
Copy link
Member

The fix in this PR unfortunately doesn't work right in all cases. Consider:

type Foo = { x: 0, y: 0, z: 'a' } | { x: 0, y: 1, z: 'b' } | { x: 1, y: 0, z: 'c' } | { x: 1, y: 1, z: 'd' };

let foo: Foo = {
    x: 0,
    y: 1,
    z: // Suggests "a" | "b" here
}

Above, only "b" should be in the completion list. The issue is that once discriminable[i] gets set to true for a particular constituent, it isn't possible for a later check to disqualify that constituent. So it doesn't work when there are multiple discriminant properties as in the example above.

In general, I find the original logic in discriminateTypeByDiscriminableItems hard to follow, and I can't really convince myself that it is correct. It basically starts out by saying that no constituents are in the discriminated result and then only includes constituents when they have a discriminant property with a matching type. I think it needs to be the other way around: By default, all constituents should be in the discriminated result, but when constituents have discriminant properties with types that don't match, they should be removed from the result. Then, in order to fix #53165, we need to additionally say that we only remove constituents when some other constituent has a discriminant property with a matching type (in other words, if we know a property will for sure cause an error, we should just ignore that property).

I'm going to put up a PR with the suggested changes.

@MariaSolOs
Copy link
Contributor Author

@ahejlsberg oh well, I tried 😅 Thank you for coming up with a proper solution!

@MariaSolOs
Copy link
Contributor Author

Closing as this PR has been superseded by #53709

@MariaSolOs MariaSolOs closed this Apr 10, 2023
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
None yet
Development

Successfully merging this pull request may close these issues.

Intellisense suggests invalid property values within union objects
7 participants