diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2015-10-11 17:15:54 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2015-11-11 17:00:34 -0800 |
commit | 5d733713904af89383cf72c85da448e45b5645ce (patch) | |
tree | 9349eca81df12583ba6691823bb8feaa42c3b374 /src/compiler | |
parent | a5a62f437f6af1f25ad56e3cf513a4ed13fbc680 (diff) | |
download | scala-5d733713904af89383cf72c85da448e45b5645ce.tar.gz scala-5d733713904af89383cf72c85da448e45b5645ce.tar.bz2 scala-5d733713904af89383cf72c85da448e45b5645ce.zip |
LazyVals looks for local vals in all term trees
Discovered while refactoring the way fields are emitted in traits.
TODO: a lot more cleanup
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/LazyVals.scala | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/LazyVals.scala b/src/compiler/scala/tools/nsc/transform/LazyVals.scala index b6695efb0b..93e41dde7b 100644 --- a/src/compiler/scala/tools/nsc/transform/LazyVals.scala +++ b/src/compiler/scala/tools/nsc/transform/LazyVals.scala @@ -38,6 +38,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD case ClassDef(_, _, _, _) | DefDef(_, _, _, _, _, _) | ModuleDef(_, _, _) => + // Avoid adding bitmaps when they are fully overshadowed by those that are added inside loops case LabelDef(name, _, _) if nme.isLoopHeaderLabel(name) => case _ => @@ -108,22 +109,16 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD } case Template(_, _, body) => atOwner(currentOwner) { - val body1 = super.transformTrees(body) + // TODO: shady business... can this logic be encapsulated in LocalLazyValFinder? var added = false - val stats = - for (stat <- body1) yield stat match { - case Block(_, _) | Apply(_, _) | If(_, _, _) | Try(_, _, _) if !added => - // Avoid adding bitmaps when they are fully overshadowed by those - // that are added inside loops - if (LocalLazyValFinder.find(stat)) { - added = true - typed(addBitmapDefs(sym, stat)) - } else stat - case ValDef(_, _, _, _) => - typed(deriveValDef(stat)(addBitmapDefs(stat.symbol, _))) - case _ => - stat + val stats = super.transformTrees(body) mapConserve { + case stat: ValDef => typed(deriveValDef(stat)(addBitmapDefs(stat.symbol, _))) + case stat: TermTree if !added && (LocalLazyValFinder find stat) => + added = true + typed(addBitmapDefs(sym, stat)) + case stat => stat } + val innerClassBitmaps = if (!added && currentOwner.isClass && bitmaps.contains(currentOwner)) { // add bitmap to inner class if necessary val toAdd0 = bitmaps(currentOwner).map(s => typed(ValDef(s, ZERO))) |