Skip to content

Documentation and a bit of cleanup. #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] = _

Expand Down
58 changes: 33 additions & 25 deletions src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/core/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/dotty/tools/dotc/transform/TreeTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] = _
Expand Down
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/util/SimpleMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down