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

Fix generic nullable checks #59437

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

Fix generic nullable checks #59437

wants to merge 6 commits into from

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Jul 26, 2024

This PR builds on #59415 to implement the following in aggregate:

  • In an indexed access expression obj[key], when obj and key both have generic types we no longer require the constraint of obj to be a non-nullable type. The rationale for this change is that when key is a valid property name for obj, it must be because obj is of a non-nullable type, as discussed here.
  • We now consider unconstrained generic types and generic types constrained to unknown to possibly be null or undefined in --strictNullChecks mode. Previously, we would only consider generic types with constraints including null or undefined to possibly be nullable.

Fixes #50603.

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Jul 26, 2024
@ahejlsberg
Copy link
Member Author

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 26, 2024

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

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

Hey @ahejlsberg, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@ahejlsberg
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 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,153 62,153 ~ ~ ~ p=1.000 n=6
Types 50,242 50,242 ~ ~ ~ p=1.000 n=6
Memory used 193,065k (± 0.72%) 194,729k (± 0.96%) ~ 192,305k 196,060k p=0.378 n=6
Parse Time 1.30s (± 1.57%) 1.31s (± 0.89%) ~ 1.29s 1.32s p=0.391 n=6
Bind Time 0.71s 0.71s ~ ~ ~ p=1.000 n=6
Check Time 9.59s (± 0.41%) 9.53s (± 0.32%) -0.06s (- 0.63%) 9.47s 9.56s p=0.024 n=6
Emit Time 2.74s (± 0.78%) 2.72s (± 1.38%) ~ 2.65s 2.76s p=0.293 n=6
Total Time 14.33s (± 0.23%) 14.26s (± 0.48%) -0.07s (- 0.52%) 14.13s 14.32s p=0.016 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 17 🔻+10 (+142.86%) ~ ~ p=0.001 n=6
Symbols 945,532 945,532 ~ ~ ~ p=1.000 n=6
Types 409,507 409,512 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 1,221,152k (± 0.00%) 1,221,178k (± 0.00%) ~ 1,221,099k 1,221,213k p=0.630 n=6
Parse Time 6.68s (± 0.83%) 6.68s (± 0.57%) ~ 6.64s 6.75s p=1.000 n=6
Bind Time 1.90s (± 0.54%) 1.90s (± 0.58%) ~ 1.89s 1.92s p=0.558 n=6
Check Time 31.26s (± 0.27%) 31.25s (± 0.57%) ~ 31.08s 31.51s p=0.377 n=6
Emit Time 15.18s (± 0.40%) 15.19s (± 0.33%) ~ 15.14s 15.27s p=0.809 n=6
Total Time 55.02s (± 0.19%) 55.02s (± 0.37%) ~ 54.87s 55.33s p=0.687 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 16 🔻+16 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 2,437,253 2,437,253 ~ ~ ~ p=1.000 n=6
Types 1,004,097 1,004,141 +44 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,426,339k (± 0.00%) 2,426,265k (± 0.00%) ~ 2,426,226k 2,426,333k p=0.066 n=6
Parse Time 8.43s (± 0.31%) 8.44s (± 0.21%) ~ 8.42s 8.47s p=0.686 n=6
Bind Time 2.08s (± 0.56%) 2.08s (± 0.30%) ~ 2.07s 2.09s p=1.000 n=6
Check Time 75.18s (± 0.66%) 74.77s (± 0.39%) -0.40s (- 0.54%) 74.23s 75.00s p=0.045 n=6
Emit Time 0.28s (± 1.47%) 0.28s (± 1.47%) ~ 0.27s 0.28s p=1.000 n=6
Total Time 85.96s (± 0.59%) 85.57s (± 0.32%) ~ 85.06s 85.77s p=0.066 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,735 1,227,781 +46 (+ 0.00%) ~ ~ p=0.001 n=6
Types 265,136 265,143 +7 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,346,556k (± 0.01%) 2,346,515k (± 0.03%) ~ 2,345,869k 2,347,878k p=0.378 n=6
Parse Time 5.03s (± 0.57%) 5.01s (± 1.07%) ~ 4.94s 5.08s p=0.471 n=6
Bind Time 1.92s (± 0.43%) 1.92s (± 0.39%) ~ 1.91s 1.93s p=0.729 n=6
Check Time 34.74s (± 0.57%) 34.78s (± 0.22%) ~ 34.69s 34.89s p=0.936 n=6
Emit Time 3.33s (± 0.94%) 3.30s (± 1.61%) ~ 3.21s 3.35s p=0.229 n=6
Total Time 45.03s (± 0.46%) 45.03s (± 0.27%) ~ 44.90s 45.20s p=0.936 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,735 1,227,781 +46 (+ 0.00%) ~ ~ p=0.001 n=6
Types 265,136 265,143 +7 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,420,283k (± 0.03%) 2,420,571k (± 0.03%) ~ 2,419,926k 2,421,919k p=1.000 n=6
Parse Time 6.19s (± 0.70%) 6.19s (± 0.69%) ~ 6.14s 6.25s p=1.000 n=6
Bind Time 2.02s (± 1.15%) 2.03s (± 0.86%) ~ 2.01s 2.06s p=0.373 n=6
Check Time 41.17s (± 0.26%) 41.05s (± 0.19%) ~ 40.94s 41.17s p=0.093 n=6
Emit Time 4.12s (± 4.15%) 4.00s (± 1.06%) ~ 3.95s 4.07s p=0.107 n=6
Total Time 53.51s (± 0.35%) 53.30s (± 0.27%) ~ 53.06s 53.47s p=0.066 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 255,950 255,952 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 104,957 104,964 +7 (+ 0.01%) ~ ~ p=0.001 n=6
Memory used 427,965k (± 0.04%) 427,955k (± 0.04%) ~ 427,739k 428,298k p=0.936 n=6
Parse Time 3.35s (± 0.70%) 3.36s (± 0.69%) ~ 3.33s 3.39s p=0.624 n=6
Bind Time 1.32s (± 0.88%) 1.31s (± 1.42%) ~ 1.29s 1.33s p=0.445 n=6
Check Time 17.98s (± 0.45%) 18.00s (± 0.39%) ~ 17.90s 18.06s p=0.809 n=6
Emit Time 1.65s (± 1.04%) 1.64s (± 1.37%) ~ 1.62s 1.67s p=0.682 n=6
Total Time 24.31s (± 0.27%) 24.32s (± 0.33%) ~ 24.21s 24.39s p=0.810 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,931 224,931 ~ ~ ~ p=1.000 n=6
Types 94,146 94,146 ~ ~ ~ p=1.000 n=6
Memory used 370,148k (± 0.04%) 370,101k (± 0.04%) ~ 369,914k 370,319k p=0.630 n=6
Parse Time 2.76s (± 0.78%) 2.76s (± 0.42%) ~ 2.74s 2.77s p=0.625 n=6
Bind Time 1.58s (± 1.09%) 1.58s (± 1.30%) ~ 1.55s 1.61s p=0.514 n=6
Check Time 15.67s (± 0.23%) 15.71s (± 0.21%) ~ 15.65s 15.75s p=0.053 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.01s (± 0.13%) 20.05s (± 0.07%) +0.04s (+ 0.19%) 20.03s 20.07s p=0.024 n=6
vscode - node (v18.15.0, x64)
Errors 11 11 ~ ~ ~ p=1.000 n=6
Symbols 2,986,839 2,986,839 ~ ~ ~ p=1.000 n=6
Types 1,027,468 1,027,468 ~ ~ ~ p=1.000 n=6
Memory used 3,110,626k (± 0.00%) 3,110,688k (± 0.00%) ~ 3,110,618k 3,110,747k p=0.128 n=6
Parse Time 13.87s (± 0.52%) 13.84s (± 0.40%) ~ 13.76s 13.93s p=0.687 n=6
Bind Time 4.35s (± 2.77%) 4.32s (± 2.02%) ~ 4.28s 4.50s p=0.624 n=6
Check Time 79.38s (± 0.42%) 79.18s (± 0.30%) ~ 78.91s 79.54s p=0.298 n=6
Emit Time 20.52s (± 0.37%) 20.50s (± 0.76%) ~ 20.23s 20.63s p=1.000 n=6
Total Time 118.12s (± 0.34%) 117.84s (± 0.29%) ~ 117.37s 118.35s p=0.298 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 267,567 267,567 ~ ~ ~ p=1.000 n=6
Types 109,077 109,077 ~ ~ ~ p=1.000 n=6
Memory used 412,438k (± 0.01%) 412,463k (± 0.02%) ~ 412,378k 412,539k p=0.689 n=6
Parse Time 3.80s (± 0.86%) 3.82s (± 0.59%) ~ 3.78s 3.85s p=0.744 n=6
Bind Time 1.70s (± 0.64%) 1.71s (± 0.86%) ~ 1.68s 1.72s p=0.131 n=6
Check Time 16.85s (± 0.38%) 16.82s (± 0.43%) ~ 16.74s 16.94s p=0.471 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.36s (± 0.31%) 22.34s (± 0.43%) ~ 22.26s 22.52s p=0.574 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 511,807 511,807 ~ ~ ~ p=1.000 n=6
Types 162,090 162,090 ~ ~ ~ p=1.000 n=6
Memory used 449,073k (± 0.08%) 449,313k (± 0.03%) ~ 449,121k 449,516k p=0.298 n=6
Parse Time 3.16s (± 0.51%) 3.16s (± 0.62%) ~ 3.13s 3.18s p=0.618 n=6
Bind Time 1.16s (± 1.01%) 1.16s (± 0.35%) ~ 1.15s 1.16s p=0.787 n=6
Check Time 17.16s (± 0.33%) 17.18s (± 0.50%) ~ 17.07s 17.33s p=0.748 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 21.48s (± 0.29%) 21.50s (± 0.43%) ~ 21.35s 21.63s p=0.936 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

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

Something interesting changed - please have a look.

Details

ag-grid/ag-grid

31 of 110 projects failed to build with the old tsc and were ignored

enterprise-modules/viewport-row-model/tsconfig.watch.json

enterprise-modules/viewport-row-model/tsconfig.types.watch.json

enterprise-modules/status-bar/tsconfig.watch.json

enterprise-modules/status-bar/tsconfig.types.watch.json

enterprise-modules/sparklines/tsconfig.watch.json

enterprise-modules/sparklines/tsconfig.types.watch.json

enterprise-modules/side-bar/tsconfig.watch.json

enterprise-modules/side-bar/tsconfig.types.watch.json

enterprise-modules/set-filter/tsconfig.watch.json

enterprise-modules/set-filter/tsconfig.types.watch.json

enterprise-modules/server-side-row-model/tsconfig.watch.json

enterprise-modules/server-side-row-model/tsconfig.types.watch.json

enterprise-modules/row-grouping/tsconfig.watch.json

enterprise-modules/row-grouping/tsconfig.types.watch.json

enterprise-modules/rich-select/tsconfig.watch.json

enterprise-modules/rich-select/tsconfig.types.watch.json

enterprise-modules/range-selection/tsconfig.watch.json

enterprise-modules/range-selection/tsconfig.types.watch.json

enterprise-modules/multi-filter/tsconfig.watch.json

enterprise-modules/multi-filter/tsconfig.types.watch.json

enterprise-modules/master-detail/tsconfig.watch.json

enterprise-modules/master-detail/tsconfig.types.watch.json

enterprise-modules/filter-tool-panel/tsconfig.watch.json

enterprise-modules/filter-tool-panel/tsconfig.types.watch.json

enterprise-modules/core/tsconfig.watch.json

enterprise-modules/core/tsconfig.types.watch.json

enterprise-modules/advanced-filter/tsconfig.watch.json

enterprise-modules/advanced-filter/tsconfig.types.watch.json

community-modules/vue3/tsconfig.watch.json

community-modules/vue3/tsconfig.types.watch.json

community-modules/infinite-row-model/tsconfig.watch.json

community-modules/infinite-row-model/tsconfig.types.watch.json

community-modules/csv-export/tsconfig.watch.json

community-modules/csv-export/tsconfig.types.watch.json

community-modules/core/tsconfig.watch.json

community-modules/core/tsconfig.types.watch.json

community-modules/client-side-row-model/tsconfig.watch.json

community-modules/client-side-row-model/tsconfig.types.watch.json

compiler-explorer/compiler-explorer

4 of 6 projects failed to build with the old tsc and were ignored

static/tsconfig.json

desktop/desktop

1 of 4 projects failed to build with the old tsc and were ignored

tsconfig.json

sequelize/sequelize

13 of 16 projects failed to build with the old tsc and were ignored

packages/utils/tsconfig.json

@ahejlsberg
Copy link
Member Author

ahejlsberg commented Jul 29, 2024

The new errors in the top 400 repos tests are all the same: Functions that compare values of unconstrained generic types. Our existing behavior is to permit such comparisons--we only error when the types have constraints that explicitly include null or undefined (which obviously is inconsistent).

We should decide if we think erroring on generic operands that are possibly null or undefined is the right thing to do since it basically amounts to a breaking change. The semantics of comparisons involving null and undefined are well defined (they act like NaN) and don't cause exceptions, yet it's probably rare for such comparisons to be intended.

@ahejlsberg ahejlsberg requested a review from RyanCavanaugh July 29, 2024 21:25
@ahejlsberg
Copy link
Member Author

We're going to wait for 5.7 on this one since it is technically a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

No error on unconstrained type parameter in > comparison
3 participants