@@ -31,13 +31,14 @@ import transform.SymUtils._
31
31
import transform .TypeUtils ._
32
32
import transform .SyntheticMembers ._
33
33
import Hashable ._
34
- import util .{Property , SourceFile , NoSource , Scheduler }
34
+ import util .{Property , SourceFile , NoSource }
35
35
import config .Config
36
36
import config .Printers .{implicits , implicitsDetailed }
37
37
import collection .mutable
38
38
import reporting .trace
39
39
import annotation .tailrec
40
40
import scala .util .control .NonFatal
41
+ import java .util .{Timer , TimerTask }
41
42
42
43
import scala .annotation .internal .sharable
43
44
import scala .annotation .threadUnsafe
@@ -68,7 +69,10 @@ object Implicits {
68
69
final val Extension = 4
69
70
}
70
71
71
- val testOneImplicitTimeOut = 1000
72
+ /** Timeout to test a single implicit value as a suggestion, in ms */
73
+ val testOneImplicitTimeOut = 500
74
+
75
+ /** Global timeout to stop looking for further implicit suggestions, in ms */
72
76
val suggestImplicitTimeOut = 10000
73
77
74
78
/** A common base class of contextual implicits and of-type implicits which
@@ -531,19 +535,21 @@ object Implicits {
531
535
else Nil
532
536
533
537
def search (given ctx : Context ): List [TermRef ] =
534
- val scheduler = new Scheduler ()
538
+ val timer = new Timer ()
535
539
val deadLine = System .currentTimeMillis() + suggestImplicitTimeOut
536
540
537
541
def test (ref : TermRef )(given Context ): Boolean =
538
542
System .currentTimeMillis < deadLine
539
543
&& {
540
- scheduler.scheduleAfter(testOneImplicitTimeOut) {
541
- implicitsDetailed.println(i " Cancelling test of $ref when making suggestions for error in ${ctx.source}" )
542
- ctx.run.isCancelled = true
544
+ val task = new TimerTask {
545
+ def run () =
546
+ implicitsDetailed.println(i " Cancelling test of $ref when making suggestions for error in ${ctx.source}" )
547
+ ctx.run.isCancelled = true
543
548
}
549
+ timer.schedule(task, testOneImplicitTimeOut)
544
550
try qualifies(ref)
545
551
finally
546
- scheduler .cancel()
552
+ task .cancel()
547
553
ctx.run.isCancelled = false
548
554
}
549
555
@@ -552,7 +558,7 @@ object Implicits {
552
558
.filterNot(root => defn.RootImportTypes .exists(_.symbol == root.symbol))
553
559
// don't suggest things that are imported by default
554
560
.flatMap(_.implicitMembers.filter(test))
555
- finally scheduler.shutdown ()
561
+ finally timer.cancel ()
556
562
end search
557
563
end suggestions
558
564
}
@@ -777,8 +783,9 @@ trait Implicits { self: Typer =>
777
783
}
778
784
779
785
/** An addendum to an error message where the error might be fixed
780
- * be some implicit value of type `pt` that is however not found.
781
- * The addendum suggests suggests implicit imports that might fix the problem.
786
+ * by some implicit value of type `pt` that is however not found.
787
+ * The addendum suggests given imports that might fix the problem.
788
+ * If there's nothing to suggest, an empty string is returned.
782
789
*/
783
790
override def implicitSuggestionsFor (pt : Type )(given ctx : Context ): String =
784
791
val suggestedRefs =
0 commit comments