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

Revert return type narrowing #61136

Merged
merged 1 commit into from
Feb 7, 2025
Merged

Revert return type narrowing #61136

merged 1 commit into from
Feb 7, 2025

Conversation

gabritto
Copy link
Member

@gabritto gabritto commented Feb 7, 2025

As discussed in design meeting on Feb 4th, the current design for return type narrowing doesn't work well with object types, and that aspect needs to be fixed before the feature can be released.
My notes on the problem are here: https://gist.github.com/gabritto/b6ebd5f9fc2bb3cfc305027609e66bca

This PR reverts return type narrowing, but keeps the change where we check each branch of a conditional return expression separately, since that change, although a breaking one, uncovered bugs in vscode and Google.

My plan is to later fix return type narrowing and get the fixed version in TS again for the 5.9. The planned fix is to restrict return type narrowing for cases where we the function/return type distinguishes between primitive types or primitive and object types, e.g. cases where the parameter has type string | number or string | string[]. These are the cases where regular type narrowing already works well, and avoids the problems mentioned in the notes. Then, on top of that restriction, we'll enable embedding the "narrowable" type parameter in an object type (see https://gist.github.com/gabritto/b6ebd5f9fc2bb3cfc305027609e66bca#alternative-2-embedding).

@gabritto
Copy link
Member Author

gabritto commented Feb 7, 2025

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

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

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 34 34 ~ ~ ~ p=1.000 n=6
Symbols 62,390 62,390 ~ ~ ~ p=1.000 n=6
Types 50,395 50,395 ~ ~ ~ p=1.000 n=6
Memory used 194,943k (± 1.03%) 194,118k (± 0.96%) ~ 192,889k 196,543k p=0.066 n=6
Parse Time 1.33s (± 0.39%) 1.30s (± 0.64%) -0.02s (- 1.63%) 1.29s 1.31s p=0.004 n=6
Bind Time 0.73s (± 0.56%) 0.73s (± 0.70%) ~ 0.73s 0.74s p=0.595 n=6
Check Time 9.80s (± 0.31%) 9.79s (± 0.23%) ~ 9.75s 9.81s p=0.685 n=6
Emit Time 2.75s (± 0.78%) 2.75s (± 0.44%) ~ 2.73s 2.76s p=0.934 n=6
Total Time 14.61s (± 0.16%) 14.57s (± 0.18%) ~ 14.53s 14.60s p=0.060 n=6
angular-1 - node (v18.15.0, x64)
Errors 37 37 ~ ~ ~ p=1.000 n=6
Symbols 948,488 948,488 ~ ~ ~ p=1.000 n=6
Types 411,006 411,006 ~ ~ ~ p=1.000 n=6
Memory used 1,225,423k (± 0.00%) 1,224,194k (± 0.01%) -1,229k (- 0.10%) 1,224,114k 1,224,328k p=0.005 n=6
Parse Time 6.71s (± 0.52%) 6.71s (± 0.70%) ~ 6.65s 6.76s p=0.222 n=6
Bind Time 1.93s (± 0.61%) 1.92s (± 0.57%) ~ 1.91s 1.94s p=0.246 n=6
Check Time 32.25s (± 0.48%) 31.95s (± 0.32%) -0.30s (- 0.92%) 31.84s 32.11s p=0.013 n=6
Emit Time 15.36s (± 0.17%) 15.41s (± 0.57%) ~ 15.32s 15.52s p=0.520 n=6
Total Time 56.25s (± 0.30%) 55.99s (± 0.19%) -0.26s (- 0.46%) 55.80s 56.06s p=0.024 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,371,940 2,371,940 ~ ~ ~ p=1.000 n=6
Types 846,141 846,141 ~ ~ ~ p=1.000 n=6
Memory used 2,138,893k (± 0.01%) 2,134,700k (± 0.00%) -4,194k (- 0.20%) 2,134,605k 2,134,811k p=0.005 n=6
Parse Time 7.31s (± 0.07%) 7.30s (± 0.11%) ~ 7.29s 7.31s p=0.070 n=6
Bind Time 2.48s (± 0.94%) 2.48s (± 0.90%) ~ 2.45s 2.51s p=0.743 n=6
Check Time 72.98s (± 0.34%) 72.26s (± 1.81%) ~ 70.25s 73.31s p=0.873 n=6
Emit Time 0.14s (± 2.88%) 0.14s (± 3.60%) ~ 0.14s 0.15s p=0.595 n=6
Total Time 82.91s (± 0.30%) 82.19s (± 1.57%) ~ 80.19s 83.25s p=0.748 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,229,397 1,229,161 -236 (- 0.02%) ~ ~ p=0.001 n=6
Types 267,085 267,043 -42 (- 0.02%) ~ ~ p=0.001 n=6
Memory used 2,361,732k (± 0.03%) 2,359,642k (± 0.02%) -2,090k (- 0.09%) 2,359,011k 2,360,154k p=0.005 n=6
Parse Time 5.22s (± 0.84%) 5.25s (± 1.40%) ~ 5.15s 5.34s p=0.748 n=6
Bind Time 1.80s (± 0.96%) 1.79s (± 1.20%) ~ 1.77s 1.82s p=0.685 n=6
Check Time 35.38s (± 0.40%) 35.46s (± 0.15%) ~ 35.40s 35.53s p=0.521 n=6
Emit Time 3.07s (± 2.95%) 3.07s (± 4.08%) ~ 2.98s 3.32s p=0.689 n=6
Total Time 45.46s (± 0.43%) 45.60s (± 0.34%) ~ 45.45s 45.87s 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,229,397 1,229,161 -236 (- 0.02%) ~ ~ p=0.001 n=6
Types 267,085 267,043 -42 (- 0.02%) ~ ~ p=0.001 n=6
Memory used 2,796,547k (±14.25%) 3,155,684k (± 0.03%) ~ 3,154,590k 3,156,765k p=1.000 n=6
Parse Time 6.93s (± 2.13%) 7.02s (± 1.35%) ~ 6.90s 7.13s p=0.298 n=6
Bind Time 2.15s (± 1.96%) 2.14s (± 1.13%) ~ 2.12s 2.19s p=0.421 n=6
Check Time 42.90s (± 0.53%) 42.94s (± 0.31%) ~ 42.78s 43.11s p=0.810 n=6
Emit Time 3.51s (± 2.84%) 3.52s (± 0.79%) ~ 3.49s 3.57s p=0.378 n=6
Total Time 55.48s (± 0.50%) 55.61s (± 0.26%) ~ 55.33s 55.72s p=0.470 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 263,074 262,860 -214 (- 0.08%) ~ ~ p=0.001 n=6
Types 106,881 106,839 -42 (- 0.04%) ~ ~ p=0.001 n=6
Memory used 441,257k (± 0.02%) 440,613k (± 0.01%) -644k (- 0.15%) 440,563k 440,649k p=0.005 n=6
Parse Time 3.56s (± 1.37%) 3.54s (± 0.93%) ~ 3.51s 3.58s p=0.466 n=6
Bind Time 1.30s (± 0.64%) 1.31s (± 0.84%) ~ 1.30s 1.32s p=0.503 n=6
Check Time 18.97s (± 0.54%) 18.92s (± 0.51%) ~ 18.82s 19.09s p=0.296 n=6
Emit Time 1.52s (± 1.31%) 1.52s (± 0.77%) ~ 1.50s 1.53s p=0.740 n=6
Total Time 25.36s (± 0.53%) 25.29s (± 0.44%) ~ 25.17s 25.47s p=0.228 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 70 70 ~ ~ ~ p=1.000 n=6
Symbols 226,113 226,113 ~ ~ ~ p=1.000 n=6
Types 94,488 94,488 ~ ~ ~ p=1.000 n=6
Memory used 371,756k (± 0.01%) 371,339k (± 0.02%) -417k (- 0.11%) 371,250k 371,460k p=0.005 n=6
Parse Time 2.89s (± 1.64%) 2.90s (± 0.34%) ~ 2.89s 2.91s p=0.870 n=6
Bind Time 1.61s (± 1.74%) 1.59s (± 1.02%) ~ 1.57s 1.61s p=0.514 n=6
Check Time 16.45s (± 0.21%) 16.47s (± 0.29%) ~ 16.38s 16.52s p=0.261 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.95s (± 0.40%) 20.96s (± 0.19%) ~ 20.90s 21.01s p=0.573 n=6
vscode - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 3,280,686 3,280,686 ~ ~ ~ p=1.000 n=6
Types 1,128,284 1,128,284 ~ ~ ~ p=1.000 n=6
Memory used 3,354,513k (± 0.01%) 3,349,070k (± 0.01%) -5,443k (- 0.16%) 3,348,734k 3,349,187k p=0.005 n=6
Parse Time 14.57s (± 0.35%) 14.58s (± 0.49%) ~ 14.52s 14.71s p=0.936 n=6
Bind Time 4.61s (± 0.61%) 4.62s (± 0.32%) ~ 4.60s 4.64s p=0.806 n=6
Check Time 91.54s (± 2.63%) 90.36s (± 2.03%) ~ 88.50s 92.62s p=0.378 n=6
Emit Time 28.89s (± 2.49%) 27.01s (± 7.68%) 🟩-1.87s (- 6.49%) 23.14s 29.15s p=0.013 n=6
Total Time 139.61s (± 2.02%) 136.56s (± 1.03%) ~ 134.89s 138.32s p=0.066 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 293,378 293,378 ~ ~ ~ p=1.000 n=6
Types 119,581 119,581 ~ ~ ~ p=1.000 n=6
Memory used 447,125k (± 0.02%) 446,941k (± 0.01%) -185k (- 0.04%) 446,844k 447,011k p=0.005 n=6
Parse Time 4.11s (± 0.76%) 4.09s (± 0.78%) ~ 4.06s 4.15s p=0.197 n=6
Bind Time 1.80s (± 1.24%) 1.77s (± 0.42%) ~ 1.76s 1.78s p=0.051 n=6
Check Time 18.80s (± 0.76%) 18.74s (± 0.49%) ~ 18.64s 18.89s p=0.297 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.72s (± 0.51%) 24.60s (± 0.39%) ~ 24.46s 24.72s p=0.173 n=6
xstate-main - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 555,375 555,375 ~ ~ ~ p=1.000 n=6
Types 186,146 186,146 ~ ~ ~ p=1.000 n=6
Memory used 494,518k (± 0.01%) 494,022k (± 0.01%) -497k (- 0.10%) 493,945k 494,092k p=0.005 n=6
Parse Time 3.42s (± 0.65%) 3.40s (± 0.22%) ~ 3.39s 3.41s p=0.111 n=6
Bind Time 1.18s (± 0.87%) 1.18s (± 1.42%) ~ 1.16s 1.21s p=0.549 n=6
Check Time 19.57s (± 0.16%) 19.45s (± 0.55%) ~ 19.33s 19.62s p=0.077 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.17s (± 0.14%) 24.03s (± 0.49%) ~ 23.90s 24.20s p=0.076 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

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

Everything looks good!

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

😢

Should we keep the tests behind for the future, rather than deleting them?

@gabritto
Copy link
Member Author

gabritto commented Feb 7, 2025

😢

Should we keep the tests behind for the future, rather than deleting them?

I'll just revert this PR when I re-introduce narrowing for 5.9, so it will have the deleted tests again.

@gabritto gabritto merged commit c3ae7c4 into main Feb 7, 2025
32 checks passed
@gabritto gabritto deleted the gabritto/revert56941 branch February 7, 2025 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants