@@ -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.
@@ -475,20 +476,25 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
475
476
476
477
object Run {
477
478
479
+ case class SubPhase (val name : String ):
480
+ override def toString : String = name
481
+
478
482
class SubPhases (val phase : Phase ):
479
483
require(phase.exists)
480
484
481
485
private def baseName : String = phase match
482
486
case phase : MegaPhase => phase.shortPhaseName
483
487
case phase => phase.phaseName
484
488
485
- val all = IArray .from(phase.subPhases.map(sub => s " $baseName ( $sub) " ))
489
+ val all = IArray .from(phase.subPhases.map(sub => s " $baseName[ $sub] " ))
486
490
487
491
def next (using Context ): Option [SubPhases ] =
488
492
val next0 = phase.megaPhase.next.megaPhase
489
493
if next0.exists then Some (SubPhases (next0))
490
494
else None
491
495
496
+ def size : Int = all.size
497
+
492
498
def subPhase (index : Int ) =
493
499
if index < all.size then all(index)
494
500
else baseName
@@ -510,14 +516,17 @@ object Run {
510
516
private var nextPhaseName : String = uninitialized // initialized by enterPhase
511
517
512
518
/** 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 =
514
520
if newPhase ne currPhase then
515
521
currPhase = newPhase
516
522
subPhases = SubPhases (newPhase)
517
523
tickSubphase()
518
524
525
+ def canAdvanceSubPhase : Boolean =
526
+ currentCompletedSubtraversalCount + 1 < subPhases.size
527
+
519
528
/** 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 =
521
530
val index = currentCompletedSubtraversalCount
522
531
val s = subPhases
523
532
currPhaseName = s.subPhase(index)
@@ -546,20 +555,20 @@ object Run {
546
555
private def requireInitialized (): Unit =
547
556
require((currPhase : Phase | Null ) != null , " enterPhase was not called" )
548
557
549
- private [ Run ] def checkCancellation (): Boolean =
558
+ def checkCancellation (): Boolean =
550
559
if Thread .interrupted() then cancel()
551
560
isCancelled()
552
561
553
562
/** 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 =
555
564
if checkCancellation() then false
556
565
else
557
566
requireInitialized()
558
567
cb.informUnitStarting(currPhaseName, unit)
559
568
true
560
569
561
570
/** 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 =
563
572
requireInitialized()
564
573
val total = totalProgress()
565
574
if total > 0 && ! cb.progress(currentProgress(), total, currPhaseName, nextPhaseName) then
@@ -581,8 +590,9 @@ object Run {
581
590
def advanceUnit ()(using Context ): Unit =
582
591
if run != null then run.doAdvanceUnit()
583
592
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()
586
596
587
597
/** advance the late count and record progress in the current phase */
588
598
def advanceLate ()(using Context ): Unit =
0 commit comments