forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile Scala library with Dotty and test its TASTy
- Loading branch information
1 parent
ce67fd1
commit b02abfc
Showing
6 changed files
with
298 additions
and
3 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
209 changes: 209 additions & 0 deletions
209
stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala
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,209 @@ | ||
package dotty.tools.dotc | ||
|
||
import org.junit.Test | ||
import org.junit.Ignore | ||
import org.junit.Assert._ | ||
|
||
import dotty.tools.io._ | ||
import dotty.tools.dotc.util.ClasspathFromClassloader | ||
|
||
import scala.quoted._ | ||
|
||
import java.io.File.pathSeparator | ||
|
||
class BootstrappedStdLibTASYyTest: | ||
|
||
import BootstrappedStdLibTASYyTest._ | ||
|
||
/** Test that we can load trees from TASTy */ | ||
@Test def testTastyInspector: Unit = | ||
loadWithTastyInspector(loadBlacklisted) | ||
|
||
/** Test that we can load and compile trees from TASTy */ | ||
@Test def testFromTasty: Unit = | ||
compileFromTasty(loadBlacklisted.union(compileBlacklisted)) | ||
|
||
@Ignore | ||
@Test def testWhiteListFromTasty: Unit = | ||
val whitelist = Set( | ||
"scala.collection.mutable.StringBuilder" | ||
) | ||
compileFromTasty(x => !whitelist(x)) | ||
|
||
@Test def blacklistNoDuplicates = | ||
def testDup(name: String, list: List[String], set: Set[String]) = | ||
assert(list.size == set.size, | ||
list.diff(set.toSeq).mkString(s"`$name` has duplicate entries:\n ", "\n ", "\n\n")) | ||
testDup("loadBlacklist", loadBlacklist, loadBlacklisted) | ||
testDup("compileBlacklist", compileBlacklist, compileBlacklisted) | ||
|
||
@Test def blacklistsNoIntersection = | ||
val intersection = loadBlacklisted & compileBlacklisted | ||
assert(intersection.isEmpty, | ||
intersection.mkString( | ||
"`compileBlacklist` contains names that are already in `loadBlacklist`: \n ", "\n ", "\n\n")) | ||
|
||
@Test def blacklistsOnlyContainsClassesThatExist = | ||
val scalaLibJarTastyClassNamesSet = scalaLibJarTastyClassNames.toSet | ||
val intersection = loadBlacklisted & compileBlacklisted | ||
assert(loadBlacklisted.diff(scalaLibJarTastyClassNamesSet).isEmpty, | ||
loadBlacklisted.diff(scalaLibJarTastyClassNamesSet).mkString( | ||
"`loadBlacklisted` contains names that are not in `scalaLibJarTastyClassNames`: \n ", "\n ", "\n\n")) | ||
assert(compileBlacklisted.diff(scalaLibJarTastyClassNamesSet).isEmpty, | ||
compileBlacklisted.diff(scalaLibJarTastyClassNamesSet).mkString( | ||
"`loadBlacklisted` contains names that are not in `scalaLibJarTastyClassNames`: \n ", "\n ", "\n\n")) | ||
|
||
@Ignore | ||
@Test def testLoadBacklistIsMinimal = | ||
var shouldBeWhitelisted = List.empty[String] | ||
val size = loadBlacklisted.size | ||
for (notBlacklisted, i) <- loadBlacklist.zipWithIndex do | ||
val blacklist = loadBlacklisted - notBlacklisted | ||
println(s"Trying withouth $notBlacklisted in the blacklist (${i+1}/$size)") | ||
try { | ||
loadWithTastyInspector(blacklist) | ||
shouldBeWhitelisted = notBlacklisted :: shouldBeWhitelisted | ||
} | ||
catch { | ||
case ex: Throwable => // ok | ||
} | ||
assert(shouldBeWhitelisted.isEmpty, | ||
shouldBeWhitelisted.mkString("Some classes do not need to be blacklisted in `loadBlacklisted`\n ", "\n ", "\n\n")) | ||
|
||
@Ignore | ||
@Test def testCompileBlacklistIsMinimal = | ||
var shouldBeWhitelisted = List.empty[String] | ||
val size = compileBlacklisted.size | ||
val blacklist0 = loadBlacklisted.union(compileBlacklisted) | ||
for (notBlacklisted, i) <- compileBlacklist.zipWithIndex do | ||
val blacklist = blacklist0 - notBlacklisted | ||
println(s"Trying withouth $notBlacklisted in the blacklist (${i+1}/$size)") | ||
try { | ||
compileFromTasty(blacklist) | ||
shouldBeWhitelisted = notBlacklisted :: shouldBeWhitelisted | ||
} | ||
catch { | ||
case ex: Throwable => // ok | ||
} | ||
assert(shouldBeWhitelisted.isEmpty, | ||
shouldBeWhitelisted.mkString("Some classes do not need to be blacklisted in `compileBlacklisted`\n ", "\n ", "\n\n")) | ||
|
||
end BootstrappedStdLibTASYyTest | ||
|
||
object BootstrappedStdLibTASYyTest: | ||
|
||
val scalaLibJarPath = System.getProperty("dotty.scala.library") | ||
|
||
val scalaLibJarTastyClassNames = { | ||
val scalaLibJar = Jar(new File(java.nio.file.Paths.get(scalaLibJarPath))) | ||
scalaLibJar.toList.map(_.toString).filter(_.endsWith(".tasty")) | ||
.map(_.stripSuffix(".tasty").replace("/", ".")) | ||
.sorted | ||
} | ||
|
||
def loadWithTastyInspector(blacklisted: String => Boolean): Unit = | ||
val inspector = new scala.tasty.inspector.TastyInspector { | ||
def processCompilationUnit(using QuoteContext)(root: qctx.reflect.Tree): Unit = | ||
root.showExtractors // Check that we can traverse the full tree | ||
() | ||
} | ||
val classNames = scalaLibJarTastyClassNames.filterNot(blacklisted) | ||
val hasErrors = inspector.inspect(scalaLibJarPath, classNames) | ||
assert(!hasErrors, "Errors reported while loading from TASTy") | ||
|
||
def compileFromTasty(blacklisted: String => Boolean): Unit = { | ||
val driver = new dotty.tools.dotc.Driver | ||
val currentClasspath = ClasspathFromClassloader(getClass.getClassLoader) | ||
val classNames = scalaLibJarTastyClassNames.filterNot(blacklisted) | ||
val args = Array( | ||
"-classpath", s"$scalaLibJarPath$pathSeparator$currentClasspath", | ||
"-from-tasty", | ||
"-nowarn" | ||
) ++ classNames | ||
val reporter = driver.process(args) | ||
assert(reporter.errorCount == 0, "Errors while re-compiling") | ||
} | ||
|
||
/** List of classes that cannot be loaded from TASTy */ | ||
def loadBlacklist = List[String]( | ||
// No issues :) | ||
) | ||
|
||
/** List of classes that cannot be recompilied from TASTy */ | ||
def compileBlacklist = List[String]( | ||
// See #10048 | ||
// failed: java.lang.AssertionError: assertion failed: class Boolean | ||
// at dotty.DottyPredef$.assertFail(DottyPredef.scala:17) | ||
// 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", | ||
"scala.Boolean", | ||
"scala.Byte", | ||
"scala.Char", | ||
"scala.Double", | ||
"scala.Float", | ||
"scala.Int", | ||
"scala.Long", | ||
"scala.Short", | ||
"scala.Unit", | ||
|
||
// See #9994 | ||
// -- Error: | ||
// | def addOne(kv: (K, V)) = { | ||
// | ^ | ||
// |error overriding method addOne in trait Growable of type (elem: (K, V)): (TrieMap.this : scala.collection.concurrent.TrieMap[K, V]); | ||
// | method addOne of type (kv: (K, V)): (TrieMap.this : scala.collection.concurrent.TrieMap[K, V]) has incompatible type | ||
// -- Error: | ||
// | def subtractOne(k: K) = { | ||
// | ^ | ||
// |error overriding method subtractOne in trait Shrinkable of type (elem: K): (TrieMap.this : scala.collection.concurrent.TrieMap[K, V]); | ||
// | method subtractOne of type (k: K): (TrieMap.this : scala.collection.concurrent.TrieMap[K, V]) has incompatible type | ||
"scala.collection.concurrent.TrieMap", | ||
"scala.collection.immutable.HashMapBuilder", | ||
"scala.collection.immutable.HashSetBuilder", | ||
"scala.collection.immutable.LazyList", | ||
"scala.collection.immutable.ListMapBuilder", | ||
"scala.collection.immutable.MapBuilderImpl", | ||
"scala.collection.immutable.SetBuilderImpl", | ||
"scala.collection.immutable.TreeSeqMap", | ||
"scala.collection.immutable.VectorBuilder", | ||
"scala.collection.immutable.VectorMapBuilder", | ||
"scala.collection.mutable.AnyRefMap", | ||
"scala.collection.mutable.ArrayBuilder", | ||
"scala.collection.mutable.CollisionProofHashMap", | ||
"scala.collection.mutable.LongMap", | ||
"scala.collection.mutable.SortedMap", | ||
"scala.collection.mutable.StringBuilder", | ||
"scala.jdk.AnyAccumulator", | ||
"scala.jdk.DoubleAccumulator", | ||
"scala.jdk.IntAccumulator", | ||
"scala.jdk.LongAccumulator", | ||
|
||
// See #9994 | ||
// -- Error: | ||
// | override def filterInPlace(p: A => Boolean): this.type = { | ||
// | ^ | ||
// |error overriding method filterInPlace in trait SetOps of type (p: A => Boolean): (HashSet.this : scala.collection.mutable.HashSet[A]); | ||
// | method filterInPlace of type (p: A => Boolean): (HashSet.this : scala.collection.mutable.HashSet[A]) has incompatible type | ||
"scala.collection.mutable.HashSet", | ||
|
||
// See #9994 | ||
// -- Error: | ||
// | def force: this.type = { | ||
// | ^ | ||
// |error overriding method force in class Stream of type => (Cons.this : scala.collection.immutable.Stream.Cons[A]); | ||
// | method force of type => (Cons.this : scala.collection.immutable.Stream.Cons[A]) has incompatible type | ||
"scala.collection.immutable.Stream", | ||
|
||
) | ||
|
||
/** Set of classes that cannot be loaded from TASTy */ | ||
def loadBlacklisted = loadBlacklist.toSet | ||
|
||
/** Set of classes that cannot be recompilied from TASTy */ | ||
def compileBlacklisted = compileBlacklist.toSet | ||
|
||
end BootstrappedStdLibTASYyTest |
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,12 @@ | ||
package hello | ||
|
||
enum Color: | ||
case Red, Green, Blue | ||
|
||
object HelloWorld: | ||
def main(args: Array[String]): Unit = { | ||
println("hello dotty.superbootstrapped!") | ||
println(Color.Red) | ||
println(Color.Green) | ||
println(Color.Blue) | ||
} |
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