diff options
author | Paul Phillips <paulp@improving.org> | 2009-08-26 15:17:51 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-08-26 15:17:51 +0000 |
commit | 904713e98047f3364aee2c236f87edcc75c44665 (patch) | |
tree | 68eacaccd078eb64b4a3ba8c9363d30129b0d1eb | |
parent | 48cc8408cfd0b57f46746162b8d4c184f7a3ed5c (diff) | |
download | scala-904713e98047f3364aee2c236f87edcc75c44665.tar.gz scala-904713e98047f3364aee2c236f87edcc75c44665.tar.bz2 scala-904713e98047f3364aee2c236f87edcc75c44665.zip |
Some functionalization achieved while trying to...
Some functionalization achieved while trying to figure out if we can
make reduceLeft work right on Stream.
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/TailCalls.scala | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/TailCalls.scala b/src/compiler/scala/tools/nsc/transform/TailCalls.scala index 0d8540e196..5a26f22db9 100644 --- a/src/compiler/scala/tools/nsc/transform/TailCalls.scala +++ b/src/compiler/scala/tools/nsc/transform/TailCalls.scala @@ -162,8 +162,8 @@ abstract class TailCalls extends Transform newCtx.label.setInfo(MethodType(currentClassParam :: tree.symbol.tpe.params, tree.symbol.tpe.finalResultType)) newCtx.tailPos = true - val t1 = if (newCtx.currentMethod.isFinal || - newCtx.currentMethod.enclClass.hasFlag(Flags.MODULE)) { + val isEligible = newCtx.currentMethod.isFinal || (newCtx.currentMethod.enclClass hasFlag Flags.MODULE) + if (isEligible) { newCtx.tparams = Nil log(" Considering " + name + " for tailcalls") tree.symbol.tpe match { @@ -171,30 +171,26 @@ abstract class TailCalls extends Transform newCtx.tparams = tparams map (_.symbol) newCtx.label.setInfo( newCtx.label.tpe.substSym(tpes, tparams map (_.symbol))) - case _ => () + case _ => } - - //println("label.tpe: " + newCtx.label.tpe) - var newRHS = transform(rhs, newCtx); - if (newCtx.accessed) { - log("Rewrote def " + newCtx.currentMethod) - isTransformed = true - - val newThis = newCtx.currentMethod.newValue(tree.pos, nme.THIS) - .setInfo(currentClass.tpe) - .setFlag(Flags.SYNTHETIC) - newRHS = - typed(atPos(tree.pos)(Block(List( - ValDef(newThis, This(currentClass))), - LabelDef(newCtx.label, - newThis :: (List.flatten(vparams) map (_.symbol)), - newRHS)))); - treeCopy.DefDef(tree, mods, name, tparams, vparams, tpt, newRHS); - } else - treeCopy.DefDef(tree, mods, name, tparams, vparams, tpt, newRHS); - } else { - treeCopy.DefDef(tree, mods, name, tparams, vparams, tpt, transform(rhs, newCtx)) } + val t1 = treeCopy.DefDef(tree, mods, name, tparams, vparams, tpt, + transform(rhs, newCtx) match { + case newRHS if isEligible && newCtx.accessed => + log("Rewrote def " + newCtx.currentMethod) + isTransformed = true + val newThis = newCtx.currentMethod + . newValue (tree.pos, nme.THIS) + . setInfo (currentClass.tpe) + . setFlag (Flags.SYNTHETIC) + + typed(atPos(tree.pos)(Block( + List(ValDef(newThis, This(currentClass))), + LabelDef(newCtx.label, newThis :: (vparams.flatten map (_.symbol)), newRHS) + ))) + case rhs => rhs + } + ) if (!isTransformed && tailrecRequired(dd)) unit.error(dd.pos, "could not optimize @tailrec annotated method") |