@@ -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.
@@ -475,20 +476,25 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
475476
476477object Run {
477478
479+ case class SubPhase (val name : String ):
480+ override def toString : String = name
481+
478482 class SubPhases (val phase : Phase ):
479483 require(phase.exists)
480484
481485 private def baseName : String = phase match
482486 case phase : MegaPhase => phase.shortPhaseName
483487 case phase => phase.phaseName
484488
485- val all = IArray .from(phase.subPhases.map(sub => s " $baseName ( $sub) " ))
489+ val all = IArray .from(phase.subPhases.map(sub => s " $baseName[ $sub] " ))
486490
487491 def next (using Context ): Option [SubPhases ] =
488492 val next0 = phase.megaPhase.next.megaPhase
489493 if next0.exists then Some (SubPhases (next0))
490494 else None
491495
496+ def size : Int = all.size
497+
492498 def subPhase (index : Int ) =
493499 if index < all.size then all(index)
494500 else baseName
@@ -510,14 +516,17 @@ object Run {
510516 private var nextPhaseName : String = uninitialized // initialized by enterPhase
511517
512518 /** Enter into a new real phase, setting the current and next (sub)phases */
513- private [ Run ] def enterPhase (newPhase : Phase )(using Context ): Unit =
519+ def enterPhase (newPhase : Phase )(using Context ): Unit =
514520 if newPhase ne currPhase then
515521 currPhase = newPhase
516522 subPhases = SubPhases (newPhase)
517523 tickSubphase()
518524
525+ def canAdvanceSubPhase : Boolean =
526+ currentCompletedSubtraversalCount + 1 < subPhases.size
527+
519528 /** Compute the current (sub)phase name and next (sub)phase name */
520- private [ Run ] def tickSubphase ()(using Context ): Unit =
529+ def tickSubphase ()(using Context ): Unit =
521530 val index = currentCompletedSubtraversalCount
522531 val s = subPhases
523532 currPhaseName = s.subPhase(index)
@@ -546,20 +555,20 @@ object Run {
546555 private def requireInitialized (): Unit =
547556 require((currPhase : Phase | Null ) != null , " enterPhase was not called" )
548557
549- private [ Run ] def checkCancellation (): Boolean =
558+ def checkCancellation (): Boolean =
550559 if Thread .interrupted() then cancel()
551560 isCancelled()
552561
553562 /** trace that we are beginning a unit in the current (sub)phase, unless cancelled */
554- private [ Run ] def tryEnterUnit (unit : CompilationUnit ): Boolean =
563+ def tryEnterUnit (unit : CompilationUnit ): Boolean =
555564 if checkCancellation() then false
556565 else
557566 requireInitialized()
558567 cb.informUnitStarting(currPhaseName, unit)
559568 true
560569
561570 /** trace the current progress out of the total, in the current (sub)phase, reporting the next (sub)phase */
562- private [ Run ] def refreshProgress ()(using Context ): Unit =
571+ def refreshProgress ()(using Context ): Unit =
563572 requireInitialized()
564573 val total = totalProgress()
565574 if total > 0 && ! cb.progress(currentProgress(), total, currPhaseName, nextPhaseName) then
@@ -581,8 +590,9 @@ object Run {
581590 def advanceUnit ()(using Context ): Unit =
582591 if run != null then run.doAdvanceUnit()
583592
584- def advanceSubPhase ()(using Context ): Unit =
585- if run != null then run.doAdvanceSubPhase()
593+ /** if there exists another subphase, switch to it and record progress */
594+ def enterNextSubphase ()(using Context ): Unit =
595+ if run != null then run.tryAdvanceSubPhase()
586596
587597 /** advance the late count and record progress in the current phase */
588598 def advanceLate ()(using Context ): Unit =
0 commit comments