Skip to content

Support benchmarking of resident compilation #39

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 2 commits into from
Aug 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ trait BaseBenchmarkDriver {
def corpusSourcePath: Path
def compilerArgs: List[String]
def sourceFiles: List[String]
def isResident: Boolean = false
}

@State(Scope.Benchmark)
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down