Skip to content

Commit adab2a8

Browse files
committed
Move loadCompilationUnit out of FromTasty
1 parent f9cca96 commit adab2a8

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import dotty.tools.dotc.core.Types.Type
55
import dotty.tools.dotc.core.tasty.{TastyUnpickler, TastyBuffer, TastyPickler}
66
import util.SourceFile
77
import ast.{tpd, untpd}
8+
import dotty.tools.dotc.ast.tpd.{ Tree, TreeTraverser }
9+
import dotty.tools.dotc.core.Contexts.Context
10+
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
811
import dotty.tools.dotc.core.Symbols._
912

1013
class CompilationUnit(val source: SourceFile) {
@@ -20,3 +23,19 @@ class CompilationUnit(val source: SourceFile) {
2023
/** Pickled TASTY binaries, indexed by class. */
2124
var pickled: Map[ClassSymbol, Array[Byte]] = Map()
2225
}
26+
27+
object CompilationUnit {
28+
29+
/** Make a compilation unit for top class `clsd` with the contends of the `unpickled` */
30+
def mkCompilationUnit(clsd: ClassDenotation, unpickled: Tree)(implicit ctx: Context): CompilationUnit = {
31+
val unit1 = new CompilationUnit(new SourceFile(clsd.symbol.sourceFile, Seq()))
32+
unit1.tpdTree = unpickled
33+
force.traverse(unit1.tpdTree)
34+
unit1
35+
}
36+
37+
/** Force the tree to be loaded */
38+
private object force extends TreeTraverser {
39+
def traverse(tree: Tree)(implicit ctx: Context): Unit = traverseChildren(tree)
40+
}
41+
}

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ object FromTasty extends Driver {
6060
override def toString = s"class file $className"
6161
}
6262

63-
object force extends TreeTraverser {
64-
def traverse(tree: Tree)(implicit ctx: Context): Unit = traverseChildren(tree)
65-
}
66-
6763
class ReadTastyTreesFromClasses extends FrontEnd {
6864

6965
override def isTyper = false
@@ -85,7 +81,7 @@ object FromTasty extends Driver {
8581
case info: ClassfileLoader =>
8682
info.load(clsd)
8783
val unpickled = clsd.symbol.asClass.tree
88-
if (unpickled != null) mkUnit(clsd, unpickled)
84+
if (unpickled != null) CompilationUnit.mkCompilationUnit(clsd, unpickled)
8985
else cannotUnpickle(s"its class file ${info.classfile} does not have a TASTY attribute")
9086
case info =>
9187
cannotUnpickle(s"its info of type ${info.getClass} is not a ClassfileLoader")
@@ -96,21 +92,4 @@ object FromTasty extends Driver {
9692
}
9793
}
9894
}
99-
100-
def loadCompilationUnit(clsd: ClassDenotation)(implicit ctx: Context): Option[CompilationUnit] = {
101-
assert(ctx.settings.XlinkOptimise.value)
102-
val tree = clsd.symbol.asClass.unitTree
103-
if (tree.isEmpty) None
104-
else {
105-
ctx.log("Loading compilation unit for: " + clsd)
106-
Some(mkUnit(clsd, tree))
107-
}
108-
}
109-
110-
private def mkUnit(clsd: ClassDenotation, unpickled: Tree)(implicit ctx: Context): CompilationUnit = {
111-
val unit1 = new CompilationUnit(new SourceFile(clsd.symbol.sourceFile, Seq()))
112-
unit1.tpdTree = unpickled
113-
force.traverse(unit1.tpdTree)
114-
unit1
115-
}
11695
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import dotty.tools.dotc.transform.TreeTransforms._
1616
*/
1717
class LinkAll extends MiniPhaseTransform {
1818
import tpd._
19+
import LinkAll._
1920

2021
override def phaseName = "linkAll"
2122

@@ -31,7 +32,7 @@ class LinkAll extends MiniPhaseTransform {
3132
else {
3233
val accum = new ClassesToLoadAccumulator
3334
val classesToLoad = unprocessed.foldLeft(Set.empty[ClassDenotation])((acc, unit) => accum.apply(acc, unit.tpdTree)) -- loadedClasses
34-
val loadedUnits = classesToLoad.flatMap(cls => FromTasty.loadCompilationUnit(cls))
35+
val loadedUnits = classesToLoad.flatMap(cls => loadCompilationUnit(cls))
3536
allUnits(processed ++ unprocessed, loadedUnits, loadedClasses ++ classesToLoad)
3637
}
3738
}
@@ -61,3 +62,17 @@ class LinkAll extends MiniPhaseTransform {
6162
}
6263
}
6364
}
65+
66+
object LinkAll {
67+
68+
private[LinkAll] def loadCompilationUnit(clsd: ClassDenotation)(implicit ctx: Context): Option[CompilationUnit] = {
69+
assert(ctx.settings.XlinkOptimise.value)
70+
val tree = clsd.symbol.asClass.unitTree
71+
if (tree.isEmpty) None
72+
else {
73+
ctx.log("Loading compilation unit for: " + clsd)
74+
Some(CompilationUnit.mkCompilationUnit(clsd, tree))
75+
}
76+
}
77+
78+
}

0 commit comments

Comments
 (0)