Skip to content

Commit 14e3ac5

Browse files
committed
Test stdlib from tasty directly from tasty files
1 parent 6837f23 commit 14e3ac5

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class BootstrappedStdLibTASYyTest:
2020
@Test def testTastyInspector: Unit =
2121
loadWithTastyInspector(loadBlacklisted)
2222

23+
/** Test that we can load and compile trees from TASTy in a Jar */
24+
@Test def testFromTastyInJar: Unit =
25+
compileFromTastyInJar(loadBlacklisted.union(compileBlacklisted))
26+
2327
/** Test that we can load and compile trees from TASTy */
2428
@Test def testFromTasty: Unit =
2529
compileFromTasty(loadBlacklisted.union(compileBlacklisted))
@@ -38,14 +42,14 @@ class BootstrappedStdLibTASYyTest:
3842
"`compileBlacklist` contains names that are already in `loadBlacklist`: \n ", "\n ", "\n\n"))
3943

4044
@Test def blacklistsOnlyContainsClassesThatExist =
41-
val scalaLibJarTastyClassNamesSet = scalaLibJarTastyClassNames.toSet
45+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
4246
val intersection = loadBlacklisted & compileBlacklisted
43-
assert(loadBlacklisted.diff(scalaLibJarTastyClassNamesSet).isEmpty,
44-
loadBlacklisted.diff(scalaLibJarTastyClassNamesSet).mkString(
45-
"`loadBlacklisted` contains names that are not in `scalaLibJarTastyClassNames`: \n ", "\n ", "\n\n"))
46-
assert(compileBlacklisted.diff(scalaLibJarTastyClassNamesSet).isEmpty,
47-
compileBlacklisted.diff(scalaLibJarTastyClassNamesSet).mkString(
48-
"`loadBlacklisted` contains names that are not in `scalaLibJarTastyClassNames`: \n ", "\n ", "\n\n"))
47+
assert(loadBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
48+
loadBlacklisted.diff(scalaLibTastyPathsSet).mkString(
49+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
50+
assert(compileBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
51+
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString(
52+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
4953

5054
@Ignore
5155
@Test def testLoadBacklistIsMinimal =
@@ -73,7 +77,7 @@ class BootstrappedStdLibTASYyTest:
7377
val blacklist = blacklist0 - notBlacklisted
7478
println(s"Trying withouth $notBlacklisted in the blacklist (${i+1}/$size)")
7579
try {
76-
compileFromTasty(blacklist)
80+
compileFromTastyInJar(blacklist)
7781
shouldBeWhitelisted = notBlacklisted :: shouldBeWhitelisted
7882
}
7983
catch {
@@ -86,7 +90,9 @@ end BootstrappedStdLibTASYyTest
8690

8791
object BootstrappedStdLibTASYyTest:
8892

89-
val scalaLibJarPath = System.getProperty("dotty.scala.library")
93+
def scalaLibJarPath = System.getProperty("dotty.scala.library")
94+
def scalaLibClassesPath =
95+
java.nio.file.Paths.get(scalaLibJarPath).getParent.resolve("classes").normalize
9096

9197
val scalaLibJarTastyClassNames = {
9298
val scalaLibJar = Jar(new File(java.nio.file.Paths.get(scalaLibJarPath)))
@@ -95,20 +101,26 @@ object BootstrappedStdLibTASYyTest:
95101
.sorted
96102
}
97103

98-
def loadWithTastyInspector(blacklisted: String => Boolean): Unit =
104+
val scalaLibTastyPaths =
105+
new Directory(scalaLibClassesPath).deepFiles
106+
.filter(_.`extension` == "tasty")
107+
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/"))
108+
.toList
109+
110+
def loadWithTastyInspector(blacklisted: Set[String]): Unit =
99111
val inspector = new scala.tasty.inspector.TastyInspector {
100112
def processCompilationUnit(using QuoteContext)(root: qctx.reflect.Tree): Unit =
101113
root.showExtractors // Check that we can traverse the full tree
102114
()
103115
}
104-
val classNames = scalaLibJarTastyClassNames.filterNot(blacklisted)
116+
val classNames = scalaLibJarTastyClassNames.filterNot(blacklisted.map(_.stripSuffix(".tasty").replace("/", ".")))
105117
val hasErrors = inspector.inspectTastyFilesInJar(scalaLibJarPath)
106118
assert(!hasErrors, "Errors reported while loading from TASTy")
107119

108-
def compileFromTasty(blacklisted: Iterable[String]): Unit = {
120+
def compileFromTastyInJar(blacklisted: Set[String]): Unit = {
109121
val driver = new dotty.tools.dotc.Driver
110122
val yFromTastyBlacklist =
111-
blacklisted.map(x => x.replace(".", separator) + ".tasty").mkString("-Yfrom-tasty-blacklist:", ",", "")
123+
blacklisted.mkString("-Yfrom-tasty-blacklist:", ",", "")
112124
val args = Array(
113125
"-classpath", ClasspathFromClassloader(getClass.getClassLoader),
114126
"-from-tasty",
@@ -120,12 +132,24 @@ object BootstrappedStdLibTASYyTest:
120132
assert(reporter.errorCount == 0, "Errors while re-compiling")
121133
}
122134

123-
/** List of classes that cannot be loaded from TASTy */
135+
def compileFromTasty(blacklisted: Set[String]): Unit = {
136+
val driver = new dotty.tools.dotc.Driver
137+
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
138+
val args = Array(
139+
"-classpath", ClasspathFromClassloader(getClass.getClassLoader),
140+
"-from-tasty",
141+
"-nowarn",
142+
) ++ tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString)
143+
val reporter = driver.process(args)
144+
assert(reporter.errorCount == 0, "Errors while re-compiling")
145+
}
146+
147+
/** List of tasty files that cannot be loaded from TASTy */
124148
def loadBlacklist = List[String](
125149
// No issues :)
126150
)
127151

128-
/** List of classes that cannot be recompilied from TASTy */
152+
/** List of tasty files that cannot be recompilied from TASTy */
129153
def compileBlacklist = List[String](
130154
// See #10048
131155
// failed: java.lang.AssertionError: assertion failed: class Boolean
@@ -135,22 +159,22 @@ object BootstrappedStdLibTASYyTest:
135159
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)
136160
// at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBTypeAndRegisterInnerClass(BCodeSkelBuilder.scala:62)
137161
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.internalName(BCodeHelpers.scala:237)
138-
"scala.Array",
139-
"scala.Boolean",
140-
"scala.Byte",
141-
"scala.Char",
142-
"scala.Double",
143-
"scala.Float",
144-
"scala.Int",
145-
"scala.Long",
146-
"scala.Short",
147-
"scala.Unit",
148-
)
149-
150-
/** Set of classes that cannot be loaded from TASTy */
162+
"scala/Array.tasty",
163+
"scala/Boolean.tasty",
164+
"scala/Byte.tasty",
165+
"scala/Char.tasty",
166+
"scala/Double.tasty",
167+
"scala/Float.tasty",
168+
"scala/Int.tasty",
169+
"scala/Long.tasty",
170+
"scala/Short.tasty",
171+
"scala/Unit.tasty",
172+
).map(_.replace("/", separator))
173+
174+
/** Set of tasty files that cannot be loaded from TASTy */
151175
def loadBlacklisted = loadBlacklist.toSet
152176

153-
/** Set of classes that cannot be recompilied from TASTy */
177+
/** Set of tasty files that cannot be recompilied from TASTy */
154178
def compileBlacklisted = compileBlacklist.toSet
155179

156180
end BootstrappedStdLibTASYyTest

0 commit comments

Comments
 (0)