|
Previously, only local classes declared final would be candidates
for outer pointer elision in the constructor phase.
This commit infers finality of local classes to expand the scope
of this optimization.
== Background ==
This was brought to our attention when shapeless enabled
indylambda and found that a hitherto serializable
data structure started to capture the enclosing class and hence
lost its serializability.
class NotSerializable {
def test = () => {
class C; assertSerializable(new C)
}
}
Under `-Ydelambdafy:inline`, it used to capture the enclosing anon
function class as its outer, which, being final, didn't in turn
capture the enclosing class.
class NotSerializable {
def test = new anonFun$1
}
class anonFun$1 {
def apply = assertSerializable(new C(this))
}
class ...$C(outer$: anonFun)
indylambda perturbs the enclosing structure of the function body.
class NotSerializable {
def anonFun$1 = {class C; assertSerializable(new C()))
def test = lambdaMetaFactory(<<anonFun$1>>)
}
Which leads to:
class NotSerializable$C(outer$: NotSerializable)
|