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

Unwrap substitution types early in getPropertyTypeForIndexType #57113

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

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Jan 21, 2024

fixes #57109
fixes #54886

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 21, 2024
@@ -16173,7 +16173,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function getSubstitutionType(baseType: Type, constraint: Type) {
return constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType || baseType.flags & TypeFlags.Any ?
return constraint.flags & TypeFlags.AnyOrUnknown || constraint === baseType || baseType.flags & TypeFlags.Any || !isGenericType(constraint) && !isGenericType(baseType) && isTypeAssignableTo(baseType, constraint) ?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

alternatively, substitution types could get some improved handling in getPropertyTypeForIndexType

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think I'd prefer getPropertyNameFromIndex + getPropertyTypeForIndexType being updated to handle substitutions - the more places we recognize them as transparently their original type (if the substituted version isn't useful), the better, since it makes it easier on us to broaden the scope of how we use substitution types to support other features.

As far as this approach goes... instantiateTypeWorker has similar logic to this - honestly, a lot of that logic should probably get moved into here, so it happens on initial construction and instantiation, rather than just instantiation.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, the right approach is to erase them where needed. Omitting the substitution type just because the constraint is assignable isn't right and will definitely have adverse effects as the constraint may be a more specific type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed out the requested change. I decided to use a similar approach of unwrapping the substation type early in getPropertyTypeForIndexType like it was done in #58292

@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 22, 2024
@Andarist Andarist changed the title Avoid creating redundant substitution types in non-generic contexts Unwrap substitution types early in getPropertyTypeForIndexType Jun 27, 2024
@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 27, 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/57113/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 192,803k (± 0.75%) 193,802k (± 0.95%) ~ 192,109k 195,760k p=0.630 n=6
Parse Time 1.30s (± 0.79%) 1.30s (± 1.06%) ~ 1.29s 1.32s p=0.799 n=6
Bind Time 0.71s (± 0.57%) 0.71s ~ ~ ~ p=0.405 n=6
Check Time 9.45s (± 0.47%) 9.46s (± 0.94%) ~ 9.40s 9.63s p=0.469 n=6
Emit Time 2.74s (± 0.54%) 2.75s (± 1.16%) ~ 2.71s 2.79s p=0.571 n=6
Total Time 14.21s (± 0.35%) 14.22s (± 0.68%) ~ 14.12s 14.40s p=0.936 n=6
angular-1 - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 944,114 944,114 ~ ~ ~ p=1.000 n=6
Types 407,050 407,050 ~ ~ ~ p=1.000 n=6
Memory used 1,218,375k (± 0.00%) 1,218,347k (± 0.01%) ~ 1,218,259k 1,218,405k p=0.471 n=6
Parse Time 6.67s (± 0.54%) 6.66s (± 0.77%) ~ 6.58s 6.73s p=1.000 n=6
Bind Time 1.86s (± 0.59%) 1.86s (± 0.81%) ~ 1.84s 1.88s p=0.663 n=6
Check Time 30.67s (± 0.48%) 30.63s (± 0.23%) ~ 30.54s 30.74s p=0.471 n=6
Emit Time 13.56s (± 0.39%) 13.54s (± 0.32%) ~ 13.47s 13.60s p=0.746 n=6
Total Time 52.76s (± 0.38%) 52.69s (± 0.15%) ~ 52.60s 52.80s p=0.230 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,133,050 2,133,050 ~ ~ ~ p=1.000 n=6
Types 926,444 926,444 ~ ~ ~ p=1.000 n=6
Memory used 2,115,455k (± 0.01%) 2,115,550k (± 0.00%) ~ 2,115,352k 2,115,635k p=0.298 n=6
Parse Time 6.66s (± 0.52%) 6.62s (± 0.23%) -0.04s (- 0.63%) 6.59s 6.63s p=0.045 n=6
Bind Time 2.34s (± 1.11%) 2.30s (± 0.70%) -0.04s (- 1.64%) 2.29s 2.33s p=0.019 n=6
Check Time 70.54s (± 1.23%) 70.96s (± 0.48%) ~ 70.37s 71.37s p=0.297 n=6
Emit Time 0.14s (± 2.95%) 0.14s (± 5.69%) ~ 0.13s 0.15s p=0.206 n=6
Total Time 79.68s (± 1.06%) 80.02s (± 0.39%) ~ 79.48s 80.40s p=0.575 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,231,640 1,231,640 ~ ~ ~ p=1.000 n=6
Types 261,187 261,187 ~ ~ ~ p=1.000 n=6
Memory used 2,347,498k (± 0.06%) 2,347,606k (± 0.02%) ~ 2,347,131k 2,348,198k p=0.810 n=6
Parse Time 5.08s (± 0.99%) 5.06s (± 0.89%) ~ 5.01s 5.12s p=0.572 n=6
Bind Time 1.94s (± 0.97%) 1.93s (± 1.01%) ~ 1.90s 1.96s p=0.624 n=6
Check Time 34.17s (± 0.20%) 34.09s (± 0.24%) ~ 33.98s 34.21s p=0.173 n=6
Emit Time 2.73s (± 3.96%) 2.75s (± 2.36%) ~ 2.68s 2.83s p=0.335 n=6
Total Time 43.92s (± 0.32%) 43.83s (± 0.34%) ~ 43.66s 44.06s p=0.378 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,231,640 1,231,640 ~ ~ ~ p=1.000 n=6
Types 261,187 261,187 ~ ~ ~ p=1.000 n=6
Memory used 2,425,268k (± 0.06%) 2,423,967k (± 0.08%) ~ 2,421,935k 2,426,256k p=0.298 n=6
Parse Time 7.80s (± 1.00%) 7.82s (± 1.27%) ~ 7.70s 7.96s p=0.689 n=6
Bind Time 2.54s (± 0.99%) 2.51s (± 0.92%) ~ 2.49s 2.54s p=0.052 n=6
Check Time 50.00s (± 0.25%) 50.05s (± 0.27%) ~ 49.87s 50.21s p=0.521 n=6
Emit Time 3.95s (± 4.70%) 4.00s (± 2.99%) ~ 3.82s 4.12s p=0.423 n=6
Total Time 64.31s (± 0.33%) 64.40s (± 0.40%) ~ 64.00s 64.68s p=0.423 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 258,818 258,818 ~ ~ ~ p=1.000 n=6
Types 104,842 104,842 ~ ~ ~ p=1.000 n=6
Memory used 428,255k (± 0.01%) 428,248k (± 0.01%) ~ 428,222k 428,276k p=0.521 n=6
Parse Time 3.31s (± 0.30%) 3.34s (± 1.33%) ~ 3.27s 3.39s p=0.193 n=6
Bind Time 1.30s (± 0.63%) 1.30s (± 0.63%) ~ 1.29s 1.31s p=1.000 n=6
Check Time 17.79s (± 0.36%) 17.77s (± 0.34%) ~ 17.67s 17.81s p=0.936 n=6
Emit Time 1.38s (± 1.21%) 1.39s (± 1.20%) ~ 1.38s 1.42s p=0.616 n=6
Total Time 23.78s (± 0.27%) 23.80s (± 0.22%) ~ 23.75s 23.87s p=1.000 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,565 224,565 ~ ~ ~ p=1.000 n=6
Types 93,734 93,734 ~ ~ ~ p=1.000 n=6
Memory used 369,531k (± 0.03%) 369,465k (± 0.03%) ~ 369,395k 369,669k p=0.298 n=6
Parse Time 2.77s (± 1.11%) 2.76s (± 0.81%) ~ 2.74s 2.79s p=1.000 n=6
Bind Time 1.57s (± 0.70%) 1.58s (± 1.09%) ~ 1.56s 1.60s p=0.240 n=6
Check Time 15.46s (± 0.32%) 15.43s (± 0.34%) ~ 15.39s 15.53s p=0.145 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 19.80s (± 0.31%) 19.77s (± 0.31%) ~ 19.71s 19.88s p=0.422 n=6
vscode - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,878,628 2,878,628 ~ ~ ~ p=1.000 n=6
Types 975,175 975,175 ~ ~ ~ p=1.000 n=6
Memory used 3,042,138k (± 0.00%) 3,042,122k (± 0.00%) ~ 3,042,068k 3,042,161k p=0.810 n=6
Parse Time 13.51s (± 0.27%) 13.54s (± 0.53%) ~ 13.48s 13.67s p=0.570 n=6
Bind Time 4.18s (± 1.96%) 4.15s (± 0.28%) ~ 4.13s 4.16s p=1.000 n=6
Check Time 72.79s (± 0.30%) 72.85s (± 0.24%) ~ 72.66s 73.10s p=0.810 n=6
Emit Time 23.75s (± 0.38%) 23.84s (± 0.73%) ~ 23.58s 24.02s p=0.574 n=6
Total Time 114.23s (± 0.23%) 114.38s (± 0.17%) ~ 114.15s 114.68s p=0.422 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 267,117 267,117 ~ ~ ~ p=1.000 n=6
Types 108,775 108,775 ~ ~ ~ p=1.000 n=6
Memory used 411,577k (± 0.01%) 411,560k (± 0.02%) ~ 411,489k 411,659k p=0.810 n=6
Parse Time 3.83s (± 0.77%) 3.83s (± 0.79%) ~ 3.79s 3.88s p=0.936 n=6
Bind Time 1.69s (± 0.49%) 1.70s (± 0.81%) ~ 1.67s 1.71s p=0.672 n=6
Check Time 16.71s (± 0.24%) 16.73s (± 0.35%) ~ 16.63s 16.80s p=0.515 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.24s (± 0.10%) 22.25s (± 0.32%) ~ 22.13s 22.33s p=0.377 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 525,251 525,251 ~ ~ ~ p=1.000 n=6
Types 178,574 178,574 ~ ~ ~ p=1.000 n=6
Memory used 462,877k (± 0.06%) 462,522k (± 0.05%) ~ 462,335k 462,920k p=0.066 n=6
Parse Time 3.19s (± 0.54%) 3.19s (± 0.79%) ~ 3.16s 3.23s p=1.000 n=6
Bind Time 1.17s (± 0.35%) 1.18s (± 0.99%) ~ 1.17s 1.20s p=0.248 n=6
Check Time 17.93s (± 0.44%) 17.90s (± 0.48%) ~ 17.77s 17.98s p=0.686 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.30s (± 0.36%) 22.27s (± 0.36%) ~ 22.14s 22.35s p=0.809 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/57113/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: Waiting on reviewers
5 participants