Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tsc/internal/checker/relater.go
Original file line number Diff line number Diff line change
Expand Up @@ -3261,7 +3261,15 @@ func (r *Relater) structuredTypeRelatedTo(source *Type, target *Type, reportErro
// needs to have its constraint hoisted into an intersection with said type parameter, this way
// the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
// For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
if result == TernaryFalse && (source.flags&TypeFlagsIntersection != 0 || source.flags&TypeFlagsTypeParameter != 0 && target.flags&TypeFlagsUnion != 0) {
// We skip the combined-constraint check while measuring variances. Variance
// measurement compares marker instantiations, and there the hoisted constraint may
// itself be an intersection with instantiable constituents (e.g. deferred conditional
// types, as produced by heavily overloaded generic builder types), so a failed
// comparison re-enters this logic with a structurally new and ever larger source
// that the relation cache and the deeply-nested-type guards never recognize as
// recursive, and the chase grows without bound (see microsoft/TypeScript#64423).
// The check never contributes to the measured relation between the marker types.
if result == TernaryFalse && len(r.c.varianceStack) == 0 && (source.flags&TypeFlagsIntersection != 0 || source.flags&TypeFlagsTypeParameter != 0 && target.flags&TypeFlagsUnion != 0) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

LLM-generated test added


Regression test checked in as bd456af6e3 (tests/cases/compiler/effectiveConstraintChaseDuringVarianceMeasurement.ts plus .types/.symbols baselines), in response to the review comment asking for a checked-in test for the variance-stack guard.

  1. Minimized from the real repro. It is hand-distilled from the three.js TSL node types that triggered [7.0 regression] Unbounded type relation expansion during variance computation causes OOM #64423. Only the constructs needed to drive the combined-constraint comparison in structuredTypeRelatedTo during variance measurement were kept — resolving uv().div(vec2()) measures the variances of the generic extension interfaces, whose hoisted constraints form deferred conditional intersections.

  2. It fails without the fix. On the pre-fix revision (673a5f17d7) this file enters the unbounded relation chase and the process dies with runtime: out of memory. Removing or weakening the variance-stack guard reintroduces this immediately, so CI catches it instead of the regression going unnoticed.

  3. It passes with the fix and pins the exact output. With the guard, the file checks to completion in under a second with no diagnostics, and the baselines record the precise inferred types (e.g. x : Node<"vec2">). This also guards the opposite failure mode: a future change that "fixes" a hang by making the checker give up and infer different types would fail the baseline comparison.

Reproducing the pre-fix failure locally:

git show 673a5f17d7:tsc/internal/checker/relater.go > tsc/internal/checker/relater.go
cd tsc && GOMAXPROCS=2 timeout 120 go test ./internal/testrunner \
  -run 'TestLocal/effectiveConstraintChaseDuringVarianceMeasurement'
# pre-fix: never terminates (chase grows until OOM) / fixed: "ok" in ~1s

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

What do you think Jake Bailey (@jakebailey)? :)

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.

If you wanted this to not be dependent on checker current-comparison state (which is unstable, and why this is maybe not the best solution), you'd wanna do this (skipping this check) for a new relationship used by variance comparisons instead of inspecting r.c.varianceStack. Without special logic to try and hierarchically share caches between that new variance-assignability and assignability, though, there's a possibility doing so impacts perf negatively.

@Amatewasu Alexis Delrieu (Amatewasu) Nov 19, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the reply!

I don't have enough experience with compiler internals to fully understand the implications or assess which approach would be best. My main motivation is simply to get our project compiling with TS7.

For reference, I benchmarked the current PR against main across six projects:

Project Wall time Δ Peak RSS Δ
vuejs/core +4.00% −1.50%
nestjs/nest −3.40% +1.09%
ReactiveX/rxjs −4.19% +0.53%
ant-design +7.24% +2.88%
angular/angular-cli −7.31% −0.34%
microsoft/vscode −4.93% +0.12%

No statistically significant differences were detected, although these results are preliminary given the different base revisions.

Benchmark methodology and detailed results

Seven alternating runs per binary. Mean wall-clock time and peak RSS measured using /usr/bin/time -v. Statistical significance assessed using an exact two-sided Mann-Whitney U test.

Project Wall main Wall PR Wall p-value RSS main RSS PR RSS p-value
vuejs/core 1.78 s 1.86 s 0.7104 192.4 MB 189.5 MB 0.1282
nestjs/nest 9.70 s 9.37 s 1.0000 742.5 MB 750.6 MB 0.3176
ReactiveX/rxjs 10.00 s 9.58 s 0.3829 563.5 MB 566.5 MB 0.7104
ant-design 27.06 s 29.02 s 0.9015 2.78 GB 2.86 GB 0.2086
angular/angular-cli 5.90 s 5.47 s 0.9015 621.0 MB 618.9 MB 1.0000
microsoft/vscode 73.30 s 69.69 s 0.8048 6.57 GB 6.58 GB 0.8048
  • tsc-main: 9c4ad5cbc5a24f3e8893c6e395ac8981c1154c16
  • tsc-pr: b08d68c34bc9f21fec2c2bd45f880c188340158e (base 056d69edb807)

var sourceTypes []*Type
if source.flags&TypeFlagsIntersection != 0 {
sourceTypes = source.Types()
Expand Down
Loading
Loading