Skip to content

Commit b59afe8

Browse files
committed
Give more information when "search too large" is hit
- show what the root query was - under -explain, show the trace until the overflow occurred.
1 parent 31c1991 commit b59afe8

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ast.Trees
1818
import config.{Feature, ScalaVersion}
1919
import typer.ErrorReporting.{err, matchReductionAddendum}
2020
import typer.ProtoTypes.ViewProto
21+
import typer.Implicits.Candidate
2122
import scala.util.control.NonFatal
2223
import StdNames.nme
2324
import printing.Formatting.hl
@@ -2516,14 +2517,25 @@ import transform.SymUtils._
25162517
|""".stripMargin
25172518
}
25182519

2519-
class ImplicitSearchTooLargeWarning(limit: Int)(using Context) extends TypeMsg(ImplicitSearchTooLargeID):
2520+
class ImplicitSearchTooLargeWarning(limit: Int, openSearchPairs: List[(Candidate, Type)])(using Context)
2521+
extends TypeMsg(ImplicitSearchTooLargeID):
25202522
override def showAlways = true
2523+
def showQuery(query: (Candidate, Type)): String =
2524+
i" ${query._1.ref.symbol.showLocated} for ${query._2}}"
25212525
def msg =
25222526
em"""Implicit search problem too large.
25232527
|an implicit search was terminated with failure after trying $limit expressions.
2528+
|The root candidate for the search was:
2529+
|
2530+
|${showQuery(openSearchPairs.last)}
25242531
|
25252532
|You can change the behavior by setting the `-Ximplicit-search-limit` value.
25262533
|Smaller values cause the search to fail faster.
25272534
|Larger values might make a very large search problem succeed.
25282535
|"""
2529-
def explain = ""
2536+
def explain =
2537+
em"""The overflow happened with the following lists of tried expressions and target types,
2538+
|starting with the root query:
2539+
|
2540+
|${openSearchPairs.reverse.map(showQuery)}%\n%
2541+
"""

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ trait Implicits:
11451145
if result then
11461146
var c = ctx
11471147
while c.outer.typer eq ctx.typer do c = c.outer
1148-
report.warning(ImplicitSearchTooLargeWarning(limit), ctx.source.atSpan(span))(using c)
1148+
report.warning(ImplicitSearchTooLargeWarning(limit, h.openSearchPairs), ctx.source.atSpan(span))(using c)
11491149
else
11501150
h.root.nestedSearches = nestedSearches + 1
11511151
result

tests/neg-custom-args/i13838.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ longer explanation available when compiling with `-explain`
2121
| ^
2222
| Implicit search problem too large.
2323
| an implicit search was terminated with failure after trying 1000 expressions.
24+
| The root candidate for the search was:
25+
|
26+
| method catsSyntaxEq for ([_] =>> Any)[Foo[Any]]}
2427
|
2528
| You can change the behavior by setting the `-Ximplicit-search-limit` value.
2629
| Smaller values cause the search to fail faster.
2730
| Larger values might make a very large search problem succeed.
31+
32+
longer explanation available when compiling with `-explain`

0 commit comments

Comments
 (0)