Skip to content

Commit 2814579

Browse files
committed
lazyvals considers local vals everywhere,
not just in a tiny sampling of term trees TODO: clean this up much more
1 parent 319d3d2 commit 2814579

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/compiler/scala/tools/nsc/transform/LazyVals.scala

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
3838

3939
case ClassDef(_, _, _, _) | DefDef(_, _, _, _, _, _) | ModuleDef(_, _, _) =>
4040

41+
// Avoid adding bitmaps when they are fully overshadowed by those that are added inside loops
4142
case LabelDef(name, _, _) if nme.isLoopHeaderLabel(name) =>
4243

4344
case _ =>
@@ -108,22 +109,16 @@ abstract class LazyVals extends Transform with TypingTransformers with ast.TreeD
108109
}
109110

110111
case Template(_, _, body) => atOwner(currentOwner) {
111-
val body1 = super.transformTrees(body)
112+
// TODO: shady business... can this logic be encapsulated in LocalLazyValFinder?
112113
var added = false
113-
val stats =
114-
for (stat <- body1) yield stat match {
115-
case Block(_, _) | Apply(_, _) | If(_, _, _) | Try(_, _, _) if !added =>
116-
// Avoid adding bitmaps when they are fully overshadowed by those
117-
// that are added inside loops
118-
if (LocalLazyValFinder.find(stat)) {
119-
added = true
120-
typed(addBitmapDefs(sym, stat))
121-
} else stat
122-
case ValDef(_, _, _, _) =>
123-
typed(deriveValDef(stat)(addBitmapDefs(stat.symbol, _)))
124-
case _ =>
125-
stat
114+
val stats = super.transformTrees(body) mapConserve {
115+
case stat: ValDef => typed(deriveValDef(stat)(addBitmapDefs(stat.symbol, _)))
116+
case stat: TermTree if !added && (LocalLazyValFinder find stat) =>
117+
added = true
118+
typed(addBitmapDefs(sym, stat))
119+
case stat => stat
126120
}
121+
127122
val innerClassBitmaps = if (!added && currentOwner.isClass && bitmaps.contains(currentOwner)) {
128123
// add bitmap to inner class if necessary
129124
val toAdd0 = bitmaps(currentOwner).map(s => typed(ValDef(s, ZERO)))

0 commit comments

Comments
 (0)