@@ -20,6 +20,10 @@ class BootstrappedStdLibTASYyTest:
20
20
@ Test def testTastyInspector : Unit =
21
21
loadWithTastyInspector(loadBlacklisted)
22
22
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
+
23
27
/** Test that we can load and compile trees from TASTy */
24
28
@ Test def testFromTasty : Unit =
25
29
compileFromTasty(loadBlacklisted.union(compileBlacklisted))
@@ -38,14 +42,14 @@ class BootstrappedStdLibTASYyTest:
38
42
" `compileBlacklist` contains names that are already in `loadBlacklist`: \n " , " \n " , " \n\n " ))
39
43
40
44
@ Test def blacklistsOnlyContainsClassesThatExist =
41
- val scalaLibJarTastyClassNamesSet = scalaLibJarTastyClassNames .toSet
45
+ val scalaLibTastyPathsSet = scalaLibTastyPaths .toSet
42
46
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 " ))
49
53
50
54
@ Ignore
51
55
@ Test def testLoadBacklistIsMinimal =
@@ -73,7 +77,7 @@ class BootstrappedStdLibTASYyTest:
73
77
val blacklist = blacklist0 - notBlacklisted
74
78
println(s " Trying withouth $notBlacklisted in the blacklist ( ${i+ 1 }/ $size) " )
75
79
try {
76
- compileFromTasty (blacklist)
80
+ compileFromTastyInJar (blacklist)
77
81
shouldBeWhitelisted = notBlacklisted :: shouldBeWhitelisted
78
82
}
79
83
catch {
@@ -86,7 +90,9 @@ end BootstrappedStdLibTASYyTest
86
90
87
91
object BootstrappedStdLibTASYyTest :
88
92
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
90
96
91
97
val scalaLibJarTastyClassNames = {
92
98
val scalaLibJar = Jar (new File (java.nio.file.Paths .get(scalaLibJarPath)))
@@ -95,20 +101,26 @@ object BootstrappedStdLibTASYyTest:
95
101
.sorted
96
102
}
97
103
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 =
99
111
val inspector = new scala.tasty.inspector.TastyInspector {
100
112
def processCompilationUnit (using QuoteContext )(root : qctx.reflect.Tree ): Unit =
101
113
root.showExtractors // Check that we can traverse the full tree
102
114
()
103
115
}
104
- val classNames = scalaLibJarTastyClassNames.filterNot(blacklisted)
116
+ val classNames = scalaLibJarTastyClassNames.filterNot(blacklisted.map(_.stripSuffix( " .tasty " ).replace( " / " , " . " )) )
105
117
val hasErrors = inspector.inspectTastyFilesInJar(scalaLibJarPath)
106
118
assert(! hasErrors, " Errors reported while loading from TASTy" )
107
119
108
- def compileFromTasty (blacklisted : Iterable [String ]): Unit = {
120
+ def compileFromTastyInJar (blacklisted : Set [String ]): Unit = {
109
121
val driver = new dotty.tools.dotc.Driver
110
122
val yFromTastyBlacklist =
111
- blacklisted.map(x => x.replace( " . " , separator) + " .tasty " ). mkString(" -Yfrom-tasty-blacklist:" , " ," , " " )
123
+ blacklisted.mkString(" -Yfrom-tasty-blacklist:" , " ," , " " )
112
124
val args = Array (
113
125
" -classpath" , ClasspathFromClassloader (getClass.getClassLoader),
114
126
" -from-tasty" ,
@@ -120,12 +132,24 @@ object BootstrappedStdLibTASYyTest:
120
132
assert(reporter.errorCount == 0 , " Errors while re-compiling" )
121
133
}
122
134
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 */
124
148
def loadBlacklist = List [String ](
125
149
// No issues :)
126
150
)
127
151
128
- /** List of classes that cannot be recompilied from TASTy */
152
+ /** List of tasty files that cannot be recompilied from TASTy */
129
153
def compileBlacklist = List [String ](
130
154
// See #10048
131
155
// failed: java.lang.AssertionError: assertion failed: class Boolean
@@ -135,22 +159,22 @@ object BootstrappedStdLibTASYyTest:
135
159
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)
136
160
// at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBTypeAndRegisterInnerClass(BCodeSkelBuilder.scala:62)
137
161
// 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 */
151
175
def loadBlacklisted = loadBlacklist.toSet
152
176
153
- /** Set of classes that cannot be recompilied from TASTy */
177
+ /** Set of tasty files that cannot be recompilied from TASTy */
154
178
def compileBlacklisted = compileBlacklist.toSet
155
179
156
180
end BootstrappedStdLibTASYyTest
0 commit comments