summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-07-16 14:17:46 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2015-07-16 14:32:52 +0200
commit0c69fd8d8d5d40bb7dda9b1e65414a5b5e0fd008 (patch)
tree7cf56258e0243a97034525c1b2e84fe426e7487e /src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala
parent743e8badadc4b9997a6847e9aa60492297f2c5ff (diff)
downloadscala-0c69fd8d8d5d40bb7dda9b1e65414a5b5e0fd008.tar.gz
scala-0c69fd8d8d5d40bb7dda9b1e65414a5b5e0fd008.tar.bz2
scala-0c69fd8d8d5d40bb7dda9b1e65414a5b5e0fd008.zip
Fix bytecode stability when running the closure optimizer
Fixes the stability regression introduced by #4619.
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala')
-rw-r--r--src/compiler/scala/tools/nsc/backend/jvm/opt/ClosureOptimizer.scala16
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)