Skip to content

Sort by type depth in inferFromMatchingTypes function#4591

Open
ahejlsberg wants to merge 4 commits into
mainfrom
fix-4462
Open

Sort by type depth in inferFromMatchingTypes function#4591
ahejlsberg wants to merge 4 commits into
mainfrom
fix-4462

Conversation

@ahejlsberg

Copy link
Copy Markdown
Member

This PR partially reverts #4389 and instead implements a more targeted fix by sorting types by their nesting depth in the inferFromMatchingTypes function.

This fixes the regression in #4462 (but doesn't add a regression test since the repro has multiple dependencies). It also fixes the regression mentioned in oxc-project/tsgolint#1058 and adds that to the tests.

Fixes #4462.

Copilot AI review requested due to automatic review settings July 10, 2026 19:22
@ahejlsberg

Copy link
Copy Markdown
Member Author

@typescript-bot perf test this faster

@typescript-automation

typescript-automation Bot commented Jul 10, 2026

Copy link
Copy Markdown

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

Command Status Results
perf test this faster ✅ Started 👀 Results

@ahejlsberg

Copy link
Copy Markdown
Member Author

@typescript-bot test top1000

@typescript-automation

typescript-automation Bot commented Jul 10, 2026

Copy link
Copy Markdown

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

Command Status Results
test top1000 ✅ Started ✅ Results

@ahejlsberg ahejlsberg added this to the Post-7.0 milestone Jul 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts type inference ordering in the Go checker to prefer inferences derived from more deeply nested generic instantiations, aiming to address regressions introduced after #4389 (notably #4462) while keeping the change targeted. It also updates/accepts compiler baseline outputs and adds coverage for a related downstream regression report.

Changes:

  • Updates inferFromMatchingTypes to optionally sort matched target types by a computed “type depth” before performing inference.
  • Removes the prior per-inference-state depth tracking / candidate depth bookkeeping and relies on inference ordering instead.
  • Adds a regression test for oxc-project/tsgolint#1058 and updates affected baselines (including a submodule conformance baseline change).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/checker/inference.go Implements depth-based sorting of matched targets in inferFromMatchingTypes and introduces depth-computation helpers.
internal/checker/checker.go Removes candidateDepths from InferenceInfo to match the new ordering strategy.
testdata/tests/cases/compiler/nestedGenericTypeInference.ts Adds a compiler regression test for oxc-project/tsgolint#1058.
testdata/baselines/reference/compiler/nestedGenericTypeInference.types Accepts updated .types baseline for the new regression test content.
testdata/baselines/reference/compiler/nestedGenericTypeInference.symbols Accepts updated .symbols baseline for the new regression test content.
testdata/baselines/reference/submodule/conformance/assignmentCompatWithGenericCallSignatures2.errors.txt Updates the expected error baseline output for this conformance case.
testdata/baselines/reference/submodule/conformance/assignmentCompatWithGenericCallSignatures2.errors.txt.diff Removes the diff baseline, indicating this case no longer differs from the comparison baseline.

Comment on lines 108 to +114
// First, infer between identically matching source and target constituents and remove the
// matching types.
tempSources, tempTargets := c.inferFromMatchingTypes(n, sourceTypes, target.Distributed(), (*Checker).isTypeOrBaseIdenticalTo)
tempSources, tempTargets := c.inferFromMatchingTypes(n, sourceTypes, target.Types(), (*Checker).isTypeOrBaseIdenticalTo, false /*sort*/)
// Next, infer between closely matching source and target constituents and remove
// the matching types. Types closely match when they are instantiations of the same
// object type or instantiations of the same type alias.
sources, targets := c.inferFromMatchingTypes(n, tempSources, tempTargets, (*Checker).isTypeCloselyMatchedBy)
sources, targets := c.inferFromMatchingTypes(n, tempSources, tempTargets, (*Checker).isTypeCloselyMatchedBy, true /*sort*/)
Comment thread internal/checker/inference.go
Co-authored-by: ahejlsberg <4226954+ahejlsberg@users.noreply.github.com>
@typescript-automation

Copy link
Copy Markdown

@ahejlsberg
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 - native
Errors 4 4 ~ ~ ~ p=1.000 n=6
Symbols 81,823 (± 0.02%) 81,807 (± 0.04%) ~ 81,746 81,834 p=0.377 n=6
Types 98,821 98,821 ~ ~ ~ p=1.000 n=6
Memory Used 179,889k (± 0.46%) 179,548k (± 0.62%) ~ 177,554k 180,915k p=0.689 n=6
Memory Allocs 2,539,337 (± 0.00%) 2,538,200 (± 0.01%) -1,138 (- 0.04%) 2,537,691 2,538,404 p=0.005 n=6
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Parse Time 0.055s (±11.59%) 0.056s (± 9.51%) ~ 0.049s 0.065s p=0.629 n=6
Bind Time 0.021s (±14.37%) 0.014s (±18.36%) 🟩-0.006s (-29.27%) 0.012s 0.019s p=0.012 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 0.882s (± 0.93%) 0.894s (± 0.91%) +0.012s (+ 1.34%) 0.886s 0.907s p=0.030 n=6
Total Time 0.959s (± 1.49%) 0.966s (± 0.87%) ~ 0.951s 0.976s p=0.568 n=6
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 872,290 (± 0.12%) 872,427 (± 0.08%) ~ 871,575 873,402 p=0.689 n=6
Types 263,953 (± 0.00%) 263,953 (± 0.00%) ~ 263,950 263,955 p=0.794 n=6
Memory Used 829,640k (± 0.05%) 829,309k (± 0.06%) ~ 828,792k 829,965k p=0.173 n=6
Memory Allocs 12,511,949 (± 0.05%) 12,447,186 (± 0.10%) -64,764 (- 0.52%) 12,436,573 12,470,542 p=0.005 n=6
Config Time 0.018s (± 3.13%) 0.018s (± 4.62%) ~ 0.017s 0.019s p=0.859 n=6
Parse Time 0.246s (± 9.55%) 0.257s (± 4.22%) ~ 0.244s 0.276s p=0.575 n=6
Bind Time 0.065s (±38.47%) 0.064s (±30.28%) ~ 0.041s 0.088s p=0.936 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 1.937s (± 1.41%) 1.947s (± 1.83%) ~ 1.912s 1.994s p=0.689 n=6
Total Time 2.276s (± 1.48%) 2.298s (± 0.97%) ~ 2.272s 2.331s p=0.230 n=6
mui-docs - native
Errors 11,279 (± 0.04%) 11,279 (± 0.01%) ~ 11,278 11,281 p=0.217 n=6
Symbols 4,625,557 4,625,462 -95 (- 0.00%) ~ ~ p=0.001 n=6
Types 1,618,177 1,618,161 -16 (- 0.00%) ~ ~ p=0.001 n=6
Memory Used 5,754,407k (± 0.03%) 5,752,780k (± 0.03%) ~ 5,750,053k 5,755,189k p=0.230 n=6
Memory Allocs 49,729,504 (± 0.04%) 49,659,660 (± 0.06%) -69,844 (- 0.14%) 49,620,043 49,693,493 p=0.005 n=6
Config Time 0.016s (± 3.16%) 0.016s (± 4.99%) ~ 0.016s 0.018s p=0.752 n=6
Parse Time 0.536s (± 1.20%) 0.527s (± 3.57%) ~ 0.493s 0.544s p=0.872 n=6
Bind Time 0.002s 0.002s ~ ~ ~ p=1.000 n=6
Check Time 17.151s (± 0.94%) 17.127s (± 1.01%) ~ 16.987s 17.462s p=0.936 n=6
Emit Time 0.518s (±26.89%) 0.465s (± 3.86%) ~ 0.453s 0.501s p=0.419 n=6
Total Time 18.963s (± 0.95%) 18.871s (± 0.90%) ~ 18.722s 19.180s p=0.471 n=6
self-build-src - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,394,272 1,394,141 -131 (- 0.01%) ~ ~ p=0.001 n=6
Types 442,245 442,163 -82 (- 0.02%) ~ ~ p=0.001 n=6
Memory Used 1,654,170k (± 0.20%) 1,654,799k (± 0.26%) ~ 1,650,410k 1,660,203k p=0.630 n=6
Memory Allocs 97,717,866 (± 0.05%) 97,171,835 (± 0.06%) -546,032 (- 0.56%) 97,086,562 97,229,271 p=0.005 n=6
Config Time 0.021s (±33.30%) 0.018s (±36.05%) ~ 0.007s 0.026s p=0.423 n=6
Parse Time 0.274s (± 4.39%) 0.274s (± 4.54%) ~ 0.261s 0.293s p=1.000 n=6
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Check Time 2.328s (± 0.82%) 2.334s (± 0.97%) ~ 2.302s 2.371s p=0.689 n=6
Emit Time 0.305s (± 2.18%) 0.311s (± 7.79%) ~ 0.293s 0.358s p=0.630 n=6
Total Time 30.685s (± 0.89%) 30.636s (± 0.98%) ~ 30.303s 31.121s p=0.689 n=6
self-compiler - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 337,637 337,634 -3 (- 0.00%) ~ ~ p=0.001 n=6
Types 199,520 199,520 ~ ~ ~ p=1.000 n=6
Memory Used 332,465k (± 0.04%) 332,294k (± 0.02%) -171k (- 0.05%) 332,198k 332,428k p=0.045 n=6
Memory Allocs 4,717,664 (± 0.01%) 4,682,110 (± 0.01%) -35,554 (- 0.75%) 4,681,207 4,682,917 p=0.005 n=6
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=6
Parse Time 0.126s (± 5.61%) 0.131s (± 4.21%) ~ 0.122s 0.137s p=0.227 n=6
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Check Time 1.389s (± 0.88%) 1.393s (± 1.23%) ~ 1.363s 1.409s p=0.810 n=6
Emit Time 0.131s (±11.89%) 0.128s (± 3.61%) ~ 0.123s 0.137s p=0.470 n=6
Total Time 1.704s (± 0.78%) 1.705s (± 0.97%) ~ 1.678s 1.727s p=0.936 n=6
ts-pre-modules - native
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 97,488 97,488 ~ ~ ~ p=1.000 n=6
Types 356 356 ~ ~ ~ p=1.000 n=6
Memory Used 133,726k (± 0.02%) 133,715k (± 0.03%) ~ 133,635k 133,759k p=1.000 n=6
Memory Allocs 180,328 (± 0.24%) 180,141 (± 0.13%) ~ 179,843 180,417 p=0.298 n=6
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=6
Parse Time 0.113s (± 4.58%) 0.113s (± 5.19%) ~ 0.105s 0.120s p=1.000 n=6
Bind Time 0.040s (±11.39%) 0.039s (± 9.68%) ~ 0.032s 0.043s p=0.462 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Total Time 0.157s (± 1.63%) 0.156s (± 4.09%) ~ 0.148s 0.164s p=0.514 n=6
vscode - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 7,097,365 7,097,303 -62 (- 0.00%) ~ ~ p=0.001 n=6
Types 2,494,774 2,494,761 -13 (- 0.00%) ~ ~ p=0.001 n=6
Memory Used 4,837,726k (± 0.02%) 4,835,763k (± 0.03%) -1,963k (- 0.04%) 4,833,881k 4,837,161k p=0.013 n=6
Memory Allocs 33,116,878 (± 0.10%) 32,795,962 (± 0.04%) -320,917 (- 0.97%) 32,775,296 32,817,884 p=0.005 n=6
Config Time 0.075s (±10.74%) 0.081s (± 6.51%) ~ 0.073s 0.087s p=0.199 n=6
Parse Time 0.916s (± 2.52%) 0.923s (± 1.98%) ~ 0.905s 0.949s p=0.689 n=6
Bind Time 0.168s (±16.91%) 0.155s (± 3.78%) ~ 0.150s 0.164s p=0.199 n=6
Check Time 9.102s (± 0.89%) 9.173s (± 1.51%) ~ 9.069s 9.395s p=0.378 n=6
Emit Time 2.548s (± 7.62%) 2.436s (± 9.27%) ~ 2.159s 2.701s p=0.378 n=6
Total Time 12.832s (± 0.89%) 12.784s (± 0.96%) ~ 12.623s 12.977s p=0.378 n=6
webpack - native
Errors 2 2 ~ ~ ~ p=1.000 n=6
Symbols 188,078 188,078 ~ ~ ~ p=1.000 n=6
Types 340 340 ~ ~ ~ p=1.000 n=6
Memory Used 229,975k (± 0.19%) 230,454k (± 0.09%) ~ 230,150k 230,685k p=0.066 n=6
Memory Allocs 952,920 (± 0.60%) 958,546 (± 0.43%) ~ 953,927 964,757 p=0.128 n=6
Config Time 0.013s (±14.68%) 0.012s (±14.54%) ~ 0.009s 0.014s p=0.681 n=6
Parse Time 0.163s (± 3.42%) 0.159s (± 2.70%) ~ 0.154s 0.166s p=0.199 n=6
Bind Time 0s 0s ~ ~ ~ p=1.000 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 0.047s (±18.73%) 0.041s (± 8.01%) ~ 0.035s 0.045s p=0.257 n=6
Total Time 0.223s (± 4.32%) 0.212s (± 1.92%) 🟩-0.010s (- 4.71%) 0.207s 0.217s p=0.036 n=6
xstate-main - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,061,625 1,061,625 ~ ~ ~ p=1.000 n=6
Types 391,325 391,325 ~ ~ ~ p=1.000 n=6
Memory Used 644,999k (± 0.02%) 644,384k (± 0.01%) -615k (- 0.10%) 644,330k 644,470k p=0.005 n=6
Memory Allocs 5,015,418 (± 0.05%) 4,981,348 (± 0.15%) -34,069 (- 0.68%) 4,974,467 4,990,942 p=0.005 n=6
Config Time 0.005s (±11.05%) 0.005s (±17.48%) ~ 0.003s 0.005s p=0.752 n=6
Parse Time 0.137s (± 6.39%) 0.137s (± 3.49%) ~ 0.131s 0.144s p=1.000 n=6
Bind Time 0.034s (±27.94%) 0.032s (±25.29%) ~ 0.026s 0.042s p=0.573 n=6
Check Time 1.313s (± 0.57%) 1.302s (± 0.51%) ~ 1.294s 1.310s p=0.054 n=6
Emit Time 0.001s 0.001s ~ ~ ~ p=1.000 n=6
Total Time 1.493s (± 0.97%) 1.479s (± 0.69%) ~ 1.465s 1.492s p=0.065 n=6
System info unknown
Hosts
  • native
Scenarios
  • Compiler-Unions - native
  • angular-1 - native
  • mui-docs - native
  • self-build-src - native
  • self-compiler - native
  • ts-pre-modules - native
  • vscode - native
  • webpack - native
  • xstate-main - native
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-automation

Copy link
Copy Markdown

@ahejlsberg Here are the results of running the top 1000 repos with tsc comparing main and refs/pull/4591/merge:

Everything looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants