Skip to content

Commit 949c69e

Browse files
committed
Fix crash reporter, units and phases
1 parent d0b790e commit 949c69e

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
308308

309309
private def printTree(last: PrintedTree)(using Context): PrintedTree = {
310310
val unit = ctx.compilationUnit
311-
val fusedPhase = ctx.phase.prevMega
311+
val fusedPhase = ctx.phase.prev.megaPhase
312312
val echoHeader = f"[[syntax trees at end of $fusedPhase%25s]] // ${unit.source}"
313313
val tree = if ctx.isAfterTyper then unit.tpdTree else unit.untpdTree
314314
val treeString = fusedPhase.show(tree)

compiler/src/dotty/tools/dotc/core/Phases.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ object Phases {
321321
def run(using Context): Unit
322322

323323
/** @pre `isRunnable` returns true */
324-
def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
324+
def runOn(units: List[CompilationUnit])(using runCtx: Context): List[CompilationUnit] =
325325
units.map { unit =>
326-
val unitCtx = ctx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports
327-
try run(using unitCtx)
326+
given unitCtx: Context = runCtx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports
327+
try run
328328
catch case ex: Throwable if !ctx.run.enrichedErrorMessage =>
329329
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
330330
throw ex
@@ -425,8 +425,8 @@ object Phases {
425425
final def prev: Phase =
426426
if (id > FirstPhaseId) myBase.phases(start - 1) else NoPhase
427427

428-
final def prevMega(using Context): Phase =
429-
ctx.base.fusedContaining(ctx.phase.prev)
428+
final def megaPhase(using Context): Phase =
429+
ctx.base.fusedContaining(this)
430430

431431
final def next: Phase =
432432
if (hasNext) myBase.phases(end + 1) else NoPhase
@@ -439,8 +439,8 @@ object Phases {
439439
final def monitor(doing: String)(body: => Unit)(using Context): Unit =
440440
try body
441441
catch
442-
case NonFatal(ex) =>
443-
report.echo(s"exception occurred while $doing ${ctx.compilationUnit}")
442+
case NonFatal(ex) if !ctx.run.enrichedErrorMessage =>
443+
report.echo(ctx.run.enrichErrorMessage(s"exception occurred while $doing ${ctx.compilationUnit}"))
444444
throw ex
445445

446446
override def toString: String = phaseName

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ object report:
151151

152152
val info1 = formatExplain(List(
153153
"while compiling" -> ctx.compilationUnit,
154-
"during phase" -> ctx.phase.prevMega,
154+
"during phase" -> ctx.phase.megaPhase,
155155
"mode" -> ctx.mode,
156156
"library version" -> scala.util.Properties.versionString,
157157
"compiler version" -> dotty.tools.dotc.config.Properties.versionString,

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class TreeChecker extends Phase with SymTransformer {
8989
if (ctx.phaseId <= erasurePhase.id) {
9090
val initial = symd.initial
9191
assert(symd == initial || symd.signature == initial.signature,
92-
i"""Signature of ${sym} in ${sym.ownersIterator.toList}%, % changed at phase ${ctx.phase.prevMega}
92+
i"""Signature of ${sym} in ${sym.ownersIterator.toList}%, % changed at phase ${ctx.phase.prev.megaPhase}
9393
|Initial info: ${initial.info}
9494
|Initial sig : ${initial.signature}
9595
|Current info: ${symd.info}
@@ -108,7 +108,7 @@ class TreeChecker extends Phase with SymTransformer {
108108
check(ctx.base.allPhases.toIndexedSeq, ctx)
109109

110110
def check(phasesToRun: Seq[Phase], ctx: Context): Tree = {
111-
val fusedPhase = ctx.phase.prevMega(using ctx)
111+
val fusedPhase = ctx.phase.prev.megaPhase(using ctx)
112112
report.echo(s"checking ${ctx.compilationUnit} after phase ${fusedPhase}")(using ctx)
113113

114114
inContext(ctx) {
@@ -129,7 +129,7 @@ class TreeChecker extends Phase with SymTransformer {
129129
catch {
130130
case NonFatal(ex) => //TODO CHECK. Check that we are bootstrapped
131131
inContext(checkingCtx) {
132-
println(i"*** error while checking ${ctx.compilationUnit} after phase ${ctx.phase.prevMega(using ctx)} ***")
132+
println(i"*** error while checking ${ctx.compilationUnit} after phase ${ctx.phase.prev.megaPhase(using ctx)} ***")
133133
}
134134
throw ex
135135
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class ReTyper(nestingLevel: Int = 0) extends Typer(nestingLevel) with ReChecking
145145
override def typedUnadapted(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree =
146146
try super.typedUnadapted(tree, pt, locked)
147147
catch case NonFatal(ex) if ctx.phase != Phases.typerPhase && ctx.phase != Phases.inliningPhase && !ctx.run.enrichedErrorMessage =>
148-
val treeStr = tree.show(using ctx.withPhase(ctx.phase.prevMega))
148+
val treeStr = tree.show(using ctx.withPhase(ctx.phase.prev.megaPhase))
149149
println(ctx.run.enrichErrorMessage(s"exception while retyping $treeStr of class ${tree.className} # ${tree.uniqueId}"))
150150
throw ex
151151

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ class TyperPhase(addRootImports: Boolean = true) extends Phase {
4646
record("retained untyped trees", unit.untpdTree.treeSize)
4747
record("retained typed trees after typer", unit.tpdTree.treeSize)
4848
ctx.run.nn.suppressions.reportSuspendedMessages(unit.source)
49-
catch
50-
case ex: CompilationUnit.SuspendException =>
51-
case ex: Throwable =>
52-
println(s"$ex while typechecking $unit")
53-
throw ex
49+
catch case _: CompilationUnit.SuspendException => ()
5450
}
5551

5652
def javaCheck(using Context): Unit = monitor("checking java") {

0 commit comments

Comments
 (0)