Skip to content

Reuse cached resolved signatures early - #60208

Merged
Gabriela Araujo Britto (gabritto) merged 2 commits into
microsoft:mainfrom
Andarist:fix/debug-failure-circular-base
Nov 6, 2024
Merged

Reuse cached resolved signatures early#60208
Gabriela Araujo Britto (gabritto) merged 2 commits into
microsoft:mainfrom
Andarist:fix/debug-failure-circular-base

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

@typescript-botTypeScript Bot (typescript-bot) added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 12, 2024
BaseClass extends new (...args: any[]) => any,
>(Base: BaseClass): any;

declare class Item extends ClientDocumentMixin(BaseItem) {}

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

due to the circular nature of this example, the compiler goes into resolveCall for the same node twice in a nested manner

  1. the first getResolvedSignature ends up calling resolveAnonymousTypeMembers for typeof BaseItem
  2. in the process it preemptively sets empty signatures, members, index infos on that type here
  3. but then it also computes real construct signatures here
  4. this in turn leads to calling getResolvedSignatureagain for the same node and all
  5. in that inner call we see no construct signatures on typeof BaseItem (those were set to an empty array) so the error is raised because signaturesRelatedTo fails to determine that this source (typeof BaseItem) has the required target signatures
  6. this inner call errors and exits, caching the getCandidateForOverloadFailure's result as the links.resolvedSignature. That signature is (Base: new (...args: any[]) => any): any
  7. this leads to resolving (): BaseItem as getDefaultConstructSignatures and that replaces the empty construct signatures preemptively set by resolveAnonymousTypeMembers
  8. now we climb up the stack, going back to the first/outer getResolvedSignature call for this. When calling getSignatureApplicabilityError the compiler returns an error because it reuses cached RelationComparisonResult.Failed that was cached when relating the argument and parameter types in that inner call
  9. so now the compiler computes getCandidateForOverloadFailure again and tries to elaborate this error (again!).
  10. this time it succeeds when relating those 2 types because the construct signatures of typeof BaseItem changed "in-between". So the debug assert kicks finally kicks in and the compiler crashes

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks a ton for this PR and the explanation! It makes the crash make much more sense to me now.

I will say some of these steps still seem to have a bit of concerning logic and seem to help explain something else weird I noted on my issue, namely that there doesn't have to be a "real" loop in the base type for you to get an error like Argument of type 'typeof BaseItem' is not assignable to parameter of type 'new (...args: any[]) => any'.

Playground (make sure to make any edit to overcome the crash and view an error!)

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

tbh your example is somewhat convoluted to the point that I'm not sure if it should error or not. It's definitely outside of the "regular TS" territory 😅 so all I was after here was to fix the crash. Once this gets fixed you might want to raise a new issue about the circularity issue if you thing it shouldn't be reported

@jakebailey

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) test it

@typescript-bot

TypeScript Bot (typescript-bot) commented Oct 12, 2024

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
test top400✅ Started✅ Results
user test this✅ Started✅ Results
run dt✅ Started✅ Results
perf test this faster✅ Started👀 Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing main and refs/pull/60208/merge:

Everything looks good!

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors3131~~~p=1.000 n=6
Symbols62,34062,340~~~p=1.000 n=6
Types50,37950,379~~~p=1.000 n=6
Memory used192,901k (± 0.09%)192,859k (± 0.07%)~192,793k193,115kp=0.810 n=6
Parse Time1.30s (± 1.37%)1.31s (± 0.62%)~1.30s1.32sp=0.157 n=6
Bind Time0.72s (± 0.57%)0.72s~~~p=0.405 n=6
Check Time9.72s (± 0.27%)9.75s (± 0.31%)~9.71s9.80sp=0.170 n=6
Emit Time2.72s (± 1.28%)2.72s (± 0.55%)~2.70s2.74sp=0.332 n=6
Total Time14.47s (± 0.30%)14.50s (± 0.21%)~14.46s14.54sp=0.420 n=6
angular-1 - node (v18.15.0, x64)
Errors3333~~~p=1.000 n=6
Symbols947,886947,886~~~p=1.000 n=6
Types410,840410,840~~~p=1.000 n=6
Memory used1,224,591k (± 0.00%)1,224,577k (± 0.00%)~1,224,544k1,224,596kp=0.688 n=6
Parse Time6.66s (± 0.72%)6.64s (± 0.87%)~6.59s6.73sp=0.573 n=6
Bind Time1.88s (± 0.27%)1.88s~~~p=0.174 n=6
Check Time31.81s (± 0.27%)31.82s (± 0.38%)~31.69s32.02sp=0.936 n=6
Emit Time15.18s (± 0.38%)15.13s (± 0.28%)~15.07s15.17sp=0.260 n=6
Total Time55.52s (± 0.30%)55.47s (± 0.30%)~55.29s55.67sp=0.575 n=6
mui-docs - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols2,530,0752,530,075~~~p=1.000 n=6
Types916,374916,374~~~p=1.000 n=6
Memory used2,341,297k (± 0.00%)2,341,307k (± 0.00%)~2,341,243k2,341,401kp=0.936 n=6
Parse Time9.37s (± 0.46%)9.39s (± 0.21%)~9.36s9.41sp=0.573 n=6
Bind Time2.17s (± 0.45%)2.16s (± 0.45%)~2.15s2.18sp=0.211 n=6
Check Time76.04s (± 0.35%)75.93s (± 0.49%)~75.56s76.55sp=0.378 n=6
Emit Time0.28s (± 2.70%)0.27s (± 2.98%)~0.27s0.29sp=0.206 n=6
Total Time87.86s (± 0.33%)87.75s (± 0.43%)~87.39s88.39sp=0.471 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,258,1091,258,110+1 (+ 0.00%)~~p=0.001 n=6
Types266,266266,266~~~p=1.000 n=6
Memory used3,146,212k (± 0.01%)3,146,853k (± 0.05%)~3,145,282k3,148,807kp=1.000 n=6
Parse Time6.59s (± 0.47%)6.60s (± 0.84%)~6.54s6.68sp=0.936 n=6
Bind Time2.32s (± 1.26%)2.28s (± 4.13%)~2.09s2.33sp=0.746 n=6
Check Time42.99s (± 0.36%)42.94s (± 0.34%)~42.75s43.11sp=0.810 n=6
Emit Time3.59s (± 1.88%)3.56s (± 2.06%)~3.49s3.68sp=0.422 n=6
Total Time55.48s (± 0.20%)55.38s (± 0.38%)~55.05s55.68sp=0.575 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,258,1091,258,110+1 (+ 0.00%)~~p=0.001 n=6
Types266,266266,266~~~p=1.000 n=6
Memory used2,739,089k (±13.56%)2,859,044k (±13.74%)~2,498,920k3,218,158kp=0.689 n=6
Parse Time6.65s (± 2.66%)6.68s (± 2.36%)~6.54s6.90sp=0.873 n=6
Bind Time2.18s (± 4.35%)2.23s (± 4.50%)~2.14s2.37sp=0.172 n=6
Check Time43.15s (± 0.23%)43.18s (± 0.41%)~42.91s43.39sp=0.689 n=6
Emit Time3.47s (± 1.77%)3.54s (± 1.86%)~3.44s3.61sp=0.173 n=6
Total Time55.47s (± 0.46%)55.63s (± 0.52%)~55.13s55.93sp=0.378 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols261,786261,787+1 (+ 0.00%)~~p=0.001 n=6
Types106,508106,508~~~p=1.000 n=6
Memory used438,538k (± 0.01%)438,572k (± 0.01%)~438,462k438,626kp=0.173 n=6
Parse Time2.90s (± 0.85%)2.90s (± 0.65%)~2.88s2.92sp=0.935 n=6
Bind Time1.10s (± 0.47%)1.10s~~~p=0.174 n=6
Check Time15.72s (± 0.24%)15.72s (± 0.31%)~15.66s15.78sp=1.000 n=6
Emit Time1.30s (± 1.58%)1.31s (± 0.93%)~1.29s1.32sp=0.871 n=6
Total Time21.03s (± 0.17%)21.02s (± 0.21%)~20.96s21.08sp=0.809 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors6868~~~p=1.000 n=6
Symbols225,919225,919~~~p=1.000 n=6
Types94,41594,415~~~p=1.000 n=6
Memory used371,058k (± 0.01%)371,089k (± 0.01%)~371,064k371,116kp=0.054 n=6
Parse Time2.89s (± 0.75%)2.88s (± 1.58%)~2.84s2.95sp=0.520 n=6
Bind Time1.57s (± 1.11%)1.58s (± 0.77%)~1.56s1.59sp=0.744 n=6
Check Time16.36s (± 0.28%)16.42s (± 0.12%)+0.06s (+ 0.36%)16.39s16.44sp=0.019 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time20.83s (± 0.21%)20.88s (± 0.30%)~20.79s20.95sp=0.171 n=6
vscode - node (v18.15.0, x64)
Errors33~~~p=1.000 n=6
Symbols3,117,4873,117,487~~~p=1.000 n=6
Types1,074,4181,074,418~~~p=1.000 n=6
Memory used3,210,903k (± 0.01%)3,210,927k (± 0.01%)~3,210,173k3,211,292kp=0.689 n=6
Parse Time14.01s (± 0.32%)14.05s (± 0.63%)~13.90s14.16sp=0.229 n=6
Bind Time4.43s (± 0.56%)4.45s (± 0.40%)~4.42s4.47sp=0.253 n=6
Check Time86.44s (± 1.85%)85.36s (± 1.16%)~83.84s86.77sp=0.378 n=6
Emit Time26.52s (± 5.23%)25.55s (± 8.17%)~22.63s27.35sp=0.173 n=6
Total Time131.40s (± 1.90%)129.40s (± 1.69%)~126.10s131.93sp=0.199 n=6
webpack - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols285,224285,224~~~p=1.000 n=6
Types115,781115,781~~~p=1.000 n=6
Memory used435,393k (± 0.04%)435,353k (± 0.03%)~435,119k435,479kp=0.689 n=6
Parse Time5.04s (± 0.71%)5.04s (± 0.52%)~5.00s5.07sp=0.808 n=6
Bind Time2.17s (± 1.78%)2.15s (± 1.48%)~2.10s2.19sp=0.169 n=6
Check Time22.80s (± 0.59%)22.80s (± 0.65%)~22.59s22.98sp=0.810 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time30.01s (± 0.52%)29.99s (± 0.58%)~29.72s30.16sp=0.936 n=6
xstate-main - node (v18.15.0, x64)
Errors33~~~p=1.000 n=6
Symbols540,222540,222~~~p=1.000 n=6
Types181,145181,145~~~p=1.000 n=6
Memory used483,836k (± 0.01%)483,870k (± 0.01%)~483,761k483,948kp=0.261 n=6
Parse Time4.18s (± 0.58%)4.17s (± 0.48%)~4.14s4.20sp=0.745 n=6
Bind Time1.45s (± 0.83%)1.46s (± 0.72%)~1.44s1.47sp=1.000 n=6
Check Time23.65s (± 0.36%)23.73s (± 0.20%)~23.66s23.78sp=0.054 n=6
Emit Time0.00s (±154.76%)0.00s (±154.76%)~0.00s0.01sp=1.000 n=6
Total Time29.28s (± 0.34%)29.36s (± 0.19%)~29.29s29.43sp=0.128 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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing main and refs/pull/60208/merge:

Everything looks good!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems like a promising idea in the absence of the possibility of fixing the assignability result inconsistency, but I left a question.

Comment threadsrc/compiler/checker.ts
Comment threadsrc/compiler/checker.ts
@gabritto

Copy link
Copy Markdown
Member

Maybe related fix: #49598

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left a question.

@gabritto
Gabriela Araujo Britto (gabritto) merged commit 5e2e321 into microsoft:mainNov 6, 2024
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"No error for last overload signature" regression in #58859

6 participants

@Andarist@jakebailey@typescript-bot@gabritto@LukeAbby@sandersn