Skip to content

Commit f1355d3

Browse files
committed
Add idempotency check on bootstrapped dotty
1 parent 8ddfcaf commit f1355d3

File tree

4 files changed

+62
-23
lines changed

4 files changed

+62
-23
lines changed

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class CompilationTests extends ParallelTesting {
207207
// compile with bootstrapped library on cp:
208208
defaultOutputDir + "lib/src/:" +
209209
// as well as bootstrapped compiler:
210-
defaultOutputDir + "dotty1/dotty1/:" +
210+
defaultOutputDir + "dotty1/dotty/:" +
211211
Jars.dottyInterfaces
212212
)
213213

@@ -241,17 +241,21 @@ class CompilationTests extends ParallelTesting {
241241

242242
def dotty1 = {
243243
compileList(
244-
"dotty1",
244+
"dotty",
245245
compilerSources ++ backendSources ++ backendJvmSources,
246246
opt)
247247
}
248248

249-
def dotty2 =
250-
compileShallowFilesInDir("../compiler/src/dotty", opt)
249+
def dotty2 = {
250+
compileList(
251+
"dotty",
252+
compilerSources ++ backendSources ++ backendJvmSources,
253+
opt)
254+
}
251255

252-
{
256+
val tests = {
253257
lib.keepOutput :: dotty1.keepOutput :: {
254-
dotty2 +
258+
dotty2.keepOutput +
255259
compileShallowFilesInDir("../compiler/src/dotty/tools", opt) +
256260
compileShallowFilesInDir("../compiler/src/dotty/tools/dotc", opt) +
257261
compileShallowFilesInDir("../compiler/src/dotty/tools/dotc/ast", opt) +
@@ -267,20 +271,24 @@ class CompilationTests extends ParallelTesting {
267271
compileList("shallow-backend", backendSources, opt) +
268272
compileList("shallow-backend-jvm", backendJvmSources, opt)
269273
} :: Nil
270-
}.map(_.checkCompile()).foreach(_.delete())
274+
}.map(_.checkCompile())
275+
276+
assert(new java.io.File("../out/dotty1/dotty/").exists)
277+
assert(new java.io.File("../out/dotty2/dotty/").exists)
278+
compileList("idempotency", List("../tests/idempotency/BootstrapChecker.scala", "../tests/idempotency/IdempotencyCheck.scala"), defaultOptions).checkRuns()
279+
280+
tests.foreach(_.delete())
271281
}
272282

273283
/** Add a `z` so that they run last. TODO: Only run them selectively? */
274284
@Test def zBytecodeIdempotency: Unit = {
275285
val opt = defaultOptions.and("-YemitTasty")
276286

277287
def idempotency1() = {
278-
compileList("dotty1", compilerSources ++ backendSources ++ backendJvmSources, opt) +
279288
compileDir("../collection-strawman/src/main", opt) +
280289
compileFilesInDir("../tests/pos", opt)
281290
}
282291
def idempotency2() = {
283-
compileList("dotty1", compilerSources ++ backendSources ++ backendJvmSources, opt) +
284292
compileDir("../collection-strawman/src/main", opt) +
285293
compileFilesInDir("../tests/pos", opt)
286294
}
@@ -290,7 +298,7 @@ class CompilationTests extends ParallelTesting {
290298
assert(new java.io.File("../out/idempotency1/").exists)
291299
assert(new java.io.File("../out/idempotency2/").exists)
292300

293-
compileFile("../tests/idempotency/IdempotencyCheck.scala", defaultOptions).checkRuns()
301+
compileList("idempotency", List("../tests/idempotency/Checker.scala", "../tests/idempotency/IdempotencyCheck.scala"), defaultOptions).checkRuns()
294302

295303
tests.delete()
296304
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import java.nio.file.{Files, Path, Paths}
2+
import java.util.stream.{ Stream => JStream }
3+
4+
import scala.collection.JavaConverters._
5+
6+
object Test {
7+
def main(args: Array[String]): Unit = IdempotencyCheck.checkIdempotency("../out/dotty")
8+
}

tests/idempotency/Checker.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
import java.nio.file.{Files, Path, Paths}
3+
import java.util.stream.{ Stream => JStream }
4+
5+
import scala.collection.JavaConverters._
6+
7+
object Test {
8+
def main(args: Array[String]): Unit =
9+
IdempotencyCheck.checkIdempotency("../out/idempotency")
10+
}

tests/idempotency/IdempotencyCheck.scala

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,31 @@ import java.util.stream.{ Stream => JStream }
44

55
import scala.collection.JavaConverters._
66

7-
object Test {
8-
9-
def main(args: Array[String]): Unit = checkIdempotency()
10-
11-
val blacklisted = Set(
12-
// Bridges on collections in different order. Second one in scala2 order.
7+
object IdempotencyCheck {
8+
val blacklistedSet = Set(
9+
// No fix needed. Bridges on collections in different order. Second one in scala2 order.
1310
"pos/Map/scala/collection/immutable/Map",
1411
"pos/Map/scala/collection/immutable/AbstractMap",
1512
"pos/t1203a/NodeSeq",
1613
"pos/i2345/Whatever"
1714
)
1815

19-
def checkIdempotency(): Unit = {
16+
def blacklisted(s: String) = {
17+
blacklistedSet(s) ||
18+
// FIXME: non-deterministic method/class names
19+
s.contains("$$anon$") ||
20+
s.contains("$$anonfun$") ||
21+
s.contains("$accu$") ||
22+
s.contains("$accum$") ||
23+
s.startsWith("/dotty/dotty/tools/dotc/sbt/ExtractAPICollector$classFirstSort$") ||
24+
s.startsWith("/dotty/dotty/tools/dotc/transform/PatternMatcher$Translator$TreeMakers$IntEqualityTestTreeMaker$") ||
25+
s.startsWith("/dotty/dotty/tools/dotc/typer/RefChecks$MixinOverrideError$") ||
26+
s.startsWith("/dotty/dotty/tools/dotc/typer/ImplicitRunInfo$liftToClasses$") ||
27+
s.startsWith("/dotty/dotty/tools/dotc/typer/Inliner$addAccessors$") ||
28+
s.startsWith("/dotty/dotty/tools/dotc/typer/ErrorReporting$reported$")
29+
}
30+
31+
def checkIdempotency(dirPrefix: String): Unit = {
2032
var failed = 0
2133
var total = 0
2234

@@ -26,20 +38,21 @@ object Test {
2638
def isBytecode(file: String) = file.endsWith(".class") || file.endsWith(".tasty")
2739
paths.iterator.asScala.filter(path => isBytecode(path.toString)).toList
2840
}
29-
val compilerDir1 = Paths.get("../out/idempotency1")
30-
val compilerDir2 = Paths.get("../out/idempotency2")
41+
val compilerDir1 = Paths.get(dirPrefix + 1)
42+
val compilerDir2 = Paths.get(dirPrefix + 2)
3143
bytecodeFiles(Files.walk(compilerDir1)) ++ bytecodeFiles(Files.walk(compilerDir2))
3244
}
33-
val groups = bytecodeFiles.groupBy(f => f.toString.substring("../out/idempotencyN/".length, f.toString.length - 6))
45+
val groups = bytecodeFiles.groupBy(f => f.toString.substring(dirPrefix.length + 1, f.toString.length - 6))
46+
3447
groups.filterNot(x => blacklisted(x._1)).valuesIterator.flatMap { g =>
3548
def pred(f: Path, i: Int, isTasty: Boolean) =
36-
f.toString.contains("idempotency" + i) && f.toString.endsWith(if (isTasty) ".tasty" else ".class")
49+
f.toString.contains(dirPrefix + i) && f.toString.endsWith(if (isTasty) ".tasty" else ".class")
3750
val class1 = g.find(f => pred(f, 1, isTasty = false))
3851
val class2 = g.find(f => pred(f, 2, isTasty = false))
3952
val tasty1 = g.find(f => pred(f, 1, isTasty = true))
4053
val tasty2 = g.find(f => pred(f, 2, isTasty = true))
41-
assert(class1.isDefined, "Could not find class in idempotency1 for " + class2)
42-
assert(class2.isDefined, "Could not find class in idempotency2 for " + class1)
54+
assert(class1.isDefined, s"Could not find class in ${dirPrefix + 1} for $class2")
55+
assert(class2.isDefined, s"Could not find class in ${dirPrefix + 2} for $class1")
4356
if (tasty1.isEmpty || tasty2.isEmpty) Nil
4457
else List(Tuple4(class1.get, tasty1.get, class2.get, tasty2.get))
4558
}.toList

0 commit comments

Comments
 (0)