Skip to content

Conversation

@nekolab
Copy link

@nekolab nekolab commented Aug 25, 2024

This PR introduces a method to narrow the types of destructured variables through control flow analysis without relying on the discriminant member.

When the initializer of the ObjectBindingPattern is available, we attempt to narrow its type, which in turn helps further refine the type of the destructured variable.

Partially fixes #59657

This PR introduces a method to narrow the types of destructured
variables through control flow analysis without relying on the
discriminant member.

When the initializer of the `ObjectBindingPattern` is available,
we attempt to narrow its type, which in turn helps further refine
the type of the destructured variable.

Partially fixes microsoft#59657
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Aug 25, 2024
@nekolab
Copy link
Author

nekolab commented Aug 25, 2024

@microsoft-github-policy-service agree

@RyanCavanaugh
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 5, 2025

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

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

@typescript-bot
Copy link
Collaborator

Hey @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 user tests with tsc comparing main and refs/pull/59745/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Git clone failed"

Otherwise...

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 62,370 62,370 ~ ~ ~ p=1.000 n=6
Types 50,387 50,387 ~ ~ ~ p=1.000 n=6
Memory used 193,332k (± 0.75%) 194,426k (± 1.00%) ~ 192,622k 196,230k p=0.810 n=6
Parse Time 1.31s (± 0.39%) 1.30s (± 0.63%) -0.01s (- 0.77%) 1.29s 1.31s p=0.050 n=6
Bind Time 0.75s 0.75s ~ ~ ~ p=1.000 n=6
Check Time 9.89s (± 0.41%) 9.90s (± 0.25%) ~ 9.85s 9.92s p=0.466 n=6
Emit Time 2.73s (± 0.71%) 2.74s (± 0.72%) ~ 2.71s 2.77s p=0.118 n=6
Total Time 14.67s (± 0.30%) 14.69s (± 0.13%) ~ 14.66s 14.71s p=0.747 n=6
angular-1 - node (v18.15.0, x64)
Errors 2 2 ~ ~ ~ p=1.000 n=6
Symbols 956,048 956,048 ~ ~ ~ p=1.000 n=6
Types 415,904 415,904 ~ ~ ~ p=1.000 n=6
Memory used 1,255,024k (± 0.00%) 1,255,049k (± 0.00%) ~ 1,255,028k 1,255,081k p=0.230 n=6
Parse Time 6.53s (± 0.82%) 6.55s (± 0.46%) ~ 6.50s 6.58s p=0.686 n=6
Bind Time 1.96s (± 0.42%) 1.96s (± 0.26%) ~ 1.96s 1.97s p=0.114 n=6
Check Time 32.40s (± 0.42%) 32.37s (± 0.28%) ~ 32.19s 32.43s p=0.936 n=6
Emit Time 14.89s (± 0.41%) 14.84s (± 0.48%) ~ 14.71s 14.93s p=0.172 n=6
Total Time 55.77s (± 0.30%) 55.72s (± 0.17%) ~ 55.58s 55.81s p=0.630 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,722,102 2,722,102 ~ ~ ~ p=1.000 n=6
Types 937,520 937,520 ~ ~ ~ p=1.000 n=6
Memory used 3,050,975k (± 0.00%) 3,050,958k (± 0.00%) ~ 3,050,887k 3,051,058k p=0.810 n=6
Parse Time 8.55s (± 0.23%) 8.54s (± 0.20%) ~ 8.52s 8.56s p=0.408 n=6
Bind Time 2.33s (± 0.53%) 2.32s (± 0.52%) ~ 2.30s 2.33s p=0.271 n=6
Check Time 93.03s (± 0.45%) 93.07s (± 0.35%) ~ 92.76s 93.58s p=0.689 n=6
Emit Time 0.31s (± 2.04%) 0.31s (± 1.31%) ~ 0.31s 0.32s p=0.673 n=6
Total Time 104.22s (± 0.40%) 104.24s (± 0.31%) ~ 103.93s 104.73s p=0.748 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,251,654 1,251,655 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 259,840 259,840 ~ ~ ~ p=1.000 n=6
Memory used 2,514,514k (± 7.45%) 2,392,739k (± 0.02%) 🟩-121,775k (- 4.84%) 2,392,066k 2,393,086k p=0.031 n=6
Parse Time 5.14s (± 0.86%) 5.12s (± 0.60%) ~ 5.07s 5.14s p=0.378 n=6
Bind Time 1.81s (± 0.95%) 1.83s (± 2.05%) ~ 1.80s 1.90s p=0.260 n=6
Check Time 35.33s (± 0.80%) 35.55s (± 0.15%) ~ 35.49s 35.63s p=0.109 n=6
Emit Time 3.00s (± 1.77%) 3.03s (± 1.15%) ~ 3.00s 3.09s p=0.518 n=6
Total Time 45.29s (± 0.63%) 45.55s (± 0.14%) ~ 45.50s 45.68s p=0.173 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,251,654 1,251,655 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 259,840 259,840 ~ ~ ~ p=1.000 n=6
Memory used 3,188,612k (± 0.02%) 3,094,218k (± 7.49%) ~ 2,620,730k 3,189,413k p=0.810 n=6
Parse Time 6.75s (± 1.16%) 6.73s (± 0.86%) ~ 6.64s 6.79s p=0.748 n=6
Bind Time 2.26s (± 1.34%) 2.26s (± 1.18%) ~ 2.21s 2.29s p=1.000 n=6
Check Time 43.03s (± 0.14%) 42.90s (± 1.09%) ~ 41.99s 43.30s p=0.688 n=6
Emit Time 3.53s (± 1.79%) 3.46s (± 1.41%) ~ 3.41s 3.52s p=0.077 n=6
Total Time 55.58s (± 0.12%) 55.33s (± 0.84%) ~ 54.42s 55.67s p=0.298 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 264,287 264,288 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 104,051 104,051 ~ ~ ~ p=1.000 n=6
Memory used 443,352k (± 0.02%) 443,311k (± 0.01%) ~ 443,245k 443,394k p=0.470 n=6
Parse Time 3.52s (± 0.62%) 3.53s (± 0.66%) ~ 3.49s 3.56s p=0.567 n=6
Bind Time 1.39s (± 1.06%) 1.37s (± 1.57%) ~ 1.34s 1.40s p=0.145 n=6
Check Time 19.22s (± 0.35%) 19.27s (± 0.42%) ~ 19.17s 19.37s p=0.332 n=6
Emit Time 1.55s (± 0.63%) 1.55s (± 0.89%) ~ 1.52s 1.56s p=0.720 n=6
Total Time 25.68s (± 0.34%) 25.71s (± 0.36%) ~ 25.61s 25.85s p=0.688 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 72 72 ~ ~ ~ p=1.000 n=6
Symbols 225,493 225,493 ~ ~ ~ p=1.000 n=6
Types 94,373 94,373 ~ ~ ~ p=1.000 n=6
Memory used 370,210k (± 0.07%) 370,141k (± 0.01%) ~ 370,082k 370,220k p=0.630 n=6
Parse Time 2.83s (± 1.06%) 2.83s (± 0.97%) ~ 2.79s 2.85s p=0.870 n=6
Bind Time 1.64s (± 1.14%) 1.64s (± 0.86%) ~ 1.62s 1.66s p=0.805 n=6
Check Time 16.64s (± 0.44%) 16.64s (± 0.28%) ~ 16.58s 16.69s p=1.000 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 21.11s (± 0.43%) 21.11s (± 0.16%) ~ 21.05s 21.14s p=0.810 n=6
vscode - node (v18.15.0, x64)
Errors 11 11 ~ ~ ~ p=1.000 n=6
Symbols 4,079,846 4,079,847 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,285,484 1,285,484 ~ ~ ~ p=1.000 n=6
Memory used 3,865,525k (± 0.00%) 3,865,433k (± 0.00%) ~ 3,865,282k 3,865,521k p=0.092 n=6
Parse Time 15.72s (± 0.67%) 15.70s (± 0.69%) ~ 15.56s 15.86s p=0.748 n=6
Bind Time 5.30s (± 0.58%) 5.36s (± 2.20%) ~ 5.27s 5.57s p=0.518 n=6
Check Time 113.30s (± 1.49%) 112.74s (± 2.48%) ~ 109.22s 117.51s p=0.689 n=6
Emit Time 40.37s (± 7.56%) 42.86s (±15.26%) ~ 38.89s 54.98s p=1.000 n=6
Total Time 174.69s (± 1.38%) 176.66s (± 2.96%) ~ 171.72s 185.18s p=0.689 n=6
webpack - node (v18.15.0, x64)
Errors 40 40 ~ ~ ~ p=1.000 n=6
Symbols 380,758 380,758 ~ ~ ~ p=1.000 n=6
Types 166,811 166,811 ~ ~ ~ p=1.000 n=6
Memory used 540,877k (± 0.01%) 540,911k (± 0.03%) ~ 540,728k 541,205k p=1.000 n=6
Parse Time 4.73s (± 0.76%) 4.71s (± 0.39%) ~ 4.69s 4.74s p=0.466 n=6
Bind Time 2.02s (± 1.58%) 2.04s (± 1.41%) ~ 2.00s 2.07s p=0.687 n=6
Check Time 23.01s (± 0.47%) 22.96s (± 0.44%) ~ 22.85s 23.12s p=0.574 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 29.76s (± 0.48%) 29.71s (± 0.40%) ~ 29.59s 29.91s p=0.575 n=6
xstate-main - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 692,951 692,951 ~ ~ ~ p=1.000 n=6
Types 210,425 210,425 ~ ~ ~ p=1.000 n=6
Memory used 588,884k (± 0.02%) 588,954k (± 0.02%) ~ 588,791k 589,117k p=0.298 n=6
Parse Time 4.18s (± 0.58%) 4.18s (± 0.40%) ~ 4.17s 4.21s p=0.803 n=6
Bind Time 1.41s (± 0.83%) 1.42s (± 0.73%) ~ 1.40s 1.43s p=0.241 n=6
Check Time 21.23s (± 1.72%) 21.13s (± 1.73%) ~ 20.75s 21.57s p=0.936 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 26.81s (± 1.30%) 26.73s (± 1.43%) ~ 26.33s 27.19s p=1.000 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@RyanCavanaugh Here are the results of running the top 400 repos with tsc comparing main and refs/pull/59745/merge:

Everything looks good!

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

Status: Not started

Development

Successfully merging this pull request may close these issues.

Make type narrowing for destructured discriminated unions work for more types

3 participants