-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Compile Scala library with Dotty and test its TASTy #9925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolasstucki
merged 2 commits into
scala:master
from
dotty-staging:scala-library-from-tasty-tests
Oct 21, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add a setting:
this way the jar will be called scala-library_3.0.0-M1.jar which makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added