Skip to content

Commit

Permalink
Remove scala2-library-tasty-tests project (#19379)
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
nicolasstucki authored Mar 19, 2024
2 parents fca115a + 96b57b8 commit 01c6623
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 206 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:

- name: Cmd Tests
run: |
./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"
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
./project/scripts/cmdTests
./project/scripts/bootstrappedOnlyCmdTests
Expand Down Expand Up @@ -584,7 +584,7 @@ jobs:

- name: Test
run: |
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala2-library-tasty-tests/test"
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*"
./project/scripts/cmdTests
./project/scripts/bootstrappedOnlyCmdTests
Expand Down
1 change: 0 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
val `scala3-bench-micro` = Build.`scala3-bench-micro`
val `scala2-library-bootstrapped` = Build.`scala2-library-bootstrapped`
val `scala2-library-tasty` = Build.`scala2-library-tasty`
val `scala2-library-tasty-tests` = Build.`scala2-library-tasty-tests`
val `scala2-library-cc` = Build.`scala2-library-cc`
val `scala2-library-cc-tasty` = Build.`scala2-library-cc-tasty`
val `tasty-core` = Build.`tasty-core`
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/fromtasty/TASTYRun.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class TASTYRun(comp: Compiler, ictx: Context) extends Run(comp, ictx) {
file.extension match
case "jar" =>
JarArchive.open(Path(file.path), create = false).allFileNames()
.map(_.stripPrefix(File.separator)) // change paths from absolute to relative
.filter(e => Path.extension(e) == "tasty" && !fromTastyIgnoreList(e))
.map(e => e.stripSuffix(".tasty").replace(File.separator, "."))
.map(_.stripPrefix("/")) // change paths from absolute to relative
.filter(e => Path.extension(e) == "tasty" && !fromTastyIgnoreList(e.replace("/", File.separator)))
.map(e => e.stripSuffix(".tasty").replace("/", "."))
.toList
case "tasty" => TastyFileUtil.getClassName(file)
case _ =>
Expand Down
26 changes: 0 additions & 26 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1250,32 +1250,6 @@ object Build {
},
)

/** Test the tasty generated by `scala2-library-bootstrapped`
*
* The sources in src are compiled using TASTy from scala2-library-tasty but then run
* with the scala-library compiled be Scala 2.
*
* The tests are run with the bootstrapped compiler and the tasty inspector on the classpath.
* The classpath has the default `scala-library` and not `scala2-library-bootstrapped`.
*
* The jar of `scala2-library-bootstrapped` is provided for to the tests.
* - inspector: test that we can load the contents of the jar using the tasty inspector
* - from-tasty: test that we can recompile the contents of the jar using `dotc -from-tasty`
*/
lazy val `scala2-library-tasty-tests` = project.in(file("scala2-library-tasty-tests")).
withCommonSettings(Bootstrapped).
dependsOn(dottyCompiler(Bootstrapped) % "compile->compile").
dependsOn(`scala3-tasty-inspector` % "test->test").
dependsOn(`scala2-library-tasty`).
settings(commonBootstrappedSettings).
settings(
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
Test / javaOptions += "-Ddotty.scala.library=" + (`scala2-library-bootstrapped` / Compile / packageBin).value.getAbsolutePath,
Compile / compile / fullClasspath ~= {
_.filterNot(file => file.data.getName == s"scala-library-$stdlibBootstrappedVersion.jar")
},
)

lazy val `scala3-sbt-bridge` = project.in(file("sbt-bridge/src")).
// We cannot depend on any bootstrapped project to compile the bridge, since the
// bridge is needed to compile these projects.
Expand Down
174 changes: 0 additions & 174 deletions scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala

This file was deleted.

53 changes: 53 additions & 0 deletions tests/run-tasty-inspector/scala2-library-test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import scala.quoted._
import scala.tasty.inspector._

import dotty.tools.io.Directory

import java.io.File.pathSeparator
import java.io.File.separator

@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".replace("/", separator))

lazy val scalaLibTastyPaths =
new Directory(scalaLibClassesPath).deepFiles
.filter(_.`extension` == "tasty")
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + separator))
.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 :)
)
74 changes: 74 additions & 0 deletions tests/run-with-compiler/scala2-library-from-tasty-jar.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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()
// FIXME this test does not work on JDK8
// Caused by: dotty.tools.dotc.core.TypeError$$anon$1: package scala.quoted.runtime.Expr does not have a member method quote
if System.getProperty("java.specification.version") != "1.8" then
compileFromTastyInJar(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${separator}bootstrap${separator}scala2-library-tasty${separator}scala-$dottyVersion-nonbootstrapped${separator}scala2-library-tasty-experimental_3-$dottyVersion.jar"

def scalaLibClassesPath =
java.nio.file.Paths.get(
s"out${separator}bootstrap${separator}scala2-library-bootstrapped${separator}scala-$dottyVersion-nonbootstrapped${separator}classes")

lazy val scalaLibTastyPaths =
new Directory(scalaLibClassesPath).deepFiles
.filter(_.`extension` == "tasty")
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + separator))
.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",
"-d", s"out${separator}scala2-library-from-tasty-jar-test-output.jar",
"-nowarn",
yFromTastyBlacklist,
scalaLibJarPath,
)
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)
s"scala${separator}Array.tasty",
s"scala${separator}Boolean.tasty",
s"scala${separator}Byte.tasty",
s"scala${separator}Char.tasty",
s"scala${separator}Double.tasty",
s"scala${separator}Float.tasty",
s"scala${separator}Int.tasty",
s"scala${separator}Long.tasty",
s"scala${separator}Short.tasty",
s"scala${separator}Unit.tasty",
)
Loading

0 comments on commit 01c6623

Please sign in to comment.