Skip to content

Skip the narrowable-reference walk of unions known to contain no type variables - #64958

Closed
Mateusz Burzyński (Andarist) wants to merge 5 commits into
microsoft:mainfrom
Andarist:andarist/go-checker-optimization-port-6b0383
Closed

Mateusz Burzyński (Andarist) wants to merge 5 commits into
microsoft:mainfrom
Andarist:andarist/go-checker-optimization-port-6b0383

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

inspired by tsrs's: oxc-project/tsrs#715

Copilot AI balanced review requested due to automatic review settings October 25, 2026 16:00
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 25, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 25, 2026
@typescript-automation

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

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.

🟡 Changes recommended

The shortcut computes uncached containment results, introducing recursive work that a cache-only guard would avoid.

1 open issue
What changed in this PR

This PR aims to reduce compiler reference-narrowing work by skipping union traversal when a union cannot contain type variables, inspired by the linked tsrs optimization.

Changes:

  • Routes the union-constraint check through a new helper.
  • Adds a containment shortcut and documents why non-generic aliases remain eligible.
File Description
tsc/​internal/​checker/​checker.go Adds the union-containment shortcut to reference narrowing.

Review effort: Balanced

Comment thread tsc/internal/checker/checker.go Outdated
@Andarist
Mateusz Burzyński (Andarist) marked this pull request as draft October 25, 2026 16:12

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.

🔵 Needs a closer look

An unresolved narrowing regression and unvalidated hot-path performance tradeoff require further validation and human review.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve narrowing for NoInfer unions with substituted constraints

tsc/​internal/​checker/​checker.go:32305

For type U = NoInfer<{ kind: "a"; a: number } | { kind: "b"; b: number }> | { kind: "c" }, this guard skips required constraint substitution: couldContainTypeVariables(U) is false for the non-generic top-level alias, but the NoInfer constituent has a union base constraint. Consequently, for a parameter u: U, if (u.kind === "a") u.a retains the wrapped union instead of narrowing to the a branch. Preserve the walk when such substitutions may be present, or cache the exact predicate, and add a compiler regression for this case.

1 resolved since last review

Review effort: Balanced

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

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants