summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2015-11-23 13:22:57 +1000
committerJason Zaugg <jzaugg@gmail.com>2015-11-23 13:26:12 +1000
commit6fb41ed2e0f001df7cea54ec70e378bdbe01aa65 (patch)
treedacf3e532d212346bdf31e21534ff7120de5e06b
parent571ed0312031a0826f65d40b27933d16b9617fbe (diff)
downloadscala-6fb41ed2e0f001df7cea54ec70e378bdbe01aa65.tar.gz
scala-6fb41ed2e0f001df7cea54ec70e378bdbe01aa65.tar.bz2
scala-6fb41ed2e0f001df7cea54ec70e378bdbe01aa65.zip
Avoid tree sharing in lazy val translation
The `cond` tree is used in two places, so make it a by-name parameter to create distinct Trees. Also, remove a dangling comment.
-rw-r--r--src/compiler/scala/tools/nsc/transform/LazyVals.scala8
-rw-r--r--src/compiler/scala/tools/nsc/transform/Mixin.scala4
2 files changed, 5 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/LazyVals.scala b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
index 73c15c1f53..7c7cffeb69 100644
--- a/src/compiler/scala/tools/nsc/transform/LazyVals.scala
+++ b/src/compiler/scala/tools/nsc/transform/LazyVals.scala
@@ -81,8 +81,6 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
* added in the first block, for all lazy values defined in such blocks.
* - remove ACCESSOR flags: accessors in traits are not statically implemented,
* but moved to the host class. local lazy values should be statically implemented.
- *
- * The general pattern is
*/
override def transform(tree: Tree): Tree = {
val sym = tree.symbol
@@ -118,7 +116,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
} else if (sym.hasAllFlags(MODULE | METHOD) && !sym.owner.isTrait) {
rhs match {
case b @ Block((assign @ Assign(moduleRef, _)) :: Nil, expr) =>
- val cond = Apply(Select(moduleRef, Object_eq), List(Literal(Constant(null))))
+ def cond = Apply(Select(moduleRef, Object_eq), List(Literal(Constant(null))))
val (fastPath, slowPath) = mkFastPathBody(sym.owner.enclClass, moduleRef.symbol, cond, transform(assign) :: Nil, Nil, transform(expr))
(localTyper.typedPos(tree.pos)(fastPath), localTyper.typedPos(tree.pos)(slowPath))
case rhs =>
@@ -236,7 +234,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
}
- def mkFastPathBody(clazz: Symbol, lzyVal: Symbol, cond: Tree, syncBody: List[Tree],
+ def mkFastPathBody(clazz: Symbol, lzyVal: Symbol, cond: => Tree, syncBody: List[Tree],
stats: List[Tree], retVal: Tree): (Tree, Tree) = {
val slowPathDef: Tree = mkSlowPathDef(clazz, lzyVal, cond, syncBody, stats, retVal)
(If(cond, Apply(Ident(slowPathDef.symbol), Nil), retVal), slowPathDef)
@@ -291,7 +289,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
(mkBlock(rhs), UNIT)
}
- val cond = (bitmapRef GEN_& (mask, bitmapKind)) GEN_== (ZERO, bitmapKind)
+ def cond = (bitmapRef GEN_& (mask, bitmapKind)) GEN_== (ZERO, bitmapKind)
val lazyDefs = mkFastPathBody(methOrClass.enclClass, lazyVal, cond, List(block), Nil, res)
(atPos(tree.pos)(localTyper.typed {lazyDefs._1 }), atPos(tree.pos)(localTyper.typed {lazyDefs._2 }))
}
diff --git a/src/compiler/scala/tools/nsc/transform/Mixin.scala b/src/compiler/scala/tools/nsc/transform/Mixin.scala
index d6e4e1a727..1cea9c159a 100644
--- a/src/compiler/scala/tools/nsc/transform/Mixin.scala
+++ b/src/compiler/scala/tools/nsc/transform/Mixin.scala
@@ -784,12 +784,12 @@ abstract class Mixin extends InfoTransform with ast.TreeDSL {
defSym
}
- def mkFastPathLazyBody(clazz: Symbol, lzyVal: Symbol, cond: Tree, syncBody: List[Tree],
+ def mkFastPathLazyBody(clazz: Symbol, lzyVal: Symbol, cond: => Tree, syncBody: List[Tree],
stats: List[Tree], retVal: Tree): Tree = {
mkFastPathBody(clazz, lzyVal, cond, syncBody, stats, retVal, gen.mkAttributedThis(clazz), List())
}
- def mkFastPathBody(clazz: Symbol, lzyVal: Symbol, cond: Tree, syncBody: List[Tree],
+ def mkFastPathBody(clazz: Symbol, lzyVal: Symbol, cond: => Tree, syncBody: List[Tree],
stats: List[Tree], retVal: Tree, attrThis: Tree, args: List[Tree]): Tree = {
val slowPathSym: Symbol = mkSlowPathDef(clazz, lzyVal, cond, syncBody, stats, retVal, attrThis, args)
If(cond, fn (This(clazz), slowPathSym, args.map(arg => Ident(arg.symbol)): _*), retVal)