Skip to content

Commit 86213e3

Browse files
committed
Backport from Linker: Fix to lambda lift. Fixes #1280.
CollectDependencies had incorrect handling of `Ident`s. If it had ever met an `Ident` to a symbol defined outside of current owner-chain(e.g. Predef.println) it would issue narrowTo(enclosingClass). This is very conservative and leads to memory leaks even in trivial lambdas. My lambda-lift-foo groes stronger :-)
1 parent 134ad7a commit 86213e3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,21 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
249249
else if (sym is Method) markCalled(sym, enclosure)
250250
else if (sym.isTerm) markFree(sym, enclosure)
251251
}
252-
if (sym.maybeOwner.isClass) narrowTo(sym.owner.asClass)
252+
def captureImplicitThis(x: Type): Unit = {
253+
x match {
254+
case TermRef(x, _) => captureImplicitThis(x)
255+
case x: ThisType => narrowTo(x.tref.typeSymbol.asClass)
256+
case _ =>
257+
}
258+
}
259+
captureImplicitThis(tree.tpe)
253260
case tree: Select =>
254261
if (sym.is(Method) && isLocal(sym)) markCalled(sym, enclosure)
255262
case tree: This =>
256263
narrowTo(tree.symbol.asClass)
257264
case tree: DefDef =>
258265
if (sym.owner.isTerm && !sym.is(Label))
259-
liftedOwner(sym) = sym.enclosingClass.topLevelClass
266+
liftedOwner(sym) = sym.enclosingPackageClass
260267
// this will make methods in supercall constructors of top-level classes owned
261268
// by the enclosing package, which means they will be static.
262269
// On the other hand, all other methods will be indirectly owned by their

0 commit comments

Comments
 (0)