Skip to content

Commit 30403cf

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.
1 parent f1bad54 commit 30403cf

File tree

6 files changed

+145
-203
lines changed

6 files changed

+145
-203
lines changed

.github/workflows/ci.yaml

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

137137
- name: Cmd Tests
138138
run: |
139-
./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"
139+
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
140140
./project/scripts/cmdTests
141141
./project/scripts/bootstrappedOnlyCmdTests
142142
@@ -547,7 +547,7 @@ jobs:
547547

548548
- name: Test
549549
run: |
550-
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala2-library-tasty-tests/test"
550+
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*"
551551
./project/scripts/cmdTests
552552
./project/scripts/bootstrappedOnlyCmdTests
553553

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`

project/Build.scala

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

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

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

Lines changed: 0 additions & 174 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import scala.quoted._
2+
import scala.tasty.inspector._
3+
4+
import dotty.tools.io.Directory
5+
6+
import java.io.File.pathSeparator
7+
8+
@main def Test: Unit =
9+
blacklistsOnlyContainsClassesThatExist()
10+
testTastyInspector()
11+
12+
/** Test that we can load trees from TASTy */
13+
def testTastyInspector(): Unit =
14+
loadWithTastyInspector(loadBlacklisted)
15+
16+
def blacklistsOnlyContainsClassesThatExist() =
17+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
18+
assert(loadBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
19+
loadBlacklisted.diff(scalaLibTastyPathsSet).mkString(
20+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
21+
22+
def dottyVersion =
23+
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
24+
case path if path.endsWith(".jar") && path.contains("/scala3-library_3-") =>
25+
path.split("/scala3-library_3-").last.stripSuffix(".jar")
26+
}.get
27+
28+
def scalaLibClassesPath =
29+
java.nio.file.Paths.get(
30+
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes")
31+
32+
lazy val scalaLibTastyPaths =
33+
new Directory(scalaLibClassesPath).deepFiles
34+
.filter(_.`extension` == "tasty")
35+
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/"))
36+
.toList
37+
38+
def loadWithTastyInspector(blacklisted: Set[String]): Unit =
39+
val inspector = new scala.tasty.inspector.Inspector {
40+
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
41+
for tasty <- tastys do
42+
tasty.ast.show(using quotes.reflect.Printer.TreeStructure) // Check that we can traverse the full tree
43+
()
44+
}
45+
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
46+
val isSuccess = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector)
47+
assert(isSuccess, "Errors reported while loading from TASTy")
48+
49+
/** Set of tasty files that cannot be loaded from TASTy */
50+
def loadBlacklisted = Set[String](
51+
// No issues :)
52+
)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
testFromTastyInJar()
10+
testFromTasty()
11+
12+
/** Test that we can load and compile trees from TASTy in a Jar */
13+
def testFromTastyInJar(): Unit =
14+
compileFromTastyInJar(compileBlacklisted)
15+
16+
/** Test that we can load and compile trees from TASTy */
17+
def testFromTasty(): Unit =
18+
compileFromTasty(compileBlacklisted)
19+
20+
def blacklistsOnlyContainsClassesThatExist() =
21+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
22+
assert(compileBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
23+
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString(
24+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
25+
26+
def dottyVersion =
27+
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
28+
case path if path.endsWith(".jar") && path.contains("/scala3-library_3-") =>
29+
path.split("/scala3-library_3-").last.stripSuffix(".jar")
30+
}.get
31+
32+
def scalaLibJarPath =
33+
s"out/bootstrap/scala2-library-tasty/scala-$dottyVersion-nonbootstrapped/scala2-library-tasty_3-$dottyVersion.jar"
34+
35+
def scalaLibClassesPath =
36+
java.nio.file.Paths.get(
37+
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes")
38+
39+
lazy val scalaLibTastyPaths =
40+
new Directory(scalaLibClassesPath).deepFiles
41+
.filter(_.`extension` == "tasty")
42+
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/"))
43+
.toList
44+
45+
def compileFromTastyInJar(blacklisted: Set[String]): Unit = {
46+
val driver = new dotty.tools.dotc.Driver
47+
val yFromTastyBlacklist =
48+
blacklisted.mkString("-Yfrom-tasty-ignore-list:", ",", "")
49+
val args = Array(
50+
"-classpath", ClasspathFromClassloader(getClass.getClassLoader),
51+
"-from-tasty",
52+
"-nowarn",
53+
yFromTastyBlacklist,
54+
scalaLibJarPath,
55+
)
56+
val reporter = driver.process(args)
57+
assert(reporter.errorCount == 0, "Errors while re-compiling")
58+
}
59+
60+
def compileFromTasty(blacklisted: Set[String]): Unit = {
61+
val driver = new dotty.tools.dotc.Driver
62+
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
63+
val args = Array(
64+
"-classpath", ClasspathFromClassloader(getClass.getClassLoader),
65+
"-from-tasty",
66+
"-nowarn",
67+
) ++ tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString)
68+
val reporter = driver.process(args)
69+
assert(reporter.errorCount == 0, "Errors while re-compiling")
70+
}
71+
72+
/** Set of tasty files that cannot be recompiled from TASTy */
73+
def compileBlacklisted = Set[String](
74+
// See #10048
75+
// failed: java.lang.AssertionError: assertion failed: class Boolean
76+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:247)
77+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass(BCodeHelpers.scala:265)
78+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)
79+
// at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBTypeAndRegisterInnerClass(BCodeSkelBuilder.scala:62)
80+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.internalName(BCodeHelpers.scala:237)
81+
"scala/Array.tasty",
82+
"scala/Boolean.tasty",
83+
"scala/Byte.tasty",
84+
"scala/Char.tasty",
85+
"scala/Double.tasty",
86+
"scala/Float.tasty",
87+
"scala/Int.tasty",
88+
"scala/Long.tasty",
89+
"scala/Short.tasty",
90+
"scala/Unit.tasty",
91+
).map(_.replace("/", separator))

0 commit comments

Comments
 (0)