[ty] Avoid bypassing lazy constraints for Divergent#26288
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
flake8
trio
|
|
mtshiba
added a commit
that referenced
this pull request
Jun 24, 2026
## Summary #26288 fixed a crash by preventing `when_constraint_set_assignable_to_owned` from returning a trivial `always` result for top-level `Divergent` pairs. The underlying issue was that the owned fast path and the lazy relation checker could disagree: the fast path treated some `Divergent` assignability checks as always satisfied, while the lazy relation checker treated top-level `Divergent` as never assignable. This patch resolves the inconsistency in the relation checker instead. Unmaterialized `Divergent` is assignability-compatible in both eager and lazy assignability, while it is still not a subtype of arbitrary types and still must not be eliminated by redundancy/union simplification. With the lazy relation checker aligned with the fast path, we no longer need the top-level `Divergent` exclusion in `is_trivially_constraint_set_assignable_to`. The regression test from #26288 still passes, and the unit test now asserts that constraint-set assignability treats `Divergent` consistently. ## Test Plan unit test updated
charliermarsh
added a commit
that referenced
this pull request
Jun 24, 2026
## Summary This reverts #26163 and its follow-up changes in #26230, #26246, #26274, #26275, and #26316. The recursive nominal-growth recovery replaces a previous cycle result nested inside a specialization with `Divergent`. The follow-up regressions show that this local replacement is not structurally safe: multi-arm union recovery can lose stable arms, and variadic tuple growth can continue after replacement. Addressing those cases required increasingly shape-specific alignment and guards without a general way to establish correspondence between fixed-point iterations. This restores the cycle-recovery behavior from before #26163. The direct self-referential `TypeOf` case and the regression coverage for astral-sh/ty#3835 and astral-sh/ty#3838 continue to pass without the heuristic and are retained. We remove only the cases that no longer converge: `TypeOf` references nested in nominal specializations and the nested-iterable case from astral-sh/ty#3827. The independent `Divergent` constraint fixes from #26288 and #26334, including the regression coverage for astral-sh/ty#3836, are also retained.
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.
Summary
when_constraint_set_assignable_to_ownedavoids entering its tracked Salsa query when a relation appears to be unconditionally satisfied. The shortcut usedmaterialized_divergent_fallback().is_none()to guard the union and intersection cases, but an unmaterializedDivergentmarker also has no fallback.During recursive inference, that allowed the shortcut to return an always-satisfied constraint set for relations such as
Divergenttoint | Divergent. Lazy constraint-set assignability intentionally handles a top-levelDivergentdifferently, so bypassing the query could admit an inconsistent bound and eventually trigger a debug assertion in constraint solving.This keeps the exact-equality fast path, but routes every other relation involving a top-level
Divergentthrough the tracked query. It also adds direct coverage for union and dynamic relations alongside the original nested-loop reproducer:Closes astral-sh/ty#3836.