Skip to content

Commit 252b6d9

Browse files
committed
Generalize lift behavior between Flatten and LambdaLift
To be combinable with follow-up mini-phases the lift operation needs to handle Thickets specially. This commit factors out the behavior from LambdaLift, so that Flatten can do the same thing.
1 parent ad45e2e commit 252b6d9

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ object Trees {
347347
s
348348
}
349349

350+
/** If this is a thicket, gerform `op` on each of its trees
351+
* otherwise, perform `op` ion tree itself.
352+
*/
353+
def foreachInThicket(op: Tree[T] => Unit): Unit = op(this)
354+
350355
override def toText(printer: Printer) = printer.toText(this)
351356

352357
override def hashCode(): Int = System.identityHashCode(this)
@@ -809,6 +814,8 @@ object Trees {
809814
val newTrees = trees.map(_.withPos(pos))
810815
new Thicket[T](newTrees).asInstanceOf[this.type]
811816
}
817+
override def foreachInThicket(op: Tree[T] => Unit): Unit =
818+
trees foreach (_.foreachInThicket(op))
812819
}
813820

814821
class EmptyValDef[T >: Untyped] extends ValDef[T](

src/dotty/tools/dotc/transform/Flatten.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Flatten extends MiniPhaseTransform with SymTransformer { thisTransform =>
3232
private def liftIfNested(tree: Tree)(implicit ctx: Context, info: TransformerInfo) =
3333
if (ctx.owner is Package) tree
3434
else {
35-
liftedDefs += transformFollowing(tree)
35+
transformFollowing(tree).foreachInThicket(liftedDefs += _)
3636
EmptyTree
3737
}
3838

src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,7 @@ class LambdaLift extends MiniPhaseTransform with IdentityDenotTransformer { this
357357

358358
private def liftDef(tree: MemberDef)(implicit ctx: Context, info: TransformerInfo): Tree = {
359359
val buf = liftedDefs(tree.symbol.owner)
360-
transformFollowing(rename(tree, tree.symbol.name)) match {
361-
case Thicket(trees) => buf ++= trees
362-
case tree => buf += tree
363-
}
360+
transformFollowing(rename(tree, tree.symbol.name)).foreachInThicket(buf += _)
364361
EmptyTree
365362
}
366363

0 commit comments

Comments
 (0)