Skip to content

Commit 51f19ec

Browse files
committed
Use java.util.Timer
Also, implement other review suggestions
1 parent 2ccec1f commit 51f19ec

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

compiler/src/dotty/tools/dotc/Run.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import scala.util.control.NonFatal
3232
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
3333

3434
/** If this variable is set to `true`, some core typer operations will
35-
* return immediately. Currently these early abort operatoons are
35+
* return immediately. Currently these early abort operations are
3636
* `Typer.typed` and `Implicits.typedImplicit`.
3737
*/
3838
@volatile var isCancelled = false

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

+17-10
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ import transform.SymUtils._
3131
import transform.TypeUtils._
3232
import transform.SyntheticMembers._
3333
import Hashable._
34-
import util.{Property, SourceFile, NoSource, Scheduler}
34+
import util.{Property, SourceFile, NoSource}
3535
import config.Config
3636
import config.Printers.{implicits, implicitsDetailed}
3737
import collection.mutable
3838
import reporting.trace
3939
import annotation.tailrec
4040
import scala.util.control.NonFatal
41+
import java.util.{Timer, TimerTask}
4142

4243
import scala.annotation.internal.sharable
4344
import scala.annotation.threadUnsafe
@@ -68,7 +69,10 @@ object Implicits {
6869
final val Extension = 4
6970
}
7071

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 */
7276
val suggestImplicitTimeOut = 10000
7377

7478
/** A common base class of contextual implicits and of-type implicits which
@@ -531,19 +535,21 @@ object Implicits {
531535
else Nil
532536

533537
def search(given ctx: Context): List[TermRef] =
534-
val scheduler = new Scheduler()
538+
val timer = new Timer()
535539
val deadLine = System.currentTimeMillis() + suggestImplicitTimeOut
536540

537541
def test(ref: TermRef)(given Context): Boolean =
538542
System.currentTimeMillis < deadLine
539543
&& {
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
543548
}
549+
timer.schedule(task, testOneImplicitTimeOut)
544550
try qualifies(ref)
545551
finally
546-
scheduler.cancel()
552+
task.cancel()
547553
ctx.run.isCancelled = false
548554
}
549555

@@ -552,7 +558,7 @@ object Implicits {
552558
.filterNot(root => defn.RootImportTypes.exists(_.symbol == root.symbol))
553559
// don't suggest things that are imported by default
554560
.flatMap(_.implicitMembers.filter(test))
555-
finally scheduler.shutdown()
561+
finally timer.cancel()
556562
end search
557563
end suggestions
558564
}
@@ -777,8 +783,9 @@ trait Implicits { self: Typer =>
777783
}
778784

779785
/** 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.
782789
*/
783790
override def implicitSuggestionsFor(pt: Type)(given ctx: Context): String =
784791
val suggestedRefs =

tests/neg/missing-implicit.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Predef.{byte2Byte => _}
1+
import Predef.{byte2Byte => _, _}
22
import math.Numeric
33

44
def consume[T: Numeric](xs: List[T], limit: T): List[T] = xs match

0 commit comments

Comments
 (0)