diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2015-09-09 15:57:41 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2015-09-17 22:05:04 +0200 |
commit | fef4b3dd5c330f1c2f18604e231ef7c45ac14d70 (patch) | |
tree | faf9821eb573121a81a754e6929a41cda8a25c22 | |
parent | c35c9c77a976b06aeae04d15493ec4995a2a6448 (diff) | |
download | scala-fef4b3dd5c330f1c2f18604e231ef7c45ac14d70.tar.gz scala-fef4b3dd5c330f1c2f18604e231ef7c45ac14d70.tar.bz2 scala-fef4b3dd5c330f1c2f18604e231ef7c45ac14d70.zip |
Reduce component nesting in backend
Make InlinerHeuristics a backend component like the others, instead
of nested within the Inliner component.
8 files changed, 18 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/AsmUtils.scala b/src/compiler/scala/tools/nsc/backend/jvm/AsmUtils.scala index cd7e0b83e8..18a495e5fd 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/AsmUtils.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/AsmUtils.scala @@ -55,6 +55,13 @@ object AsmUtils { node } + def readClass(filename: String): ClassNode = { + val f = new java.io.RandomAccessFile(filename, "r") + val b = new Array[Byte](f.length.toInt) + f.read(b) + readClass(b) + } + /** * Returns a human-readable representation of the cnode ClassNode. */ diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala b/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala index 12cd9c7f5c..6bc9f76e1a 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala @@ -44,6 +44,8 @@ abstract class BTypes { val inliner: Inliner[this.type] + val inlinerHeuristics: InlinerHeuristics[this.type] + val closureOptimizer: ClosureOptimizer[this.type] val callGraph: CallGraph[this.type] @@ -234,7 +236,7 @@ abstract class BTypes { InlineInfo( traitImplClassSelfType = None, isEffectivelyFinal = BytecodeUtils.isFinalClass(classNode), - sam = inliner.heuristics.javaSam(classNode.name), + sam = inlinerHeuristics.javaSam(classNode.name), methodInfos = methodInfos, warning) } diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala b/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala index 160c1283f1..dc87ed631d 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala @@ -42,6 +42,8 @@ class BTypesFromSymbols[G <: Global](val global: G) extends BTypes { val inliner: Inliner[this.type] = new Inliner(this) + val inlinerHeuristics: InlinerHeuristics[this.type] = new InlinerHeuristics(this) + val closureOptimizer: ClosureOptimizer[this.type] = new ClosureOptimizer(this) val callGraph: CallGraph[this.type] = new CallGraph(this) diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BackendStats.scala b/src/compiler/scala/tools/nsc/backend/jvm/BackendStats.scala index 03306f30aa..8d0547b607 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BackendStats.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BackendStats.scala @@ -8,6 +8,7 @@ package backend.jvm import scala.reflect.internal.util.Statistics +// Enable with `-Ystatistics:jvm` object BackendStats { import Statistics.{newTimer, newSubTimer} val bcodeTimer = newTimer("time in backend", "jvm") 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 f9ba109358..7a0b41a49a 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/CallGraph.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/CallGraph.scala @@ -277,7 +277,7 @@ class CallGraph[BT <: BTypes](val btypes: BT) { safeToRewrite = canInlineFromSource && isRewritableTraitCall, // (2) annotatedInline = methodInlineInfo.annotatedInline, annotatedNoInline = methodInlineInfo.annotatedNoInline, - higherOrderParams = inliner.heuristics.higherOrderParams(calleeMethodNode, receiverType), + higherOrderParams = inlinerHeuristics.higherOrderParams(calleeMethodNode, receiverType), warning = warning) case None => diff --git a/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala b/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala index 70e203aac1..a509bed5c5 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala @@ -246,7 +246,7 @@ class ClosureOptimizer[BT <: BTypes](val btypes: BT) { safeToRewrite = false, // the lambda body method is not a trait interface method annotatedInline = false, annotatedNoInline = false, - inliner.heuristics.higherOrderParams(bodyMethodNode, bodyDeclClassType), + inlinerHeuristics.higherOrderParams(bodyMethodNode, bodyDeclClassType), calleeInfoWarning = None) }) val bodyMethodCallsite = Callsite( 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 2918c33c74..144a899c03 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/Inliner.scala @@ -25,9 +25,7 @@ import scala.tools.nsc.backend.jvm.BTypes.InternalName class Inliner[BT <: BTypes](val btypes: BT) { import btypes._ import callGraph._ - - val heuristics: InlinerHeuristics[btypes.type] = new InlinerHeuristics(btypes) - import heuristics._ + import inlinerHeuristics._ def eliminateUnreachableCodeAndUpdateCallGraph(methodNode: MethodNode, definingClass: InternalName): Unit = { localOpt.minimalRemoveUnreachableCode(methodNode, definingClass) foreach { 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 6dfdf20587..a462b4ff0a 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/InlinerTest.scala @@ -91,7 +91,7 @@ class InlinerTest extends ClearAfterClass { def makeInlineRequest( callsiteInstruction: MethodInsnNode, callsiteMethod: MethodNode, callsiteClass: ClassBType, callee: MethodNode, calleeDeclarationClass: ClassBType, callsiteStackHeight: Int, receiverKnownNotNull: Boolean, - post: List[inliner.heuristics.PostInlineRequest] = Nil) = inliner.heuristics.InlineRequest( + post: List[inlinerHeuristics.PostInlineRequest] = Nil) = inlinerHeuristics.InlineRequest( callsite = callGraph.Callsite( callsiteInstruction = callsiteInstruction, callsiteMethod = callsiteMethod, @@ -1093,7 +1093,7 @@ class InlinerTest extends ClearAfterClass { calleeDeclarationClass = cTp, callsiteStackHeight = analyzer.frameAt(gCall).getStackSize, receiverKnownNotNull = false, - post = List(inliner.heuristics.PostInlineRequest(fCall, Nil)) + post = List(inlinerHeuristics.PostInlineRequest(fCall, Nil)) ) val r = inliner.inline(request) |