diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-09-09 16:44:38 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-09-17 22:05:04 +0200 |
commit | 4129a03ecc2f953e8b79ec1a2a545a96efb057b4 (patch) | |
tree | dc6fa43a2d5bf09b5abc9adea4c12840e1d65ff3 /test | |
parent | a477c40f13644dbd596126c238dbdc262639b002 (diff) | |
download | scala-4129a03ecc2f953e8b79ec1a2a545a96efb057b4.tar.gz scala-4129a03ecc2f953e8b79ec1a2a545a96efb057b4.tar.bz2 scala-4129a03ecc2f953e8b79ec1a2a545a96efb057b4.zip |
Avoid re-computing argInfos after inlining and closure optimization
The call graph holds an argInfos field for every callsite, which
contains additional information about the argument passed to the
callee. For example, an argInfo specifies if the argument is a
function literal or a parameter of the callsite method.
Computing the argInfo requires running an ASM analyzer, which is not
cheap. This change assembles the argInfos for callsites that are
created or changed by the inliner / closure optimizer from the
available information instead of just running the analyzer again.
Diffstat (limited to 'test')
-rw-r--r-- | test/junit/scala/tools/nsc/backend/jvm/opt/CallGraphTest.scala | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/CallGraphTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/CallGraphTest.scala index b518cbdc50..995e008912 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/CallGraphTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/CallGraphTest.scala @@ -185,4 +185,28 @@ class CallGraphTest extends ClearAfterClass { val selfSamCall = callIn("selfSamCall") assertEquals(selfSamCall.argInfos.toList, List((0,ForwardedParam(0)))) } + + @Test + def argInfoAfterInlining(): Unit = { + val code = + """class C { + | def foo(f: Int => Int) = f(1) // not inlined + | @inline final def bar(g: Int => Int) = foo(g) // forwarded param 1 + | @inline final def baz = foo(x => x + 1) // literal + | + | def t1 = bar(x => x + 1) // call to foo should have argInfo literal + | def t2(x: Int, f: Int => Int) = x + bar(f) // call to foo should have argInfo forwarded param 2 + | def t3 = baz // call to foo should have argInfo literal + | def someFun: Int => Int = null + | def t4(x: Int) = x + bar(someFun) // call to foo has empty argInfo + |} + """.stripMargin + + compile(code) + def callIn(m: String) = callGraph.callsites.find(_._1.name == m).get._2.values.head + assertEquals(callIn("t1").argInfos.toList, List((1, FunctionLiteral))) + assertEquals(callIn("t2").argInfos.toList, List((1, ForwardedParam(2)))) + assertEquals(callIn("t3").argInfos.toList, List((1, FunctionLiteral))) + assertEquals(callIn("t4").argInfos.toList, Nil) + } } |