Skip to content

Fix dotr -tasty #3436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ pipeline:
image: lampepfl/dotty:2017-10-20
commands:
- cp -R . /tmp/1/ && cd /tmp/1/
- ./project/scripts/sbt ";compile ;testAll ;dotty-bench/jmh:run 1 1 tests/pos/alias.scala"
- ./project/scripts/sbt ";compile ;testAll"
- ./project/scripts/sbtTests

test_bootstrapped:
group: test
image: lampepfl/dotty:2017-10-20
commands:
- cp -R . /tmp/2/ && cd /tmp/2/
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/testAll ;dotty-bench-bootstrapped/jmh:run 1 1 tests/pos/alias.scala"
- ./project/scripts/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/testAll"
- ./project/scripts/sbtBootstrappedTests

test_optimised:
group: test
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import core.Contexts.{Context, ContextBase}
import util.DotClass
import reporting._
import scala.util.control.NonFatal
import fromtasty.TASTYCompiler

/** Run the Dotty compiler.
*
Expand All @@ -15,7 +16,9 @@ import scala.util.control.NonFatal
*/
class Driver extends DotClass {

protected def newCompiler(implicit ctx: Context): Compiler = new Compiler
protected def newCompiler(implicit ctx: Context): Compiler =
if (ctx.settings.tasty.value) new TASTYCompiler
else new Compiler

protected def emptyReporter: Reporter = new StoreReporter(null)

Expand Down
114 changes: 0 additions & 114 deletions compiler/src/dotty/tools/dotc/FromTasty.scala

This file was deleted.

2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/Main.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dotty.tools
package dotc

import core.Contexts.Context

/** Main class of the `dotc` batch compiler. */
object Main extends Driver
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ScalaSettings extends Settings.SettingGroup {
val language = MultiStringSetting("-language", "feature", "Enable one or more language features.")
val rewrite = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax")
val silentWarnings = BooleanSetting("-nowarn", "Silence all warnings.")
val tasty = BooleanSetting("-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.")

/** -X "Advanced" settings
*/
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
val (classRoot, moduleRoot) = rootDenots(root.asClass)
val classfileParser = new ClassfileParser(classfile, classRoot, moduleRoot)(ctx)
val result = classfileParser.run()
if (ctx.settings.YretainTrees.value || ctx.settings.XlinkOptimise.value) {
if (mayLoadTreesFromTasty) {
result match {
case Some(unpickler: tasty.DottyUnpickler) =>
classRoot.symbol.asClass.unpickler = unpickler
Expand All @@ -335,6 +335,9 @@ class ClassfileLoader(val classfile: AbstractFile) extends SymbolLoader {
}
}
}

private def mayLoadTreesFromTasty(implicit ctx: Context): Boolean =
ctx.settings.YretainTrees.value || ctx.settings.XlinkOptimise.value || ctx.settings.tasty.value
}

class SourcefileLoader(val srcfile: AbstractFile) extends SymbolLoader {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package dotty.tools
package dotc
package fromtasty

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.core.Names._
import dotty.tools.dotc.core.NameOps._
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
import dotty.tools.dotc.core._
import dotty.tools.dotc.typer.FrontEnd

class ReadTastyTreesFromClasses extends FrontEnd {

override def isTyper = false

override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] =
units.flatMap(readTASTY)

def readTASTY(unit: CompilationUnit)(implicit ctx: Context): Option[CompilationUnit] = unit match {
case unit: TASTYCompilationUnit =>
val className = unit.className.toTypeName
def compilationUnit(className: TypeName): Option[CompilationUnit] = {
tree(className).flatMap {
case (clsd, unpickled) =>
if (unpickled.isEmpty) None
else Some(CompilationUnit.mkCompilationUnit(clsd, unpickled, forceTrees = true))

}
}
// The TASTY section in a/b/C.class may either contain a class a.b.C, an object a.b.C, or both.
// We first try to load the class and fallback to loading the object if the class doesn't exist.
// Note that if both the class and the object are present, then loading the class will also load
// the object, this is why we use orElse here, otherwise we could load the object twice and
// create ambiguities!
compilationUnit(className).orElse(compilationUnit(className.moduleClassName))
}

private def tree(className: TypeName)(implicit ctx: Context): Option[(ClassDenotation, tpd.Tree)] = {
val clsd = ctx.base.staticRef(className)
ctx.base.staticRef(className) match {
case clsd: ClassDenotation =>
def cannotUnpickle(reason: String) =
ctx.error(s"class $className cannot be unpickled because $reason")
def tryToLoad = clsd.infoOrCompleter match {
case info: ClassfileLoader =>
info.load(clsd)
Option(clsd.symbol.asClass.tree).orElse {
cannotUnpickle(s"its class file ${info.classfile} does not have a TASTY attribute")
None
}

case info =>
cannotUnpickle(s"its info of type ${info.getClass} is not a ClassfileLoader")
None
}
Option(clsd.symbol.asClass.tree).orElse(tryToLoad).map(tree => (clsd, tree))

case _ =>
ctx.error(s"class not found: $className")
None
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dotty.tools.dotc.fromtasty

import dotty.tools.dotc.CompilationUnit
import dotty.tools.dotc.util.NoSource

class TASTYCompilationUnit(val className: String) extends CompilationUnit(NoSource) {
override def toString = s"class file $className"
}
24 changes: 24 additions & 0 deletions compiler/src/dotty/tools/dotc/fromtasty/TASTYCompiler.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dotty.tools
package dotc
package fromtasty

import core._
import Contexts._
import Phases.Phase
import dotty.tools.dotc.transform.Pickler

class TASTYCompiler extends Compiler {

override def phases: List[List[Phase]] = {
val backendPhases = super.phases.dropWhile {
case List(_: Pickler) => false
case _ => true
}.tail
List(new ReadTastyTreesFromClasses) :: backendPhases
}

override def newRun(implicit ctx: Context): Run = {
reset()
new TASTYRun(this, ctx)
}
}
12 changes: 12 additions & 0 deletions compiler/src/dotty/tools/dotc/fromtasty/TASTYRun.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dotty.tools
package dotc
package fromtasty

import core.Contexts._

class TASTYRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) {
override def compile(classNames: List[String]) = {
units = classNames.map(new TASTYCompilationUnit(_))
compileUnits()
}
}
8 changes: 5 additions & 3 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
protected def compileFromTasty(flags0: TestFlags, suppressErrors: Boolean, targetDir: JFile): TestReporter = {
val tastyOutput = new JFile(targetDir.getPath + "_from-tasty")
tastyOutput.mkdir()
val flags = flags0 and ("-d", tastyOutput.getAbsolutePath)
val flags = flags0 and ("-d", tastyOutput.getAbsolutePath) and "-tasty"

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

val driver = new Driver

// Compile with a try to catch any StackTrace generated by the compiler:
try {
dotc.FromTasty.process(flags.all ++ classes, reporter = reporter)
driver.process(flags.all ++ classes, reporter = reporter)
}
catch {
case NonFatal(ex) => reporter.logStackTrace(ex)
Expand Down Expand Up @@ -1097,7 +1099,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
val target = JointCompilationSource(
testGroup.name,
Array(sourceFile),
flags.withClasspath(tastySource.getPath) and "-Yretain-trees",
flags.withClasspath(tastySource.getPath) and "-tasty",
tastySource,
fromTasty = true
)
Expand Down
2 changes: 0 additions & 2 deletions dist/bin/dotc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ default_java_opts="-Xmx768m -Xms768m"
bootcp=true

CompilerMain=dotty.tools.dotc.Main
FromTasty=dotty.tools.dotc.FromTasty
ReplMain=dotty.tools.repl.Main

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