-
Notifications
You must be signed in to change notification settings - Fork 31
Compile benchmark with Dotty, fixes #29. #31
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
Changes from 9 commits
700448d
16fe81a
1bd6dd5
ccc6b38
49b2fb0
ef391dd
1a975a9
88190e1
6ed08f2
ab1080a
4f27da1
0a937bb
dd00264
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ name := "compiler-benchmark" | |
|
||
version := "1.0-SNAPSHOT" | ||
|
||
scalaVersion in ThisBuild := "2.11.8" | ||
def scala211 = "2.11.11" | ||
def dottyLatest = "0.2.0-RC1" | ||
scalaVersion in ThisBuild := scala211 | ||
|
||
resolvers += "scala-integration" at "https://scala-ci.typesafe.com/artifactory/scala-integration/" | ||
|
||
|
@@ -36,8 +38,17 @@ lazy val compilation = addJmh(project).settings( | |
// We should be able to switch this project to a broad range of Scala versions for comparative | ||
// benchmarking. As such, this project should only depend on the high level `MainClass` compiler API. | ||
description := "Black box benchmark of the compiler", | ||
libraryDependencies += scalaOrganization.value % "scala-compiler" % scalaVersion.value, | ||
mainClass in (Jmh, run) := Some("scala.bench.ScalacBenchmarkRunner") | ||
libraryDependencies += { | ||
if (isDotty.value) "ch.epfl.lamp" %% "dotty-compiler" % scalaVersion.value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to also use Sbt's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that help when the artifact id is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, I opened #34 myself. |
||
else scalaOrganization.value % "scala-compiler" % scalaVersion.value | ||
}, | ||
crossScalaVersions := List(scala211, dottyLatest), | ||
unmanagedSourceDirectories.in(Compile) += | ||
sourceDirectory.in(Compile).value / (if (isDotty.value) "dotc" else "scalac"), | ||
mainClass in (Jmh, run) := Some("scala.bench.ScalacBenchmarkRunner"), | ||
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test, | ||
testOptions in Test += Tests.Argument(TestFrameworks.JUnit), | ||
fork in (Test, test) := true // jmh scoped tasks run with fork := true. | ||
).settings(addJavaOptions).dependsOn(infrastructure) | ||
|
||
lazy val micro = addJmh(project).settings( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package scala.tools.benchmark | ||
|
||
import java.io.File | ||
import scala.tools.nsc.BaseBenchmarkDriver | ||
import dotty.tools.dotc.core.Contexts.ContextBase | ||
|
||
trait BenchmarkDriver extends BaseBenchmarkDriver { | ||
def compileImpl(): Unit = { | ||
implicit val ctx = new ContextBase().initialCtx.fresh | ||
ctx.setSetting(ctx.settings.usejavacp, true) | ||
if (depsClasspath != null) { | ||
ctx.setSetting(ctx.settings.classpath, | ||
depsClasspath.mkString(File.pathSeparator)) | ||
} | ||
ctx.setSetting(ctx.settings.migration, true) | ||
ctx.setSetting(ctx.settings.d, tempDir.getAbsolutePath) | ||
ctx.setSetting(ctx.settings.language, List("Scala2")) | ||
val compiler = new dotty.tools.dotc.Compiler | ||
val args = compilerArgs ++ sourceFiles | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also process There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. |
||
val reporter = dotty.tools.dotc.Bench.doCompile(compiler, args) | ||
assert(!reporter.hasErrors) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package scala.tools.benchmark | ||
|
||
import java.nio.file._ | ||
import scala.tools.nsc._ | ||
|
||
trait BenchmarkDriver extends BaseBenchmarkDriver { | ||
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)) | ||
compiler.reporter.reset() | ||
new compiler.Run() compile command.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 | ||
} | ||
} | ||
val driver = new MainClass | ||
|
||
val extras = if (extraArgs != null && extraArgs != "") extraArgs.split('|').toList else Nil | ||
val allArgs = compilerArgs ++ extras ++ sourceFiles | ||
driver.process(allArgs.toArray) | ||
assert(!driver.reporter.hasErrors) | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package scala.tools.benchmark | ||
|
||
import scala.tools.nsc.ScalacBenchmark | ||
import org.junit.Test | ||
|
||
class BenchmarkTest { | ||
@Test def compilesOK() = { | ||
val bench = new ScalacBenchmark | ||
bench.source = "../corpus/vector" | ||
bench.corpusVersion = "latest" | ||
bench.initTemp() | ||
bench.compileImpl() | ||
bench.clearTemp() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we're running
test:compile
andhot...
only on scalac for now because@Fork
still crashes dotc, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
@Fork
annotation issue has been fixed, I can change the CI to run dotty benchmarks in CI too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still a comment in the diff that links to scala/scala3#2704
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the comment, the issue has been fixed and should be closed.