Skip to content
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

Add debug help to find out what's compiling #22522

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 22 additions & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Run.Progress
import scala.compiletime.uninitialized
import dotty.tools.dotc.transform.MegaPhase
import dotty.tools.dotc.transform.Pickler.AsyncTastyHolder
import java.util.{Timer, TimerTask}

/** A compiler run. Exports various methods to compile source files */
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {
Expand Down Expand Up @@ -382,7 +383,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
initializeAsyncTasty()
else () => {}

runPhases(allPhases = fusedPhases)(using runCtx)
showProgress(runPhases(allPhases = fusedPhases)(using runCtx))
cancelAsyncTasty()

ctx.reporter.finalizeReporting()
Expand Down Expand Up @@ -433,6 +434,26 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
process()(using unitCtx)
}

/** If set to true, prints every 10 seconds the files currently being compiled.
* Turn this flag on if you want to find out which test among many takes more time
* to compile than the others or causes an infinite loop in the compiler.
*/
private inline val debugPrintProgress = false

/** Period between progress reports, in ms */
private inline val printProgressPeriod = 10000

/** Shows progress if debugPrintProgress is true */
private def showProgress(proc: => Unit)(using Context): Unit =
if !debugPrintProgress then proc
else
val watchdog = new TimerTask:
def run() = println(i"[compiling $units]")
try
new Timer().schedule(watchdog, printProgressPeriod, printProgressPeriod)
proc
finally watchdog.cancel()

private sealed trait PrintedTree
private /*final*/ case class SomePrintedTree(phase: String, tree: String) extends PrintedTree
private object NoPrintedTree extends PrintedTree
Expand Down