From 949c69e07eb41daea7488805b330ba483b71eb97 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 1 Jun 2023 17:13:14 +0100 Subject: [PATCH] Fix crash reporter, units and phases --- compiler/src/dotty/tools/dotc/Run.scala | 2 +- compiler/src/dotty/tools/dotc/core/Phases.scala | 14 +++++++------- compiler/src/dotty/tools/dotc/report.scala | 2 +- .../dotty/tools/dotc/transform/TreeChecker.scala | 6 +++--- compiler/src/dotty/tools/dotc/typer/ReTyper.scala | 2 +- .../src/dotty/tools/dotc/typer/TyperPhase.scala | 6 +----- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index 944ae794c94f..27f13f63783d 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -308,7 +308,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint private def printTree(last: PrintedTree)(using Context): PrintedTree = { val unit = ctx.compilationUnit - val fusedPhase = ctx.phase.prevMega + val fusedPhase = ctx.phase.prev.megaPhase val echoHeader = f"[[syntax trees at end of $fusedPhase%25s]] // ${unit.source}" val tree = if ctx.isAfterTyper then unit.tpdTree else unit.untpdTree val treeString = fusedPhase.show(tree) diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index 3c4c45ab254a..2a3828004525 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -321,10 +321,10 @@ object Phases { def run(using Context): Unit /** @pre `isRunnable` returns true */ - def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = + def runOn(units: List[CompilationUnit])(using runCtx: Context): List[CompilationUnit] = units.map { unit => - val unitCtx = ctx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports - try run(using unitCtx) + given unitCtx: Context = runCtx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports + try run catch case ex: Throwable if !ctx.run.enrichedErrorMessage => println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit")) throw ex @@ -425,8 +425,8 @@ object Phases { final def prev: Phase = if (id > FirstPhaseId) myBase.phases(start - 1) else NoPhase - final def prevMega(using Context): Phase = - ctx.base.fusedContaining(ctx.phase.prev) + final def megaPhase(using Context): Phase = + ctx.base.fusedContaining(this) final def next: Phase = if (hasNext) myBase.phases(end + 1) else NoPhase @@ -439,8 +439,8 @@ object Phases { final def monitor(doing: String)(body: => Unit)(using Context): Unit = try body catch - case NonFatal(ex) => - report.echo(s"exception occurred while $doing ${ctx.compilationUnit}") + case NonFatal(ex) if !ctx.run.enrichedErrorMessage => + report.echo(ctx.run.enrichErrorMessage(s"exception occurred while $doing ${ctx.compilationUnit}")) throw ex override def toString: String = phaseName diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index 38f2ab347c4c..99aa09fd3958 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -151,7 +151,7 @@ object report: val info1 = formatExplain(List( "while compiling" -> ctx.compilationUnit, - "during phase" -> ctx.phase.prevMega, + "during phase" -> ctx.phase.megaPhase, "mode" -> ctx.mode, "library version" -> scala.util.Properties.versionString, "compiler version" -> dotty.tools.dotc.config.Properties.versionString, diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index fcb20ea920e9..2869819ecca5 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -89,7 +89,7 @@ class TreeChecker extends Phase with SymTransformer { if (ctx.phaseId <= erasurePhase.id) { val initial = symd.initial assert(symd == initial || symd.signature == initial.signature, - i"""Signature of ${sym} in ${sym.ownersIterator.toList}%, % changed at phase ${ctx.phase.prevMega} + i"""Signature of ${sym} in ${sym.ownersIterator.toList}%, % changed at phase ${ctx.phase.prev.megaPhase} |Initial info: ${initial.info} |Initial sig : ${initial.signature} |Current info: ${symd.info} @@ -108,7 +108,7 @@ class TreeChecker extends Phase with SymTransformer { check(ctx.base.allPhases.toIndexedSeq, ctx) def check(phasesToRun: Seq[Phase], ctx: Context): Tree = { - val fusedPhase = ctx.phase.prevMega(using ctx) + val fusedPhase = ctx.phase.prev.megaPhase(using ctx) report.echo(s"checking ${ctx.compilationUnit} after phase ${fusedPhase}")(using ctx) inContext(ctx) { @@ -129,7 +129,7 @@ class TreeChecker extends Phase with SymTransformer { catch { case NonFatal(ex) => //TODO CHECK. Check that we are bootstrapped inContext(checkingCtx) { - println(i"*** error while checking ${ctx.compilationUnit} after phase ${ctx.phase.prevMega(using ctx)} ***") + println(i"*** error while checking ${ctx.compilationUnit} after phase ${ctx.phase.prev.megaPhase(using ctx)} ***") } throw ex } diff --git a/compiler/src/dotty/tools/dotc/typer/ReTyper.scala b/compiler/src/dotty/tools/dotc/typer/ReTyper.scala index 1fa6e967fbe1..9d4e25cd6577 100644 --- a/compiler/src/dotty/tools/dotc/typer/ReTyper.scala +++ b/compiler/src/dotty/tools/dotc/typer/ReTyper.scala @@ -145,7 +145,7 @@ class ReTyper(nestingLevel: Int = 0) extends Typer(nestingLevel) with ReChecking override def typedUnadapted(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree = try super.typedUnadapted(tree, pt, locked) catch case NonFatal(ex) if ctx.phase != Phases.typerPhase && ctx.phase != Phases.inliningPhase && !ctx.run.enrichedErrorMessage => - val treeStr = tree.show(using ctx.withPhase(ctx.phase.prevMega)) + val treeStr = tree.show(using ctx.withPhase(ctx.phase.prev.megaPhase)) println(ctx.run.enrichErrorMessage(s"exception while retyping $treeStr of class ${tree.className} # ${tree.uniqueId}")) throw ex diff --git a/compiler/src/dotty/tools/dotc/typer/TyperPhase.scala b/compiler/src/dotty/tools/dotc/typer/TyperPhase.scala index 60f0c043b435..f0218413d6ab 100644 --- a/compiler/src/dotty/tools/dotc/typer/TyperPhase.scala +++ b/compiler/src/dotty/tools/dotc/typer/TyperPhase.scala @@ -46,11 +46,7 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase { record("retained untyped trees", unit.untpdTree.treeSize) record("retained typed trees after typer", unit.tpdTree.treeSize) ctx.run.nn.suppressions.reportSuspendedMessages(unit.source) - catch - case ex: CompilationUnit.SuspendException => - case ex: Throwable => - println(s"$ex while typechecking $unit") - throw ex + catch case _: CompilationUnit.SuspendException => () } def javaCheck(using Context): Unit = monitor("checking java") {