@@ -220,14 +220,15 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
220220 // no subphases were ran, remove traversals from expected total
221221 progress.totalTraversals -= currentPhase.traversals
222222
223- private def doAdvanceSubPhase ()(using Context ): Unit =
223+ private def tryAdvanceSubPhase ()(using Context ): Unit =
224224 trackProgress : progress =>
225- progress.currentUnitCount = 0 // reset unit count in current (sub)phase
226- progress.seenPhaseCount += 1 // trace that we've seen a (sub)phase
227- progress.completedTraversalCount += 1 // add an extra traversal now that we completed a (sub)phase
228- progress.currentCompletedSubtraversalCount += 1 // record that we've seen a subphase
229- if ! progress.isCancelled() then
230- progress.tickSubphase()
225+ if progress.canAdvanceSubPhase then
226+ progress.currentUnitCount = 0 // reset unit count in current (sub)phase
227+ progress.seenPhaseCount += 1 // trace that we've seen a (sub)phase
228+ progress.completedTraversalCount += 1 // add an extra traversal now that we completed a (sub)phase
229+ progress.currentCompletedSubtraversalCount += 1 // record that we've seen a subphase
230+ if ! progress.isCancelled() then
231+ progress.tickSubphase()
231232
232233 /** Will be set to true if any of the compiled compilation units contains
233234 * a pureFunctions language import.
@@ -476,20 +477,25 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
476477
477478object Run {
478479
480+ case class SubPhase (val name : String ):
481+ override def toString : String = name
482+
479483 class SubPhases (val phase : Phase ):
480484 require(phase.exists)
481485
482486 private def baseName : String = phase match
483487 case phase : MegaPhase => phase.shortPhaseName
484488 case phase => phase.phaseName
485489
486- val all = IArray .from(phase.subPhases.map(sub => s " $baseName ( $sub) " ))
490+ val all = IArray .from(phase.subPhases.map(sub => s " $baseName[ $sub] " ))
487491
488492 def next (using Context ): Option [SubPhases ] =
489493 val next0 = phase.megaPhase.next.megaPhase
490494 if next0.exists then Some (SubPhases (next0))
491495 else None
492496
497+ def size : Int = all.size
498+
493499 def subPhase (index : Int ) =
494500 if index < all.size then all(index)
495501 else baseName
@@ -511,14 +517,17 @@ object Run {
511517 private var nextPhaseName : String = uninitialized // initialized by enterPhase
512518
513519 /** Enter into a new real phase, setting the current and next (sub)phases */
514- private [ Run ] def enterPhase (newPhase : Phase )(using Context ): Unit =
520+ def enterPhase (newPhase : Phase )(using Context ): Unit =
515521 if newPhase ne currPhase then
516522 currPhase = newPhase
517523 subPhases = SubPhases (newPhase)
518524 tickSubphase()
519525
526+ def canAdvanceSubPhase : Boolean =
527+ currentCompletedSubtraversalCount + 1 < subPhases.size
528+
520529 /** Compute the current (sub)phase name and next (sub)phase name */
521- private [ Run ] def tickSubphase ()(using Context ): Unit =
530+ def tickSubphase ()(using Context ): Unit =
522531 val index = currentCompletedSubtraversalCount
523532 val s = subPhases
524533 currPhaseName = s.subPhase(index)
@@ -547,20 +556,20 @@ object Run {
547556 private def requireInitialized (): Unit =
548557 require((currPhase : Phase | Null ) != null , " enterPhase was not called" )
549558
550- private [ Run ] def checkCancellation (): Boolean =
559+ def checkCancellation (): Boolean =
551560 if Thread .interrupted() then cancel()
552561 isCancelled()
553562
554563 /** trace that we are beginning a unit in the current (sub)phase, unless cancelled */
555- private [ Run ] def tryEnterUnit (unit : CompilationUnit ): Boolean =
564+ def tryEnterUnit (unit : CompilationUnit ): Boolean =
556565 if checkCancellation() then false
557566 else
558567 requireInitialized()
559568 cb.informUnitStarting(currPhaseName, unit)
560569 true
561570
562571 /** trace the current progress out of the total, in the current (sub)phase, reporting the next (sub)phase */
563- private [ Run ] def refreshProgress ()(using Context ): Unit =
572+ def refreshProgress ()(using Context ): Unit =
564573 requireInitialized()
565574 val total = totalProgress()
566575 if total > 0 && ! cb.progress(currentProgress(), total, currPhaseName, nextPhaseName) then
@@ -582,8 +591,9 @@ object Run {
582591 def advanceUnit ()(using Context ): Unit =
583592 if run != null then run.doAdvanceUnit()
584593
585- def advanceSubPhase ()(using Context ): Unit =
586- if run != null then run.doAdvanceSubPhase()
594+ /** if there exists another subphase, switch to it and record progress */
595+ def enterNextSubphase ()(using Context ): Unit =
596+ if run != null then run.tryAdvanceSubPhase()
587597
588598 /** advance the late count and record progress in the current phase */
589599 def advanceLate ()(using Context ): Unit =
0 commit comments