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

Use better context scope for class constructor implementation signatures in JS files #61013

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

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Jan 22, 2025

fixes #60988 , it fixes a regression from #57403 that was not addressed by #58168 , cc @weswigham

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 22, 2025
@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 22, 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

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

Something interesting changed - please have a look.

Details

webpack

tsconfig.types.json

tsconfig.json

@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
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 196,755k (± 0.13%) 195,667k (± 0.93%) ~ 193,315k 196,979k p=0.378 n=6
Parse Time 1.61s (± 1.22%) 1.61s (± 0.82%) ~ 1.59s 1.63s p=0.741 n=6
Bind Time 0.88s (± 1.51%) 0.88s (± 1.56%) ~ 0.86s 0.90s p=0.452 n=6
Check Time 11.83s (± 0.53%) 11.78s (± 0.57%) ~ 11.67s 11.88s p=0.199 n=6
Emit Time 3.34s (± 2.72%) 3.30s (± 0.74%) ~ 3.27s 3.33s p=0.624 n=6
Total Time 17.66s (± 0.71%) 17.57s (± 0.37%) ~ 17.48s 17.64s p=0.226 n=6
angular-1 - node (v18.15.0, x64)
Errors 37 37 ~ ~ ~ p=1.000 n=6
Symbols 948,492 948,492 ~ ~ ~ p=1.000 n=6
Types 411,004 411,004 ~ ~ ~ p=1.000 n=6
Memory used 1,225,498k (± 0.00%) 1,225,499k (± 0.01%) ~ 1,225,426k 1,225,645k p=0.936 n=6
Parse Time 8.02s (± 0.79%) 8.02s (± 0.76%) ~ 7.94s 8.10s p=0.872 n=6
Bind Time 2.31s (± 0.42%) 2.29s (± 0.53%) -0.02s (- 0.72%) 2.28s 2.31s p=0.048 n=6
Check Time 38.30s (± 0.54%) 38.37s (± 0.50%) ~ 38.04s 38.56s p=0.378 n=6
Emit Time 18.23s (± 0.38%) 18.32s (± 0.53%) ~ 18.16s 18.42s p=0.109 n=6
Total Time 66.86s (± 0.41%) 67.01s (± 0.30%) ~ 66.64s 67.20s p=0.229 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,444,910 2,444,910 ~ ~ ~ p=1.000 n=6
Types 896,791 896,791 ~ ~ ~ p=1.000 n=6
Memory used 2,303,627k (± 0.00%) 2,303,578k (± 0.01%) ~ 2,303,349k 2,303,748k p=0.810 n=6
Parse Time 10.77s (± 0.64%) 10.78s (± 0.67%) ~ 10.64s 10.84s p=0.810 n=6
Bind Time 2.60s (± 0.94%) 2.63s (± 0.57%) ~ 2.60s 2.64s p=0.050 n=6
Check Time 89.46s (± 1.94%) 89.39s (± 1.73%) ~ 87.72s 91.19s p=1.000 n=6
Emit Time 0.35s (± 1.59%) 0.69s (±121.40%) ~ 0.34s 2.39s p=0.476 n=6
Total Time 103.18s (± 1.63%) 103.48s (± 1.33%) ~ 101.53s 104.95s p=0.689 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,228,792 1,228,793 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 266,906 266,905 -1 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 3,092,401k (± 0.01%) 2,727,494k (±14.62%) 🟩-364,907k (-11.80%) 2,362,288k 3,092,514k p=0.020 n=6
Parse Time 6.80s (± 0.83%) 6.71s (± 1.57%) ~ 6.58s 6.83s p=0.230 n=6
Bind Time 2.12s (± 2.08%) 2.17s (± 1.51%) ~ 2.11s 2.20s p=0.065 n=6
Check Time 42.99s (± 0.30%) 42.72s (± 0.29%) -0.26s (- 0.61%) 42.55s 42.90s p=0.008 n=6
Emit Time 3.47s (± 1.59%) 3.53s (± 2.29%) ~ 3.46s 3.67s p=0.230 n=6
Total Time 55.40s (± 0.26%) 55.14s (± 0.28%) -0.26s (- 0.47%) 54.98s 55.36s p=0.016 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,228,792 1,228,793 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 266,906 266,905 -1 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 2,794,341k (±14.22%) 3,037,093k (± 9.74%) ~ 2,432,790k 3,158,401k p=0.128 n=6
Parse Time 8.56s (± 1.52%) 8.63s (± 0.96%) ~ 8.47s 8.69s p=0.336 n=6
Bind Time 2.66s (± 2.03%) 2.65s (± 1.54%) ~ 2.58s 2.70s p=0.575 n=6
Check Time 53.02s (± 0.61%) 53.16s (± 0.38%) ~ 52.94s 53.45s p=0.575 n=6
Emit Time 4.27s (± 2.34%) 4.32s (± 2.52%) ~ 4.19s 4.48s p=0.471 n=6
Total Time 68.51s (± 0.61%) 68.76s (± 0.47%) ~ 68.32s 69.21s p=0.298 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 262,659 262,660 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 106,711 106,710 -1 (- 0.00%) ~ ~ p=0.001 n=6
Memory used 440,865k (± 0.02%) 440,873k (± 0.02%) ~ 440,762k 441,007k p=1.000 n=6
Parse Time 3.53s (± 0.73%) 3.55s (± 0.78%) ~ 3.50s 3.57s p=0.145 n=6
Bind Time 1.32s (± 1.25%) 1.31s (± 0.64%) ~ 1.29s 1.31s p=0.218 n=6
Check Time 19.02s (± 0.50%) 18.96s (± 0.48%) ~ 18.82s 19.04s p=0.199 n=6
Emit Time 1.55s (± 0.97%) 1.53s (± 0.72%) -0.02s (- 1.50%) 1.52s 1.55s p=0.018 n=6
Total Time 25.41s (± 0.41%) 25.34s (± 0.39%) ~ 25.18s 25.43s p=0.227 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,733k (± 0.02%) 371,773k (± 0.03%) ~ 371,636k 372,003k p=0.810 n=6
Parse Time 2.89s (± 0.97%) 2.90s (± 1.28%) ~ 2.85s 2.96s p=0.871 n=6
Bind Time 1.61s (± 1.51%) 1.60s (± 2.16%) ~ 1.57s 1.66s p=0.418 n=6
Check Time 16.47s (± 0.35%) 16.50s (± 0.62%) ~ 16.36s 16.64s p=0.810 n=6
Emit Time 0.00s (±244.70%) 0.00s ~ ~ ~ p=0.405 n=6
Total Time 20.97s (± 0.37%) 21.00s (± 0.58%) ~ 20.79s 21.12s p=0.630 n=6
vscode - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 3,262,929 3,262,929 ~ ~ ~ p=1.000 n=6
Types 1,122,055 1,122,055 ~ ~ ~ p=1.000 n=6
Memory used 3,336,525k (± 0.00%) 3,336,537k (± 0.01%) ~ 3,336,018k 3,336,789k p=0.689 n=6
Parse Time 14.50s (± 0.64%) 14.58s (± 0.70%) ~ 14.46s 14.71s p=0.172 n=6
Bind Time 4.58s (± 0.23%) 4.56s (± 0.43%) ~ 4.53s 4.58s p=0.084 n=6
Check Time 88.55s (± 1.52%) 89.69s (± 3.16%) ~ 87.65s 95.01s p=0.575 n=6
Emit Time 27.00s (± 7.85%) 26.82s (± 7.55%) ~ 22.92s 28.93s p=0.471 n=6
Total Time 134.62s (± 0.73%) 135.65s (± 1.38%) ~ 133.84s 138.76s p=0.575 n=6
webpack - node (v18.15.0, x64)
Errors 0 1 🔻+1 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 292,550 292,643 +93 (+ 0.03%) ~ ~ p=0.001 n=6
Types 119,124 119,168 +44 (+ 0.04%) ~ ~ p=0.001 n=6
Memory used 446,032k (± 0.03%) 446,133k (± 0.03%) ~ 445,914k 446,207k p=0.199 n=6
Parse Time 4.05s (± 1.52%) 4.07s (± 0.37%) ~ 4.05s 4.08s p=0.745 n=6
Bind Time 1.76s (± 0.93%) 1.79s (± 0.84%) +0.03s (+ 1.70%) 1.77s 1.81s p=0.019 n=6
Check Time 18.80s (± 0.99%) 19.04s (± 2.15%) ~ 18.79s 19.87s p=0.748 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.62s (± 0.75%) 24.91s (± 1.63%) ~ 24.65s 25.73s p=0.173 n=6
xstate-main - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 555,376 555,376 ~ ~ ~ p=1.000 n=6
Types 186,151 186,151 ~ ~ ~ p=1.000 n=6
Memory used 494,406k (± 0.02%) 494,394k (± 0.01%) ~ 494,345k 494,441k p=0.810 n=6
Parse Time 2.76s (± 0.30%) 2.77s (± 0.20%) ~ 2.76s 2.77s p=0.859 n=6
Bind Time 0.96s (± 0.42%) 0.96s (± 0.57%) ~ 0.96s 0.97s p=0.282 n=6
Check Time 16.32s (± 0.26%) 16.30s (± 0.26%) ~ 16.23s 16.35s p=0.747 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.04s (± 0.20%) 20.03s (± 0.20%) ~ 19.97s 20.07s p=0.872 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/61013/merge:

Everything looks good!

@@ -36138,8 +36141,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (candidate.typeParameters) {
// If we are *inside the body of candidate*, we need to create a clone of `candidate` with differing type parameter identities,
// so our inference results for this call doesn't pollute expression types referencing the outer type parameter!
const paramLocation = candidate.typeParameters[0].symbol.declarations?.[0]?.parent;
const candidateParameterContext = paramLocation || (candidate.declaration && isConstructorDeclaration(candidate.declaration) ? candidate.declaration.parent : candidate.declaration);
const paramHost = getEffectiveTypeParameterHost(candidate.typeParameters[0]);
Copy link
Member

Choose a reason for hiding this comment

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

Do we actually use the term "host" like this elsewhere?

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 guess "host" might only be appropriate in the JSDoc context but I don't have a better name for this that would cover both TS and JSDoc-based types

Copy link
Member

Choose a reason for hiding this comment

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

I mean "context" is what the PR title and the code below uses; could technically just inline it too. But, the existing JSDoc func used the term, so it's probably okay.

@Andarist
Copy link
Contributor Author

Andarist commented Jan 22, 2025

Regarding this reported change. I don't quite know on the spot why this has changed but it looks like a correct change. At the very least the new behavior matches existing TS behavior. See those 2: JS playground and TS playground. It also looks like the original intention of this cast was a non-null-like assertion but accidentally [] were forgotten?

EDIT: this error was reported in TS 5.4 (TS playground) so that just assures me it's the "new" behavior is the correct one :p

const tp = getDeclarationOfKind<TypeParameterDeclaration>(typeParameter.symbol, SyntaxKind.TypeParameter)!;
const host = isJSDocTemplateTag(tp.parent) ? getEffectiveContainerForJSDocTemplateTag(tp.parent) : tp.parent;
return isJSDocTemplateTag(tp.parent) ? getEffectiveJSDocHost(tp.parent) : tp.parent;
Copy link
Member

Choose a reason for hiding this comment

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

This sort of makes me wonder when we really should be using getEffectiveJSDocHost where we are currently using getEffectiveContainerForJSDocTemplateTag...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, but to be fair - I had to use getEffectiveJSDocHost to fix this issue at hand and it didn't look to me like this older function would have to stick to the other one. There is a chance that it should not use this - but there is also a chance that this change fixed some other issue ;p

In the ideal world, I'd go through all of the callers to both and assess their needs but I just don't have time to do that right now 😢

@jakebailey
Copy link
Member

Regarding this reported change. I don't quite know on the spot why this has changed but it looks like a correct change. At the very least the new behavior matches existing TS behavior. See those 2: JS playground and TS playground. It also looks like the original intention of this cast was a non-null-like assertion but accidentally [] were forgotten?

EDIT: this error was reported in TS 5.4 (TS playground) so that just assures me it's the "new" behavior is the correct one :p

The thing I'm most confused about is that it says []any; why is it any? Just because it's T &?

@Andarist
Copy link
Contributor Author

The thing I'm most confused about is that it says []any; why is it any? Just because it's T &?

It fails to infer it completely so it uses the default for an unconstrained type parameter. It happens that in JS files it's any and in TS files it's unknown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

JSDoc recursive inference not working properly on generic array wrapping
3 participants