Skip to content

Commit 81e7f67

Browse files
committed
Revert "SI-2897, SI-6231 method-local traits capturing variables"
This reverts commit 9b4da70562ef49c02d3227906a062113056d8424.
1 parent 80987e3 commit 81e7f67

File tree

2 files changed

+14
-88
lines changed

2 files changed

+14
-88
lines changed

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

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -309,22 +309,17 @@ abstract class LambdaLift extends InfoTransform {
309309
afterOwnPhase {
310310
for ((owner, freeValues) <- free.toList) {
311311
val newFlags = SYNTHETIC | (
312-
if (owner.isTrait) PARAMACCESSOR | TRANS_FLAG // will need an impl in subclass that mixes in the trait
313-
else if (owner.isClass) PARAMACCESSOR | PrivateLocal
312+
if (owner.isClass) PARAMACCESSOR | PrivateLocal
314313
else PARAM)
315314

316315
proxies(owner) =
317316
for (fv <- freeValues.toList) yield {
318317
val proxyName = proxyNames.getOrElse(fv, fv.name)
319-
println(s"new proxy ${proxyName} in ${owner.fullLocationString}")
320-
val proxy =
321-
if (owner.isTrait) owner.newMethod(proxyName.toTermName, owner.pos, newFlags.toLong) setInfo MethodType(Nil, fv.info)
322-
else owner.newValue(proxyName.toTermName, owner.pos, newFlags.toLong) setInfo fv.info
318+
debuglog(s"new proxy ${proxyName} in ${owner.fullLocationString}")
319+
val proxy = owner.newValue(proxyName.toTermName, owner.pos, newFlags.toLong) setInfo fv.info
323320
if (owner.isClass) owner.info.decls enter proxy
324321
proxy
325322
}
326-
327-
proxies(owner.toInterface) = proxies(owner)
328323
}
329324
}
330325
}
@@ -373,11 +368,7 @@ abstract class LambdaLift extends InfoTransform {
373368

374369
qual match {
375370
case EmptyTree => EmptyTree
376-
case qual =>
377-
val sel = Select(qual, sym) setType sym.tpe
378-
379-
if (sym.isParamAccessor && (sym hasFlag TRANS_FLAG)) Apply(sel, Nil) setType sym.tpe.finalResultType
380-
else sel
371+
case qual => Select(qual, sym) setType sym.tpe
381372
}
382373
}
383374

@@ -388,43 +379,19 @@ abstract class LambdaLift extends InfoTransform {
388379

389380
def freeArgsOrNil(sym: Symbol) = free.getOrElse(sym, Nil).toList
390381

391-
private def transformApply(tree: Apply) = {
392-
val Apply(fn, args) = tree
393-
val sym = tree.symbol
394-
val pos = tree.pos
382+
private def freeArgs(sym: Symbol): List[Symbol] =
383+
freeArgsOrNil(sym)
395384

396-
if (sym.isMethod && sym.isConstructor && sym.owner.isTrait) {
397-
// TODO: add types / symbols
398-
val inits = freeParams(currentOwner).map { ctorParam =>
399-
ugh, since we just mutate trees without first transforming infos, we can't get to the symbol
400-
val proxyFieldSym = currentClass.info.decl(ctorParam.name)
401-
val proxyField = gen.mkAttributedSelect(gen.mkAttributedThis(currentClass), proxyFieldSym)
402-
403-
atPos(currentOwner.pos)(Assign(proxyField, Ident(ctorParam))) setType BoxedUnitTpe
404-
}
405-
Block(inits, tree) setType tree.tpe setPos tree.pos
406-
} else {
407-
val newArgs =
408-
freeArgsOrNil(sym) match {
409-
case Nil => args
410-
case fvs => addFree (sym, free = fvs map (fv => atPos (pos) (proxyRef (fv) ) ), original = args)
411-
}
412-
413-
treeCopy.Apply(tree, fn, newArgs)
385+
private def addFreeArgs(pos: Position, sym: Symbol, args: List[Tree]) =
386+
freeArgs(sym) match {
387+
case Nil => args
388+
case fvs => addFree(sym, free = fvs map (fv => atPos(pos)(proxyRef(fv))), original = args)
414389
}
415-
}
416390

417391
def proxiesOrNil(sym: Symbol) = proxies.getOrElse(sym, Nil)
418392

419-
private def mixinProxies(mixin: Symbol): List[Symbol] = {
420-
proxiesOrNil(mixin) map (mixedin => mixedin.cloneSymbol setFlag TRANS_FLAG)
421-
}
422-
423393
private def freeParams(sym: Symbol): List[Symbol] =
424-
if (sym.isMethod && sym.isConstructor && sym.owner.isTrait) Nil
425-
else if (sym.isClass && !sym.isTrait)
426-
proxiesOrNil(sym) ++ (sym.mixinClasses flatMap mixinProxies)
427-
else proxiesOrNil(sym)
394+
proxiesOrNil(sym)
428395

429396
private def addFreeParams(tree: Tree, sym: Symbol): Tree =
430397
tree match {
@@ -440,31 +407,12 @@ abstract class LambdaLift extends InfoTransform {
440407
copyDefDef(tree)(vparamss = List(addFree(sym, free = paramDefs, original = vparams)))
441408
}
442409

443-
case ClassDef(_, _, _, _) if !sym.isTrait =>
410+
case ClassDef(_, _, _, _) =>
444411
val freeParamDefs = freeParams(sym) map (p => ValDef(p) setPos tree.pos setType NoType)
445412

446413
if (freeParamDefs isEmpty) tree
447414
else deriveClassDef(tree)(impl => deriveTemplate(impl)(_ ::: freeParamDefs))
448415

449-
case ClassDef(_, _, _, _) =>
450-
// SI-2897, SI-6231
451-
// Disabled attempt to to add getters to freeParams
452-
// this does not work yet. Problem is that local symbols need local names
453-
// and references to local symbols need to be transformed into
454-
// method calls to setters.
455-
// def paramGetter(param: Symbol): Tree = {
456-
// val getter = param.newGetter setFlag TRANS_FLAG resetFlag PARAMACCESSOR // mark because we have to add them to interface
457-
// sym.info.decls.enter(getter)
458-
// val rhs = Select(gen.mkAttributedThis(sym), param) setType param.tpe
459-
// DefDef(getter, rhs) setPos tree.pos setType NoType
460-
// }
461-
val ps = freeParams(sym)
462-
if (ps isEmpty) tree
463-
else {
464-
val freeParams = ps map (p => DefDef(p, EmptyTree) setPos tree.pos setType NoType)
465-
deriveClassDef(tree)(impl => deriveTemplate(impl)(_ ::: freeParams))
466-
}
467-
468416
case _ => tree
469417
}
470418

@@ -556,7 +504,8 @@ abstract class LambdaLift extends InfoTransform {
556504
case Return(expr) =>
557505
assert(sym == currentMethod, sym)
558506
tree
559-
case tree: Apply => transformApply(tree)
507+
case Apply(fn, args) =>
508+
treeCopy.Apply(tree, fn, addFreeArgs(tree.pos, sym, args))
560509
case Assign(Apply(TypeApply(sel @ Select(qual, _), _), List()), rhs) =>
561510
// eliminate casts introduced by selecting a captured variable field
562511
// on the lhs of an assignment.

test/files/trait-defaults/lambdalift.scala

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)