Skip to content

Commit a630e9e

Browse files
authored
Add debug help to find out what's compiling (#22522)
We sometimes see that compiling test suites takes a long time or loops infinitely. Then the first problem is to find out which test source caused this behavior in the compiler. This can now be shown by turning on a new flag `debugPrintProgress` in `Run.scala`. If that flag is set to `true`, the compiler will print out each 10 seconds the list of currently compiled source files.
2 parents 0dac4c3 + 702dba3 commit a630e9e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Run.Progress
3838
import scala.compiletime.uninitialized
3939
import dotty.tools.dotc.transform.MegaPhase
4040
import dotty.tools.dotc.transform.Pickler.AsyncTastyHolder
41+
import java.util.{Timer, TimerTask}
4142

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

385-
runPhases(allPhases = fusedPhases)(using runCtx)
386+
showProgress(runPhases(allPhases = fusedPhases)(using runCtx))
386387
cancelAsyncTasty()
387388

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

437+
/** If set to true, prints every 10 seconds the files currently being compiled.
438+
* Turn this flag on if you want to find out which test among many takes more time
439+
* to compile than the others or causes an infinite loop in the compiler.
440+
*/
441+
private inline val debugPrintProgress = false
442+
443+
/** Period between progress reports, in ms */
444+
private inline val printProgressPeriod = 10000
445+
446+
/** Shows progress if debugPrintProgress is true */
447+
private def showProgress(proc: => Unit)(using Context): Unit =
448+
if !debugPrintProgress then proc
449+
else
450+
val watchdog = new TimerTask:
451+
def run() = println(i"[compiling $units]")
452+
try
453+
new Timer().schedule(watchdog, printProgressPeriod, printProgressPeriod)
454+
proc
455+
finally watchdog.cancel()
456+
436457
private sealed trait PrintedTree
437458
private /*final*/ case class SomePrintedTree(phase: String, tree: String) extends PrintedTree
438459
private object NoPrintedTree extends PrintedTree

0 commit comments

Comments
 (0)