Skip to content

Commit 3726933

Browse files
committed
Move SetRootTree right before Pickler
1 parent 251eceb commit 3726933

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Compiler {
3939
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
4040
List(new PostTyper) :: // Additional checks and cleanups after type checking
4141
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
42+
List(new SetRootTree) :: // Set the `rootTreeOrProvider` on class symbols
4243
Nil
4344

4445
/** Phases dealing with TASTY tree pickling and unpickling */
@@ -52,7 +53,6 @@ class Compiler {
5253
List(new FirstTransform, // Some transformations to put trees into a canonical form
5354
new CheckReentrant, // Internal use only: Check that compiled program has no data races involving global vars
5455
new ElimPackagePrefixes, // Eliminate references to package prefixes in Select nodes
55-
new SetRootTree, // Set the `rootTreeOrProvider` on class symbols
5656
new CookComments) :: // Cook the comments: expand variables, doc, etc.
5757
List(new CheckStatic, // Check restrictions that apply to @static members
5858
new ElimRepeated, // Rewrite vararg parameters and arguments

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
215215
def processUnit() = {
216216
unit.tpdTree = ctx.typer.typedExpr(unit.untpdTree)
217217
val phase = new transform.SetRootTree()
218-
phase.runOn(unit)
218+
phase.run
219219
}
220220
if (typeCheck)
221221
if (compiling) finalizeActions += (() => processUnit()) else processUnit()

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,34 @@ package dotty.tools.dotc.transform
33
import dotty.tools.dotc.CompilationUnit
44
import dotty.tools.dotc.ast.tpd
55
import dotty.tools.dotc.core.Contexts.Context
6-
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
6+
import dotty.tools.dotc.core.Phases.Phase
77

88
/** Set the `rootTreeOrProvider` property of class symbols. */
9-
class SetRootTree extends MiniPhase {
9+
class SetRootTree extends Phase {
1010

1111
override val phaseName: String = SetRootTree.name
1212
override def isRunnable(implicit ctx: Context) =
1313
super.isRunnable && ctx.settings.YretainTrees.value
1414

15-
def runOn(unit: CompilationUnit)(implicit ctx: Context) = {
16-
val runCtx = ctx.fresh.setCompilationUnit(unit)
17-
traverser.traverse(unit.tpdTree)(runCtx)
18-
}
19-
20-
override def transformTypeDef(tree: tpd.TypeDef)(implicit ctx: Context): tpd.Tree = {
21-
if (tree.symbol.isClass) {
22-
val sym = tree.symbol.asClass
23-
tpd.sliceTopLevel(ctx.compilationUnit.tpdTree, sym) match {
24-
case (pkg: tpd.PackageDef) :: Nil =>
25-
sym.rootTreeOrProvider = pkg
26-
case _ =>
27-
sym.rootTreeOrProvider = tree
28-
}
29-
}
30-
tree
15+
override def run(implicit ctx: Context): Unit = {
16+
val tree = ctx.compilationUnit.tpdTree
17+
traverser.traverse(tree)
3118
}
3219

3320
private def traverser = new tpd.TreeTraverser {
34-
override def traverse(tree: tpd.Tree)(implicit ctx: Context): Unit = tree match {
35-
case typeDef: tpd.TypeDef => transformTypeDef(typeDef)
36-
case other => traverseChildren(other)
21+
override def traverse(tree: tpd.Tree)(implicit ctx: Context): Unit = {
22+
if (tree.isInstanceOf[tpd.TypeDef] && tree.symbol.isClass) {
23+
val sym = tree.symbol.asClass
24+
tpd.sliceTopLevel(ctx.compilationUnit.tpdTree, sym) match {
25+
case (pkg: tpd.PackageDef) :: Nil =>
26+
sym.rootTreeOrProvider = pkg
27+
case _ =>
28+
sym.rootTreeOrProvider = tree
29+
}
30+
}
31+
traverseChildren(tree)
3732
}
3833
}
39-
40-
4134
}
4235

4336
object SetRootTree {

0 commit comments

Comments
 (0)