Skip to content

[ty] Add bounded constraint solution projections - #27949

Merged
carljm merged 3 commits into
mainfrom
cjm/ty-3557-bounded-constraint-projection
Aug 21, 2026
Merged

[ty] Add bounded constraint solution projections#27949
carljm merged 3 commits into
mainfrom
cjm/ty-3557-bounded-constraint-projection

Conversation

@carljm

@carljm carljm commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Constraint solution extraction can enumerate an exponentially large family of paths even when sequent derivation and intersection construction stay within their existing limits. This adds separate limits for solution traversal, collected paths, and retained type terms. Exceeding a limit aborts the projection without exposing a partial family as the complete answer.

ConstraintSet solution collection is fallible and bounded by default. Callers preserve the original signature or constraints, decline optional narrowing, or use Unknown when a projection cannot finish. Generic inference does not treat evidence from the remaining arguments as complete.

A fallible fold processes complete per-path bindings, preserving correlations between type variables until the consumer combines alternatives. Generic inference uses the collector and fold while retaining its merged-specialization behavior below the limits.

This is a foundation for astral-sh/ty#3557. It does not yet change call inference to intersect separately specialized return types.

Test plan

  • Verify correlated alternatives and Cartesian products, exact budget boundaries, interning/source-order permutations, and early termination before or during solution selection.
  • Exercise shared preprocessing/collection limits and restoration of path state after traversal and path-budget cancellation.
  • Cover incomplete, rejected, and unsolved solutions; alias and set-theoretic term accounting; bounded DNF expansion; and conservative generic fallback.
  • Add an mdtest with four independent intersection arguments, checking the existing inferred union in both argument orders.
  • Preserve return-type inference from an overloaded callback with a catch-all overload and partially annotated literal-specific overloads.
  • Verify Unknown recovery after genuine projection exhaustion, even with precise evidence from another argument, in both argument orders.

@carljm carljm added the ty Multi-file analysis & type inference label Aug 21, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 97.68%. The percentage of expected errors that received a diagnostic held steady at 93.44%. The number of fully passing files held steady at 109/136.

@astral-sh-bot

astral-sh-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@carljm
carljm requested a review from dcreager August 21, 2026 04:23
@carljm
carljm marked this pull request as ready for review August 21, 2026 04:24
@carljm
carljm requested a review from a team as a code owner August 21, 2026 04:24

@dcreager dcreager left a comment

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.

Looks good. Should we consider using this new trait for the fuel budget inside of PathAssignments at some point, as well? That would let it be a shared budget. Not at all a blocker.

/// that can expand them. It should combine alternatives commutatively when their order is not
/// meaningful to its consumer. Existing limitations in solution extraction still apply; this
/// API does not make an order-sensitive selector or fold order-independent.
#[expect(clippy::too_many_arguments)]

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.

ah clippy

@carljm

carljm commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Looks good. Should we consider using this new trait for the fuel budget inside of PathAssignments at some point, as well? That would let it be a shared budget. Not at all a blocker.

Yeah I think that's worth evaluating. It's almost certainly possible to share more infrastructure; whether they should actually be shared budgets is less clear to me.

@carljm
carljm merged commit 5708b03 into main Aug 21, 2026
67 checks passed
@carljm
carljm deleted the cjm/ty-3557-bounded-constraint-projection branch August 21, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants