Skip to content

Commit

Permalink
Fix crash reporter, units and phases
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jun 20, 2023
1 parent d0b790e commit 739a310
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ 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
given unitCtx: Context = runCtx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports
try run(using unitCtx)
catch case ex: Throwable if !ctx.run.enrichedErrorMessage =>
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
Expand Down Expand Up @@ -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(ctx.phase)

final def next: Phase =
if (hasNext) myBase.phases(end + 1) else NoPhase
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions compiler/src/dotty/tools/dotc/typer/TyperPhase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 739a310

Please sign in to comment.