Skip to content

Commit ab8bd9e

Browse files
authored
Merge pull request #5020 from dotty-staging/fix-bench
Fail jhm on error and fix benchmarks
2 parents 7ef4491 + f247238 commit ab8bd9e

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

bench/src/main/scala/Benchmarks.scala

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package dotty.tools.benchmarks
22

33
import dotty.tools.dotc._
44
import core.Contexts.Context
5+
import dotty.tools.FatalError
6+
import reporting._
57

68
import org.openjdk.jmh.results.RunResult
79
import org.openjdk.jmh.runner.Runner
@@ -34,10 +36,9 @@ object Bench {
3436
}
3537
storeCompileOptions(args2)
3638

37-
val libs = System.getProperty("BENCH_CLASS_PATH")
38-
3939
val opts = new OptionsBuilder()
40-
.jvmArgsPrepend(s"-classpath $libs", "-Xms2G", "-Xmx2G")
40+
.shouldFailOnError(true)
41+
.jvmArgs("-Xms2G", "-Xmx2G")
4142
.mode(Mode.AverageTime)
4243
.timeUnit(TimeUnit.MILLISECONDS)
4344
.warmupIterations(warmup)
@@ -54,9 +55,20 @@ object Bench {
5455
def removeCompileOptions: Unit = new File(COMPILE_OPTS_FILE).delete()
5556

5657
def storeCompileOptions(args: Array[String]): Unit = {
58+
val standard_libs = System.getProperty("BENCH_CLASS_PATH")
59+
val compiler_libs = System.getProperty("BENCH_COMPILER_CLASS_PATH")
60+
61+
val libs = if (args.contains("-with-compiler")) compiler_libs else standard_libs
62+
var argsNorm = args.filter(_ != "-with-compiler")
63+
64+
var cpIndex = argsNorm.indexOf("-classpath")
65+
if (cpIndex == -1) cpIndex = argsNorm.indexOf("-cp")
66+
if (cpIndex != -1) argsNorm(cpIndex + 1) = argsNorm(cpIndex + 1) + ":" + libs
67+
else argsNorm = argsNorm :+ "-classpath" :+ libs
68+
5769
val file = new File(COMPILE_OPTS_FILE)
5870
val bw = new BufferedWriter(new FileWriter(file))
59-
bw.write(args.mkString("\n"))
71+
bw.write(argsNorm.mkString("", "\n", "\n"))
6072
bw.close()
6173
}
6274

@@ -75,6 +87,21 @@ class CompilerOptions {
7587
}
7688

7789
class Worker extends Driver {
90+
// override to avoid printing summary information
91+
override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Reporter =
92+
if (fileNames.nonEmpty)
93+
try {
94+
val run = compiler.newRun
95+
run.compile(fileNames)
96+
ctx.reporter
97+
}
98+
catch {
99+
case ex: FatalError =>
100+
ctx.error(ex.getMessage) // signals that we should fail compilation.
101+
ctx.reporter
102+
}
103+
else ctx.reporter
104+
78105
@Benchmark
79106
def compile(state: CompilerOptions): Unit = {
80107
val res = process(state.opts)

project/Build.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ object Build {
302302
lazy val commonBenchmarkSettings = Seq(
303303
outputStrategy := Some(StdoutOutput),
304304
mainClass in (Jmh, run) := Some("dotty.tools.benchmarks.Bench"), // custom main for jmh:run
305-
javaOptions += "-DBENCH_CLASS_PATH=" + Attributed.data((fullClasspath in Compile).value).mkString("", ":", "")
305+
javaOptions += "-DBENCH_COMPILER_CLASS_PATH=" + Attributed.data((fullClasspath in (`dotty-bootstrapped`, Compile)).value).mkString("", ":", ""),
306+
javaOptions += "-DBENCH_CLASS_PATH=" + Attributed.data((fullClasspath in (`dotty-library-bootstrapped`, Compile)).value).mkString("", ":", "")
306307
)
307308

308309
// sbt >= 0.13.12 will automatically rewrite transitive dependencies on

project/scripts/cmdTests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ EXPECTED_OUTPUT="hello world"
1212
# check that benchmarks can run
1313
"$SBT" "dotty-bench/jmh:run 1 1 tests/pos/alias.scala"
1414
"$SBT" "dotty-bench-bootstrapped/jmh:run 1 1 tests/pos/alias.scala"
15+
"$SBT" "dotty-bench-bootstrapped/jmh:run 1 1 -with-compiler compiler/src/dotty/tools/dotc/core/Types.scala"
1516

1617
OUT=$(mktemp -d)
1718
OUT1=$(mktemp -d)

0 commit comments

Comments
 (0)