From 3ea341ee02f760ff4d50c05e8b3e76cf30519923 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Fri, 25 Aug 2017 16:43:01 +1000 Subject: [PATCH 1/2] Support benchmarking of resident compilation --- .../tools/benchmark/BenchmarkDriver.scala | 2 +- .../scala/tools/nsc/ScalacBenchmark.scala | 6 ++ .../tools/benchmark/BenchmarkDriver.scala | 61 +++++++++++++------ 3 files changed, 48 insertions(+), 21 deletions(-) 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..3f03a82 100644 --- a/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala +++ b/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala @@ -4,31 +4,52 @@ 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 { + def resident(compiler: Global): Unit = loop { line => + val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError)) + compiler.reporter.reset() + new compiler.Run() compile command.files + } + 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) } From d1c128f12040057deea7b7776aae126d0e07b0e0 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 30 Aug 2017 13:39:35 +1000 Subject: [PATCH 2/2] Remove unused method --- .../main/scalac/scala/tools/benchmark/BenchmarkDriver.scala | 5 ----- 1 file changed, 5 deletions(-) diff --git a/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala b/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala index 3f03a82..e5e400b 100644 --- a/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala +++ b/compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala @@ -9,11 +9,6 @@ trait BenchmarkDriver extends BaseBenchmarkDriver { // MainClass is copy-pasted from compiler for source compatibility with 2.10.x - 2.13.x private class MainClass extends Driver with EvalLoop { - def resident(compiler: Global): Unit = loop { line => - val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError)) - compiler.reporter.reset() - new compiler.Run() compile command.files - } var compiler: Global = _ override def newCompiler(): Global = { compiler = Global(settings, reporter)