diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-08-25 11:42:46 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-08-28 13:24:01 +0200 |
commit | 9fc684b3cacdc008507a1e32cdab4408a080e60d (patch) | |
tree | 1840cb9e7147224fd1e9c68ca77da547be58b1f3 | |
parent | 294bd25d884f62fcda4dc024c1fdef094b2eae84 (diff) | |
download | scala-9fc684b3cacdc008507a1e32cdab4408a080e60d.tar.gz scala-9fc684b3cacdc008507a1e32cdab4408a080e60d.tar.bz2 scala-9fc684b3cacdc008507a1e32cdab4408a080e60d.zip |
Ensure the call graph contains all inlined callsites
After inlining, inlined callsites are added to the call graph.
For efficiency, the callsites of the callee are copied and adapted
(the alternative would be to re-add the entire method to the call
graph, which involves running data flow analyses).
If the callee is in a class parsed from bytecode (vs a class being
compiled), it might not yet be in the call graph. This commit ensures
that the method is added to the call graph before looking for its
callsites.
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/opt/CallGraph.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala | 2 |
2 files changed, 6 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/CallGraph.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/CallGraph.scala index e11ae08a8c..c1293d4e81 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/CallGraph.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/CallGraph.scala @@ -53,6 +53,10 @@ class CallGraph[BT <: BTypes](val btypes: BT) { classNode.methods.asScala.foreach(addMethod(_, classType)) } + def addIfMissing(methodNode: MethodNode, definingClass: ClassBType): Unit = { + if (!callsites.contains(methodNode)) addMethod(methodNode, definingClass) + } + /** * Returns a list of callsites in the method, plus a list of closure instantiation indy instructions. */ diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala index a2eea1af2e..f4673be974 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala @@ -405,6 +405,8 @@ class Inliner[BT <: BTypes](val btypes: BT) { callsiteMethod.localVariables.addAll(cloneLocalVariableNodes(callee, labelsMap, callee.name + "_").asJava) callsiteMethod.tryCatchBlocks.addAll(cloneTryCatchBlockNodes(callee, labelsMap).asJava) + callGraph.addIfMissing(callee, calleeDeclarationClass) + // Add all invocation instructions and closure instantiations that were inlined to the call graph callGraph.callsites(callee).valuesIterator foreach { originalCallsite => val newCallsiteIns = instructionMap(originalCallsite.callsiteInstruction).asInstanceOf[MethodInsnNode] |