summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2014-08-12 16:12:15 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2014-08-19 17:50:02 +0200
commitf73f026bf250e6eb3c22c2b1975d4fdc2f23eab6 (patch)
treeb1d49a853c90740c6e4b15b0c8365c72b702970d /test
parentbdc3ff97e7f869b393de7e4deb53535a93738ad1 (diff)
downloadscala-f73f026bf250e6eb3c22c2b1975d4fdc2f23eab6.tar.gz
scala-f73f026bf250e6eb3c22c2b1975d4fdc2f23eab6.tar.bz2
scala-f73f026bf250e6eb3c22c2b1975d4fdc2f23eab6.zip
Remove Tracked, add type information to ClassBType
Before this change, a ClassBType was just a name. The `exemplars` map stored a Tracked instance for every ClassBType. Tracked stored type information that is required later in the backend when things may run concurrently. In particular: superclass, interfaces, flags and information for emitting the InnerClass attribute. Now we put all the information stored in Tracked directly in the ClassBType. There is still one hash map: `classBTypeFromInternalNameMap` maps a JVM internal class name (e.g. "scala/Predef$") to the corresponding ClassBType. This map is used during bytecode generation, when the ASM framework computes stack map frames. In order to compute stack map frames, the ASM framework needs to be able to get the LUB of two types. The default implementation uses reflection to get type information, however that doesn't work in our case: the classes we compile are not on the classpath. So instead, the backend overwrites the method `getCommonSuperClass` of the ClassWriter. This method receives two class internal names and computes their LUB. This is done by looking up the ClassBTypes in the `classBTypeFromInternalNameMap` and invoking `jvmWiseLUB`. This commit was reviwed in https://github.com/scala/scala/pull/3855. It consists of all commits labelled [squash-after-review], squashed into one.
Diffstat (limited to 'test')
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala55
1 files changed, 21 insertions, 34 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala b/test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala
index b592d06501..cb7e7050b0 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/BTypesTest.scala
@@ -10,29 +10,33 @@ import org.junit.Assert._
@RunWith(classOf[JUnit4])
class BTypesTest {
- val g: Global = new Global(new Settings())
+ val settings = new Settings()
+ settings.processArgumentString("-usejavacp")
+ val g: Global = new Global(settings)
+ val run = new g.Run() // initializes some compiler internals
+ import g.{definitions => d, Symbol}
- val btypes = new BTypes[g.type](g) {
- def chrs = g.chrs
- override type BTypeName = g.TypeName
- override def createNewName(s: String) = g.newTypeName(s)
- }
+ def duringBackend[T](f: => T) = g.exitingDelambdafy(f)
+ val btypes = new BTypesFromSymbols[g.type](g)
import btypes._
+ duringBackend(btypes.intializeCoreBTypes())
+
+ def classBTypeFromSymbol(sym: Symbol) = duringBackend(btypes.classBTypeFromSymbol(sym))
- val jls = "java/lang/String"
- val jlo = "java/lang/Object"
+ val jlo = d.ObjectClass
+ val jls = d.StringClass
- val o = ClassBType(jlo)
- val s = ClassBType(jls)
+ val o = classBTypeFromSymbol(jlo)
+ val s = classBTypeFromSymbol(jls)
val oArr = ArrayBType(o)
val method = MethodBType(List(oArr, INT, DOUBLE, s), UNIT)
@Test
def classBTypesEquality() {
- val s1 = ClassBType(jls)
- val s2 = ClassBType(jls)
- val o = ClassBType(jlo)
+ val s1 = classBTypeFromSymbol(jls)
+ val s2 = classBTypeFromSymbol(jls)
+ val o = classBTypeFromSymbol(jlo)
assertEquals(s1, s2)
assertEquals(s1.hashCode, s2.hashCode)
assert(s1 != o)
@@ -40,11 +44,6 @@ class BTypesTest {
}
@Test
- def classBTypeRequiresInternalName() {
- assertThrows[AssertionError](ClassBType(s"L$jls;"), _ contains "Descriptor instead of internal name")
- }
-
- @Test
def typedOpcodes() {
assert(UNIT.typedOpcode(Opcodes.IALOAD) == Opcodes.IALOAD)
assert(INT.typedOpcode(Opcodes.IALOAD) == Opcodes.IALOAD)
@@ -55,7 +54,7 @@ class BTypesTest {
assert(FLOAT.typedOpcode(Opcodes.IALOAD) == Opcodes.FALOAD)
assert(LONG.typedOpcode(Opcodes.IALOAD) == Opcodes.LALOAD)
assert(DOUBLE.typedOpcode(Opcodes.IALOAD) == Opcodes.DALOAD)
- assert(ClassBType(jls).typedOpcode(Opcodes.IALOAD) == Opcodes.AALOAD)
+ assert(classBTypeFromSymbol(jls).typedOpcode(Opcodes.IALOAD) == Opcodes.AALOAD)
assert(UNIT.typedOpcode(Opcodes.IRETURN) == Opcodes.RETURN)
assert(BOOL.typedOpcode(Opcodes.IRETURN) == Opcodes.IRETURN)
@@ -66,7 +65,7 @@ class BTypesTest {
assert(FLOAT.typedOpcode(Opcodes.IRETURN) == Opcodes.FRETURN)
assert(LONG.typedOpcode(Opcodes.IRETURN) == Opcodes.LRETURN)
assert(DOUBLE.typedOpcode(Opcodes.IRETURN) == Opcodes.DRETURN)
- assert(ClassBType(jls).typedOpcode(Opcodes.IRETURN) == Opcodes.ARETURN)
+ assert(classBTypeFromSymbol(jls).typedOpcode(Opcodes.IRETURN) == Opcodes.ARETURN)
}
@Test
@@ -84,21 +83,9 @@ class BTypesTest {
}
}
+ // TODO @lry do more tests
@Test
- def parseMethodDescriptorTest() {
- val descriptors = List(
- "()V",
- "(ID)I",
- "([[I[D)[D",
- s"(L$jls;[L$jlo;)[[L$jls;",
- s"(IL$jlo;)L$jls;"
- )
- for (d <- descriptors) {
- assertEquals(d, MethodBType(d).descriptor)
- }
+ def maxTypeTest() {
- // class types in method descriptor need surrounding 'L' and ';'
- assertThrows[MatchError](MethodBType("(java/lang/String)V"), _ == "j (of class java.lang.Character)")
- assertThrows[AssertionError](MethodBType("I"), _ contains "Not a valid method descriptor")
}
}