Fixes #24914 Treat equivalent candidates as divergent in implicit search#25910
Open
soronpo wants to merge 2 commits intoscala:mainfrom
Open
Fixes #24914 Treat equivalent candidates as divergent in implicit search#25910soronpo wants to merge 2 commits intoscala:mainfrom
soronpo wants to merge 2 commits intoscala:mainfrom
Conversation
The divergence check in `checkDivergence` only considered two open searches as potential loops when they used the exact same candidate reference. Given several sibling givens with identical declared types — a common pattern when modelling a type class hierarchy where each instance recursively needs another instance — the search would still branch into every permutation of the candidates before eventually giving up once the expression-count limit tripped. For the minimization in scala#24914 this was a factorial blow-up: six sibling Monad givens led to tens of thousands of `tryImplicit` calls and compilation took well over a minute before failing with "search problem too large". Extending the check so that candidates whose `ref.info` types are equivalent are also subject to the usual size and covering-set test lets ordinary divergence detection cut the recursion short; the test file now fails in roughly five seconds with a clean error instead. https://claude.ai/code/session_01JTYTJU8w2jxH1QLqD8of4x
599b194 to
485952f
Compare
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.
The divergence check in
checkDivergenceonly considered two open searches as potential loops when they used the exact same candidate reference. Given several sibling givens with identical declared types — a common pattern when modelling a type class hierarchy where each instance recursively needs another instance — the search would still branch into every permutation of the candidates before eventually giving up once the expression-count limit tripped.For the minimization in #24914 this was a factorial blow-up: six sibling Monad givens led to tens of thousands of
tryImplicitcalls and compilation took well over a minute before failing with "search problem too large". Extending the check so that candidates whoseref.infotypes are equivalent are also subject to the usual size and covering-set test lets ordinary divergence detection cut the recursion short; the test file now fails in roughly five seconds with a clean error instead.Fixes #24914
How much have you relied on LLM-based tools in this contribution?
Extensively, but the fix is small.
How was the solution tested?
New automated tests (including the issue's reproducer, if applicable)