Skip to content

Fix crash reporter, units and phases #17754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
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(this)

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: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/TreeChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ReTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

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