diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2016-07-19 14:45:15 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2016-07-19 14:47:55 +0200 |
commit | 2c2fd4f4b63e1d9a6ee1243637ad8bcb0deb11d6 (patch) | |
tree | 169bc0545d5e96f9a87ecdd8fd019b4a258648dc /test | |
parent | 31db427375ed50a0ccf1e9ea12d858c71f3f5777 (diff) | |
download | scala-2c2fd4f4b63e1d9a6ee1243637ad8bcb0deb11d6.tar.gz scala-2c2fd4f4b63e1d9a6ee1243637ad8bcb0deb11d6.tar.bz2 scala-2c2fd4f4b63e1d9a6ee1243637ad8bcb0deb11d6.zip |
SD-20 Inlcude static methods in the InlineInfo in mixed compilation
In mixed compilation, the InlineInfo for a Java-defined class is created
using the class symbol (vs in separate compilation, where the info is
created by looking at the classfile and its methods). The scala compiler
puts static java methods into the companion symbol, and we forgot to
include them in the list of methods in the InlineInfo.
Diffstat (limited to 'test')
3 files changed, 56 insertions, 5 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala index a691d63471..6f098e1432 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineInfoTest.scala @@ -2,18 +2,20 @@ package scala.tools.nsc package backend.jvm package opt +import org.junit.Assert._ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 import scala.collection.JavaConverters._ import scala.collection.generic.Clearable +import scala.tools.nsc.backend.jvm.BTypes.MethodInlineInfo import scala.tools.nsc.backend.jvm.BackendReporting._ import scala.tools.testing.BytecodeTesting @RunWith(classOf[JUnit4]) class InlineInfoTest extends BytecodeTesting { - import compiler.global + import compiler._ import global.genBCode.bTypes override def compilerArgs = "-opt:l:classpath" @@ -59,4 +61,20 @@ class InlineInfoTest extends BytecodeTesting { assert(fromSyms == fromAttrs) } + + @Test // scala-dev#20 + def javaStaticMethodsInlineInfoInMixedCompilation(): Unit = { + val jCode = + """public class A { + | public static final int bar() { return 100; } + | public final int baz() { return 100; } + |} + """.stripMargin + compileClasses("class C { new A }", javaCode = List((jCode, "A.java"))) + val info = global.genBCode.bTypes.classBTypeFromInternalName("A").info.get.inlineInfo + assertEquals(info.methodInfos, Map( + "bar()I" -> MethodInlineInfo(true,false,false), + "<init>()V" -> MethodInlineInfo(false,false,false), + "baz()I" -> MethodInlineInfo(true,false,false))) + } } diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala index 5254d7e1f2..5bd2ce68f1 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlineWarningTest.scala @@ -75,12 +75,12 @@ class InlineWarningTest extends BytecodeTesting { val warns = List( """failed to determine if bar should be inlined: |The method bar()I could not be found in the class A or any of its parents. - |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin, + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin, """B::flop()I is annotated @inline but could not be inlined: |Failed to check if B::flop()I can be safely inlined to B without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed: |The method bar()I could not be found in the class A or any of its parents. - |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin) + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin) var c = 0 val List(b) = compileToBytes(scalaCode, List((javaCode, "A.java")), allowMessage = i => {c += 1; warns.tail.exists(i.msg contains _)}) @@ -168,4 +168,37 @@ class InlineWarningTest extends BytecodeTesting { compileToBytes(code, allowMessage = i => { c += 1; i.msg contains warn }) assert(c == 1, c) } + + @Test // scala-dev#20 + def mixedCompilationSpuriousWarning(): Unit = { + val jCode = + """public class A { + | public static final int bar() { return 100; } + | public final int baz() { return 100; } + |} + """.stripMargin + + val sCode = + """class C { + | @inline final def foo = A.bar() + | @inline final def fii(a: A) = a.baz() + | def t = foo + fii(new A) + |} + """.stripMargin + + val warns = List( + """C::foo()I is annotated @inline but could not be inlined: + |Failed to check if C::foo()I can be safely inlined to C without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed: + |The method bar()I could not be found in the class A or any of its parents. + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin, + + """C::fii(LA;)I is annotated @inline but could not be inlined: + |Failed to check if C::fii(LA;)I can be safely inlined to C without causing an IllegalAccessError. Checking instruction INVOKEVIRTUAL A.baz ()I failed: + |The method baz()I could not be found in the class A or any of its parents. + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin + ) + var c = 0 + compileClasses(sCode, javaCode = List((jCode, "A.java")), allowMessage = i => { c += 1; warns.exists(i.msg.contains)}) + assert(c == 2) + } } diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala index f531ce9322..0f292517ef 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala @@ -416,7 +416,7 @@ class InlinerTest extends BytecodeTesting { """B::flop()I is annotated @inline but could not be inlined: |Failed to check if B::flop()I can be safely inlined to B without causing an IllegalAccessError. Checking instruction INVOKESTATIC A.bar ()I failed: |The method bar()I could not be found in the class A or any of its parents. - |Note that the parent class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin + |Note that class A is defined in a Java source (mixed compilation), no bytecode is available.""".stripMargin var c = 0 val List(b) = compile(scalaCode, List((javaCode, "A.java")), allowMessage = i => {c += 1; i.msg contains warn}) @@ -819,7 +819,7 @@ class InlinerTest extends BytecodeTesting { val warn = """failed to determine if <init> should be inlined: |The method <init>()V could not be found in the class A$Inner or any of its parents. - |Note that the parent class A$Inner could not be found on the classpath.""".stripMargin + |Note that class A$Inner could not be found on the classpath.""".stripMargin var c = 0 |