Skip to content

Commit 5c1a149

Browse files
oderskyDarkDimius
authored andcommitted
Maintaining owners during transformations
The transformation framework needed to be changed so that contexts passed to transformations have correct owner chains. These owner chins are demanded by the Splitter phase. Note: I eliminated the contexts array in TransformInfo because it interfered with the owner computations. Generally, caching contexts with some phase is best done in Contexts, because withPhase is also used heavily in othre code, not just in Transformers. New phase: Splitter When it is complete, it will make sure that every term Ident and Select node carries a symbol. Right now, all it does is coverting self reference idents to "this"-nodes.
1 parent 9bd1e6a commit 5c1a149

File tree

5 files changed

+115
-80
lines changed

5 files changed

+115
-80
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Compiler {
2121
List(
2222
List(new FrontEnd),
2323
List(new LazyValsCreateCompanionObjects, new PatternMatcher), //force separataion between lazyVals and LVCreateCO
24-
List(new LazyValTranformContext().transformer, new TypeTestsCasts),
24+
List(new LazyValTranformContext().transformer, new Splitter, new TypeTestsCasts),
2525
List(new Erasure),
2626
List(new UncurryTreeTransform)
2727
)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ object Contexts {
277277
newctx.asInstanceOf[FreshContext]
278278
}
279279

280+
final def withOwner(owner: Symbol): Context =
281+
if (owner ne this.owner) fresh.setOwner(owner) else this
282+
280283
final def withMode(mode: Mode): Context =
281284
if (mode != this.mode) fresh.setMode(mode) else this
282285

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ object PostTyperTransformers {
4848
reorder0(stats)
4949
}
5050

51-
override def transformStats(trees: List[tpd.Tree], info: TransformerInfo, current: Int)(implicit ctx: Context): List[tpd.Tree] =
52-
super.transformStats(reorder(trees)(ctx, info), info, current)
51+
override def transformStats(trees: List[tpd.Tree], exprOwner: Symbol, info: TransformerInfo, current: Int)(implicit ctx: Context): List[tpd.Tree] =
52+
super.transformStats(reorder(trees)(ctx, info), exprOwner, info, current)
5353

5454
override def transform(tree: tpd.Tree, info: TransformerInfo, cur: Int)(implicit ctx: Context): tpd.Tree = tree match {
5555
case tree: Import => EmptyTree
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dotty.tools.dotc
2+
package transform
3+
4+
import TreeTransforms._
5+
import ast.Trees._
6+
import core.Contexts._
7+
import core.Types._
8+
9+
/** This transform makes usre 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.
14+
*/
15+
class Splitter extends TreeTransform {
16+
import ast.tpd._
17+
18+
override def name: String = "splitter"
19+
20+
/** Replace self referencing idents with ThisTypes. */
21+
override def transformIdent(tree: Ident)(implicit ctx: Context, info: TransformerInfo) = tree.tpe match {
22+
case ThisType(cls) =>
23+
println(s"owner = ${ctx.owner}, context = ${ctx}")
24+
This(cls) withPos tree.pos
25+
case _ => tree
26+
}
27+
}

0 commit comments

Comments
 (0)