@@ -220,14 +220,15 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
220
220
// no subphases were ran, remove traversals from expected total
221
221
progress.totalTraversals -= currentPhase.traversals
222
222
223
- private def doAdvanceSubPhase ()(using Context ): Unit =
223
+ private def tryAdvanceSubPhase ()(using Context ): Unit =
224
224
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()
231
232
232
233
/** Will be set to true if any of the compiled compilation units contains
233
234
* a pureFunctions language import.
@@ -476,20 +477,25 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
476
477
477
478
object Run {
478
479
480
+ case class SubPhase (val name : String ):
481
+ override def toString : String = name
482
+
479
483
class SubPhases (val phase : Phase ):
480
484
require(phase.exists)
481
485
482
486
private def baseName : String = phase match
483
487
case phase : MegaPhase => phase.shortPhaseName
484
488
case phase => phase.phaseName
485
489
486
- val all = IArray .from(phase.subPhases.map(sub => s " $baseName ( $sub) " ))
490
+ val all = IArray .from(phase.subPhases.map(sub => s " $baseName[ $sub] " ))
487
491
488
492
def next (using Context ): Option [SubPhases ] =
489
493
val next0 = phase.megaPhase.next.megaPhase
490
494
if next0.exists then Some (SubPhases (next0))
491
495
else None
492
496
497
+ def size : Int = all.size
498
+
493
499
def subPhase (index : Int ) =
494
500
if index < all.size then all(index)
495
501
else baseName
@@ -511,14 +517,17 @@ object Run {
511
517
private var nextPhaseName : String = uninitialized // initialized by enterPhase
512
518
513
519
/** 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 =
515
521
if newPhase ne currPhase then
516
522
currPhase = newPhase
517
523
subPhases = SubPhases (newPhase)
518
524
tickSubphase()
519
525
526
+ def canAdvanceSubPhase : Boolean =
527
+ currentCompletedSubtraversalCount + 1 < subPhases.size
528
+
520
529
/** 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 =
522
531
val index = currentCompletedSubtraversalCount
523
532
val s = subPhases
524
533
currPhaseName = s.subPhase(index)
@@ -547,20 +556,20 @@ object Run {
547
556
private def requireInitialized (): Unit =
548
557
require((currPhase : Phase | Null ) != null , " enterPhase was not called" )
549
558
550
- private [ Run ] def checkCancellation (): Boolean =
559
+ def checkCancellation (): Boolean =
551
560
if Thread .interrupted() then cancel()
552
561
isCancelled()
553
562
554
563
/** 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 =
556
565
if checkCancellation() then false
557
566
else
558
567
requireInitialized()
559
568
cb.informUnitStarting(currPhaseName, unit)
560
569
true
561
570
562
571
/** 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 =
564
573
requireInitialized()
565
574
val total = totalProgress()
566
575
if total > 0 && ! cb.progress(currentProgress(), total, currPhaseName, nextPhaseName) then
@@ -582,8 +591,9 @@ object Run {
582
591
def advanceUnit ()(using Context ): Unit =
583
592
if run != null then run.doAdvanceUnit()
584
593
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()
587
597
588
598
/** advance the late count and record progress in the current phase */
589
599
def advanceLate ()(using Context ): Unit =
0 commit comments