Skip to content

Commit 6e16866

Browse files
committed
Use SuperPhase instead of TreeTransformer
SuperPhase is a simplified version of TreeTransformer - about half of the size - no need for separate TransformerInfo arguments - simpler wiring logic The simplifications are largely due to two changes - use of function values, where wiring is done by a sort of staging - prepare... operations return a Context instead of a TreeTranform
1 parent 0ed03c5 commit 6e16866

File tree

84 files changed

+882
-2143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+882
-2143
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotty.tools.backend.jvm
33
import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.core.Contexts.Context
55
import dotty.tools.dotc.core.Types
6-
import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, TreeTransform, MiniPhase, MiniPhaseTransform}
6+
import dotty.tools.dotc.transform.SuperPhase._
77
import dotty.tools.dotc.ast.tpd
88
import dotty.tools.dotc
99
import dotty.tools.dotc.backend.jvm.DottyPrimitives
@@ -35,10 +35,10 @@ import StdNames.nme
3535
/**
3636
* Created by dark on 26/11/14.
3737
*/
38-
class CollectEntryPoints extends MiniPhaseTransform {
38+
class CollectEntryPoints extends MiniPhase {
3939
def phaseName: String = "Collect entry points"
4040

41-
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
41+
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context): tpd.Tree = {
4242
if ((tree.symbol ne NoSymbol) && CollectEntryPoints.isJavaEntryPoint(tree.symbol)) {
4343
ctx.genBCodePhase.asInstanceOf[GenBCode].registerEntryPoint(tree.symbol)
4444
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import dotty.tools.dotc.ast.Trees._
55
import dotty.tools.dotc.core.Contexts.Context
66
import dotty.tools.dotc.core.Symbols._
77
import dotty.tools.dotc.core.Flags.Trait
8-
import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo}
8+
import dotty.tools.dotc.transform.SuperPhase.MiniPhase
99

1010
/** Collect all super calls to trait members.
1111
*
@@ -17,12 +17,12 @@ import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, Transforme
1717
* methods in a redundant mixin class could be implemented with a default abstract method,
1818
* the redundant mixin class could be required as a parent by the JVM.
1919
*/
20-
class CollectSuperCalls extends MiniPhaseTransform {
20+
class CollectSuperCalls extends MiniPhase {
2121
import tpd._
2222

2323
def phaseName: String = "collectSuperCalls"
2424

25-
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo): Tree = {
25+
override def transformSelect(tree: Select)(implicit ctx: Context): Tree = {
2626
tree.qualifier match {
2727
case sup: Super =>
2828
if (tree.symbol.owner.is(Trait))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dotty.tools.dotc.ast.Trees.Thicket
44
import dotty.tools.dotc.ast.{Trees, tpd}
55
import dotty.tools.dotc.core.Contexts.Context
66
import dotty.tools.dotc.core.Types
7-
import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, TreeTransform, MiniPhase, MiniPhaseTransform}
7+
import dotty.tools.dotc.transform.SuperPhase._
88
import dotty.tools.dotc
99
import dotty.tools.dotc.backend.jvm.DottyPrimitives
1010
import dotty.tools.dotc.core.Flags.FlagSet
@@ -81,14 +81,14 @@ import StdNames.nme
8181
*
8282
* @author Dmitry Petrashko
8383
*/
84-
class LabelDefs extends MiniPhaseTransform {
84+
class LabelDefs extends MiniPhase {
8585
def phaseName: String = "labelDef"
8686

8787
val queue = new ArrayBuffer[Tree]()
8888
val beingAppended = new mutable.HashSet[Symbol]()
8989
var labelLevel = 0
9090

91-
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
91+
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context): tpd.Tree = {
9292
if (tree.symbol is Flags.Label) tree
9393
else {
9494
collectLabelDefs.clear

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import reporting.{Reporter, ConsoleReporter}
1212
import Phases.Phase
1313
import transform._
1414
import util.FreshNameCreator
15-
import transform.TreeTransforms.{TreeTransform, TreeTransformer}
1615
import core.DenotTransformers.DenotTransformer
1716
import core.Denotations.SingleDenotation
1817

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Types._
1010
import Scopes._
1111
import typer.{FrontEnd, Typer, ImportInfo, RefChecks}
1212
import Decorators._
13-
import dotty.tools.dotc.transform.TreeTransforms.TreeTransformer
1413
import io.PlainFile
1514
import scala.io.Codec
1615
import util._

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ object Trees {
6363
final val Annotated = 38
6464
final val Thicket = 39
6565

66+
final val NumTypedTreeTags = 40
67+
6668
final val TypedSplice = 40
6769
final val ModuleDef = 41
6870
final val ParsedTry = 42
@@ -83,6 +85,8 @@ object Trees {
8385
final val GenAlias = 47
8486
final val ContextBounds = 48
8587
final val PatDef = 49
88+
89+
final val NumTags = 50
8690
}
8791

8892
// Note: it would be more logical to make Untyped = Nothing.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Symbols._
66
import Contexts._, Names._, Phases._, printing.Texts._, printing.Printer, printing.Showable
77
import util.Positions.Position, util.SourcePosition
88
import collection.mutable.ListBuffer
9-
import dotty.tools.dotc.transform.TreeTransforms._
9+
import dotty.tools.dotc.transform.SuperPhase
1010
import ast.tpd._
1111
import scala.language.implicitConversions
1212
import printing.Formatting._
@@ -152,7 +152,7 @@ object Decorators {
152152
*/
153153
implicit class PhaseListDecorator(val names: List[String]) extends AnyVal {
154154
def containsPhase(phase: Phase): Boolean = phase match {
155-
case phase: TreeTransformer => phase.miniPhases.exists(containsPhase)
155+
case phase: SuperPhase => phase.miniPhases.exists(containsPhase)
156156
case _ =>
157157
names exists { name =>
158158
name == "all" || {

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Denotations._
1111
import Decorators._
1212
import config.Printers.config
1313
import scala.collection.mutable.{ListBuffer, ArrayBuffer}
14-
import dotty.tools.dotc.transform.TreeTransforms.{TreeTransformer, MiniPhase, TreeTransform}
14+
import dotty.tools.dotc.transform.SuperPhase._
1515
import dotty.tools.dotc.transform._
1616
import Periods._
1717
import typer.{FrontEnd, RefChecks}
@@ -111,12 +111,9 @@ object Phases {
111111
assert(false, s"Only tree transforms can be squashed, ${phase.phaseName} can not be squashed")
112112
}
113113
}
114-
val block = new TreeTransformer {
115-
override def phaseName: String = miniPhases.map(_.phaseName).mkString("TreeTransform:{", ", ", "}")
116-
override def miniPhases: Array[MiniPhase] = filteredPhaseBlock.asInstanceOf[List[MiniPhase]].toArray
117-
}
114+
val superPhase = new SuperPhase(filteredPhaseBlock.asInstanceOf[List[MiniPhase]].toArray)
118115
prevPhases ++= filteredPhaseBlock.map(_.getClazz)
119-
block
116+
superPhase
120117
} else { // block of a single phase, no squashing
121118
val phase = filteredPhaseBlock.head
122119
prevPhases += phase.getClazz
@@ -144,7 +141,7 @@ object Phases {
144141
val flatPhases = collection.mutable.ListBuffer[Phase]()
145142

146143
phasess.foreach(p => p match {
147-
case t: TreeTransformer => flatPhases ++= t.miniPhases
144+
case p: SuperPhase => flatPhases ++= p.miniPhases
148145
case _ => flatPhases += p
149146
})
150147

@@ -172,12 +169,12 @@ object Phases {
172169
while (i < phasess.length) {
173170
val phase = phasess(i)
174171
phase match {
175-
case t: TreeTransformer =>
176-
val miniPhases = t.miniPhases
172+
case p: SuperPhase =>
173+
val miniPhases = p.miniPhases
177174
miniPhases.foreach{ phase =>
178175
checkRequirements(phase)
179176
phase.init(this, nextPhaseId)}
180-
t.init(this, miniPhases.head.id, miniPhases.last.id)
177+
p.init(this, miniPhases.head.id, miniPhases.last.id)
181178
case _ =>
182179
phase.init(this, nextPhaseId)
183180
checkRequirements(phase)
@@ -345,7 +342,7 @@ object Phases {
345342
final def sameParentsStartId = mySameParentsStartId
346343
// id of first phase where all symbols are guaranteed to have the same parents as in this phase
347344

348-
protected[Phases] def init(base: ContextBase, start: Int, end:Int): Unit = {
345+
protected[Phases] def init(base: ContextBase, start: Int, end: Int): Unit = {
349346
if (start >= FirstPhaseId)
350347
assert(myPeriod == Periods.InvalidPeriod, s"phase $this has already been used once; cannot be reused")
351348
assert(start <= Periods.MaxPossiblePhaseId, s"Too many phases, Period bits overflow")

compiler/src/dotty/tools/dotc/transform/ArrayConstructors.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools.dotc
22
package transform
33

44
import core._
5-
import TreeTransforms._
5+
import SuperPhase._
66
import Contexts.Context
77
import Flags._
88
import SymUtils._
@@ -29,12 +29,12 @@ import scala.collection.immutable.::
2929
* It assummes that generic arrays have already been handled by typer(see Applications.convertNewGenericArray).
3030
* Additionally it optimizes calls to scala.Array.ofDim functions by replacing them with calls to newArray with specific dimensions
3131
*/
32-
class ArrayConstructors extends MiniPhaseTransform { thisTransform =>
32+
class ArrayConstructors extends MiniPhase {
3333
import ast.tpd._
3434

3535
override def phaseName: String = "arrayConstructors"
3636

37-
override def transformApply(tree: tpd.Apply)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
37+
override def transformApply(tree: tpd.Apply)(implicit ctx: Context): tpd.Tree = {
3838
def rewrite(elemType: Type, dims: List[Tree]) =
3939
tpd.newArray(elemType, tree.tpe, tree.pos, JavaSeqLiteral(dims, TypeTree(defn.IntClass.typeRef)))
4040

compiler/src/dotty/tools/dotc/transform/AugmentScala2Traits.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools.dotc
22
package transform
33

44
import core._
5-
import TreeTransforms._
5+
import SuperPhase._
66
import Contexts.Context
77
import Flags._
88
import SymUtils._
@@ -28,7 +28,7 @@ import ast.Trees._
2828
* Furthermore, it expands the names of all private getters and setters as well as super accessors in the trait and makes
2929
* them not-private.
3030
*/
31-
class AugmentScala2Traits extends MiniPhaseTransform with IdentityDenotTransformer with FullParameterization { thisTransform =>
31+
class AugmentScala2Traits extends MiniPhase with IdentityDenotTransformer with FullParameterization { thisPhase =>
3232
import ast.tpd._
3333

3434
override def changesMembers = true
@@ -37,7 +37,7 @@ class AugmentScala2Traits extends MiniPhaseTransform with IdentityDenotTransform
3737

3838
override def rewiredTarget(referenced: Symbol, derived: Symbol)(implicit ctx: Context) = NoSymbol
3939

40-
override def transformTemplate(impl: Template)(implicit ctx: Context, info: TransformerInfo) = {
40+
override def transformTemplate(impl: Template)(implicit ctx: Context) = {
4141
val cls = impl.symbol.owner.asClass
4242
for (mixin <- cls.mixins)
4343
if (mixin.is(Scala2x))
@@ -49,15 +49,15 @@ class AugmentScala2Traits extends MiniPhaseTransform with IdentityDenotTransform
4949
if (mixin.implClass.is(Scala2x)) () // nothing to do, mixin was already augmented
5050
else {
5151
//println(i"creating new implclass for $mixin ${mixin.implClass}")
52-
val ops = new MixinOps(cls, thisTransform)
52+
val ops = new MixinOps(cls, thisPhase)
5353
import ops._
5454

5555
val implClass = ctx.newCompleteClassSymbol(
5656
owner = mixin.owner,
5757
name = mixin.name.implClassName,
5858
flags = Abstract | Scala2x | ImplClass,
5959
parents = defn.ObjectType :: Nil,
60-
assocFile = mixin.assocFile).enteredAfter(thisTransform)
60+
assocFile = mixin.assocFile).enteredAfter(thisPhase)
6161

6262
def implMethod(meth: TermSymbol): Symbol = {
6363
val mold =
@@ -91,11 +91,11 @@ class AugmentScala2Traits extends MiniPhaseTransform with IdentityDenotTransform
9191
}
9292
else if (!sym.is(Deferred) && !sym.setter.exists &&
9393
!sym.info.resultType.isInstanceOf[ConstantType])
94-
traitSetter(sym.asTerm).enteredAfter(thisTransform)
94+
traitSetter(sym.asTerm).enteredAfter(thisPhase)
9595
if ((sym.is(PrivateAccessor) && !sym.name.is(ExpandedName) &&
9696
(sym.isGetter || sym.isSetter)) // strangely, Scala 2 fields are also methods that have Accessor set.
9797
|| sym.isSuperAccessor) // scala2 superaccessors are pickled as private, but are compiled as public expanded
98-
sym.ensureNotPrivate.installAfter(thisTransform)
98+
sym.ensureNotPrivate.installAfter(thisPhase)
9999
}
100100
ctx.log(i"Scala2x trait decls of $mixin = ${mixin.info.decls.toList.map(_.showDcl)}%\n %")
101101
ctx.log(i"Scala2x impl decls of $mixin = ${implClass.info.decls.toList.map(_.showDcl)}%\n %")

compiler/src/dotty/tools/dotc/transform/ByNameClosures.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dotty.tools.dotc
22
package transform
33

4-
import TreeTransforms._
54
import core._
65
import Symbols._
76
import SymDenotations._
@@ -24,14 +23,14 @@ import core.StdNames.nme
2423
*
2524
* is a synthetic method defined in Definitions. Erasure will later strip the <cbn-arg> wrappers.
2625
*/
27-
class ByNameClosures extends TransformByNameApply with IdentityDenotTransformer { thisTransformer =>
26+
class ByNameClosures extends TransformByNameApply with IdentityDenotTransformer { thisPhase =>
2827
import ast.tpd._
2928

3029
override def phaseName: String = "byNameClosures"
3130

3231
override def mkByNameClosure(arg: Tree, argType: Type)(implicit ctx: Context): Tree = {
3332
val meth = ctx.newSymbol(
3433
ctx.owner, nme.ANON_FUN, Synthetic | Method, MethodType(Nil, Nil, argType))
35-
Closure(meth, _ => arg.changeOwnerAfter(ctx.owner, meth, thisTransformer))
34+
Closure(meth, _ => arg.changeOwnerAfter(ctx.owner, meth, thisPhase))
3635
}
3736
}

0 commit comments

Comments
 (0)