Skip to content

Commit f922858

Browse files
committed
Perf?
1 parent 6accf62 commit f922858

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

compiler/src/dotty/tools/backend/jvm/CoreBTypesFromSymbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ final class CoreBTypesFromSymbols(val ppa: PostProcessorFrontendAccess)(using va
211211
if (innerClassSym.isAnonymousClass || innerClassSym.isAnonymousFunction) None
212212
else {
213213
val original = innerClassSym.initial
214-
Some(atPhase(original.validFor.firstPhaseId)(innerClassSym.name).mangledString) // moduleSuffix for module classes
214+
Some(atPhase(original.validFor.lastPhaseId)(innerClassSym.name).mangledString) // moduleSuffix for module classes
215215
}
216216
}
217217

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ object DottyBackendInterface {
8080
// for example by specialization
8181
val original = toDenot(sym).initial
8282
val validity = original.validFor
83-
atPhase(validity.firstPhaseId) {
83+
atPhase(validity.lastPhaseId) {
8484
toDenot(sym).isStatic
8585
}
8686
}
@@ -90,7 +90,7 @@ object DottyBackendInterface {
9090
// it is very tricky in presence of classes(and anonymous classes) defined inside supper calls.
9191
if (sym.exists) {
9292
val validity = toDenot(sym).initial.validFor
93-
atPhase(validity.firstPhaseId) {
93+
atPhase(validity.lastPhaseId) {
9494
toDenot(sym).lexicallyEnclosingClass
9595
}
9696
} else NoSymbol

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ 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-
* run id: 17 bits
37-
* last phase id: 7 bits
38-
* first phase id: 7 bits
35+
* sign, always 0: 1 bit
36+
* run id: 17 bits
37+
* last phase id: 7 bits
38+
* #phases before last: 7 bits
3939
*
40+
* This encoding ensures the < and > operators can be delegated as-is to `code`, making them cheap.
4041
*/
4142
class Period private[Periods] (private val code: Int) extends AnyVal with Showable {
4243

@@ -47,7 +48,7 @@ object Periods {
4748
def lastPhaseId: PhaseId = (code >>> PhaseWidth) & PhaseMask
4849

4950
/** The first phase of this period */
50-
def firstPhaseId: PhaseId = code & PhaseMask
51+
def firstPhaseId: PhaseId = lastPhaseId - (code & PhaseMask)
5152

5253
def containsPhaseId(id: PhaseId): Boolean = firstPhaseId <= id && id <= lastPhaseId
5354

@@ -80,10 +81,10 @@ object Periods {
8081
this.lastPhaseId max that.lastPhaseId)
8182

8283
inline def <(that: Period): Boolean =
83-
this.runId < that.runId || (this.runId == that.runId && this.lastPhaseId < that.firstPhaseId)
84+
this.code < that.code
8485

8586
inline def >(that: Period): Boolean =
86-
this.runId > that.runId || (this.runId == that.runId && this.firstPhaseId > that.lastPhaseId)
87+
this.code > that.code
8788

8889
def toText(p: Printer): Text =
8990
inContext(p.printerContext):
@@ -113,11 +114,11 @@ object Periods {
113114

114115
/** The single-phase period consisting of given run id and phase id */
115116
def apply(rid: RunId, pid: PhaseId): Period =
116-
new Period((((rid << PhaseWidth) | pid) << PhaseWidth) | pid)
117+
new Period(((rid << PhaseWidth) | pid) << PhaseWidth)
117118

118119
/** The period consisting of given run id, and lo/hi phase ids */
119120
def apply(rid: RunId, loPid: PhaseId, hiPid: PhaseId): Period =
120-
new Period((((rid << PhaseWidth) | hiPid) << PhaseWidth) | loPid)
121+
new Period((((rid << PhaseWidth) | hiPid) << PhaseWidth) | (hiPid - loPid))
121122

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ object Phases {
4949

5050
def recordRecheckPhase(phase: Recheck): Unit =
5151
val id = phase.id
52-
assert(id < 64, s"Recheck phase with id $id outside permissible range 0..63")
52+
assert(id < 64, s"Recheck phase with id $id outside range 0..63, cannot use Long bits encoding")
5353
myRecheckPhaseIds |= (1L << id)
5454

5555
object SomePhase extends Phase {

0 commit comments

Comments
 (0)