Skip to content

Commit dab02ed

Browse files
authored
Merge pull request #5609 from dotty-staging/from-tasty
Use `-from-tasty` flag to enable/disable some phases
2 parents 62292f2 + 5b6fb10 commit dab02ed

File tree

16 files changed

+143
-152
lines changed

16 files changed

+143
-152
lines changed

compiler/src/dotty/tools/backend/sjs/GenSJSIR.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import Phases._
88
class GenSJSIR extends Phase {
99
def phaseName: String = "genSJSIR"
1010

11-
def run(implicit ctx: Context): Unit = {
12-
if (ctx.settings.scalajs.value)
13-
new JSCodeGen().run()
14-
}
11+
override def isRunnable(implicit ctx: Context): Boolean =
12+
super.isRunnable && ctx.settings.scalajs.value
13+
14+
def run(implicit ctx: Context): Unit =
15+
new JSCodeGen().run()
1516
}

compiler/src/dotty/tools/dotc/consumetasty/TastyFromClass.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.tasty.file.TastyConsumer
88
class TastyFromClass(consumer: TastyConsumer) extends TASTYCompiler {
99

1010
override protected def frontendPhases: List[List[Phase]] =
11-
List(new ReadTastyTreesFromClasses) :: // Load classes from tasty
11+
List(new ReadTasty) :: // Load classes from tasty
1212
Nil
1313

1414
override protected def picklerPhases: List[List[Phase]] = Nil

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ object Phases {
262262
final def isAfterTyper(phase: Phase): Boolean = phase.id > typerPhase.id
263263
}
264264

265-
trait Phase {
265+
abstract class Phase {
266266

267267
/** A name given to the `Phase` that can be used to debug the compiler. For
268268
* instance, it is possible to print trees after a given phase using:

compiler/src/dotty/tools/dotc/decompiler/TASTYDecompiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dotty.tools.dotc.core.Phases.Phase
1111
class TASTYDecompiler extends TASTYCompiler {
1212

1313
override protected def frontendPhases: List[List[Phase]] =
14-
List(new ReadTastyTreesFromClasses) :: // Load classes from tasty
14+
List(new ReadTasty) :: // Load trees from TASTY files
1515
Nil
1616

1717
override protected def picklerPhases: List[List[Phase]] = Nil

compiler/src/dotty/tools/dotc/fromtasty/ReadTastyTreesFromClasses.scala renamed to compiler/src/dotty/tools/dotc/fromtasty/ReadTasty.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ import Decorators._
77
import Contexts.Context
88
import Symbols.{Symbol, ClassSymbol}
99
import SymDenotations.ClassDenotation
10-
import typer.FrontEnd
1110
import NameOps._
1211
import ast.Trees.Tree
1312
import CompilationUnit.mkCompilationUnit
13+
import Phases.Phase
1414

15-
class ReadTastyTreesFromClasses extends FrontEnd {
1615

17-
override def isTyper: Boolean = false
16+
/** Load trees from TASTY files */
17+
class ReadTasty extends Phase {
18+
19+
def phaseName: String = "readTasty"
20+
21+
override def isRunnable(implicit ctx: Context): Boolean =
22+
ctx.settings.fromTasty.value
1823

1924
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] =
2025
units.flatMap(readTASTY(_)(ctx.addMode(Mode.ReadPositions)))
@@ -71,4 +76,6 @@ class ReadTastyTreesFromClasses extends FrontEnd {
7176
case unit =>
7277
Some(unit)
7378
}
79+
80+
def run(implicit ctx: Context): Unit = unsupported("run")
7481
}

compiler/src/dotty/tools/dotc/fromtasty/TASTYCompiler.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import dotty.tools.dotc.transform._
1010
class TASTYCompiler extends Compiler {
1111

1212
override protected def frontendPhases: List[List[Phase]] =
13-
List(new ReadTastyTreesFromClasses) :: Nil
14-
15-
override protected def picklerPhases: List[List[Phase]] =
16-
super.picklerPhases.map(_.filterNot(_.isInstanceOf[Pickler])) // No need to repickle
13+
List(new ReadTasty) :: Nil
1714

1815
override def newRun(implicit ctx: Context): Run = {
1916
reset()

compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package quoted
34

45
import dotty.tools.dotc.ast.tpd
@@ -14,7 +15,6 @@ import dotty.tools.dotc.core.Symbols.defn
1415
import dotty.tools.dotc.core.Types.ExprType
1516
import dotty.tools.dotc.core.quoted.PickledQuotes
1617
import dotty.tools.dotc.transform.Staging
17-
import dotty.tools.dotc.typer.FrontEnd
1818
import dotty.tools.dotc.util.Positions.Position
1919
import dotty.tools.dotc.util.SourceFile
2020
import dotty.tools.io.{Path, VirtualFile}
@@ -40,10 +40,10 @@ class QuoteCompiler extends Compiler {
4040
def outputClassName: TypeName = "Quoted".toTypeName
4141

4242
/** Frontend that receives a scala.quoted.Expr or scala.quoted.Type as input */
43-
class QuotedFrontend(putInClass: Boolean) extends FrontEnd {
43+
class QuotedFrontend(putInClass: Boolean) extends Phase {
4444
import tpd._
4545

46-
override def isTyper: Boolean = false
46+
def phaseName: String = "quotedFrontend"
4747

4848
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
4949
units.map {
@@ -80,6 +80,8 @@ class QuoteCompiler extends Compiler {
8080
val classTree = ClassDef(cls, DefDef(cls.primaryConstructor.asTerm), run :: Nil)
8181
PackageDef(ref(defn.RootPackage).asInstanceOf[Ident], classTree :: Nil).withPos(pos)
8282
}
83+
84+
def run(implicit ctx: Context): Unit = unsupported("run")
8385
}
8486

8587
class ExprRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) {
@@ -92,5 +94,4 @@ class QuoteCompiler extends Compiler {
9294
compileUnits(units)
9395
}
9496
}
95-
9697
}

compiler/src/dotty/tools/dotc/sbt/ExtractAPI.scala

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ import scala.collection.mutable
4141
class ExtractAPI extends Phase {
4242
override def phaseName: String = "sbt-api"
4343

44+
override def isRunnable(implicit ctx: Context): Boolean = {
45+
def forceRun = ctx.settings.YdumpSbtInc.value || ctx.settings.YforceSbtPhases.value
46+
super.isRunnable && (ctx.sbtCallback != null || forceRun)
47+
}
48+
4449
// SuperAccessors need to be part of the API (see the scripted test
4550
// `trait-super` for an example where this matters), this is only the case
4651
// after `PostTyper` (unlike `ExtractDependencies`, the simplication to trees
@@ -50,30 +55,26 @@ class ExtractAPI extends Phase {
5055

5156
override def run(implicit ctx: Context): Unit = {
5257
val unit = ctx.compilationUnit
53-
val dumpInc = ctx.settings.YdumpSbtInc.value
54-
val forceRun = dumpInc || ctx.settings.YforceSbtPhases.value
55-
if ((ctx.sbtCallback != null || forceRun) && !unit.isJava) {
56-
val sourceFile = unit.source.file
57-
if (ctx.sbtCallback != null)
58-
ctx.sbtCallback.startSource(sourceFile.file)
59-
60-
val apiTraverser = new ExtractAPICollector
61-
val classes = apiTraverser.apiSource(unit.tpdTree)
62-
val mainClasses = apiTraverser.mainClasses
63-
64-
if (dumpInc) {
65-
// Append to existing file that should have been created by ExtractDependencies
66-
val pw = new PrintWriter(File(sourceFile.jpath).changeExtension("inc").toFile
67-
.bufferedWriter(append = true), true)
68-
try {
69-
classes.foreach(source => pw.println(DefaultShowAPI(source)))
70-
} finally pw.close()
71-
}
58+
val sourceFile = unit.source.file
59+
if (ctx.sbtCallback != null)
60+
ctx.sbtCallback.startSource(sourceFile.file)
61+
62+
val apiTraverser = new ExtractAPICollector
63+
val classes = apiTraverser.apiSource(unit.tpdTree)
64+
val mainClasses = apiTraverser.mainClasses
65+
66+
if (ctx.settings.YdumpSbtInc.value) {
67+
// Append to existing file that should have been created by ExtractDependencies
68+
val pw = new PrintWriter(File(sourceFile.jpath).changeExtension("inc").toFile
69+
.bufferedWriter(append = true), true)
70+
try {
71+
classes.foreach(source => pw.println(DefaultShowAPI(source)))
72+
} finally pw.close()
73+
}
7274

73-
if (ctx.sbtCallback != null) {
74-
classes.foreach(ctx.sbtCallback.api(sourceFile.file, _))
75-
mainClasses.foreach(ctx.sbtCallback.mainClass(sourceFile.file, _))
76-
}
75+
if (ctx.sbtCallback != null) {
76+
classes.foreach(ctx.sbtCallback.api(sourceFile.file, _))
77+
mainClasses.foreach(ctx.sbtCallback.mainClass(sourceFile.file, _))
7778
}
7879
}
7980
}

compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,52 +49,51 @@ class ExtractDependencies extends Phase {
4949

5050
override def phaseName: String = "sbt-deps"
5151

52+
override def isRunnable(implicit ctx: Context): Boolean = {
53+
def forceRun = ctx.settings.YdumpSbtInc.value || ctx.settings.YforceSbtPhases.value
54+
super.isRunnable && (ctx.sbtCallback != null || forceRun)
55+
}
56+
5257
// This phase should be run directly after `Frontend`, if it is run after
5358
// `PostTyper`, some dependencies will be lost because trees get simplified.
5459
// See the scripted test `constants` for an example where this matters.
5560
// TODO: Add a `Phase#runsBefore` method ?
5661

5762
override def run(implicit ctx: Context): Unit = {
5863
val unit = ctx.compilationUnit
59-
val dumpInc = ctx.settings.YdumpSbtInc.value
60-
val forceRun = dumpInc || ctx.settings.YforceSbtPhases.value
61-
val shouldRun = !unit.isJava && (ctx.sbtCallback != null || forceRun)
62-
63-
if (shouldRun) {
64-
val collector = new ExtractDependenciesCollector
65-
collector.traverse(unit.tpdTree)
66-
67-
if (dumpInc) {
68-
val deps = collector.dependencies.map(_.toString).toArray[Object]
69-
val names = collector.usedNames.map { case (clazz, names) => s"$clazz: $names" }.toArray[Object]
70-
Arrays.sort(deps)
71-
Arrays.sort(names)
72-
73-
val pw = io.File(unit.source.file.jpath).changeExtension("inc").toFile.printWriter()
74-
// val pw = Console.out
75-
try {
76-
pw.println("Used Names:")
77-
pw.println("===========")
78-
names.foreach(pw.println)
79-
pw.println()
80-
pw.println("Dependencies:")
81-
pw.println("=============")
82-
deps.foreach(pw.println)
83-
} finally pw.close()
84-
}
85-
86-
if (ctx.sbtCallback != null) {
87-
collector.usedNames.foreach {
88-
case (clazz, usedNames) =>
89-
val className = classNameAsString(clazz)
90-
usedNames.names.foreach {
91-
case (usedName, scopes) =>
92-
ctx.sbtCallback.usedName(className, usedName.toString, scopes)
93-
}
94-
}
64+
val collector = new ExtractDependenciesCollector
65+
collector.traverse(unit.tpdTree)
66+
67+
if (ctx.settings.YdumpSbtInc.value) {
68+
val deps = collector.dependencies.map(_.toString).toArray[Object]
69+
val names = collector.usedNames.map { case (clazz, names) => s"$clazz: $names" }.toArray[Object]
70+
Arrays.sort(deps)
71+
Arrays.sort(names)
72+
73+
val pw = io.File(unit.source.file.jpath).changeExtension("inc").toFile.printWriter()
74+
// val pw = Console.out
75+
try {
76+
pw.println("Used Names:")
77+
pw.println("===========")
78+
names.foreach(pw.println)
79+
pw.println()
80+
pw.println("Dependencies:")
81+
pw.println("=============")
82+
deps.foreach(pw.println)
83+
} finally pw.close()
84+
}
9585

96-
collector.dependencies.foreach(recordDependency)
86+
if (ctx.sbtCallback != null) {
87+
collector.usedNames.foreach {
88+
case (clazz, usedNames) =>
89+
val className = classNameAsString(clazz)
90+
usedNames.names.foreach {
91+
case (usedName, scopes) =>
92+
ctx.sbtCallback.usedName(className, usedName.toString, scopes)
93+
}
9794
}
95+
96+
collector.dependencies.foreach(recordDependency)
9897
}
9998
}
10099

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class Pickler extends Phase {
2424

2525
override def phaseName: String = Pickler.name
2626

27+
// No need to repickle trees comming from TASTY
28+
override def isRunnable(implicit ctx: Context): Boolean =
29+
super.isRunnable && !ctx.settings.fromTasty.value
30+
2731
private def output(name: String, msg: String) = {
2832
val s = new PrintStream(name)
2933
s.print(msg)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class TreeChecker extends Phase with SymTransformer {
9090
def run(implicit ctx: Context): Unit = {
9191
if (ctx.settings.YtestPickler.value && ctx.phase.prev.isInstanceOf[Pickler])
9292
ctx.echo("Skipping Ycheck after pickling with -Ytest-pickler, the returned tree contains stale symbols")
93-
else
93+
else if (ctx.phase.prev.isCheckable)
9494
check(ctx.base.allPhases, ctx)
9595
}
9696

compiler/src/dotty/tools/dotc/typer/FrontEnd.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package typer
34

45
import core._
@@ -90,11 +91,7 @@ class FrontEnd extends Phase {
9091
unitContexts.map(_.compilationUnit).filterNot(discardAfterTyper)
9192
}
9293

93-
override def run(implicit ctx: Context): Unit = {
94-
parse
95-
enterSyms
96-
typeCheck
97-
}
94+
def run(implicit ctx: Context): Unit = unsupported("run")
9895
}
9996

10097
object FrontEnd {

0 commit comments

Comments
 (0)