Skip to content

Commit fe24786

Browse files
Merge pull request #3436 from dotty-staging/abstract-dotc-repl
Fix dotr -tasty
2 parents 01c533f + faedad7 commit fe24786

16 files changed

+225
-158
lines changed

.drone.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ pipeline:
2525
image: lampepfl/dotty:2017-10-20
2626
commands:
2727
- cp -R . /tmp/1/ && cd /tmp/1/
28-
- ./project/scripts/sbt ";compile ;testAll ;dotty-bench/jmh:run 1 1 tests/pos/alias.scala"
28+
- ./project/scripts/sbt ";compile ;testAll"
29+
- ./project/scripts/sbtTests
2930

3031
test_bootstrapped:
3132
group: test
3233
image: lampepfl/dotty:2017-10-20
3334
commands:
3435
- cp -R . /tmp/2/ && cd /tmp/2/
35-
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/testAll ;dotty-bench-bootstrapped/jmh:run 1 1 tests/pos/alias.scala"
36+
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/testAll"
37+
- ./project/scripts/sbtBootstrappedTests
3638

3739
test_optimised:
3840
group: test

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import core.Contexts.{Context, ContextBase}
66
import util.DotClass
77
import reporting._
88
import scala.util.control.NonFatal
9+
import fromtasty.TASTYCompiler
910

1011
/** Run the Dotty compiler.
1112
*
@@ -15,7 +16,9 @@ import scala.util.control.NonFatal
1516
*/
1617
class Driver extends DotClass {
1718

18-
protected def newCompiler(implicit ctx: Context): Compiler = new Compiler
19+
protected def newCompiler(implicit ctx: Context): Compiler =
20+
if (ctx.settings.tasty.value) new TASTYCompiler
21+
else new Compiler
1922

2023
protected def emptyReporter: Reporter = new StoreReporter(null)
2124

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

Lines changed: 0 additions & 114 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package dotty.tools
22
package dotc
33

4-
import core.Contexts.Context
5-
64
/** Main class of the `dotc` batch compiler. */
75
object Main extends Driver

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class ScalaSettings extends Settings.SettingGroup {
4242
val language = MultiStringSetting("-language", "feature", "Enable one or more language features.")
4343
val rewrite = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax")
4444
val silentWarnings = BooleanSetting("-nowarn", "Silence all warnings.")
45+
val tasty = BooleanSetting("-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.")
4546

4647
/** -X "Advanced" settings
4748
*/

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
326326
val (classRoot, moduleRoot) = rootDenots(root.asClass)
327327
val classfileParser = new ClassfileParser(classfile, classRoot, moduleRoot)(ctx)
328328
val result = classfileParser.run()
329-
if (ctx.settings.YretainTrees.value || ctx.settings.XlinkOptimise.value) {
329+
if (mayLoadTreesFromTasty) {
330330
result match {
331331
case Some(unpickler: tasty.DottyUnpickler) =>
332332
classRoot.symbol.asClass.unpickler = unpickler
@@ -335,6 +335,9 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
335335
}
336336
}
337337
}
338+
339+
private def mayLoadTreesFromTasty(implicit ctx: Context): Boolean =
340+
ctx.settings.YretainTrees.value || ctx.settings.XlinkOptimise.value || ctx.settings.tasty.value
338341
}
339342

340343
class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package dotty.tools
2+
package dotc
3+
package fromtasty
4+
5+
import dotty.tools.dotc.ast.tpd
6+
import dotty.tools.dotc.core.Contexts.Context
7+
import dotty.tools.dotc.core.Decorators._
8+
import dotty.tools.dotc.core.Names._
9+
import dotty.tools.dotc.core.NameOps._
10+
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
11+
import dotty.tools.dotc.core._
12+
import dotty.tools.dotc.typer.FrontEnd
13+
14+
class ReadTastyTreesFromClasses extends FrontEnd {
15+
16+
override def isTyper = false
17+
18+
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] =
19+
units.flatMap(readTASTY)
20+
21+
def readTASTY(unit: CompilationUnit)(implicit ctx: Context): Option[CompilationUnit] = unit match {
22+
case unit: TASTYCompilationUnit =>
23+
val className = unit.className.toTypeName
24+
def compilationUnit(className: TypeName): Option[CompilationUnit] = {
25+
tree(className).flatMap {
26+
case (clsd, unpickled) =>
27+
if (unpickled.isEmpty) None
28+
else Some(CompilationUnit.mkCompilationUnit(clsd, unpickled, forceTrees = true))
29+
30+
}
31+
}
32+
// The TASTY section in a/b/C.class may either contain a class a.b.C, an object a.b.C, or both.
33+
// We first try to load the class and fallback to loading the object if the class doesn't exist.
34+
// Note that if both the class and the object are present, then loading the class will also load
35+
// the object, this is why we use orElse here, otherwise we could load the object twice and
36+
// create ambiguities!
37+
compilationUnit(className).orElse(compilationUnit(className.moduleClassName))
38+
}
39+
40+
private def tree(className: TypeName)(implicit ctx: Context): Option[(ClassDenotation, tpd.Tree)] = {
41+
val clsd = ctx.base.staticRef(className)
42+
ctx.base.staticRef(className) match {
43+
case clsd: ClassDenotation =>
44+
def cannotUnpickle(reason: String) =
45+
ctx.error(s"class $className cannot be unpickled because $reason")
46+
def tryToLoad = clsd.infoOrCompleter match {
47+
case info: ClassfileLoader =>
48+
info.load(clsd)
49+
Option(clsd.symbol.asClass.tree).orElse {
50+
cannotUnpickle(s"its class file ${info.classfile} does not have a TASTY attribute")
51+
None
52+
}
53+
54+
case info =>
55+
cannotUnpickle(s"its info of type ${info.getClass} is not a ClassfileLoader")
56+
None
57+
}
58+
Option(clsd.symbol.asClass.tree).orElse(tryToLoad).map(tree => (clsd, tree))
59+
60+
case _ =>
61+
ctx.error(s"class not found: $className")
62+
None
63+
}
64+
}
65+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dotty.tools.dotc.fromtasty
2+
3+
import dotty.tools.dotc.CompilationUnit
4+
import dotty.tools.dotc.util.NoSource
5+
6+
class TASTYCompilationUnit(val className: String) extends CompilationUnit(NoSource) {
7+
override def toString = s"class file $className"
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package dotty.tools
2+
package dotc
3+
package fromtasty
4+
5+
import core._
6+
import Contexts._
7+
import Phases.Phase
8+
import dotty.tools.dotc.transform.Pickler
9+
10+
class TASTYCompiler extends Compiler {
11+
12+
override def phases: List[List[Phase]] = {
13+
val backendPhases = super.phases.dropWhile {
14+
case List(_: Pickler) => false
15+
case _ => true
16+
}.tail
17+
List(new ReadTastyTreesFromClasses) :: backendPhases
18+
}
19+
20+
override def newRun(implicit ctx: Context): Run = {
21+
reset()
22+
new TASTYRun(this, ctx)
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package dotty.tools
2+
package dotc
3+
package fromtasty
4+
5+
import core.Contexts._
6+
7+
class TASTYRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) {
8+
override def compile(classNames: List[String]) = {
9+
units = classNames.map(new TASTYCompilationUnit(_))
10+
compileUnits()
11+
}
12+
}

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
395395
protected def compileFromTasty(flags0: TestFlags, suppressErrors: Boolean, targetDir: JFile): TestReporter = {
396396
val tastyOutput = new JFile(targetDir.getPath + "_from-tasty")
397397
tastyOutput.mkdir()
398-
val flags = flags0 and ("-d", tastyOutput.getAbsolutePath)
398+
val flags = flags0 and ("-d", tastyOutput.getAbsolutePath) and "-tasty"
399399

400400
def hasTastyFileToClassName(f: JFile): String =
401401
targetDir.toPath.relativize(f.toPath).toString.dropRight(".hasTasty".length).replace('/', '.')
@@ -405,9 +405,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
405405
TestReporter.reporter(realStdout, logLevel =
406406
if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR)
407407

408+
val driver = new Driver
409+
408410
// Compile with a try to catch any StackTrace generated by the compiler:
409411
try {
410-
dotc.FromTasty.process(flags.all ++ classes, reporter = reporter)
412+
driver.process(flags.all ++ classes, reporter = reporter)
411413
}
412414
catch {
413415
case NonFatal(ex) => reporter.logStackTrace(ex)
@@ -1097,7 +1099,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
10971099
val target = JointCompilationSource(
10981100
testGroup.name,
10991101
Array(sourceFile),
1100-
flags.withClasspath(tastySource.getPath) and "-Yretain-trees",
1102+
flags.withClasspath(tastySource.getPath) and "-tasty",
11011103
tastySource,
11021104
fromTasty = true
11031105
)

dist/bin/dotc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ default_java_opts="-Xmx768m -Xms768m"
3131
bootcp=true
3232

3333
CompilerMain=dotty.tools.dotc.Main
34-
FromTasty=dotty.tools.dotc.FromTasty
3534
ReplMain=dotty.tools.repl.Main
3635

3736
PROG_NAME=$CompilerMain
@@ -82,7 +81,6 @@ case "$1" in
8281
# Optimize for short-running applications, see https://github.com/lampepfl/dotty/issues/222
8382
-Oshort) addJava "-XX:+TieredCompilation -XX:TieredStopAtLevel=1" && shift ;;
8483
-repl) PROG_NAME="$ReplMain" && shift ;;
85-
-tasty) PROG_NAME="$FromTasty" && shift ;;
8684
-compile) PROG_NAME="$CompilerMain" && shift ;;
8785
-run) PROG_NAME="$ReplMain" && shift ;;
8886
-bootcp) bootcp=true && shift ;;

0 commit comments

Comments
 (0)