Skip to content

Commit 96b57b8

Browse files
committed
Port tests form scala2-library-tasty-tests to normal tests
Split BootstrappedStdLibTASYyTest into the part that tests the TASTy inspector and the part that tests recompilation. We also remove `scala2-library-tasty-tests` as it is now empty and will not serve any purpose anymore. This test also discovered a bug in TASTYRun with the path separators of `JarArchive`s in Windows. The "/" is used in the JAR paths but the "\" is used for OS paths. This is now fixed.
1 parent 1e56ca0 commit 96b57b8

File tree

7 files changed

+147
-174
lines changed

7 files changed

+147
-174
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141

142142
- name: Cmd Tests
143143
run: |
144-
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala2-library-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
144+
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
145145
./project/scripts/cmdTests
146146
./project/scripts/bootstrappedOnlyCmdTests
147147
@@ -585,7 +585,7 @@ jobs:
585585

586586
- name: Test
587587
run: |
588-
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala2-library-tasty-tests/test"
588+
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*"
589589
./project/scripts/cmdTests
590590
./project/scripts/bootstrappedOnlyCmdTests
591591

build.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
1616
val `scala3-bench-micro` = Build.`scala3-bench-micro`
1717
val `scala2-library-bootstrapped` = Build.`scala2-library-bootstrapped`
1818
val `scala2-library-tasty` = Build.`scala2-library-tasty`
19-
val `scala2-library-tasty-tests` = Build.`scala2-library-tasty-tests`
2019
val `scala2-library-cc` = Build.`scala2-library-cc`
2120
val `scala2-library-cc-tasty` = Build.`scala2-library-cc-tasty`
2221
val `tasty-core` = Build.`tasty-core`

compiler/src/dotty/tools/dotc/fromtasty/TASTYRun.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class TASTYRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) {
2222
file.extension match
2323
case "jar" =>
2424
JarArchive.open(Path(file.path), create = false).allFileNames()
25-
.map(_.stripPrefix(File.separator)) // change paths from absolute to relative
26-
.filter(e => Path.extension(e) == "tasty" && !fromTastyIgnoreList(e))
27-
.map(e => e.stripSuffix(".tasty").replace(File.separator, "."))
25+
.map(_.stripPrefix("/")) // change paths from absolute to relative
26+
.filter(e => Path.extension(e) == "tasty" && !fromTastyIgnoreList(e.replace("/", File.separator)))
27+
.map(e => e.stripSuffix(".tasty").replace("/", "."))
2828
.toList
2929
case "tasty" => TastyFileUtil.getClassName(file)
3030
case _ =>

project/Build.scala

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,32 +1249,6 @@ object Build {
12491249
},
12501250
)
12511251

1252-
/** Test the tasty generated by `scala2-library-bootstrapped`
1253-
*
1254-
* The sources in src are compiled using TASTy from scala2-library-tasty but then run
1255-
* with the scala-library compiled be Scala 2.
1256-
*
1257-
* The tests are run with the bootstrapped compiler and the tasty inspector on the classpath.
1258-
* The classpath has the default `scala-library` and not `scala2-library-bootstrapped`.
1259-
*
1260-
* The jar of `scala2-library-bootstrapped` is provided for to the tests.
1261-
* - inspector: test that we can load the contents of the jar using the tasty inspector
1262-
* - from-tasty: test that we can recompile the contents of the jar using `dotc -from-tasty`
1263-
*/
1264-
lazy val `scala2-library-tasty-tests` = project.in(file("scala2-library-tasty-tests")).
1265-
withCommonSettings(Bootstrapped).
1266-
dependsOn(dottyCompiler(Bootstrapped) % "compile->compile").
1267-
dependsOn(`scala3-tasty-inspector` % "test->test").
1268-
dependsOn(`scala2-library-tasty`).
1269-
settings(commonBootstrappedSettings).
1270-
settings(
1271-
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
1272-
Test / javaOptions += "-Ddotty.scala.library=" + (`scala2-library-bootstrapped` / Compile / packageBin).value.getAbsolutePath,
1273-
Compile / compile / fullClasspath ~= {
1274-
_.filterNot(file => file.data.getName == s"scala-library-$stdlibBootstrappedVersion.jar")
1275-
},
1276-
)
1277-
12781252
lazy val `scala3-sbt-bridge` = project.in(file("sbt-bridge/src")).
12791253
// We cannot depend on any bootstrapped project to compile the bridge, since the
12801254
// bridge is needed to compile these projects.

scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala

Lines changed: 0 additions & 142 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import dotty.tools.io.Directory
2+
import dotty.tools.dotc.util.ClasspathFromClassloader
3+
4+
import java.io.File.pathSeparator
5+
import java.io.File.separator
6+
7+
@main def Test: Unit =
8+
blacklistsOnlyContainsClassesThatExist()
9+
// FIXME this test does not work on JDK8
10+
// Caused by: dotty.tools.dotc.core.TypeError$$anon$1: package scala.quoted.runtime.Expr does not have a member method quote
11+
if System.getProperty("java.specification.version") != "1.8" then
12+
compileFromTastyInJar(compileBlacklisted)
13+
14+
def blacklistsOnlyContainsClassesThatExist() =
15+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
16+
assert(compileBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
17+
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString(
18+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
19+
20+
def dottyVersion =
21+
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
22+
case path if path.endsWith(".jar") && path.contains("scala3-library_3-") =>
23+
path.split("scala3-library_3-").last.stripSuffix(".jar")
24+
}.get
25+
26+
def scalaLibJarPath =
27+
s"out${separator}bootstrap${separator}scala2-library-tasty${separator}scala-$dottyVersion-nonbootstrapped${separator}scala2-library-tasty-experimental_3-$dottyVersion.jar"
28+
29+
def scalaLibClassesPath =
30+
java.nio.file.Paths.get(
31+
s"out${separator}bootstrap${separator}scala2-library-bootstrapped${separator}scala-$dottyVersion-nonbootstrapped${separator}classes")
32+
33+
lazy val scalaLibTastyPaths =
34+
new Directory(scalaLibClassesPath).deepFiles
35+
.filter(_.`extension` == "tasty")
36+
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + separator))
37+
.toList
38+
39+
def compileFromTastyInJar(blacklisted: Set[String]): Unit = {
40+
val driver = new dotty.tools.dotc.Driver
41+
val yFromTastyBlacklist =
42+
blacklisted.mkString("-Yfrom-tasty-ignore-list:", ",", "")
43+
val args = Array(
44+
"-classpath", ClasspathFromClassloader(getClass.getClassLoader),
45+
"-from-tasty",
46+
"-d", s"out${separator}scala2-library-from-tasty-jar-test-output.jar",
47+
"-nowarn",
48+
yFromTastyBlacklist,
49+
scalaLibJarPath,
50+
)
51+
val reporter = driver.process(args)
52+
assert(reporter.errorCount == 0, "Errors while re-compiling")
53+
}
54+
55+
/** Set of tasty files that cannot be recompiled from TASTy */
56+
def compileBlacklisted = Set[String](
57+
// See #10048
58+
// failed: java.lang.AssertionError: assertion failed: class Boolean
59+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:247)
60+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass(BCodeHelpers.scala:265)
61+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)
62+
// at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBTypeAndRegisterInnerClass(BCodeSkelBuilder.scala:62)
63+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.internalName(BCodeHelpers.scala:237)
64+
s"scala${separator}Array.tasty",
65+
s"scala${separator}Boolean.tasty",
66+
s"scala${separator}Byte.tasty",
67+
s"scala${separator}Char.tasty",
68+
s"scala${separator}Double.tasty",
69+
s"scala${separator}Float.tasty",
70+
s"scala${separator}Int.tasty",
71+
s"scala${separator}Long.tasty",
72+
s"scala${separator}Short.tasty",
73+
s"scala${separator}Unit.tasty",
74+
)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import dotty.tools.io.Directory
2+
import dotty.tools.dotc.util.ClasspathFromClassloader
3+
4+
import java.io.File.pathSeparator
5+
import java.io.File.separator
6+
7+
@main def Test: Unit =
8+
blacklistsOnlyContainsClassesThatExist()
9+
// FIXME this test does not work on JDK8
10+
// Caused by: dotty.tools.dotc.core.TypeError$$anon$1: package scala.quoted.runtime.Expr does not have a member method quote
11+
if System.getProperty("java.specification.version") != "1.8" then
12+
compileFromTasty(compileBlacklisted)
13+
14+
def blacklistsOnlyContainsClassesThatExist() =
15+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
16+
assert(compileBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
17+
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString(
18+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
19+
20+
def dottyVersion =
21+
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
22+
case path if path.endsWith(".jar") && path.contains("scala3-library_3-") =>
23+
path.split("scala3-library_3-").last.stripSuffix(".jar")
24+
}.get
25+
26+
def scalaLibClassesPath =
27+
java.nio.file.Paths.get(
28+
s"out${separator}bootstrap${separator}scala2-library-bootstrapped${separator}scala-$dottyVersion-nonbootstrapped${separator}classes")
29+
30+
lazy val scalaLibTastyPaths =
31+
new Directory(scalaLibClassesPath).deepFiles
32+
.filter(_.`extension` == "tasty")
33+
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + separator))
34+
.toList
35+
36+
def compileFromTasty(blacklisted: Set[String]): Unit = {
37+
val driver = new dotty.tools.dotc.Driver
38+
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
39+
val args = Array(
40+
"-classpath", ClasspathFromClassloader(getClass.getClassLoader),
41+
"-from-tasty",
42+
"-d", s"out${separator}scala2-library-from-tasty-test-output.jar",
43+
"-nowarn",
44+
) ++ tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString)
45+
val reporter = driver.process(args)
46+
assert(reporter.errorCount == 0, "Errors while re-compiling")
47+
}
48+
49+
/** Set of tasty files that cannot be recompiled from TASTy */
50+
def compileBlacklisted = Set[String](
51+
// See #10048
52+
// failed: java.lang.AssertionError: assertion failed: class Boolean
53+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:247)
54+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass(BCodeHelpers.scala:265)
55+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)
56+
// at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBTypeAndRegisterInnerClass(BCodeSkelBuilder.scala:62)
57+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.internalName(BCodeHelpers.scala:237)
58+
s"scala${separator}Array.tasty",
59+
s"scala${separator}Boolean.tasty",
60+
s"scala${separator}Byte.tasty",
61+
s"scala${separator}Char.tasty",
62+
s"scala${separator}Double.tasty",
63+
s"scala${separator}Float.tasty",
64+
s"scala${separator}Int.tasty",
65+
s"scala${separator}Long.tasty",
66+
s"scala${separator}Short.tasty",
67+
s"scala${separator}Unit.tasty",
68+
)

0 commit comments

Comments
 (0)