-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
f1bad54
commit 30403cf
Showing
6 changed files
with
145 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 0 additions & 174 deletions
174
scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import scala.quoted._ | ||
import scala.tasty.inspector._ | ||
|
||
import dotty.tools.io.Directory | ||
|
||
import java.io.File.pathSeparator | ||
|
||
@main def Test: Unit = | ||
blacklistsOnlyContainsClassesThatExist() | ||
testTastyInspector() | ||
|
||
/** Test that we can load trees from TASTy */ | ||
def testTastyInspector(): Unit = | ||
loadWithTastyInspector(loadBlacklisted) | ||
|
||
def blacklistsOnlyContainsClassesThatExist() = | ||
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet | ||
assert(loadBlacklisted.diff(scalaLibTastyPathsSet).isEmpty, | ||
loadBlacklisted.diff(scalaLibTastyPathsSet).mkString( | ||
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n")) | ||
|
||
def dottyVersion = | ||
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst { | ||
case path if path.endsWith(".jar") && path.contains("/scala3-library_3-") => | ||
path.split("/scala3-library_3-").last.stripSuffix(".jar") | ||
}.get | ||
|
||
def scalaLibClassesPath = | ||
java.nio.file.Paths.get( | ||
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes") | ||
|
||
lazy val scalaLibTastyPaths = | ||
new Directory(scalaLibClassesPath).deepFiles | ||
.filter(_.`extension` == "tasty") | ||
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/")) | ||
.toList | ||
|
||
def loadWithTastyInspector(blacklisted: Set[String]): Unit = | ||
val inspector = new scala.tasty.inspector.Inspector { | ||
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit = | ||
for tasty <- tastys do | ||
tasty.ast.show(using quotes.reflect.Printer.TreeStructure) // Check that we can traverse the full tree | ||
() | ||
} | ||
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted) | ||
val isSuccess = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector) | ||
assert(isSuccess, "Errors reported while loading from TASTy") | ||
|
||
/** Set of tasty files that cannot be loaded from TASTy */ | ||
def loadBlacklisted = Set[String]( | ||
// No issues :) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import dotty.tools.io.Directory | ||
import dotty.tools.dotc.util.ClasspathFromClassloader | ||
|
||
import java.io.File.pathSeparator | ||
import java.io.File.separator | ||
|
||
@main def Test: Unit = | ||
blacklistsOnlyContainsClassesThatExist() | ||
testFromTastyInJar() | ||
testFromTasty() | ||
|
||
/** Test that we can load and compile trees from TASTy in a Jar */ | ||
def testFromTastyInJar(): Unit = | ||
compileFromTastyInJar(compileBlacklisted) | ||
|
||
/** Test that we can load and compile trees from TASTy */ | ||
def testFromTasty(): Unit = | ||
compileFromTasty(compileBlacklisted) | ||
|
||
def blacklistsOnlyContainsClassesThatExist() = | ||
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet | ||
assert(compileBlacklisted.diff(scalaLibTastyPathsSet).isEmpty, | ||
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString( | ||
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n")) | ||
|
||
def dottyVersion = | ||
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst { | ||
case path if path.endsWith(".jar") && path.contains("/scala3-library_3-") => | ||
path.split("/scala3-library_3-").last.stripSuffix(".jar") | ||
}.get | ||
|
||
def scalaLibJarPath = | ||
s"out/bootstrap/scala2-library-tasty/scala-$dottyVersion-nonbootstrapped/scala2-library-tasty_3-$dottyVersion.jar" | ||
|
||
def scalaLibClassesPath = | ||
java.nio.file.Paths.get( | ||
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes") | ||
|
||
lazy val scalaLibTastyPaths = | ||
new Directory(scalaLibClassesPath).deepFiles | ||
.filter(_.`extension` == "tasty") | ||
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/")) | ||
.toList | ||
|
||
def compileFromTastyInJar(blacklisted: Set[String]): Unit = { | ||
val driver = new dotty.tools.dotc.Driver | ||
val yFromTastyBlacklist = | ||
blacklisted.mkString("-Yfrom-tasty-ignore-list:", ",", "") | ||
val args = Array( | ||
"-classpath", ClasspathFromClassloader(getClass.getClassLoader), | ||
"-from-tasty", | ||
"-nowarn", | ||
yFromTastyBlacklist, | ||
scalaLibJarPath, | ||
) | ||
val reporter = driver.process(args) | ||
assert(reporter.errorCount == 0, "Errors while re-compiling") | ||
} | ||
|
||
def compileFromTasty(blacklisted: Set[String]): Unit = { | ||
val driver = new dotty.tools.dotc.Driver | ||
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted) | ||
val args = Array( | ||
"-classpath", ClasspathFromClassloader(getClass.getClassLoader), | ||
"-from-tasty", | ||
"-nowarn", | ||
) ++ tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString) | ||
val reporter = driver.process(args) | ||
assert(reporter.errorCount == 0, "Errors while re-compiling") | ||
} | ||
|
||
/** Set of tasty files that cannot be recompiled from TASTy */ | ||
def compileBlacklisted = Set[String]( | ||
// See #10048 | ||
// failed: java.lang.AssertionError: assertion failed: class Boolean | ||
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:247) | ||
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass(BCodeHelpers.scala:265) | ||
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210) | ||
// at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBTypeAndRegisterInnerClass(BCodeSkelBuilder.scala:62) | ||
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.internalName(BCodeHelpers.scala:237) | ||
"scala/Array.tasty", | ||
"scala/Boolean.tasty", | ||
"scala/Byte.tasty", | ||
"scala/Char.tasty", | ||
"scala/Double.tasty", | ||
"scala/Float.tasty", | ||
"scala/Int.tasty", | ||
"scala/Long.tasty", | ||
"scala/Short.tasty", | ||
"scala/Unit.tasty", | ||
).map(_.replace("/", separator)) |