@@ -24,7 +24,7 @@ object Periods {
2424 /** Are all base types in the current period guaranteed to be the same as in period `p`? */
2525 def currentHasSameBaseTypesAs (p : Period )(using Context ): Boolean =
2626 val period = ctx.period
27- period.code == p.code ||
27+ period == p ||
2828 period.runId == p.runId &&
2929 unfusedPhases(period.phaseId).sameBaseTypesStartId ==
3030 unfusedPhases(p.phaseId).sameBaseTypesStartId
@@ -37,9 +37,8 @@ object Periods {
3737 * last phase id: 7 bits
3838 * #phases before last: 7 bits
3939 *
40- * // Dmitry: sign == 0 isn't actually always true, in some cases phaseId == -1 is used for shifts, that easily creates code < 0
4140 */
42- class Period ( val code : Int ) extends AnyVal with Showable {
41+ class Period private [ Periods ] ( private val code : Int ) extends AnyVal with Showable {
4342
4443 /** The run identifier of this period. */
4544 def runId : RunId = code >>> (PhaseWidth * 2 )
@@ -52,7 +51,7 @@ object Periods {
5251 (code >>> PhaseWidth ) & PhaseMask
5352
5453 /** The first phase of this period */
55- def firstPhaseId : Int = lastPhaseId - (code & PhaseMask )
54+ def firstPhaseId : PhaseId = lastPhaseId - (code & PhaseMask )
5655
5756 def containsPhaseId (id : PhaseId ): Boolean = firstPhaseId <= id && id <= lastPhaseId
5857
@@ -76,7 +75,7 @@ object Periods {
7675 // iff r1 == r2 & l1 >= l2 && l1 - d1 <= l2 - d2
7776 // q.e.d
7877 val lastDiff = (code - that.code) >>> PhaseWidth
79- lastDiff + (that.code & PhaseMask ) <= (this .code & PhaseMask )
78+ lastDiff + (that.code & PhaseMask ) <= (this .code & PhaseMask )
8079 }
8180
8281 /** Does this period overlap with given period? */
@@ -101,25 +100,31 @@ object Periods {
101100 this .firstPhaseId min that.firstPhaseId,
102101 this .lastPhaseId max that.lastPhaseId)
103102
103+ inline def < (that : Period ): Boolean =
104+ this .code < that.code
105+
106+ inline def > (that : Period ): Boolean =
107+ this .code > that.code
108+
104109 def toText (p : Printer ): Text =
105110 inContext(p.printerContext):
106111 this match
107- case Nowhere => " Nowhere"
108- case InitialPeriod => " InitialPeriod"
109- case InvalidPeriod => " InvalidPeriod"
110- case Period (NoRunId , 0 , PhaseMask ) => s " Period(NoRunId.all) "
111- case Period (runId, 0 , PhaseMask ) => s " Period( $runId.all) "
112- case Period (runId, p1, pn) if p1 == pn => s " Period( $runId. $p1( ${ctx.base.phases(p1)})) "
113- case Period (runId, p1, pn) => s " Period( $runId. $p1( ${ctx.base.phases(p1)})- $pn( ${ctx.base.phases(pn)})) "
112+ case Nowhere => " Nowhere"
113+ case InitialPeriod => " InitialPeriod"
114+ case InvalidPeriod => " InvalidPeriod"
115+ case Period (NoRunId , FirstPhaseId , MaxPossiblePhaseId ) => s " Period(NoRunId.all) "
116+ case Period (runId, FirstPhaseId , MaxPossiblePhaseId ) => s " Period( $runId.all) "
117+ case Period (runId, p1, pn) if p1 == pn => s " Period( $runId. $p1( ${ctx.base.phases(p1)})) "
118+ case Period (runId, p1, pn) => s " Period( $runId. $p1( ${ctx.base.phases(p1)})- $pn( ${ctx.base.phases(pn)})) "
114119
115120 override def toString : String = this match
116- case Nowhere => " Nowhere"
117- case InitialPeriod => " InitialPeriod"
118- case InvalidPeriod => " InvalidPeriod"
119- case Period (NoRunId , 0 , PhaseMask ) => s " Period(NoRunId.all) "
120- case Period (runId, 0 , PhaseMask ) => s " Period( $runId.all) "
121- case Period (runId, p1, pn) if p1 == pn => s " Period( $runId. $p1) "
122- case Period (runId, p1, pn) => s " Period( $runId. $p1- $pn) "
121+ case Nowhere => " Nowhere"
122+ case InitialPeriod => " InitialPeriod"
123+ case InvalidPeriod => " InvalidPeriod"
124+ case Period (NoRunId , FirstPhaseId , MaxPossiblePhaseId ) => s " Period(NoRunId.all) "
125+ case Period (runId, FirstPhaseId , MaxPossiblePhaseId ) => s " Period( $runId.all) "
126+ case Period (runId, p1, pn) if p1 == pn => s " Period( $runId. $p1) "
127+ case Period (runId, p1, pn) => s " Period( $runId. $p1- $pn) "
123128
124129 def == (that : Period ): Boolean = this .code == that.code
125130 def != (that : Period ): Boolean = this .code != that.code
@@ -137,7 +142,7 @@ object Periods {
137142
138143 /** The interval consisting of all periods of given run id */
139144 def allInRun (rid : RunId ): Period =
140- apply(rid, 0 , PhaseMask )
145+ apply(rid, FirstPhaseId , MaxPossiblePhaseId )
141146
142147 def unapply (p : Period ): Extractor = new Extractor (p.code)
143148
@@ -151,13 +156,6 @@ object Periods {
151156 }
152157 }
153158
154- inline val NowhereCode = 0
155- final val Nowhere : Period = new Period (NowhereCode )
156-
157- final val InitialPeriod : Period = Period (InitialRunId , FirstPhaseId )
158-
159- final val InvalidPeriod : Period = Period (NoRunId , NoPhaseId )
160-
161159 /** An ordinal number for compiler runs. First run has number 1. */
162160 type RunId = Int
163161 inline val NoRunId = 0
@@ -172,6 +170,11 @@ object Periods {
172170
173171 /** The number of bits needed to encode a phase identifier. */
174172 inline val PhaseWidth = 7
175- inline val PhaseMask = (1 << PhaseWidth ) - 1
173+ private inline val PhaseMask = (1 << PhaseWidth ) - 1
176174 inline val MaxPossiblePhaseId = PhaseMask
175+
176+ private inline val NowhereCode = 0
177+ final val Nowhere : Period = new Period (NowhereCode )
178+ final val InitialPeriod : Period = Period (InitialRunId , FirstPhaseId )
179+ final val InvalidPeriod : Period = Period (NoRunId , NoPhaseId )
177180}
0 commit comments