Skip to content

Commit f651ca5

Browse files
committed
Documentation and a bit of cleanup.
Added documentation for non-trivial logic in Contexts, Phases and TreeTransforms. Removed redundant vars and casts
1 parent 2033b56 commit f651ca5

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

src/dotty/tools/dotc/core/Contexts.scala

+5
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ object Contexts {
181181
protected def searchHistory_= (searchHistory: SearchHistory) = _searchHistory = searchHistory
182182
def searchHistory: SearchHistory = _searchHistory
183183

184+
/** Those fields are used to cache phases created in withPhase.
185+
* phasedCtx is first phase with altered phase ever requested.
186+
* phasedCtxs is array that uses phaseId's as indexes,
187+
* contexts are created only on request and cached in this array
188+
*/
184189
private var phasedCtx: Context = _
185190
private var phasedCtxs: Array[Context] = _
186191

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

+33-25
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@ object Phases {
6767
override def lastPhaseId(implicit ctx: Context) = id
6868
}
6969

70+
/** Squash TreeTransform's beloning to same sublist to a single TreeTransformer
71+
* Each TreeTransform gets own period,
72+
* whereas a combined TreeTransformer gets period equal to union of periods of it's TreeTransforms
73+
* first TreeTransformer emitted is PostTyperTransformer that simplifies trees, see it's documentation
74+
*/
75+
private def squashPhases(phasess: List[List[Phase]]): Array[Phase] = {
76+
val squashedPhases = ListBuffer[Phase]()
77+
var postTyperEmmited = false
78+
var i = 0
79+
while (i < phasess.length) {
80+
if (phasess(i).length > 1) {
81+
assert(phasess(i).forall(x => x.isInstanceOf[TreeTransform]), "Only tree transforms can be squashed")
82+
83+
val transforms = phasess(i).asInstanceOf[List[TreeTransform]]
84+
val block =
85+
if (!postTyperEmmited) {
86+
postTyperEmmited = true
87+
new PostTyperTransformer {
88+
override def name: String = transformations.map(_.name).mkString("TreeTransform:{", ", ", "}")
89+
override def transformations: Array[TreeTransform] = transforms.toArray
90+
}
91+
} else new TreeTransformer {
92+
override def name: String = transformations.map(_.name).mkString("TreeTransform:{", ", ", "}")
93+
override def transformations: Array[TreeTransform] = transforms.toArray
94+
}
95+
squashedPhases += block
96+
block.init(this, phasess(i).head.id, phasess(i).last.id)
97+
} else squashedPhases += phasess(i).head
98+
i += 1
99+
}
100+
(NoPhase :: squashedPhases.toList ::: new TerminalPhase :: Nil).toArray
101+
}
70102

71103
/** Use the following phases in the order they are given.
72104
* The list should never contain NoPhase.
@@ -94,31 +126,7 @@ object Phases {
94126
}
95127

96128
if (squash) {
97-
val squashedPhases = ListBuffer[Phase]()
98-
var postTyperEmmited = false
99-
var i = 0
100-
while (i < phasess.length) {
101-
if (phasess(i).length > 1) {
102-
assert(phasess(i).forall(x => x.isInstanceOf[TreeTransform]), "Only tree transforms can be squashed")
103-
104-
val transforms = phasess(i).asInstanceOf[List[TreeTransform]]
105-
val block =
106-
if (!postTyperEmmited) {
107-
postTyperEmmited = true
108-
new PostTyperTransformer {
109-
override def name: String = transformations.map(_.name).mkString("TreeTransform:{", ", ", "}")
110-
override def transformations: Array[TreeTransform] = transforms.toArray
111-
}
112-
} else new TreeTransformer {
113-
override def name: String = transformations.map(_.name).mkString("TreeTransform:{", ", ", "}")
114-
override def transformations: Array[TreeTransform] = transforms.toArray
115-
}
116-
squashedPhases += block
117-
block.init(this, phasess(i).head.id, phasess(i).last.id)
118-
} else squashedPhases += phasess(i).head
119-
i += 1
120-
}
121-
this.squashedPhases = (NoPhase::squashedPhases.toList :::new TerminalPhase :: Nil).toArray
129+
this.squashedPhases = squashPhases(phasess)
122130
} else {
123131
this.squashedPhases = this.phases
124132
}

src/dotty/tools/dotc/core/transform/Erasure.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object Erasure {
1717
(if (isConstructor) 4 else 0) +
1818
(if (wildcardOK) 8 else 0)
1919

20-
private var erasures = new Array[Erasure](16)
20+
private val erasures = new Array[Erasure](16)
2121

2222
for {
2323
isJava <- List(false, true)

src/dotty/tools/dotc/transform/TreeTransform.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ object TreeTransforms {
2323
*
2424
* If all transforms in a group are NoTransforms, the tree is no longer traversed.
2525
*
26-
* @param group The group this transform belongs to
27-
* @param idx The index of this transform in its group
2826
*
2927
* Performance analysis: Taking the dotty compiler frontend as a use case, we are aiming for a warm performance of
3028
* 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 {
346344
nxTransStats = indexUpdate(prev.nxTransStats, changedTansformation, transformationIndex, "transformStats", copy)
347345
}
348346

347+
/**
348+
* Those arrays are used as "execution plan" in order to only execute non-tivial transformations\preparations
349+
* for every integer i array(i) contains first non trivial transformation\preparation on particular tree subtype.
350+
* If no nontrivial transformation are left stored value is greater than transformers.size
351+
*/
349352
var nxPrepIdent: Array[Int] = _
350353
var nxPrepSelect: Array[Int] = _
351354
var nxPrepThis: Array[Int] = _

src/dotty/tools/dotc/util/SimpleMap.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ object SimpleMap {
174174
return {
175175
if (v eq bindings(i + 1)) this
176176
else {
177-
val bindings1 = bindings.clone.asInstanceOf[Array[AnyRef]]
177+
val bindings1 = bindings.clone
178178
bindings1(i + 1) = v
179179
new MapMore(bindings1)
180180
}
@@ -204,7 +204,7 @@ object SimpleMap {
204204
val v = value(i)
205205
val v1 = f(key(i), v)
206206
if ((v1 ne v) && (bindings1 eq bindings))
207-
bindings1 = bindings.clone.asInstanceOf[Array[AnyRef]]
207+
bindings1 = bindings.clone
208208
bindings1(i) = bindings(i)
209209
bindings1(i + 1) = v1
210210
i += 2

0 commit comments

Comments
 (0)