From c3540bbcfd1af6d8db5c6a8b646688954cd8b41f Mon Sep 17 00:00:00 2001 From: odersky Date: Sat, 20 Aug 2022 11:31:33 +0200 Subject: [PATCH] Provide better info on compiler crashes When encountering a compiler crash, show the current phase and the currently compiled unit. --- compiler/src/dotty/tools/dotc/core/Phases.scala | 5 ++++- compiler/src/dotty/tools/dotc/typer/TyperPhase.scala | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index aeb0d2697a0b..b5ad289554c9 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -308,7 +308,10 @@ object Phases { def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = units.map { unit => val unitCtx = ctx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports - run(using unitCtx) + try run(using unitCtx) + catch case ex: Throwable => + println(s"$ex while running $phaseName on $unit") + throw ex unitCtx.compilationUnit } diff --git a/compiler/src/dotty/tools/dotc/typer/TyperPhase.scala b/compiler/src/dotty/tools/dotc/typer/TyperPhase.scala index 44eed484b823..60f0c043b435 100644 --- a/compiler/src/dotty/tools/dotc/typer/TyperPhase.scala +++ b/compiler/src/dotty/tools/dotc/typer/TyperPhase.scala @@ -38,8 +38,8 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase { } def typeCheck(using Context): Unit = monitor("typechecking") { + val unit = ctx.compilationUnit try - val unit = ctx.compilationUnit if !unit.suspended then unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree) typr.println("typed: " + unit.source) @@ -48,6 +48,9 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase { ctx.run.nn.suppressions.reportSuspendedMessages(unit.source) catch case ex: CompilationUnit.SuspendException => + case ex: Throwable => + println(s"$ex while typechecking $unit") + throw ex } def javaCheck(using Context): Unit = monitor("checking java") {