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

Simplify object types when distributing index over them #60021

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

Conversation

Andarist
Copy link
Contributor

fixes #59946

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Sep 21, 2024
@@ -18997,7 +18997,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// (T | U)[K] -> T[K] & U[K] (writing)
// (T & U)[K] -> T[K] & U[K]
if (objectType.flags & TypeFlags.Union || objectType.flags & TypeFlags.Intersection && !shouldDeferIndexType(objectType)) {
const types = map((objectType as UnionOrIntersectionType).types, t => getSimplifiedType(getIndexedAccessType(t, indexType), writing));
const types = map((objectType as UnionOrIntersectionType).types, t => getSimplifiedType(getIndexedAccessType(getSimplifiedType(t, writing), indexType), writing));
Copy link
Contributor Author

@Andarist Andarist Sep 21, 2024

Choose a reason for hiding this comment

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

It's important to simplify the t (a constituent of the objectType) here "eagerly". At this stage getIndexedAccessType has a chance to return unknownType (thus effectively eliminating this constituent from the overall simplified indexed access type on an intersection, since T & unknown is T).

Without it, the compiler comes back to getSimplifiedIndexedAccessType with the non-simplified indexed access. It simplifies the object type there, but it also decides there is nothing to simplify further so it returns the original non-simplified type. That leads to a relationship error.

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 21, 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

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

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

@jakebailey
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,601k (± 0.97%) 192,981k (± 0.74%) ~ 192,390k 195,879k p=0.810 n=6
Parse Time 1.30s (± 0.79%) 1.30s (± 0.93%) ~ 1.29s 1.32s p=1.000 n=6
Bind Time 0.71s 0.71s ~ ~ ~ p=1.000 n=6
Check Time 9.58s (± 0.41%) 9.56s (± 0.47%) ~ 9.50s 9.63s p=0.225 n=6
Emit Time 2.70s (± 1.73%) 2.72s (± 0.95%) ~ 2.68s 2.75s p=1.000 n=6
Total Time 14.29s (± 0.46%) 14.28s (± 0.31%) ~ 14.20s 14.32s p=1.000 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 7 ~ ~ ~ p=1.000 n=6
Symbols 945,753 945,753 ~ ~ ~ p=1.000 n=6
Types 410,067 410,067 ~ ~ ~ p=1.000 n=6
Memory used 1,222,743k (± 0.00%) 1,222,748k (± 0.00%) ~ 1,222,686k 1,222,810k p=0.936 n=6
Parse Time 6.63s (± 0.34%) 6.65s (± 0.63%) ~ 6.57s 6.68s p=0.090 n=6
Bind Time 1.86s (± 0.40%) 1.86s (± 0.40%) ~ 1.85s 1.87s p=0.487 n=6
Check Time 31.25s (± 0.50%) 31.24s (± 0.43%) ~ 31.11s 31.46s p=0.936 n=6
Emit Time 15.02s (± 0.37%) 15.00s (± 0.46%) ~ 14.90s 15.08s p=0.689 n=6
Total Time 54.77s (± 0.29%) 54.75s (± 0.32%) ~ 54.46s 54.94s p=0.936 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,529,472 2,529,472 ~ ~ ~ p=1.000 n=6
Types 936,018 936,018 ~ ~ ~ p=1.000 n=6
Memory used 2,364,766k (± 0.00%) 2,364,771k (± 0.00%) ~ 2,364,737k 2,364,843k p=0.873 n=6
Parse Time 9.41s (± 0.17%) 9.43s (± 0.23%) ~ 9.40s 9.46s p=0.060 n=6
Bind Time 2.18s (± 0.29%) 2.17s (± 0.24%) ~ 2.17s 2.18s p=0.091 n=6
Check Time 72.83s (± 0.39%) 72.99s (± 0.48%) ~ 72.73s 73.60s p=0.521 n=6
Emit Time 0.28s (± 1.45%) 0.28s (± 2.95%) ~ 0.27s 0.29s p=0.206 n=6
Total Time 84.69s (± 0.33%) 84.86s (± 0.41%) ~ 84.59s 85.47s p=0.470 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,246,550 1,246,550 ~ ~ ~ p=1.000 n=6
Types 264,444 264,444 ~ ~ ~ p=1.000 n=6
Memory used 2,398,967k (± 0.04%) 2,398,824k (± 0.02%) ~ 2,398,301k 2,399,394k p=1.000 n=6
Parse Time 5.09s (± 0.45%) 5.12s (± 0.31%) +0.03s (+ 0.59%) 5.09s 5.13s p=0.036 n=6
Bind Time 1.91s (± 0.91%) 1.92s (± 0.47%) ~ 1.91s 1.93s p=0.459 n=6
Check Time 34.88s (± 0.44%) 34.90s (± 0.71%) ~ 34.62s 35.31s p=1.000 n=6
Emit Time 3.09s (± 5.89%) 3.08s (± 5.50%) ~ 2.95s 3.41s p=0.873 n=6
Total Time 44.98s (± 0.43%) 45.03s (± 0.40%) ~ 44.73s 45.28s 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,246,550 1,246,550 ~ ~ ~ p=1.000 n=6
Types 264,444 264,444 ~ ~ ~ p=1.000 n=6
Memory used 2,473,990k (± 0.05%) 2,498,948k (± 2.50%) ~ 2,472,829k 2,626,800k p=0.936 n=6
Parse Time 6.33s (± 0.63%) 6.39s (± 0.73%) ~ 6.34s 6.47s p=0.066 n=6
Bind Time 2.05s (± 0.85%) 2.06s (± 0.97%) ~ 2.03s 2.09s p=0.466 n=6
Check Time 41.46s (± 0.47%) 41.65s (± 0.59%) ~ 41.26s 41.85s p=0.128 n=6
Emit Time 3.56s (± 2.92%) 3.56s (± 1.22%) ~ 3.51s 3.61s p=0.688 n=6
Total Time 53.42s (± 0.40%) 53.66s (± 0.52%) ~ 53.24s 53.94s p=0.173 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 259,902 259,902 ~ ~ ~ p=1.000 n=6
Types 106,141 106,141 ~ ~ ~ p=1.000 n=6
Memory used 435,643k (± 0.02%) 435,563k (± 0.01%) ~ 435,502k 435,633k p=0.230 n=6
Parse Time 3.41s (± 1.17%) 3.42s (± 0.48%) ~ 3.41s 3.45s p=0.808 n=6
Bind Time 1.28s (± 1.45%) 1.30s +0.02s (+ 1.30%) ~ ~ p=0.028 n=6
Check Time 18.12s (± 0.40%) 18.15s (± 0.28%) ~ 18.10s 18.21s p=0.469 n=6
Emit Time 1.52s (± 2.66%) 1.52s (± 1.78%) ~ 1.48s 1.56s p=1.000 n=6
Total Time 24.34s (± 0.19%) 24.39s (± 0.23%) ~ 24.33s 24.47s p=0.195 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,018 225,018 ~ ~ ~ p=1.000 n=6
Types 94,249 94,249 ~ ~ ~ p=1.000 n=6
Memory used 370,195k (± 0.02%) 370,233k (± 0.02%) ~ 370,150k 370,332k p=0.575 n=6
Parse Time 2.74s (± 0.48%) 2.76s (± 1.11%) ~ 2.71s 2.79s p=0.360 n=6
Bind Time 1.55s (± 0.88%) 1.56s (± 0.48%) ~ 1.55s 1.57s p=0.149 n=6
Check Time 15.71s (± 0.32%) 15.72s (± 0.33%) ~ 15.62s 15.76s p=0.575 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 19.99s (± 0.29%) 20.04s (± 0.24%) ~ 19.98s 20.10s p=0.199 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,094,261 3,094,261 ~ ~ ~ p=1.000 n=6
Types 1,066,604 1,066,604 ~ ~ ~ p=1.000 n=6
Memory used 3,191,745k (± 0.00%) 3,191,733k (± 0.00%) ~ 3,191,686k 3,191,775k p=0.936 n=6
Parse Time 13.99s (± 0.25%) 13.99s (± 0.32%) ~ 13.92s 14.04s p=0.936 n=6
Bind Time 4.36s (± 0.48%) 4.36s (± 0.24%) ~ 4.35s 4.38s p=0.570 n=6
Check Time 82.04s (± 0.69%) 82.10s (± 0.25%) ~ 81.88s 82.45s p=0.575 n=6
Emit Time 22.39s (± 0.31%) 22.39s (± 0.44%) ~ 22.31s 22.57s p=0.687 n=6
Total Time 122.78s (± 0.47%) 122.84s (± 0.17%) ~ 122.54s 123.05s p=0.298 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 277,196 277,196 ~ ~ ~ p=1.000 n=6
Types 112,950 112,950 ~ ~ ~ p=1.000 n=6
Memory used 426,903k (± 0.02%) 426,967k (± 0.02%) ~ 426,879k 427,049k p=0.173 n=6
Parse Time 3.95s (± 0.32%) 3.95s (± 0.30%) ~ 3.93s 3.96s p=0.801 n=6
Bind Time 1.73s (± 1.24%) 1.72s (± 1.20%) ~ 1.69s 1.75s p=1.000 n=6
Check Time 17.61s (± 0.52%) 17.66s (± 0.59%) ~ 17.55s 17.80s p=0.575 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 23.29s (± 0.35%) 23.34s (± 0.50%) ~ 23.20s 23.49s p=0.575 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 539,943 539,943 ~ ~ ~ p=1.000 n=6
Types 181,263 181,263 ~ ~ ~ p=1.000 n=6
Memory used 483,329k (± 0.02%) 483,310k (± 0.01%) ~ 483,241k 483,361k p=0.810 n=6
Parse Time 4.03s (± 0.36%) 4.02s (± 0.40%) ~ 4.00s 4.04s p=0.324 n=6
Bind Time 1.45s (± 1.07%) 1.44s (± 0.81%) ~ 1.43s 1.46s p=0.249 n=6
Check Time 22.69s (± 0.22%) 22.66s (± 0.20%) ~ 22.61s 22.73s p=0.375 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.17s (± 0.17%) 28.11s (± 0.20%) ~ 28.04s 28.19s p=0.108 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

@jakebailey Here are the results of running the top 400 repos with tsc comparing main and refs/pull/60021/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.

Fail to infer Indexed access to the intersection type when it includes an union derived from a generic input
3 participants