aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-31 21:29:28 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-04-01 14:24:05 +0200
commitf651ca5ed1caf70aabe0d803949f430d08bf3915 (patch)
treeeb98347f653f47d6bb8e6e67f10af54410c65c24 /src/dotty/tools
parent2033b5607a41b77590b8d23bf5c40c906a0b42e7 (diff)
downloaddotty-f651ca5ed1caf70aabe0d803949f430d08bf3915.tar.gz
dotty-f651ca5ed1caf70aabe0d803949f430d08bf3915.tar.bz2
dotty-f651ca5ed1caf70aabe0d803949f430d08bf3915.zip
Documentation and a bit of cleanup.
Added documentation for non-trivial logic in Contexts, Phases and TreeTransforms. Removed redundant vars and casts
Diffstat (limited to 'src/dotty/tools')
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala5
-rw-r--r--src/dotty/tools/dotc/core/Phases.scala58
-rw-r--r--src/dotty/tools/dotc/core/transform/Erasure.scala2
-rw-r--r--src/dotty/tools/dotc/transform/TreeTransform.scala7
-rw-r--r--src/dotty/tools/dotc/util/SimpleMap.scala4
5 files changed, 46 insertions, 30 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index b0214a631..ac27b74c7 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -181,6 +181,11 @@ object Contexts {
protected def searchHistory_= (searchHistory: SearchHistory) = _searchHistory = searchHistory
def searchHistory: SearchHistory = _searchHistory
+ /** Those fields are used to cache phases created in withPhase.
+ * phasedCtx is first phase with altered phase ever requested.
+ * phasedCtxs is array that uses phaseId's as indexes,
+ * contexts are created only on request and cached in this array
+ */
private var phasedCtx: Context = _
private var phasedCtxs: Array[Context] = _
diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala
index 8b5606da2..eb3b1d7fc 100644
--- a/src/dotty/tools/dotc/core/Phases.scala
+++ b/src/dotty/tools/dotc/core/Phases.scala
@@ -67,6 +67,38 @@ object Phases {
override def lastPhaseId(implicit ctx: Context) = id
}
+ /** Squash TreeTransform's beloning to same sublist to a single TreeTransformer
+ * Each TreeTransform gets own period,
+ * whereas a combined TreeTransformer gets period equal to union of periods of it's TreeTransforms
+ * first TreeTransformer emitted is PostTyperTransformer that simplifies trees, see it's documentation
+ */
+ private def squashPhases(phasess: List[List[Phase]]): Array[Phase] = {
+ val squashedPhases = ListBuffer[Phase]()
+ var postTyperEmmited = false
+ var i = 0
+ while (i < phasess.length) {
+ if (phasess(i).length > 1) {
+ assert(phasess(i).forall(x => x.isInstanceOf[TreeTransform]), "Only tree transforms can be squashed")
+
+ val transforms = phasess(i).asInstanceOf[List[TreeTransform]]
+ val block =
+ if (!postTyperEmmited) {
+ postTyperEmmited = true
+ new PostTyperTransformer {
+ override def name: String = transformations.map(_.name).mkString("TreeTransform:{", ", ", "}")
+ override def transformations: Array[TreeTransform] = transforms.toArray
+ }
+ } else new TreeTransformer {
+ override def name: String = transformations.map(_.name).mkString("TreeTransform:{", ", ", "}")
+ override def transformations: Array[TreeTransform] = transforms.toArray
+ }
+ squashedPhases += block
+ block.init(this, phasess(i).head.id, phasess(i).last.id)
+ } else squashedPhases += phasess(i).head
+ i += 1
+ }
+ (NoPhase :: squashedPhases.toList ::: new TerminalPhase :: Nil).toArray
+ }
/** Use the following phases in the order they are given.
* The list should never contain NoPhase.
@@ -94,31 +126,7 @@ object Phases {
}
if (squash) {
- val squashedPhases = ListBuffer[Phase]()
- var postTyperEmmited = false
- var i = 0
- while (i < phasess.length) {
- if (phasess(i).length > 1) {
- assert(phasess(i).forall(x => x.isInstanceOf[TreeTransform]), "Only tree transforms can be squashed")
-
- val transforms = phasess(i).asInstanceOf[List[TreeTransform]]
- val block =
- if (!postTyperEmmited) {
- postTyperEmmited = true
- new PostTyperTransformer {
- override def name: String = transformations.map(_.name).mkString("TreeTransform:{", ", ", "}")
- override def transformations: Array[TreeTransform] = transforms.toArray
- }
- } else new TreeTransformer {
- override def name: String = transformations.map(_.name).mkString("TreeTransform:{", ", ", "}")
- override def transformations: Array[TreeTransform] = transforms.toArray
- }
- squashedPhases += block
- block.init(this, phasess(i).head.id, phasess(i).last.id)
- } else squashedPhases += phasess(i).head
- i += 1
- }
- this.squashedPhases = (NoPhase::squashedPhases.toList :::new TerminalPhase :: Nil).toArray
+ this.squashedPhases = squashPhases(phasess)
} else {
this.squashedPhases = this.phases
}
diff --git a/src/dotty/tools/dotc/core/transform/Erasure.scala b/src/dotty/tools/dotc/core/transform/Erasure.scala
index 842e2f81f..9fb580ae8 100644
--- a/src/dotty/tools/dotc/core/transform/Erasure.scala
+++ b/src/dotty/tools/dotc/core/transform/Erasure.scala
@@ -17,7 +17,7 @@ object Erasure {
(if (isConstructor) 4 else 0) +
(if (wildcardOK) 8 else 0)
- private var erasures = new Array[Erasure](16)
+ private val erasures = new Array[Erasure](16)
for {
isJava <- List(false, true)
diff --git a/src/dotty/tools/dotc/transform/TreeTransform.scala b/src/dotty/tools/dotc/transform/TreeTransform.scala
index 425410ae7..0e182a99a 100644
--- a/src/dotty/tools/dotc/transform/TreeTransform.scala
+++ b/src/dotty/tools/dotc/transform/TreeTransform.scala
@@ -23,8 +23,6 @@ object TreeTransforms {
*
* If all transforms in a group are NoTransforms, the tree is no longer traversed.
*
- * @param group The group this transform belongs to
- * @param idx The index of this transform in its group
*
* Performance analysis: Taking the dotty compiler frontend as a use case, we are aiming for a warm performance of
* about 4000 lines / sec. This means 6 seconds for a codebase of 24'000 lines. Of these the frontend consumes
@@ -346,6 +344,11 @@ object TreeTransforms {
nxTransStats = indexUpdate(prev.nxTransStats, changedTansformation, transformationIndex, "transformStats", copy)
}
+ /**
+ * Those arrays are used as "execution plan" in order to only execute non-tivial transformations\preparations
+ * for every integer i array(i) contains first non trivial transformation\preparation on particular tree subtype.
+ * If no nontrivial transformation are left stored value is greater than transformers.size
+ */
var nxPrepIdent: Array[Int] = _
var nxPrepSelect: Array[Int] = _
var nxPrepThis: Array[Int] = _
diff --git a/src/dotty/tools/dotc/util/SimpleMap.scala b/src/dotty/tools/dotc/util/SimpleMap.scala
index 84b9cb258..7bd263f0f 100644
--- a/src/dotty/tools/dotc/util/SimpleMap.scala
+++ b/src/dotty/tools/dotc/util/SimpleMap.scala
@@ -174,7 +174,7 @@ object SimpleMap {
return {
if (v eq bindings(i + 1)) this
else {
- val bindings1 = bindings.clone.asInstanceOf[Array[AnyRef]]
+ val bindings1 = bindings.clone
bindings1(i + 1) = v
new MapMore(bindings1)
}
@@ -204,7 +204,7 @@ object SimpleMap {
val v = value(i)
val v1 = f(key(i), v)
if ((v1 ne v) && (bindings1 eq bindings))
- bindings1 = bindings.clone.asInstanceOf[Array[AnyRef]]
+ bindings1 = bindings.clone
bindings1(i) = bindings(i)
bindings1(i + 1) = v1
i += 2