Skip to content

Commit 5115c7f

Browse files
committed
Add documentation and improve code
1 parent 7906928 commit 5115c7f

File tree

6 files changed

+25
-20
lines changed

6 files changed

+25
-20
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Compiler {
4747
List(new PostTyper), // Additional checks and cleanups after type checking
4848
List(new sbt.ExtractAPI), // Sends a representation of the API of classes to sbt via callbacks
4949
List(new Pickler), // Generate TASTY info
50-
List(new LinkAll), // Link all
50+
List(new LinkAll), // Reload compilation units from TASTY for library code (if needed)
5151
List(new FirstTransform, // Some transformations to put trees into a canonical form
5252
new CheckReentrant, // Internal use only: Check that compiled program has no data races involving global vars
5353
new ElimJavaPackages), // Eliminate syntactic references to Java packages

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ScalaSettings extends Settings.SettingGroup {
114114
val YoptPhases = PhasesSetting("-Yopt-phases", "Restrict the optimisation phases to execute under -optimise.")
115115
val YoptFuel = IntSetting("-Yopt-fuel", "Maximum number of optimisations performed under -optimise.", -1)
116116
val optimise = BooleanSetting("-optimise", "Generates faster bytecode by applying local optimisations to the .program") withAbbreviation "-optimize"
117-
val XlinkOptimise = BooleanSetting("-Xlink-optimise", "Link class files.").withAbbreviation("-Xlink-optimize")
117+
val XlinkOptimise = BooleanSetting("-Xlink-optimise", "Recompile library code with the application.").withAbbreviation("-Xlink-optimize")
118118

119119
/** Dottydoc specific settings */
120120
val siteRoot = StringSetting(

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,10 @@ object Symbols {
555555

556556
type ThisName = TypeName
557557

558-
/** If this is a top-level class, and if `-Yretain-trees` or `-Xlink-optimise` is set,
559-
* return the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
558+
/** If this is either:
559+
* - a top-level class and `-Yretain-trees` is set
560+
* - a top-level class loaded from TASTY and `-Xlink-optimise` is set
561+
* then return the TypeDef tree (possibly wrapped inside PackageDefs) for this class, otherwise EmptyTree.
560562
* This will force the info of the class.
561563
*/
562564
def tree(implicit ctx: Context): tpd.Tree /* tpd.PackageDef | tpd.TypeDef | tpd.EmptyTree */ = {
@@ -570,7 +572,7 @@ object Symbols {
570572
}
571573
myTree
572574
}
573-
private var myTree: tpd.Tree /* tpd.PackageDef | tpd.TypeDef | tpd.EmptyTree */ = tpd.EmptyTree
575+
private[this] var myTree: tpd.Tree /* tpd.PackageDef | tpd.TypeDef | tpd.EmptyTree */ = tpd.EmptyTree
574576
private[dotc] var unpickler: tasty.DottyUnpickler = _
575577

576578
private[dotc] def registerTree(tree: tpd.TypeDef)(implicit ctx: Context): Unit = {

compiler/src/dotty/tools/dotc/interactive/SourceTree.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ object SourceTree {
4444
None
4545
else {
4646
import ast.Trees._
47-
def findTree(tree: tpd.Tree): Option[SourceTree] = tree match {
48-
case PackageDef(_, stats) => stats.flatMap(findTree).headOption
47+
def sourceTreeOfClass(tree: tpd.Tree): Option[SourceTree] = tree match {
48+
case PackageDef(_, stats) => stats.flatMap(sourceTreeOfClass).headOption
4949
case tree: tpd.TypeDef if tree.symbol == sym =>
5050
val sourceFile = new SourceFile(sym.sourceFile, Codec.UTF8)
5151
Some(SourceTree(tree, sourceFile))
5252
case _ => None
5353
}
54-
findTree(sym.tree)
54+
sourceTreeOfClass(sym.tree)
5555
}
5656
}
5757
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ class FirstTransform extends MiniPhaseTransform with InfoTransformer with Annota
154154
cpy.Template(impl)(self = EmptyValDef)
155155
}
156156

157+
/** Eliminate empty package definitions that may have been stored in the TASTY trees */
157158
override def transformPackageDef(tree: PackageDef)(implicit ctx: Context, info: TransformerInfo): Tree =
158-
if (tree.stats.isEmpty) theEmptyTree else tree
159+
if (tree.stats.isEmpty) EmptyTree else tree
159160

160161
override def transformDefDef(ddef: DefDef)(implicit ctx: Context, info: TransformerInfo) = {
161162
if (ddef.symbol.hasAnnotation(defn.NativeAnnot)) {

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,21 @@ class LinkAll extends MiniPhaseTransform {
2222

2323
override def prepareForUnit(tree: tpd.Tree)(implicit ctx: Context): TreeTransform = NoTransform
2424

25-
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] =
26-
if (ctx.settings.XlinkOptimise.value) super.runOn(allUnits(Set.empty, units.toSet, Set.empty))
27-
else super.runOn(units)
25+
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
26+
/** Loads and processes new compilation units, possibly loading more units. */
27+
def allUnits(processed: Set[CompilationUnit], unprocessed: Set[CompilationUnit], loadedClasses: Set[ClassDenotation])(implicit ctx: Context): List[CompilationUnit] = {
28+
if (unprocessed.isEmpty) processed.toList
29+
else {
30+
val accum = new ClassesToLoadAccumulator
31+
val classesToLoad = unprocessed.foldLeft(Set.empty[ClassDenotation])((acc, unit) => accum.apply(acc, unit.tpdTree)) -- loadedClasses
32+
val loadedUnits = classesToLoad.flatMap(cls => loadCompilationUnit(cls))
33+
allUnits(processed ++ unprocessed, loadedUnits, loadedClasses ++ classesToLoad)
2834

29-
/** Loads and processes new compilation units, possibly loading more units. */
30-
private def allUnits(processed: Set[CompilationUnit], unprocessed: Set[CompilationUnit], loadedClasses: Set[ClassDenotation])(implicit ctx: Context): List[CompilationUnit] = {
31-
if (unprocessed.isEmpty) processed.toList
32-
else {
33-
val accum = new ClassesToLoadAccumulator
34-
val classesToLoad = unprocessed.foldLeft(Set.empty[ClassDenotation])((acc, unit) => accum.apply(acc, unit.tpdTree)) -- loadedClasses
35-
val loadedUnits = classesToLoad.flatMap(cls => loadCompilationUnit(cls))
36-
allUnits(processed ++ unprocessed, loadedUnits, loadedClasses ++ classesToLoad)
35+
}
3736
}
37+
38+
if (ctx.settings.XlinkOptimise.value) super.runOn(allUnits(Set.empty, units.toSet, Set.empty))
39+
else super.runOn(units)
3840
}
3941

4042
/** Collects all class denotations that may need to be loaded. */

0 commit comments

Comments
 (0)