@@ -31,7 +31,7 @@ import transform.SymUtils._
3131import transform .TypeUtils ._
3232import transform .SyntheticMembers ._
3333import Hashable ._
34- import util .{Property , SourceFile , NoSource }
34+ import util .{Property , SourceFile , NoSource , Scheduler }
3535import config .Config
3636import config .Printers .{implicits , implicitsDetailed }
3737import collection .mutable
@@ -68,6 +68,9 @@ object Implicits {
6868 final val Extension = 4
6969 }
7070
71+ val testOneImplicitTimeOut = 1000
72+ val suggestImplicitTimeOut = 10000
73+
7174 /** A common base class of contextual implicits and of-type implicits which
7275 * represents a set of references to implicit definitions.
7376 */
@@ -528,10 +531,29 @@ object Implicits {
528531 else Nil
529532
530533 def search (given ctx : Context ): List [TermRef ] =
531- roots
532- .filterNot(root => defn.RootImportTypes .exists(_.symbol == root.symbol))
534+ val scheduler = new Scheduler ()
535+ val deadLine = System .currentTimeMillis() + suggestImplicitTimeOut
536+
537+ def test (ref : TermRef )(given Context ): Boolean =
538+ System .currentTimeMillis < deadLine
539+ && {
540+ scheduler.scheduleAfter(testOneImplicitTimeOut) {
541+ println(i " Cancelling test of $ref when making suggestions for error in ${ctx.source}" )
542+ ctx.run.isCancelled = true
543+ }
544+ try qualifies(ref)
545+ finally
546+ scheduler.cancel()
547+ ctx.run.isCancelled = false
548+ }
549+
550+ try
551+ roots
552+ .filterNot(root => defn.RootImportTypes .exists(_.symbol == root.symbol))
533553 // don't suggest things that are imported by default
534- .flatMap(_.implicitMembers.filter(qualifies))
554+ .flatMap(_.implicitMembers.filter(test))
555+ finally scheduler.shutdown()
556+ end search
535557 end suggestions
536558}
537559
0 commit comments