Skip to content

Commit fe77e76

Browse files
committed
Refactor Splitter functionality
Splitting or types is no longer needed with new scheme. Replacing idents with This nodes is better done in ExplicitSelf. So splitter now just distributes applications into and ifs.
1 parent 4e33a41 commit fe77e76

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,21 @@ import Flags._
1919
* C.this.asInstanceOf[S].m
2020
*
2121
* where `S` is the self type of `C`.
22+
*
23+
* Also replaces idents referring to the self type with ThisTypes.
2224
*/
2325
class ExplicitSelf extends MiniPhaseTransform { thisTransform =>
2426
import ast.tpd._
2527

2628
override def phaseName = "explicitSelf"
2729

30+
override def transformIdent(tree: Ident)(implicit ctx: Context, info: TransformerInfo) = tree.tpe match {
31+
case tp: ThisType =>
32+
ctx.debuglog(s"owner = ${ctx.owner}, context = ${ctx}")
33+
This(tp.cls) withPos tree.pos
34+
case _ => tree
35+
}
36+
2837
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo): Tree = tree match {
2938
case Select(thiz: This, name) if name.isTermName =>
3039
val cls = thiz.symbol.asClass

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

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,34 @@ import ast.Trees._
66
import core._
77
import Contexts._, Types._, Decorators._, Denotations._, Symbols._, SymDenotations._, Names._
88

9-
/** This transform makes sure every identifier and select node
10-
* carries a symbol. To do this, certain qualifiers with a union type
11-
* have to be "splitted" with a type test.
12-
*
13-
* For now, only self references are treated.
9+
/** Distribute applications into Block and If nodes
1410
*/
1511
class Splitter extends MiniPhaseTransform { thisTransform =>
1612
import ast.tpd._
1713

1814
override def phaseName: String = "splitter"
1915

20-
/** Replace self referencing idents with ThisTypes. */
21-
override def transformIdent(tree: Ident)(implicit ctx: Context, info: TransformerInfo) = tree.tpe match {
22-
case tp: ThisType =>
23-
ctx.debuglog(s"owner = ${ctx.owner}, context = ${ctx}")
24-
This(tp.cls) withPos tree.pos
25-
case _ => tree
16+
/** Distribute arguments among splitted branches */
17+
def distribute(tree: GenericApply[Type], rebuild: (Tree, List[Tree]) => Context => Tree)(implicit ctx: Context) = {
18+
def recur(fn: Tree): Tree = fn match {
19+
case Block(stats, expr) => Block(stats, recur(expr))
20+
case If(cond, thenp, elsep) => If(cond, recur(thenp), recur(elsep))
21+
case _ => rebuild(fn, tree.args)(ctx) withPos tree.pos
22+
}
23+
recur(tree.fun)
2624
}
2725

26+
override def transformTypeApply(tree: TypeApply)(implicit ctx: Context, info: TransformerInfo) =
27+
distribute(tree, typeApply)
28+
29+
override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo) =
30+
distribute(tree, apply)
31+
32+
private val typeApply = (fn: Tree, args: List[Tree]) => (ctx: Context) => TypeApply(fn, args)(ctx)
33+
private val apply = (fn: Tree, args: List[Tree]) => (ctx: Context) => Apply(fn, args)(ctx)
34+
35+
/* The following is no longer necessary, since we select members on the join of an or type:
36+
*
2837
/** If we select a name, make sure the node has a symbol.
2938
* If necessary, split the qualifier with type tests.
3039
* Example: Assume:
@@ -108,23 +117,5 @@ class Splitter extends MiniPhaseTransform { thisTransform =>
108117
evalOnce(qual)(qual => choose(qual, candidates(qual.tpe)))
109118
}
110119
}
111-
112-
/** Distribute arguments among splitted branches */
113-
def distribute(tree: GenericApply[Type], rebuild: (Tree, List[Tree]) => Context => Tree)(implicit ctx: Context) = {
114-
def recur(fn: Tree): Tree = fn match {
115-
case Block(stats, expr) => Block(stats, recur(expr))
116-
case If(cond, thenp, elsep) => If(cond, recur(thenp), recur(elsep))
117-
case _ => rebuild(fn, tree.args)(ctx) withPos tree.pos
118-
}
119-
recur(tree.fun)
120-
}
121-
122-
override def transformTypeApply(tree: TypeApply)(implicit ctx: Context, info: TransformerInfo) =
123-
distribute(tree, typeApply)
124-
125-
override def transformApply(tree: Apply)(implicit ctx: Context, info: TransformerInfo) =
126-
distribute(tree, apply)
127-
128-
private val typeApply = (fn: Tree, args: List[Tree]) => (ctx: Context) => TypeApply(fn, args)(ctx)
129-
private val apply = (fn: Tree, args: List[Tree]) => (ctx: Context) => Apply(fn, args)(ctx)
120+
*/
130121
}

0 commit comments

Comments
 (0)