aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-26 18:07:24 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-27 15:02:53 +0100
commitded9e61673261bf4534ee6b5a66ff9b5554a6ed0 (patch)
tree3f6bd9f906b7b5ea79d343c9d713223bc946274f /src/dotty/tools/dotc/core
parent97faee5a82b40b4c980c8cb222ff5ac4cb9083a4 (diff)
downloaddotty-ded9e61673261bf4534ee6b5a66ff9b5554a6ed0.tar.gz
dotty-ded9e61673261bf4534ee6b5a66ff9b5554a6ed0.tar.bz2
dotty-ded9e61673261bf4534ee6b5a66ff9b5554a6ed0.zip
Fix #95: Phases now have their own periods.
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala12
-rw-r--r--src/dotty/tools/dotc/core/Periods.scala2
-rw-r--r--src/dotty/tools/dotc/core/Phases.scala30
3 files changed, 29 insertions, 15 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index 12a83185e..8d083b29c 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -280,10 +280,14 @@ object Contexts {
final def withMode(mode: Mode): Context =
if (mode != this.mode) fresh.setMode(mode) else this
- final def withPhase(phase: PhaseId): Context =
- if (this.phaseId == phaseId) this else fresh.setPhase(phase)
+ /**
+ * This method will always return a phase period equal to phaseId, thus will never return squashed phases
+ */
+ final def withPhase(phaseId: PhaseId): Context =
+ if (this.phaseId == phaseId) this else fresh.setPhase(phaseId)
final def withPhase(phase: Phase): Context =
- withPhase(phase.id)
+ if (this.period == phase.period) this else fresh.setPhase(phase)
+
final def addMode(mode: Mode): Context = withMode(this.mode | mode)
final def maskMode(mode: Mode): Context = withMode(this.mode & mode)
@@ -330,7 +334,7 @@ object Contexts {
def setProperty(prop: (String, Any)): this.type = setMoreProperties(moreProperties + prop)
def setPhase(pid: PhaseId): this.type = setPeriod(Period(runId, pid))
- def setPhase(phase: Phase): this.type = setPhase(phase.id)
+ def setPhase(phase: Phase): this.type = setPeriod(Period(runId, phase.start, phase.end))
def setSetting[T](setting: Setting[T], value: T): this.type =
setSettings(setting.updateIn(sstate, value))
diff --git a/src/dotty/tools/dotc/core/Periods.scala b/src/dotty/tools/dotc/core/Periods.scala
index 370cc2b96..4ab04fad0 100644
--- a/src/dotty/tools/dotc/core/Periods.scala
+++ b/src/dotty/tools/dotc/core/Periods.scala
@@ -129,6 +129,8 @@ object Periods {
final val InitialPeriod = Period(InitialRunId, FirstPhaseId)
+ final val InvalidPeriod = Period(NoRunId, NoPhaseId)
+
/** An ordinal number for compiler runs. First run has number 1. */
type RunId = Int
final val NoRunId = 0
diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala
index 3de42fb4e..12e700521 100644
--- a/src/dotty/tools/dotc/core/Phases.scala
+++ b/src/dotty/tools/dotc/core/Phases.scala
@@ -12,13 +12,14 @@ import dotty.tools.dotc.transform.TreeTransforms.{TreeTransformer, TreeTransform
import dotty.tools.dotc.transform.PostTyperTransformers.PostTyperTransformer
import dotty.tools.dotc.transform.TreeTransforms
import TreeTransforms.Separator
+import Periods._
trait Phases {
self: Context =>
import Phases._
- def phase: Phase = base.phases(period.phaseId)
+ def phase: Phase = base.phases(period.firstPhaseId)
def phasesStack: List[Phase] =
if ((this eq NoContext) || !phase.exists) Nil
@@ -66,6 +67,7 @@ object Phases {
override def lastPhaseId(implicit ctx: Context) = id
}
+
/** Use the following phases in the order they are given.
* The list should never contain NoPhase.
* if squashing is enabled, phases in same subgroup will be squashed to single phase.
@@ -112,7 +114,7 @@ object Phases {
override protected def transformations: Array[TreeTransform] = transforms.toArray
}
squashedPhases += block
- block.init(this, phasess(i).head.id)
+ block.init(this, phasess(i).head.id, phasess(i).last.id)
} else squashedPhases += phasess(i).head
i += 1
}
@@ -171,7 +173,7 @@ object Phases {
def exists: Boolean = true
- private var myId: PhaseId = -1
+ private var myPeriod: Period = Periods.InvalidPeriod
private var myBase: ContextBase = null
private var myErasedTypes = false
private var myFlatClasses = false
@@ -181,32 +183,38 @@ object Phases {
* is reserved for NoPhase and the first real phase is at position 1.
* -1 if the phase is not installed in the context.
*/
- def id = myId
+ def id = myPeriod.firstPhaseId
+
+ def period = myPeriod
+ def start = myPeriod.firstPhaseId
+ def end = myPeriod.lastPhaseId
final def erasedTypes = myErasedTypes
final def flatClasses = myFlatClasses
final def refChecked = myRefChecked
- protected[Phases] def init(base: ContextBase, id: Int): Unit = {
- if (id >= FirstPhaseId)
- assert(myId == -1, s"phase $this has already been used once; cannot be reused")
+ protected[Phases] def init(base: ContextBase, start: Int, end:Int): Unit = {
+ if (start >= FirstPhaseId)
+ assert(myPeriod == Periods.InvalidPeriod, s"phase $this has already been used once; cannot be reused")
myBase = base
- myId = id
+ myPeriod = Period(start, end)
myErasedTypes = prev.name == erasureName || prev.erasedTypes
myFlatClasses = prev.name == flattenName || prev.flatClasses
myRefChecked = prev.name == refChecksName || prev.refChecked
}
+ protected[Phases] def init(base: ContextBase, id: Int): Unit = init(base, id, id)
+
final def <=(that: Phase)(implicit ctx: Context) =
exists && id <= that.id
final def prev: Phase =
- if (id > FirstPhaseId) myBase.phases(id - 1) else myBase.NoPhase
+ if (id > FirstPhaseId) myBase.phases(start - 1) else myBase.NoPhase
final def next: Phase =
- if (hasNext) myBase.phases(id + 1) else myBase.NoPhase
+ if (hasNext) myBase.phases(end + 1) else myBase.NoPhase
- final def hasNext = id >= FirstPhaseId && id + 1 < myBase.phases.length
+ final def hasNext = start >= FirstPhaseId && end + 1 < myBase.phases.length
final def iterator =
Iterator.iterate(this)(_.next) takeWhile (_.hasNext)