Skip to content

Commit 01c6623

Browse files
Remove scala2-library-tasty-tests project (#19379)
Split BootstrappedStdLibTASYyTest into the part that tests the TASTy inspector and the part that tests recompilation. The `tests/run/scala2-library-test` test will be tested with the original Scala 2 library JAR and with the Scala 2 library TASTy JAR depending on the `scala2Library` SBT setting. 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. [test_java8]
2 parents fca115a + 96b57b8 commit 01c6623

File tree

8 files changed

+200
-206
lines changed

8 files changed

+200
-206
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
@@ -584,7 +584,7 @@ jobs:
584584

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

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
@@ -1250,32 +1250,6 @@ object Build {
12501250
},
12511251
)
12521252

1253-
/** Test the tasty generated by `scala2-library-bootstrapped`
1254-
*
1255-
* The sources in src are compiled using TASTy from scala2-library-tasty but then run
1256-
* with the scala-library compiled be Scala 2.
1257-
*
1258-
* The tests are run with the bootstrapped compiler and the tasty inspector on the classpath.
1259-
* The classpath has the default `scala-library` and not `scala2-library-bootstrapped`.
1260-
*
1261-
* The jar of `scala2-library-bootstrapped` is provided for to the tests.
1262-
* - inspector: test that we can load the contents of the jar using the tasty inspector
1263-
* - from-tasty: test that we can recompile the contents of the jar using `dotc -from-tasty`
1264-
*/
1265-
lazy val `scala2-library-tasty-tests` = project.in(file("scala2-library-tasty-tests")).
1266-
withCommonSettings(Bootstrapped).
1267-
dependsOn(dottyCompiler(Bootstrapped) % "compile->compile").
1268-
dependsOn(`scala3-tasty-inspector` % "test->test").
1269-
dependsOn(`scala2-library-tasty`).
1270-
settings(commonBootstrappedSettings).
1271-
settings(
1272-
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
1273-
Test / javaOptions += "-Ddotty.scala.library=" + (`scala2-library-bootstrapped` / Compile / packageBin).value.getAbsolutePath,
1274-
Compile / compile / fullClasspath ~= {
1275-
_.filterNot(file => file.data.getName == s"scala-library-$stdlibBootstrappedVersion.jar")
1276-
},
1277-
)
1278-
12791253
lazy val `scala3-sbt-bridge` = project.in(file("sbt-bridge/src")).
12801254
// We cannot depend on any bootstrapped project to compile the bridge, since the
12811255
// 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: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import scala.quoted._
2+
import scala.tasty.inspector._
3+
4+
import dotty.tools.io.Directory
5+
6+
import java.io.File.pathSeparator
7+
import java.io.File.separator
8+
9+
@main def Test: Unit =
10+
blacklistsOnlyContainsClassesThatExist()
11+
testTastyInspector()
12+
13+
/** Test that we can load trees from TASTy */
14+
def testTastyInspector(): Unit =
15+
loadWithTastyInspector(loadBlacklisted)
16+
17+
def blacklistsOnlyContainsClassesThatExist() =
18+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
19+
assert(loadBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
20+
loadBlacklisted.diff(scalaLibTastyPathsSet).mkString(
21+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
22+
23+
def dottyVersion =
24+
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
25+
case path if path.endsWith(".jar") && path.contains("scala3-library_3-") =>
26+
path.split("scala3-library_3-").last.stripSuffix(".jar")
27+
}.get
28+
29+
def scalaLibClassesPath =
30+
java.nio.file.Paths.get(
31+
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes".replace("/", separator))
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 loadWithTastyInspector(blacklisted: Set[String]): Unit =
40+
val inspector = new scala.tasty.inspector.Inspector {
41+
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
42+
for tasty <- tastys do
43+
tasty.ast.show(using quotes.reflect.Printer.TreeStructure) // Check that we can traverse the full tree
44+
()
45+
}
46+
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
47+
val isSuccess = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector)
48+
assert(isSuccess, "Errors reported while loading from TASTy")
49+
50+
/** Set of tasty files that cannot be loaded from TASTy */
51+
def loadBlacklisted = Set[String](
52+
// No issues :)
53+
)
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+
)

0 commit comments

Comments
 (0)