Skip to content

Commit da04386

Browse files
committed
Store first phase ID directly
1 parent 16c17c0 commit da04386

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

compiler/src/dotty/tools/dotc/core/Periods.scala

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ object Periods {
3232
/** A period is a contiguous sequence of phase ids in some run.
3333
* It is coded as follows:
3434
*
35-
* sign, always 0 1 bit
36-
* runid 17 bits
37-
* last phase id: 7 bits
38-
* #phases before last: 7 bits
35+
* sign, always 0: 1 bit
36+
* run id: 17 bits
37+
* last phase id: 7 bits
38+
* first phase id: 7 bits
3939
*
4040
*/
4141
class Period private[Periods] (private val code: Int) extends AnyVal with Showable {
@@ -44,14 +44,13 @@ object Periods {
4444
def runId: RunId = code >>> (PhaseWidth * 2)
4545

4646
/** The phase identifier of this single-phase period. */
47-
def phaseId: PhaseId = (code >>> PhaseWidth) & PhaseMask
47+
def phaseId: PhaseId = firstPhaseId
4848

4949
/** The last phase of this period */
50-
def lastPhaseId: PhaseId =
51-
(code >>> PhaseWidth) & PhaseMask
50+
def lastPhaseId: PhaseId = (code >>> PhaseWidth) & PhaseMask
5251

5352
/** The first phase of this period */
54-
def firstPhaseId: PhaseId = lastPhaseId - (code & PhaseMask)
53+
def firstPhaseId: PhaseId = code & PhaseMask
5554

5655
def containsPhaseId(id: PhaseId): Boolean = firstPhaseId <= id && id <= lastPhaseId
5756

@@ -84,10 +83,10 @@ object Periods {
8483
this.lastPhaseId max that.lastPhaseId)
8584

8685
inline def <(that: Period): Boolean =
87-
this.code < that.code
86+
this.runId < that.runId || (this.runId == that.runId && this.lastPhaseId < that.firstPhaseId)
8887

8988
inline def >(that: Period): Boolean =
90-
this.code > that.code
89+
this.runId > that.runId || (this.runId == that.runId && this.firstPhaseId > that.lastPhaseId)
9190

9291
def toText(p: Printer): Text =
9392
inContext(p.printerContext):
@@ -117,11 +116,11 @@ object Periods {
117116

118117
/** The single-phase period consisting of given run id and phase id */
119118
def apply(rid: RunId, pid: PhaseId): Period =
120-
new Period(((rid << PhaseWidth) | pid) << PhaseWidth)
119+
new Period((((rid << PhaseWidth) | pid) << PhaseWidth) | pid)
121120

122121
/** The period consisting of given run id, and lo/hi phase ids */
123122
def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period =
124-
new Period(((rid << PhaseWidth) | hiPid) << PhaseWidth | (hiPid - loPid))
123+
new Period((((rid << PhaseWidth) | hiPid) << PhaseWidth) | loPid)
125124

126125
/** The interval consisting of all periods of given run id */
127126
def allInRun(rid: RunId): Period =

0 commit comments

Comments
 (0)