diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-09-17 20:15:36 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-09-18 10:32:28 +0200 |
commit | 41e5ef4396a1526cd8c58157912ffed830a96f1e (patch) | |
tree | d406ff22f3588ac9c47ff0067a002efa30ca5cef /test/junit | |
parent | 59a5d3b8fd036d36afcf6349bc3cc527344981a1 (diff) | |
download | scala-41e5ef4396a1526cd8c58157912ffed830a96f1e.tar.gz scala-41e5ef4396a1526cd8c58157912ffed830a96f1e.tar.bz2 scala-41e5ef4396a1526cd8c58157912ffed830a96f1e.zip |
First version of inliningh heuristics that prefer higher-order methos
When invoking a higher-order method and the value passed for the
SAM type is either a function literal or a parameter of the callsite
method, inline the higher-order method into the callee.
This is a first version, the heuristics will be refined further.
Diffstat (limited to 'test/junit')
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala | 33 |
1 files changed, 33 insertions, 0 deletions
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 622715ab3a..8429a583b5 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala @@ -1101,4 +1101,37 @@ class InlinerTest extends ClearAfterClass { assertInvoke(getSingleMethod(c, "g"), "C", "f") // g itself still has the call to f assert(r.isEmpty, r) } + + /** + * NOTE: if this test fails for you when running within the IDE, it's probably because you're + * using 2.12.0-M2 for compilining within the IDE, which doesn't add SAM information to the + * InlineInfo attribute. So the InlineInfo in the classfile for Function1 doesn't say that + * it's a SAM type. The test passes when running with ant (which does a full bootstrap). + */ + @Test + def inlineHigherOrder(): Unit = { + val code = + """class C { + | final def h(f: Int => Int): Int = f(0) + | def t1 = h(x => x + 1) + | def t2 = { + | val fun = (x: Int) => x + 1 + | h(fun) + | } + | def t3(f: Int => Int) = h(f) + | def t4(f: Int => Int) = { + | val fun = f + | h(fun) + | } + | def t5 = h(Map(0 -> 10)) // not currently inlined + |} + """.stripMargin + + val List(c) = compile(code) + assertInvoke(getSingleMethod(c, "t1"), "C", "C$$$anonfun$1") + assertInvoke(getSingleMethod(c, "t2"), "C", "C$$$anonfun$2") + assertInvoke(getSingleMethod(c, "t3"), "scala/Function1", "apply$mcII$sp") + assertInvoke(getSingleMethod(c, "t4"), "scala/Function1", "apply$mcII$sp") + assertInvoke(getSingleMethod(c, "t5"), "C", "h") + } } |