Skip to content

Fixes #24914 Treat equivalent candidates as divergent in implicit search#25910

Open
soronpo wants to merge 2 commits intoscala:mainfrom
soronpo:claude/fix-24914
Open

Fixes #24914 Treat equivalent candidates as divergent in implicit search#25910
soronpo wants to merge 2 commits intoscala:mainfrom
soronpo:claude/fix-24914

Conversation

@soronpo
Copy link
Copy Markdown
Contributor

@soronpo soronpo commented Apr 22, 2026

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 #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.

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)

@soronpo soronpo changed the title #24914 Treat equivalent candidates as divergent in implicit search Fixes #24914 Treat equivalent candidates as divergent in implicit search Apr 22, 2026
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
@soronpo soronpo marked this pull request as ready for review April 23, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

large implicit search fails compilation

2 participants