Skip to content

Commit 5e3f11c

Browse files
committed
Implement cancellation
Add an `isCancelled` variable to `Run`. If this variable is true, `typed` and `typedImplicit` calls will return immediately.
1 parent e1360eb commit 5e3f11c

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ import scala.util.control.NonFatal
3131
/** A compiler run. Exports various methods to compile source files */
3232
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
3333

34+
/** If this variable is set to `true`, some core typer operations will
35+
* return immediately. Currently these early abort operatoons are
36+
* `Typer.typed` and `Implicits.typedImplicit`.
37+
*/
38+
var isCancelled = false
39+
3440
/** Produces the following contexts, from outermost to innermost
3541
*
3642
* bootStrap: A context with next available runId and a scope consisting of

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@ trait Implicits { self: Typer =>
14841484

14851485
/** Try to typecheck an implicit reference */
14861486
def typedImplicit(cand: Candidate, contextual: Boolean)(implicit ctx: Context): SearchResult = trace(i"typed implicit ${cand.ref}, pt = $pt, implicitsEnabled == ${ctx.mode is ImplicitsEnabled}", implicits, show = true) {
1487+
if ctx.run.isCancelled then return NoMatchingImplicitsFailure
14871488
record("typedImplicit")
14881489
val ref = cand.ref
14891490
val generated: Tree = tpd.ref(ref).withSpan(span.startPos)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,9 @@ class Typer extends Namer
22102210
if (tree.source != ctx.source && tree.source.exists)
22112211
typed(tree, pt, locked)(ctx.withSource(tree.source))
22122212
else
2213-
try adapt(typedUnadapted(tree, pt, locked), pt, locked)
2213+
try
2214+
if ctx.run.isCancelled then tree.withType(WildcardType)
2215+
else adapt(typedUnadapted(tree, pt, locked), pt, locked)
22142216
catch {
22152217
case ex: TypeError =>
22162218
errorTree(tree, ex, tree.sourcePos.focus)

0 commit comments

Comments
 (0)