Sort by type depth in inferFromMatchingTypes function#4591
Open
ahejlsberg wants to merge 4 commits into
Open
Conversation
Member
Author
|
@typescript-bot perf test this faster |
Member
Author
|
@typescript-bot test top1000 |
Contributor
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. |
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*/) |
Co-authored-by: ahejlsberg <4226954+ahejlsberg@users.noreply.github.com>
|
@ahejlsberg Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@ahejlsberg Here are the results of running the top 1000 repos with tsc comparing Everything looks good! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.