Last active
June 9, 2017 13:59
-
-
Save jonas/a0728dbb7667d9c6f47f55ff5ed87f72 to your computer and use it in GitHub Desktop.
Scala Native CollectionReachabilitySuite
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
package scala.scalanative.linker | |
import org.scalatest._ | |
import scalanative.nir.Global | |
class CollectionReachabilitySuite extends ReachabilitySuite { | |
val sources = Seq(""" | |
trait Collection[E] { | |
def isEmpty: Boolean | |
def size: Int | |
} | |
trait Set[E] extends Collection[E] | |
abstract class AbstractCollection[E] extends Collection[E] { | |
override def isEmpty = size == 0 | |
} | |
abstract class AbstractSet[E] extends AbstractCollection[E] with Set[E] | |
class TreeSet[E] extends AbstractSet[E] { | |
override def size = 42 | |
} | |
""") | |
val Object = g("java.lang.Object") | |
val Collection = g("Collection") | |
val Collection_isEmpty = g("Collection", "isEmpty_bool") | |
val Set = g("Set") | |
val Set_isEmpty = g("Set", "isEmpty_bool") | |
val AbstractCollection = g("AbstractCollection") | |
val AbstractCollection_isEmpty = g("AbstractCollection", "isEmpty_bool") | |
val AbstractSet = g("AbstractSet") | |
val AbstractSet_isEmpty = g("AbstractSet", "isEmpty_bool") | |
val TreeSet = g("TreeSet") | |
val TreeSet_isEmpty = g("TreeSet", "isEmpty_bool") | |
testReachable("Collection")(Collection)(Collection) | |
testReachable("Collection_isEmpty")(Collection_isEmpty)(Collection, Collection_isEmpty) | |
testReachable("Set")(Set)(Set, Collection) | |
testReachable("Set_isEmpty")(Set_isEmpty)(Set, Set_isEmpty, Collection, Collection_isEmpty) | |
testReachable("AbstractCollection")(AbstractCollection)(AbstractCollection, Collection, Object) | |
testReachable("AbstractCollection_isEmpty")(AbstractCollection_isEmpty)( | |
AbstractCollection, AbstractCollection_isEmpty, Collection, Collection_isEmpty) | |
testReachable("AbstractSet")(AbstractSet)(AbstractSet, Set, AbstractCollection, Collection, Object) | |
testReachable("AbstractSet_isEmpty")(AbstractSet_isEmpty)( | |
AbstractSet, AbstractSet_isEmpty, AbstractCollection, AbstractCollection_isEmpty, Collection, Collection_isEmpty) | |
testReachable("TreeSet")(TreeSet)(TreeSet, AbstractSet, Set, AbstractCollection, Collection, Object) | |
testReachable("TreeSet_isEmpty")(TreeSet_isEmpty)( | |
TreeSet, TreeSet_isEmpty, AbstractSet, AbstractSet_isEmpty, AbstractCollection, AbstractCollection_isEmpty, Collection, Collection_isEmpty) | |
} |
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
> console | |
[info] Starting scala interpreter... | |
[info] | |
Welcome to Scala version 2.10.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_73). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> trait Collection[E] { | |
| def isEmpty: Boolean | |
| def size: Int | |
| } | |
defined trait Collection | |
scala> trait Set[E] extends Collection[E] | |
defined trait Set | |
scala> | |
scala> abstract class AbstractCollection[E] extends Collection[E] { | |
| override def isEmpty = size == 0 | |
| } | |
defined class AbstractCollection | |
scala> abstract class AbstractSet[E] extends AbstractCollection[E] with Set[E] | |
defined class AbstractSet | |
scala> | |
scala> class TreeSet[E] extends AbstractSet[E] { | |
| override def size = 42 | |
| } | |
defined class TreeSet | |
scala> println((new TreeSet[Int]).size) | |
42 |
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
/* | |
> sandbox/run | |
[info] Compiling 1 Scala source to /opt/scala-native/sandbox/target/scala-2.11/classes... | |
[info] Linking (596 ms) | |
[error] cannot link: @java.util.Set::add_java.lang.Object_bool | |
[error] cannot link: @java.util.Set::clear_unit | |
[error] cannot link: @java.util.Set::contains_java.lang.Object_bool | |
[error] cannot link: @java.util.Set::isEmpty_bool | |
[error] cannot link: @java.util.Set::iterator_java.util.Iterator | |
[error] cannot link: @java.util.Set::remove_java.lang.Object_bool | |
[error] cannot link: @java.util.Set::size_i32 | |
[error] unable to link | |
[error] (sandbox/compile:nativeLinkNIR) unable to link | |
[error] Total time: 1 s, completed 9-Jun-2017 9:59:11 AM | |
*/ | |
trait Collection[E] { | |
def isEmpty: Boolean | |
def size: Int | |
} | |
trait Set[E] extends Collection[E] | |
abstract class AbstractCollection[E] extends Collection[E] { | |
override def isEmpty = size == 0 | |
} | |
abstract class AbstractSet[E] extends AbstractCollection[E] with Set[E] | |
class TreeSet[E] extends AbstractSet[E] { | |
override def size = 42 | |
} | |
object Test { | |
def main(args: Array[String]): Unit = { | |
println((new TreeSet[Int]).size) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment