diff --git a/compilation/src/main/dotc/scala/tools/benchmark/BenchmarkDriver.scala b/compilation/src/main/dotc/scala/tools/benchmark/BenchmarkDriver.scala index 6047a33..632210d 100644 --- a/compilation/src/main/dotc/scala/tools/benchmark/BenchmarkDriver.scala +++ b/compilation/src/main/dotc/scala/tools/benchmark/BenchmarkDriver.scala @@ -12,7 +12,7 @@ trait BenchmarkDriver extends BaseBenchmarkDriver { ctx.setSetting(ctx.settings.classpath, depsClasspath.mkString(File.pathSeparator)) } - ctx.setSetting(ctx.settings.migration, true) + ctx.setSetting(ctx.settings.migration, false) ctx.setSetting(ctx.settings.d, tempDir.getAbsolutePath) ctx.setSetting(ctx.settings.language, List("Scala2")) val compiler = new dotty.tools.dotc.Compiler diff --git a/compilation/src/main/scala/scala/tools/nsc/ScalacBenchmark.scala b/compilation/src/main/scala/scala/tools/nsc/ScalacBenchmark.scala index aede754..6c6955c 100644 --- a/compilation/src/main/scala/scala/tools/nsc/ScalacBenchmark.scala +++ b/compilation/src/main/scala/scala/tools/nsc/ScalacBenchmark.scala @@ -25,6 +25,7 @@ trait BaseBenchmarkDriver { def corpusSourcePath: Path def compilerArgs: List[String] def sourceFiles: List[String] + def isResident: Boolean = false } @State(Scope.Benchmark) @@ -40,6 +41,11 @@ class ScalacBenchmark extends BenchmarkDriver { @Param(value = Array("latest")) var corpusVersion: String = _ + @Param(value = Array("false")) + var resident: Boolean = false + + override def isResident = resident + var depsClasspath: String = _ def compilerArgs: List[String] = if (source.startsWith("@")) source :: Nil else Nil diff --git a/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala b/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala index 687414a..e5e400b 100644 --- a/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala +++ b/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala @@ -4,31 +4,47 @@ import java.nio.file._ import scala.tools.nsc._ trait BenchmarkDriver extends BaseBenchmarkDriver { + private var driver: MainClass = _ + private var files: List[String] = _ + + // MainClass is copy-pasted from compiler for source compatibility with 2.10.x - 2.13.x + private class MainClass extends Driver with EvalLoop { + var compiler: Global = _ + override def newCompiler(): Global = { + compiler = Global(settings, reporter) + compiler + } + + override protected def processSettingsHook(): Boolean = { + if (source == "scala") + settings.sourcepath.value = Paths.get(s"../corpus/$source/$corpusVersion/library").toAbsolutePath.normalize.toString + else + settings.usejavacp.value = true + settings.outdir.value = tempDir.getAbsolutePath + settings.nowarn.value = true + if (depsClasspath != null) + settings.processArgumentString(s"-cp $depsClasspath") + true + } + } + def compileImpl(): Unit = { - // MainClass is copy-pasted from compiler for source compatibility with 2.10.x - 2.13.x - class MainClass extends Driver with EvalLoop { - def resident(compiler: Global): Unit = loop { line => - val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError)) + if (isResident) { + if (driver == null) { + driver = new MainClass + driver.process(allArgs.toArray) + val command = new CompilerCommand(allArgs, driver.compiler.settings) + files = command.files + } else { + val compiler = driver.compiler compiler.reporter.reset() - new compiler.Run() compile command.files + new compiler.Run() compile files } - override def newCompiler(): Global = Global(settings, reporter) - - override protected def processSettingsHook(): Boolean = { - if (source == "scala") - settings.sourcepath.value = Paths.get(s"../corpus/$source/$corpusVersion/library").toAbsolutePath.normalize.toString - else - settings.usejavacp.value = true - settings.outdir.value = tempDir.getAbsolutePath - settings.nowarn.value = true - if (depsClasspath != null) - settings.processArgumentString(s"-cp $depsClasspath") - true - } + } else { + driver = new MainClass + driver.process(allArgs.toArray) } - val driver = new MainClass - driver.process(allArgs.toArray) assert(!driver.reporter.hasErrors) }