diff options
author | Seth Tisue <seth@tisue.net> | 2015-07-16 15:41:07 -0400 |
---|---|---|
committer | Seth Tisue <seth@tisue.net> | 2015-07-16 15:41:07 -0400 |
commit | 8f0c4b42617903ef974e25ff45250a34e93f40e7 (patch) | |
tree | 3b569f718f4e24f5adfc03885e06c01c6afac541 | |
parent | 2595b11eb2758459b973d68e4a670b5c88b43e4a (diff) | |
parent | 0c69fd8d8d5d40bb7dda9b1e65414a5b5e0fd008 (diff) | |
download | scala-8f0c4b42617903ef974e25ff45250a34e93f40e7.tar.gz scala-8f0c4b42617903ef974e25ff45250a34e93f40e7.tar.bz2 scala-8f0c4b42617903ef974e25ff45250a34e93f40e7.zip |
Merge pull request #4639 from lrytz/closure-opt-stability
Fix bytecode stability when running the closure optimizer
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala | 16 |
1 files changed, 8 insertions, 8 deletions
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 58f0813bd8..92b9b34006 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala @@ -70,10 +70,10 @@ class ClosureOptimizer[BT <: BTypes](val btypes: BT) { } } - // Group the closure instantiations by method allows running the ProdConsAnalyzer only once per method. - // Also sort the instantiations: If there are multiple closure instantiations in a method, closure - // invocations need to be re-written in a consistent order for bytecode stability. The local variable - // slots for storing captured values depends on the order of rewriting. + // Grouping the closure instantiations by method allows running the ProdConsAnalyzer only once per + // method. Also sort the instantiations: If there are multiple closure instantiations in a method, + // closure invocations need to be re-written in a consistent order for bytecode stability. The local + // variable slots for storing captured values depends on the order of rewriting. val closureInstantiationsByMethod: Map[MethodNode, immutable.TreeSet[ClosureInstantiation]] = { closureInstantiations.values.groupBy(_.ownerMethod).mapValues(immutable.TreeSet.empty ++ _) } @@ -81,13 +81,13 @@ class ClosureOptimizer[BT <: BTypes](val btypes: BT) { // For each closure instantiation, a list of callsites of the closure that can be re-written // If a callsite cannot be rewritten, for example because the lambda body method is not accessible, // a warning is returned instead. - val callsitesToRewrite: Map[ClosureInstantiation, List[Either[RewriteClosureApplyToClosureBodyFailed, (MethodInsnNode, Int)]]] = { - closureInstantiationsByMethod flatMap { + val callsitesToRewrite: List[(ClosureInstantiation, List[Either[RewriteClosureApplyToClosureBodyFailed, (MethodInsnNode, Int)]])] = { + closureInstantiationsByMethod.iterator.flatMap({ case (methodNode, closureInits) => // A lazy val to ensure the analysis only runs if necessary (the value is passed by name to `closureCallsites`) lazy val prodCons = new ProdConsAnalyzer(methodNode, closureInits.head.ownerClass.internalName) - closureInits.map(init => (init, closureCallsites(init, prodCons))) - } + closureInits.iterator.map(init => (init, closureCallsites(init, prodCons))) + }).toList // mapping to a list (not a map) to keep the sorting of closureInstantiationsByMethod } // Rewrite all closure callsites (or issue inliner warnings for those that cannot be rewritten) |