[ty] Allow recursive type expansion a limited number of times during type relation checking - #26989
Closed
mtshiba wants to merge 4 commits into
Closed
[ty] Allow recursive type expansion a limited number of times during type relation checking#26989mtshiba wants to merge 4 commits into
mtshiba wants to merge 4 commits into
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 96.95%. The percentage of expected errors that received a diagnostic held steady at 92.58%. The number of fully passing files held steady at 104/133. |
Memory usage reportMemory usage unchanged ✅ |
|
mtshiba
force-pushed
the
cycle-detector-visit-limit
branch
2 times, most recently
from
July 20, 2026 14:35
9591845 to
7d9d11b
Compare
mtshiba
force-pushed
the
cycle-detector-visit-limit
branch
from
August 5, 2026 14:08
7d9d11b to
ec031ea
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
This reverts commit 22458a5.
Collaborator
Author
|
This approach has the undesirable side effect that the union type reduction results depend on the order. Therefore, it cannot be adopted. type Left12[A, B, C, D, E, F, G, H, I, J, K] = tuple[A, Left12[B, C, D, E, F, G, H, I, J, K, L, None]]
type Right12[A, B, C, D, E, F, G, H, I, J, K] = tuple[A, Right12[B, C, D, E, F, G, H, I, J, K, L, None]]
type Source = Left12[int, int, int, int, int, int, int, int, int, int, int, int]
type RightAfterTwo = Right12[int, int, int, int, int, int, int, int, int, int, None, None]
type Shortcut = tuple[int, tuple[int, RightAfterTwo]]
# Shortcut is equivalent to LongPath
type LongPath = Right12[int, int, int, int, int, int, int, int, int, int, int, int]
static_assert(is_subtype_of(Source, Shortcut))
static_assert(is_subtype_of(Source, Shortcut | LongPath))
static_assert(is_subtype_of(Source, LongPath | Shortcut)) # failure!Instead, it is necessary to redesign |
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
This PR addresses #26503 (comment)
As described in the comment, instead of immediately returning the
Cyclestate when a same identity is found, we expect the recursive expansion to stabilize byPendingseveral times. If it does not stabilize even after expanding 10 times, it will be determined as a cycle.This makes
DefinitionReferenceVisitorcompletely unnecessary. In other words, even if we see signs of a growing pattern, we will try expanding recursive types up to 10 times. At first glance, it might seem better to keep theDefinitionReferenceVisitorguard in place, but doing so would actually cause us to miss patterns that look like growing patterns but ultimately converge in a finite number of steps. For example:Now consider these type relations:
CycleDetectorobserves the increase in specialization as follows. However, this will eventually converge after a finite number of steps. In other words, it is not possible to conclude that "this type relation check will not stop" just from the increasing structure of specialization observed byCycleDetector.Test Plan
mdtest updated