summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform/LazyVals.scala
diff options
context:
space:
mode:
authorIulian Dragos <jaguarul@gmail.com>2008-01-17 16:01:55 +0000
committerIulian Dragos <jaguarul@gmail.com>2008-01-17 16:01:55 +0000
commit0f73d8ae863b588939ed57874aae5db6edee1111 (patch)
treeb57c38fc1ce0c5e530bbb1712fa63610189e00ac /src/compiler/scala/tools/nsc/transform/LazyVals.scala
parent13fc5575c5a2b0c119bf7e5514261090d2f19f5e (diff)
downloadscala-0f73d8ae863b588939ed57874aae5db6edee1111.tar.gz
scala-0f73d8ae863b588939ed57874aae5db6edee1111.tar.bz2
scala-0f73d8ae863b588939ed57874aae5db6edee1111.zip
Fixed ticket #356
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/LazyVals.scala')
-rw-r--r--src/compiler/scala/tools/nsc/transform/LazyVals.scala24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/LazyVals.scala b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
index eeddb24124..43565eb087 100644
--- a/src/compiler/scala/tools/nsc/transform/LazyVals.scala
+++ b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
@@ -46,7 +46,7 @@ abstract class LazyVals extends Transform {
* but moved to the host class. local lazy values should be statically implemented.
*/
override def transform(tree: Tree): Tree = {
- val sym = tree.symbol
+ val sym = tree.symbol
tree match {
case DefDef(mods, name, tparams, vparams, tpt, rhs) =>
val res = if (!sym.owner.isClass && sym.hasFlag(LAZY)) {
@@ -58,12 +58,32 @@ abstract class LazyVals extends Transform {
} else
super.transform(rhs)
val bmps = bitmaps(sym) map { b => ValDef(b, Literal(Constant(0))) }
- copy.DefDef(tree, mods, name, tparams, vparams, tpt, typed(if (bmps.isEmpty) res else Block(bmps, res)))
+ val tmp = addBitmapDefs(sym, res, bmps)
+ copy.DefDef(tree, mods, name, tparams, vparams, tpt,
+ typed(addBitmapDefs(sym, res, bmps)))
case _ => super.transform(tree)
}
}
+ /** Add the bitmap definitions to the rhs of a method definition.
+ * If the rhs has been tail-call trasnformed, insert the bitmap
+ * definitions inside the top-level label definition, so that each
+ * iteration has the lazy values un-initialized. Otherwise add them
+ * at the very beginning of the method.
+ */
+ private def addBitmapDefs(methSym: Symbol, rhs: Tree, bmps: List[Tree]): Tree = {
+ if (bmps.isEmpty) rhs else rhs match {
+ case Block(assign, l @ LabelDef(name, params, rhs1))
+ if (name.toString.equals("_" + methSym.name)
+ && List.forall2(params.tail, methSym.tpe.paramTypes) { (ident, tpe) => ident.tpe == tpe }) =>
+ val sym = l.symbol
+ Block(assign, copy.LabelDef(l, name, params, typed(Block(bmps, rhs1))))
+
+ case _ => Block(bmps, rhs)
+ }
+ }
+
/** return a 'lazified' version of rhs. Rhs should conform to the
* following schema:
* {