Skip to content

Fix missed errors in switch when using union of literal and non-literal types (#38686) #51373

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 2 commits into from
Dec 6, 2022

Conversation

ericbf
Copy link
Contributor

@ericbf ericbf commented Nov 1, 2022

This commit makes it so we don’t use the base type of literals when checking comparability in switch. The comparability checks handle that case already, is my understanding, so we don’t need to clobber the type before actually doing the check, causing missed errors.

When comparing the types in switch, if a union with a literal and a non-literal was used, the compiler in checker.ts would automatically get the base type of all parts of the union, resulting in missed errors. For example, if the union of the non-literal number and literal "hello" was compared to the literal "world" in a switch case, the compiler would miss that they’re actually not comparable.

Maybe someone can tell me why we were getting the base type before checking comparability, rather than relying on the logic within the comparability checks to handle literal/base type comparability?

Fixes #38686

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Nov 1, 2022
@ericbf
Copy link
Contributor Author

ericbf commented Nov 1, 2022

@microsoft-github-policy-service agree

@RyanCavanaugh
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 1, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 1, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 1, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 1, 2022

Heya @RyanCavanaugh, I've started to run the perf test suite on this PR at 83bf937. 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/51373/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

Heya @RyanCavanaugh, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - main..51373
Metric main 51373 Delta Best Worst
Angular - node (v18.10.0, x64)
Memory used 353,963k (± 0.02%) 353,963k (± 0.02%) -0k (- 0.00%) 353,731k 354,148k
Parse Time 1.56s (± 0.49%) 1.57s (± 0.70%) +0.02s (+ 1.09%) 1.55s 1.60s
Bind Time 0.61s (± 0.60%) 0.62s (± 0.96%) +0.01s (+ 1.65%) 0.61s 0.63s
Check Time 4.42s (± 0.55%) 4.47s (± 0.56%) +0.05s (+ 1.06%) 4.40s 4.52s
Emit Time 4.93s (± 0.64%) 4.98s (± 1.10%) +0.05s (+ 1.12%) 4.86s 5.14s
Total Time 11.51s (± 0.46%) 11.64s (± 0.62%) +0.13s (+ 1.11%) 11.47s 11.81s
Compiler-Unions - node (v18.10.0, x64)
Memory used 200,772k (± 0.62%) 200,185k (± 0.82%) -587k (- 0.29%) 195,752k 201,446k
Parse Time 0.60s (± 1.33%) 0.61s (± 0.77%) +0.01s (+ 1.33%) 0.60s 0.62s
Bind Time 0.36s (± 0.94%) 0.37s (± 1.41%) +0.01s (+ 1.65%) 0.36s 0.38s
Check Time 5.37s (± 0.75%) 5.43s (± 0.69%) +0.05s (+ 0.97%) 5.32s 5.48s
Emit Time 1.81s (± 0.81%) 1.83s (± 1.12%) +0.02s (+ 0.94%) 1.80s 1.89s
Total Time 8.15s (± 0.71%) 8.23s (± 0.46%) +0.08s (+ 0.97%) 8.12s 8.29s
Monaco - node (v18.10.0, x64)
Memory used 331,748k (± 0.01%) 331,746k (± 0.01%) -2k (- 0.00%) 331,673k 331,808k
Parse Time 1.17s (± 0.65%) 1.17s (± 0.63%) +0.00s (+ 0.34%) 1.16s 1.19s
Bind Time 0.56s (± 1.25%) 0.56s (± 1.03%) -0.00s (- 0.18%) 0.55s 0.57s
Check Time 4.31s (± 0.90%) 4.33s (± 0.58%) +0.02s (+ 0.35%) 4.28s 4.38s
Emit Time 2.61s (± 0.72%) 2.64s (± 0.94%) +0.03s (+ 1.07%) 2.59s 2.70s
Total Time 8.66s (± 0.71%) 8.70s (± 0.56%) +0.04s (+ 0.45%) 8.59s 8.82s
TFS - node (v18.10.0, x64)
Memory used 294,811k (± 0.01%) 294,767k (± 0.02%) -44k (- 0.01%) 294,603k 294,841k
Parse Time 0.94s (± 1.05%) 0.94s (± 1.01%) +0.01s (+ 0.64%) 0.92s 0.96s
Bind Time 0.60s (± 3.95%) 0.60s (± 3.70%) -0.00s (- 0.17%) 0.56s 0.65s
Check Time 4.01s (± 0.67%) 4.08s (± 0.50%) +0.07s (+ 1.65%) 4.01s 4.11s
Emit Time 2.63s (± 0.60%) 2.67s (± 0.51%) +0.03s (+ 1.33%) 2.62s 2.70s
Total Time 8.18s (± 0.72%) 8.29s (± 0.52%) +0.10s (+ 1.27%) 8.17s 8.37s
material-ui - node (v18.10.0, x64)
Memory used 439,901k (± 0.01%) 439,939k (± 0.02%) +38k (+ 0.01%) 439,790k 440,131k
Parse Time 1.37s (± 0.84%) 1.37s (± 0.78%) -0.00s (- 0.07%) 1.34s 1.39s
Bind Time 0.44s (± 1.07%) 0.45s (± 1.04%) +0.01s (+ 2.27%) 0.44s 0.46s
Check Time 10.83s (± 0.24%) 11.09s (± 1.18%) +0.26s (+ 2.41%) 10.73s 11.29s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 12.64s (± 0.22%) 12.91s (± 1.09%) +0.27s (+ 2.11%) 12.52s 13.11s
xstate - node (v18.10.0, x64)
Memory used 557,292k (± 0.01%) 557,241k (± 0.01%) -51k (- 0.01%) 557,151k 557,330k
Parse Time 1.91s (± 0.56%) 1.93s (± 0.49%) +0.01s (+ 0.78%) 1.90s 1.94s
Bind Time 0.69s (± 2.31%) 0.69s (± 0.75%) +0.00s (+ 0.14%) 0.68s 0.70s
Check Time 1.10s (± 0.62%) 1.11s (± 1.03%) +0.01s (+ 0.63%) 1.09s 1.14s
Emit Time 0.06s (± 0.00%) 0.06s (± 0.00%) 0.00s ( 0.00%) 0.06s 0.06s
Total Time 3.76s (± 0.52%) 3.78s (± 0.50%) +0.02s (+ 0.61%) 3.73s 3.82s
Angular - node (v16.17.1, x64)
Memory used 353,451k (± 0.02%) 353,456k (± 0.01%) +5k (+ 0.00%) 353,383k 353,541k
Parse Time 1.90s (± 0.53%) 1.92s (± 0.81%) +0.02s (+ 1.00%) 1.90s 1.98s
Bind Time 0.75s (± 0.89%) 0.75s (± 1.33%) +0.00s (+ 0.40%) 0.74s 0.79s
Check Time 5.70s (± 0.46%) 5.70s (± 0.40%) -0.00s (- 0.02%) 5.64s 5.74s
Emit Time 6.10s (± 0.47%) 6.12s (± 0.46%) +0.02s (+ 0.34%) 6.08s 6.21s
Total Time 14.46s (± 0.39%) 14.50s (± 0.16%) +0.04s (+ 0.30%) 14.45s 14.54s
Compiler-Unions - node (v16.17.1, x64)
Memory used 198,088k (± 0.49%) 198,762k (± 0.62%) +675k (+ 0.34%) 197,337k 200,922k
Parse Time 0.79s (± 1.22%) 0.78s (± 0.83%) -0.00s (- 0.38%) 0.77s 0.80s
Bind Time 0.45s (± 0.89%) 0.45s (± 0.80%) +0.00s (+ 0.67%) 0.45s 0.46s
Check Time 6.43s (± 0.56%) 6.41s (± 0.48%) -0.02s (- 0.23%) 6.37s 6.50s
Emit Time 2.26s (± 0.85%) 2.27s (± 0.99%) +0.01s (+ 0.53%) 2.22s 2.33s
Total Time 9.92s (± 0.34%) 9.92s (± 0.48%) -0.00s (- 0.03%) 9.83s 10.07s
Monaco - node (v16.17.1, x64)
Memory used 331,211k (± 0.02%) 331,189k (± 0.02%) -22k (- 0.01%) 331,078k 331,316k
Parse Time 1.43s (± 0.62%) 1.43s (± 0.43%) -0.00s (- 0.21%) 1.42s 1.45s
Bind Time 0.69s (± 0.84%) 0.69s (± 0.58%) -0.00s (- 0.29%) 0.68s 0.70s
Check Time 5.47s (± 0.58%) 5.49s (± 0.45%) +0.01s (+ 0.22%) 5.42s 5.53s
Emit Time 3.25s (± 0.50%) 3.25s (± 0.52%) +0.00s (+ 0.09%) 3.22s 3.30s
Total Time 10.85s (± 0.36%) 10.86s (± 0.33%) +0.01s (+ 0.08%) 10.77s 10.95s
TFS - node (v16.17.1, x64)
Memory used 294,130k (± 0.02%) 294,196k (± 0.01%) +66k (+ 0.02%) 294,114k 294,258k
Parse Time 1.23s (± 0.89%) 1.22s (± 1.30%) -0.01s (- 0.49%) 1.18s 1.25s
Bind Time 0.64s (± 1.37%) 0.64s (± 0.69%) -0.00s (- 0.16%) 0.63s 0.65s
Check Time 5.14s (± 0.45%) 5.13s (± 0.43%) -0.01s (- 0.21%) 5.07s 5.17s
Emit Time 3.49s (± 0.40%) 3.49s (± 0.69%) -0.00s (- 0.11%) 3.42s 3.54s
Total Time 10.50s (± 0.39%) 10.48s (± 0.39%) -0.02s (- 0.22%) 10.39s 10.57s
material-ui - node (v16.17.1, x64)
Memory used 439,323k (± 0.02%) 439,343k (± 0.01%) +19k (+ 0.00%) 439,257k 439,497k
Parse Time 1.72s (± 1.19%) 1.73s (± 1.23%) +0.01s (+ 0.35%) 1.67s 1.76s
Bind Time 0.54s (± 0.63%) 0.54s (± 1.03%) +0.00s (+ 0.93%) 0.53s 0.56s
Check Time 12.44s (± 0.57%) 12.53s (± 0.66%) +0.09s (+ 0.71%) 12.40s 12.73s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 14.70s (± 0.46%) 14.80s (± 0.64%) +0.10s (+ 0.65%) 14.60s 15.03s
xstate - node (v16.17.1, x64)
Memory used 554,924k (± 0.01%) 554,979k (± 0.02%) +55k (+ 0.01%) 554,824k 555,320k
Parse Time 2.31s (± 0.35%) 2.31s (± 0.30%) -0.00s (- 0.04%) 2.29s 2.32s
Bind Time 0.89s (± 2.01%) 0.89s (± 2.26%) +0.00s (+ 0.34%) 0.87s 0.95s
Check Time 1.43s (± 0.80%) 1.43s (± 0.45%) -0.01s (- 0.35%) 1.41s 1.44s
Emit Time 0.07s (± 4.37%) 0.07s (± 3.23%) +0.00s (+ 1.47%) 0.06s 0.07s
Total Time 4.70s (± 0.39%) 4.70s (± 0.37%) -0.00s (- 0.06%) 4.67s 4.75s
Angular - node (v14.15.1, x64)
Memory used 347,641k (± 0.01%) 347,660k (± 0.01%) +18k (+ 0.01%) 347,602k 347,729k
Parse Time 2.07s (± 0.45%) 2.09s (± 1.38%) +0.02s (+ 1.01%) 2.04s 2.17s
Bind Time 0.80s (± 0.87%) 0.80s (± 0.77%) 0.00s ( 0.00%) 0.79s 0.82s
Check Time 6.00s (± 0.40%) 5.99s (± 0.46%) -0.01s (- 0.15%) 5.96s 6.06s
Emit Time 6.29s (± 0.94%) 6.32s (± 0.94%) +0.03s (+ 0.54%) 6.21s 6.48s
Total Time 15.16s (± 0.43%) 15.21s (± 0.54%) +0.05s (+ 0.31%) 15.08s 15.40s
Compiler-Unions - node (v14.15.1, x64)
Memory used 190,940k (± 0.67%) 190,343k (± 0.01%) -598k (- 0.31%) 190,281k 190,382k
Parse Time 0.86s (± 0.47%) 0.86s (± 0.55%) -0.00s (- 0.23%) 0.85s 0.87s
Bind Time 0.49s (± 1.06%) 0.49s (± 0.00%) -0.00s (- 0.20%) 0.49s 0.49s
Check Time 6.78s (± 0.55%) 6.77s (± 0.63%) -0.00s (- 0.07%) 6.70s 6.88s
Emit Time 2.43s (± 0.88%) 2.43s (± 1.09%) +0.00s (+ 0.12%) 2.39s 2.50s
Total Time 10.56s (± 0.39%) 10.55s (± 0.54%) -0.00s (- 0.01%) 10.44s 10.69s
Monaco - node (v14.15.1, x64)
Memory used 326,563k (± 0.01%) 326,541k (± 0.01%) -22k (- 0.01%) 326,482k 326,620k
Parse Time 1.59s (± 0.75%) 1.58s (± 0.39%) -0.01s (- 0.44%) 1.57s 1.59s
Bind Time 0.73s (± 0.41%) 0.73s (± 0.65%) +0.00s (+ 0.14%) 0.72s 0.74s
Check Time 5.76s (± 0.39%) 5.76s (± 0.58%) -0.00s (- 0.05%) 5.68s 5.85s
Emit Time 3.39s (± 0.38%) 3.39s (± 0.81%) +0.01s (+ 0.27%) 3.33s 3.48s
Total Time 11.47s (± 0.18%) 11.47s (± 0.47%) -0.00s (- 0.00%) 11.37s 11.59s
TFS - node (v14.15.1, x64)
Memory used 289,789k (± 0.01%) 289,789k (± 0.01%) -1k (- 0.00%) 289,749k 289,862k
Parse Time 1.29s (± 0.48%) 1.30s (± 0.71%) +0.01s (+ 0.70%) 1.28s 1.32s
Bind Time 0.80s (± 0.45%) 0.79s (± 2.68%) -0.02s (- 1.87%) 0.72s 0.81s
Check Time 5.40s (± 0.35%) 5.40s (± 0.34%) -0.01s (- 0.15%) 5.34s 5.43s
Emit Time 3.61s (± 0.84%) 3.66s (± 1.12%) +0.05s (+ 1.25%) 3.58s 3.76s
Total Time 11.11s (± 0.33%) 11.14s (± 0.50%) +0.03s (+ 0.27%) 11.02s 11.27s
material-ui - node (v14.15.1, x64)
Memory used 435,469k (± 0.00%) 435,454k (± 0.00%) -15k (- 0.00%) 435,429k 435,494k
Parse Time 1.90s (± 0.92%) 1.89s (± 0.35%) -0.02s (- 0.79%) 1.87s 1.90s
Bind Time 0.59s (± 0.62%) 0.58s (± 0.85%) -0.00s (- 0.17%) 0.58s 0.60s
Check Time 12.87s (± 0.38%) 12.80s (± 0.61%) -0.07s (- 0.53%) 12.67s 13.02s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.36s (± 0.35%) 15.27s (± 0.52%) -0.09s (- 0.57%) 15.13s 15.48s
xstate - node (v14.15.1, x64)
Memory used 543,999k (± 0.01%) 544,000k (± 0.00%) +1k (+ 0.00%) 543,955k 544,046k
Parse Time 2.61s (± 0.59%) 2.62s (± 0.78%) +0.01s (+ 0.42%) 2.59s 2.69s
Bind Time 0.98s (± 1.17%) 0.99s (± 1.39%) +0.01s (+ 1.12%) 0.97s 1.03s
Check Time 1.51s (± 0.39%) 1.51s (± 0.62%) -0.00s (- 0.07%) 1.50s 1.54s
Emit Time 0.07s (± 3.14%) 0.07s (± 0.00%) -0.00s (- 1.41%) 0.07s 0.07s
Total Time 5.18s (± 0.35%) 5.20s (± 0.40%) +0.02s (+ 0.39%) 5.16s 5.25s
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-126-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 51373 10
Baseline main 10

TSServer

Comparison Report - main..51373
Metric main 51373 Delta Best Worst
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 1,066ms (± 0.34%) 1,078ms (± 0.83%) +11ms (+ 1.05%) 1,059ms 1,097ms
Req 2 - geterr 2,738ms (± 0.48%) 2,750ms (± 0.67%) +12ms (+ 0.45%) 2,698ms 2,788ms
Req 3 - references 191ms (± 0.97%) 193ms (± 0.80%) +1ms (+ 0.73%) 188ms 196ms
Req 4 - navto 147ms (± 1.34%) 151ms (± 3.26%) +4ms (+ 2.79%) 145ms 169ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 44ms (± 1.27%) 45ms (± 0.76%) +1ms (+ 2.05%) 44ms 45ms
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 1,132ms (± 0.81%) 1,145ms (± 0.71%) +12ms (+ 1.10%) 1,126ms 1,161ms
Req 2 - geterr 1,616ms (± 0.58%) 1,626ms (± 0.59%) +10ms (+ 0.59%) 1,607ms 1,646ms
Req 3 - references 198ms (± 0.95%) 200ms (± 0.60%) +2ms (+ 1.01%) 199ms 204ms
Req 4 - navto 161ms (± 1.18%) 163ms (± 1.73%) +2ms (+ 1.37%) 156ms 168ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 86ms (± 6.89%) 82ms (± 3.48%) 🟩-4ms (- 5.01%) 78ms 90ms
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 1,628ms (± 0.43%) 1,629ms (± 0.49%) +1ms (+ 0.09%) 1,614ms 1,645ms
Req 2 - geterr 570ms (± 0.63%) 580ms (± 0.40%) +9ms (+ 1.65%) 575ms 584ms
Req 3 - references 52ms (± 1.28%) 53ms (± 1.44%) +1ms (+ 1.15%) 51ms 54ms
Req 4 - navto 207ms (± 0.85%) 210ms (± 0.99%) +3ms (+ 1.45%) 204ms 214ms
Req 5 - completionInfo count 3,209 (± 0.00%) 3,209 (± 0.00%) 0 ( 0.00%) 3,209 3,209
Req 5 - completionInfo 209ms (± 1.79%) 211ms (± 2.01%) +2ms (+ 1.01%) 202ms 220ms
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 1,329ms (± 0.37%) 1,322ms (± 0.31%) -7ms (- 0.50%) 1,311ms 1,329ms
Req 2 - geterr 3,266ms (± 0.72%) 3,287ms (± 0.52%) +21ms (+ 0.64%) 3,241ms 3,315ms
Req 3 - references 224ms (± 1.19%) 223ms (± 1.42%) -1ms (- 0.62%) 217ms 229ms
Req 4 - navto 158ms (± 0.61%) 159ms (± 0.81%) +1ms (+ 0.57%) 157ms 162ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 53ms (± 1.16%) 53ms (± 1.40%) -0ms (- 0.19%) 52ms 55ms
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 1,411ms (± 0.46%) 1,410ms (± 0.49%) -1ms (- 0.06%) 1,397ms 1,426ms
Req 2 - geterr 2,123ms (± 0.48%) 2,125ms (± 0.67%) +2ms (+ 0.08%) 2,103ms 2,175ms
Req 3 - references 232ms (± 0.78%) 235ms (± 1.43%) +3ms (+ 1.08%) 230ms 245ms
Req 4 - navto 172ms (± 1.22%) 179ms (± 8.56%) +7ms (+ 3.96%) 167ms 222ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 52ms (± 1.43%) 53ms (± 2.34%) +1ms (+ 1.34%) 51ms 57ms
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 1,920ms (± 0.52%) 1,927ms (± 0.66%) +7ms (+ 0.35%) 1,903ms 1,960ms
Req 2 - geterr 734ms (± 0.59%) 734ms (± 0.48%) -0ms (- 0.05%) 724ms 740ms
Req 3 - references 60ms (± 1.25%) 61ms (± 1.09%) +1ms (+ 1.49%) 60ms 63ms
Req 4 - navto 209ms (± 0.81%) 209ms (± 0.73%) -0ms (- 0.10%) 205ms 212ms
Req 5 - completionInfo count 3,209 (± 0.00%) 3,209 (± 0.00%) 0 ( 0.00%) 3,209 3,209
Req 5 - completionInfo 259ms (± 0.73%) 257ms (± 0.40%) -2ms (- 0.70%) 254ms 259ms
Compiler-UnionsTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 1,453ms (± 0.60%) 1,452ms (± 0.33%) -1ms (- 0.10%) 1,442ms 1,461ms
Req 2 - geterr 3,548ms (± 0.72%) 3,536ms (± 0.44%) -12ms (- 0.34%) 3,509ms 3,573ms
Req 3 - references 234ms (± 0.38%) 233ms (± 0.79%) -1ms (- 0.26%) 230ms 238ms
Req 4 - navto 174ms (± 0.82%) 174ms (± 1.89%) +1ms (+ 0.52%) 171ms 187ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 56ms (± 3.73%) 55ms (± 1.65%) -2ms (- 2.66%) 54ms 58ms
CompilerTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 1,528ms (± 0.71%) 1,540ms (± 0.59%) +12ms (+ 0.79%) 1,523ms 1,555ms
Req 2 - geterr 2,332ms (± 0.68%) 2,323ms (± 0.55%) -9ms (- 0.38%) 2,293ms 2,354ms
Req 3 - references 246ms (± 0.44%) 246ms (± 0.38%) -1ms (- 0.20%) 243ms 248ms
Req 4 - navto 184ms (± 0.65%) 185ms (± 0.54%) +1ms (+ 0.49%) 182ms 186ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 55ms (± 1.35%) 55ms (± 1.07%) +0ms (+ 0.18%) 54ms 57ms
xstateTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 2,144ms (± 0.73%) 2,146ms (± 0.50%) +2ms (+ 0.11%) 2,118ms 2,171ms
Req 2 - geterr 760ms (± 0.52%) 759ms (± 0.51%) -0ms (- 0.05%) 752ms 769ms
Req 3 - references 67ms (± 2.61%) 67ms (± 3.42%) +1ms (+ 1.35%) 63ms 73ms
Req 4 - navto 230ms (± 0.96%) 229ms (± 0.42%) -2ms (- 0.65%) 227ms 231ms
Req 5 - completionInfo count 3,209 (± 0.00%) 3,209 (± 0.00%) 0 ( 0.00%) 3,209 3,209
Req 5 - completionInfo 279ms (± 1.01%) 276ms (± 1.00%) -3ms (- 0.93%) 270ms 281ms
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-126-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 51373 10
Baseline main 10

Startup

Comparison Report - main..51373
Metric main 51373 Delta Best Worst
tsc-startup - node (v16.17.1, x64)
Execution time 158.07ms (± 0.38%) 159.89ms (± 0.43%) +1.82ms (+ 1.15%) 156.55ms 168.02ms
tsserver-startup - node (v16.17.1, x64)
Execution time 222.85ms (± 0.30%) 224.98ms (± 0.32%) +2.13ms (+ 0.96%) 221.43ms 235.07ms
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 211.02ms (± 0.30%) 212.76ms (± 0.30%) +1.74ms (+ 0.83%) 209.45ms 220.41ms
typescript-startup - node (v16.17.1, x64)
Execution time 200.94ms (± 0.31%) 202.71ms (± 0.32%) +1.76ms (+ 0.88%) 199.53ms 217.90ms
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-126-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 51373 10
Baseline main 10

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/51373/merge:

Everything looks good!

@RyanCavanaugh
Copy link
Member

@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Nov 2, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..51373

Metric main 51373 Delta Best Worst
Angular - node (v16.17.1, x64)
Memory used 353,451k (± 0.02%) 353,470k (± 0.02%) +19k (+ 0.01%) 353,306k 353,567k
Parse Time 1.90s (± 0.53%) 1.91s (± 0.68%) +0.00s (+ 0.21%) 1.88s 1.94s
Bind Time 0.75s (± 0.89%) 0.76s (± 0.79%) +0.01s (+ 0.67%) 0.74s 0.77s
Check Time 5.70s (± 0.46%) 5.72s (± 0.52%) +0.02s (+ 0.35%) 5.64s 5.78s
Emit Time 6.10s (± 0.47%) 6.06s (± 0.56%) -0.04s (- 0.72%) 5.99s 6.17s
Total Time 14.46s (± 0.39%) 14.44s (± 0.35%) -0.01s (- 0.08%) 14.34s 14.59s
Compiler-Unions - node (v16.17.1, x64)
Memory used 198,088k (± 0.49%) 198,714k (± 0.61%) +626k (+ 0.32%) 197,313k 200,737k
Parse Time 0.79s (± 1.22%) 0.79s (± 0.66%) +0.00s (+ 0.51%) 0.78s 0.80s
Bind Time 0.45s (± 0.89%) 0.46s (± 1.08%) +0.00s (+ 1.11%) 0.45s 0.47s
Check Time 6.43s (± 0.56%) 6.49s (± 0.61%) +0.07s (+ 1.06%) 6.40s 6.57s
Emit Time 2.26s (± 0.85%) 2.29s (± 1.09%) +0.03s (+ 1.28%) 2.25s 2.37s
Total Time 9.92s (± 0.34%) 10.03s (± 0.55%) +0.11s (+ 1.08%) 9.91s 10.13s
Monaco - node (v16.17.1, x64)
Memory used 331,211k (± 0.02%) 331,206k (± 0.02%) -5k (- 0.00%) 331,090k 331,397k
Parse Time 1.43s (± 0.62%) 1.43s (± 0.65%) -0.00s (- 0.14%) 1.42s 1.46s
Bind Time 0.69s (± 0.84%) 0.70s (± 0.80%) +0.01s (+ 0.72%) 0.68s 0.71s
Check Time 5.47s (± 0.58%) 5.50s (± 0.49%) +0.02s (+ 0.42%) 5.44s 5.56s
Emit Time 3.25s (± 0.50%) 3.26s (± 0.61%) +0.01s (+ 0.22%) 3.22s 3.31s
Total Time 10.85s (± 0.36%) 10.89s (± 0.39%) +0.03s (+ 0.30%) 10.81s 11.00s
TFS - node (v16.17.1, x64)
Memory used 294,130k (± 0.02%) 294,151k (± 0.01%) +20k (+ 0.01%) 294,059k 294,225k
Parse Time 1.23s (± 0.89%) 1.24s (± 1.38%) +0.01s (+ 0.57%) 1.20s 1.28s
Bind Time 0.64s (± 1.37%) 0.64s (± 0.74%) 0.00s ( 0.00%) 0.63s 0.65s
Check Time 5.14s (± 0.45%) 5.14s (± 0.48%) -0.01s (- 0.10%) 5.10s 5.20s
Emit Time 3.49s (± 0.40%) 3.48s (± 0.38%) -0.01s (- 0.23%) 3.46s 3.51s
Total Time 10.50s (± 0.39%) 10.50s (± 0.39%) -0.01s (- 0.07%) 10.42s 10.57s
material-ui - node (v16.17.1, x64)
Memory used 439,323k (± 0.02%) 439,331k (± 0.01%) +8k (+ 0.00%) 439,278k 439,448k
Parse Time 1.72s (± 1.19%) 1.75s (± 1.52%) +0.02s (+ 1.45%) 1.69s 1.80s
Bind Time 0.54s (± 0.63%) 0.54s (± 0.63%) +0.01s (+ 1.12%) 0.54s 0.55s
Check Time 12.44s (± 0.57%) 12.50s (± 0.52%) +0.06s (+ 0.50%) 12.43s 12.70s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 14.70s (± 0.46%) 14.79s (± 0.52%) +0.09s (+ 0.61%) 14.66s 15.04s
xstate - node (v16.17.1, x64)
Memory used 554,924k (± 0.01%) 555,025k (± 0.01%) +101k (+ 0.02%) 554,869k 555,166k
Parse Time 2.31s (± 0.35%) 2.32s (± 0.61%) +0.01s (+ 0.26%) 2.29s 2.36s
Bind Time 0.89s (± 2.01%) 0.89s (± 0.95%) +0.00s (+ 0.11%) 0.88s 0.92s
Check Time 1.43s (± 0.80%) 1.44s (± 0.78%) +0.01s (+ 0.42%) 1.41s 1.47s
Emit Time 0.07s (± 4.37%) 0.07s (± 4.37%) 0.00s ( 0.00%) 0.06s 0.07s
Total Time 4.70s (± 0.39%) 4.71s (± 0.35%) +0.01s (+ 0.26%) 4.68s 4.76s
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-126-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 51373 10
Baseline main 10

Developer Information:

Download Benchmark

@ericbf
Copy link
Contributor Author

ericbf commented Nov 15, 2022

Should I resolve the conflicts? Or someone else will handle that?

@andrewbranch
Copy link
Member

You’ll need to resolve them. We migrated the codebase to ES modules so the indentation of every line has change. We’ve found that git is very bad at figuring out where the meaningful changes are in these conflicts, but VS Code’s “Resolve in Merge Editor” functionality usually gets it right.

@ericbf
Copy link
Contributor Author

ericbf commented Nov 15, 2022

@andrewbranch cool, I already did that locally, but it looks like some tests are failing on the latest main branch.

…al types (microsoft#38686)

This commit makes it so we don’t use the base type of literals when checking comparability in switch. The comparability checks handle that case already, is my understanding, so we don’t need to clobber the type before actually doing the check, causing missed errors.

When comparing the types in switch, if a union with a literal and a non-literal was used, the compiler in `checker.ts` would automatically get the base type of all parts of the union, resulting in missed errors. For example, if the union of the non-literal `number` and literal `"hello"` was compared to the literal `"world"` in a switch case, the compiler would miss that they’re actually not comparable.

Maybe someone can tell me why we were getting the base type before checking comparability, rather than relying on the logic within the comparability checks to handle literal/base type comparability?
@ericbf
Copy link
Contributor Author

ericbf commented Nov 15, 2022

I rebased this branch onto the latest main then. Some tests were failing on main itself locally, so it may fail. We’ll see.

@ericbf
Copy link
Contributor Author

ericbf commented Nov 16, 2022

Looks like worked fine—cool beans.

@andrewbranch
Copy link
Member

@sandersn you wrote the code this is deleting (albeit 6 years ago) if you want to add a review

@gabritto
Copy link
Member

I think this is good, but before merging I'd like to hear from @sandersn when he gets back to see if there was any particular reason why we were using the base types for this comparison check.

@ericbf
Copy link
Contributor Author

ericbf commented Dec 3, 2022

Is @sandersn around yet?

@gabritto
Copy link
Member

gabritto commented Dec 6, 2022

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 6, 2022

Heya @gabritto, I've started to run the tarball bundle task on this PR at 95ff120. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 6, 2022

Hey @gabritto, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/139760/artifacts?artifactName=tgz&fileId=FED62DBF6AFCEAABAE18CC4E3552A2D15E5D94307E111C22C88033248B61D23302&fileName=/typescript-5.0.0-insiders.20221206.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.0.0-pr-51373-23".;

@gabritto gabritto merged commit af1d91d into microsoft:main Dec 6, 2022
@gabritto
Copy link
Member

gabritto commented Dec 6, 2022

I talked to @sandersn offline about the old implementation. The use of base types for the case and expression types was implemented in #11633 as a fix to a bug (#10892). As seen in this bug, the way we checked type comparability involving literal types was inadequate in some cases, and thus motivated the original PR that used the base types instead. But we have made several improvements to type (equality) comparability in the meantime, such that using the literal types for case and expression types and checking for equality comparability in the original code of the bug #10892 doesn't lead to an error anymore. It seems that we simply didn't update the type comparability implementation for switch statements, leading to the problem this PR fixed.

Ideally, in the future we'd like type comparability in switch statements to be the same as type comparability for equality (e.g. if (x === y)), with the same nice error messages that mention type overlap, so that whenever we improve/change type equality comparability, we don't forget to update and end up with inconsistent behavior.

@ericbf
Copy link
Contributor Author

ericbf commented Dec 6, 2022

Cool beans—thanks for the follow up @gabritto! Maybe I can look into doing that later 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Switch statement does not flag non-comparable cases with non-overlapping literal and non-literal union types
5 participants