Repository navigation
Sort by type depth in inferFromMatchingTypes function - #4591
Conversation
|
TypeScript Bot (@typescript-bot) perf test this faster |
|
TypeScript Bot (@typescript-bot) test top1000 |
There was a problem hiding this comment.
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
inferFromMatchingTypesto 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. |
| // 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*/) |
Co-authored-by: ahejlsberg <4226954+ahejlsberg@users.noreply.github.com>
|
Anders Hejlsberg (@ahejlsberg) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top 1000 repos with tsc comparing Everything looks good! |
…pescript-go#4591) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ahejlsberg <4226954+ahejlsberg@users.noreply.github.com>
This PR partially reverts #4389 and instead implements a more targeted fix by sorting types by their nesting depth in the
inferFromMatchingTypesfunction.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.