summaryrefslogtreecommitdiff
path: root/test/junit
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2016-07-04 16:45:01 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2016-07-04 16:47:26 +0200
commite5886361006f1b315af13f6aa98cf54a2f7ebe0b (patch)
tree6e1b7056e4c6c6c827f4c2afb7559aeefeb98578 /test/junit
parent6612ba010b0e70c53550d1e47141c8dc89a55f23 (diff)
downloadscala-e5886361006f1b315af13f6aa98cf54a2f7ebe0b.tar.gz
scala-e5886361006f1b315af13f6aa98cf54a2f7ebe0b.tar.bz2
scala-e5886361006f1b315af13f6aa98cf54a2f7ebe0b.zip
SI-9515 closure elimination also for non-Scala-Function SAM types
Also logged in as SD-162 The optimizer had conservative checks in place to perform closure elimination only for Scala Function types. We can eliminate IndyLambda instructions for any functional interface. LambdaMetaFactory only constructs lambda objects for interface types, which don't have any side-effects on construction - they don't have a constructor.
Diffstat (limited to 'test/junit')
-rw-r--r--test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala
index 938bc7b846..2c697bfe50 100644
--- a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala
+++ b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala
@@ -750,4 +750,24 @@ class MethodLevelOptsTest extends BytecodeTesting {
-1, LDC, ASTORE,
-1, ALOAD, ARETURN))
}
+
+ @Test
+ def elimSamLambda(): Unit = {
+ val code =
+ """class C {
+ | def t1(x: Int) = {
+ | val fun: java.util.function.IntFunction[Int] = y => y + 1
+ | fun(x)
+ | }
+ | def t2(x: Int) = {
+ | val fun: T = i => i + 1
+ | fun.f(x)
+ | }
+ |}
+ |trait T { def f(x: Int): Int }
+ """.stripMargin
+ val List(c, t) = compileClasses(code)
+ assertSameSummary(getMethod(c, "t1"), List(ILOAD, "$anonfun$t1$1", IRETURN))
+ assertSameSummary(getMethod(c, "t2"), List(ILOAD, "$anonfun$t2$1", IRETURN))
+ }
}