Skip to content

Commit 9db42ed

Browse files
authored
Merge pull request #39 from retronym/topic/resident
Support benchmarking of resident compilation
2 parents 4c573db + d1c128f commit 9db42ed

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

compilation/src/main/dotc/scala/tools/benchmark/BenchmarkDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait BenchmarkDriver extends BaseBenchmarkDriver {
1212
ctx.setSetting(ctx.settings.classpath,
1313
depsClasspath.mkString(File.pathSeparator))
1414
}
15-
ctx.setSetting(ctx.settings.migration, true)
15+
ctx.setSetting(ctx.settings.migration, false)
1616
ctx.setSetting(ctx.settings.d, tempDir.getAbsolutePath)
1717
ctx.setSetting(ctx.settings.language, List("Scala2"))
1818
val compiler = new dotty.tools.dotc.Compiler

compilation/src/main/scala/scala/tools/nsc/ScalacBenchmark.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ trait BaseBenchmarkDriver {
2525
def corpusSourcePath: Path
2626
def compilerArgs: List[String]
2727
def sourceFiles: List[String]
28+
def isResident: Boolean = false
2829
}
2930

3031
@State(Scope.Benchmark)
@@ -40,6 +41,11 @@ class ScalacBenchmark extends BenchmarkDriver {
4041
@Param(value = Array("latest"))
4142
var corpusVersion: String = _
4243

44+
@Param(value = Array("false"))
45+
var resident: Boolean = false
46+
47+
override def isResident = resident
48+
4349
var depsClasspath: String = _
4450

4551
def compilerArgs: List[String] = if (source.startsWith("@")) source :: Nil else Nil

compilation/src/main/scalac/scala/tools/benchmark/BenchmarkDriver.scala

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,47 @@ import java.nio.file._
44
import scala.tools.nsc._
55

66
trait BenchmarkDriver extends BaseBenchmarkDriver {
7+
private var driver: MainClass = _
8+
private var files: List[String] = _
9+
10+
// MainClass is copy-pasted from compiler for source compatibility with 2.10.x - 2.13.x
11+
private class MainClass extends Driver with EvalLoop {
12+
var compiler: Global = _
13+
override def newCompiler(): Global = {
14+
compiler = Global(settings, reporter)
15+
compiler
16+
}
17+
18+
override protected def processSettingsHook(): Boolean = {
19+
if (source == "scala")
20+
settings.sourcepath.value = Paths.get(s"../corpus/$source/$corpusVersion/library").toAbsolutePath.normalize.toString
21+
else
22+
settings.usejavacp.value = true
23+
settings.outdir.value = tempDir.getAbsolutePath
24+
settings.nowarn.value = true
25+
if (depsClasspath != null)
26+
settings.processArgumentString(s"-cp $depsClasspath")
27+
true
28+
}
29+
}
30+
731
def compileImpl(): Unit = {
8-
// MainClass is copy-pasted from compiler for source compatibility with 2.10.x - 2.13.x
9-
class MainClass extends Driver with EvalLoop {
10-
def resident(compiler: Global): Unit = loop { line =>
11-
val command = new CompilerCommand(line split "\\s+" toList, new Settings(scalacError))
32+
if (isResident) {
33+
if (driver == null) {
34+
driver = new MainClass
35+
driver.process(allArgs.toArray)
36+
val command = new CompilerCommand(allArgs, driver.compiler.settings)
37+
files = command.files
38+
} else {
39+
val compiler = driver.compiler
1240
compiler.reporter.reset()
13-
new compiler.Run() compile command.files
41+
new compiler.Run() compile files
1442
}
1543

16-
override def newCompiler(): Global = Global(settings, reporter)
17-
18-
override protected def processSettingsHook(): Boolean = {
19-
if (source == "scala")
20-
settings.sourcepath.value = Paths.get(s"../corpus/$source/$corpusVersion/library").toAbsolutePath.normalize.toString
21-
else
22-
settings.usejavacp.value = true
23-
settings.outdir.value = tempDir.getAbsolutePath
24-
settings.nowarn.value = true
25-
if (depsClasspath != null)
26-
settings.processArgumentString(s"-cp $depsClasspath")
27-
true
28-
}
44+
} else {
45+
driver = new MainClass
46+
driver.process(allArgs.toArray)
2947
}
30-
val driver = new MainClass
31-
driver.process(allArgs.toArray)
3248
assert(!driver.reporter.hasErrors)
3349
}
3450

0 commit comments

Comments
 (0)