diff options
author | Martin Odersky <odersky@gmail.com> | 2014-10-21 16:41:16 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-10-26 16:24:01 +0100 |
commit | 138045cc5545519c87044147dd7bb5b14729d2d2 (patch) | |
tree | 594bffe5d488d5b60f4867d1cefbb9b3ac2af994 | |
parent | 98deca5e3e5e98c77b1440c8ab0d9bfd232e7357 (diff) | |
download | dotty-138045cc5545519c87044147dd7bb5b14729d2d2.tar.gz dotty-138045cc5545519c87044147dd7bb5b14729d2d2.tar.bz2 dotty-138045cc5545519c87044147dd7bb5b14729d2d2.zip |
Fixes to LambdaLift
Several fixes to LambdaLift. The test suite now succeeds with LambdaLift enabled.
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/LambdaLift.scala | 23 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index 1aa1cce10..ec899ebb8 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -53,8 +53,8 @@ class Compiler { new Literalize, new GettersSetters), List(new Erasure), - List(new CapturedVars, new Constructors)/*, - List(new LambdaLift)*/ + List(new CapturedVars, new Constructors), + List(new LambdaLift) ) var runId = 1 diff --git a/src/dotty/tools/dotc/transform/LambdaLift.scala b/src/dotty/tools/dotc/transform/LambdaLift.scala index 4a59be45a..cd74da603 100644 --- a/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -88,7 +88,7 @@ class LambdaLift extends MiniPhaseTransform with IdentityDenotTransformer { this } def narrowLiftedOwner(sym: Symbol, owner: Symbol)(implicit ctx: Context) = { - println(i"narrow lifted $sym") + println(i"narrow lifted $sym to $owner") if (sym.owner.skipConstructor.isTerm && owner.isProperlyContainedIn(liftedOwner(sym))) { changedLiftedOwner = true @@ -183,7 +183,7 @@ class LambdaLift extends MiniPhaseTransform with IdentityDenotTransformer { this case tree: TypeDef => if (sym.owner.isTerm) liftedOwner(sym) = sym.topLevelClass.owner case tree: Template => - liftedDefs(enclosure) = new mutable.ListBuffer + liftedDefs(tree.symbol.owner) = new mutable.ListBuffer case _ => } foldOver(enclosure, tree) @@ -292,8 +292,11 @@ class LambdaLift extends MiniPhaseTransform with IdentityDenotTransformer { this private def proxy(sym: Symbol)(implicit ctx: Context): Symbol = { def searchIn(enclosure: Symbol): Symbol = { - if (!enclosure.exists) - throw new IllegalArgumentException(i"Could not find proxy for ${sym.showDcl} in ${sym.ownersIterator.toList}, currentOwner= $currentEnclosure") + if (!enclosure.exists) { + def enclosures(encl: Symbol): List[Symbol] = + if (encl.exists) encl :: enclosures(encl.enclosure) else Nil + throw new IllegalArgumentException(i"Could not find proxy for ${sym.showDcl} in ${sym.ownersIterator.toList}, encl = $currentEnclosure, owners = ${currentEnclosure.ownersIterator.toList}%, %; enclosures = ${enclosures(currentEnclosure)}%, %") + } ctx.debuglog(i"searching for $sym(${sym.owner}) in $enclosure") proxyMap get enclosure match { case Some(pmap) => @@ -309,13 +312,15 @@ class LambdaLift extends MiniPhaseTransform with IdentityDenotTransformer { this } private def memberRef(sym: Symbol)(implicit ctx: Context, info: TransformerInfo): Tree = { - val clazz = sym.owner - val qual = if (clazz.isStaticOwner) singleton(clazz.thisType) else outer.path(clazz) + val clazz = sym.enclosingClass + val qual = + if (clazz.isStaticOwner) singleton(clazz.thisType) + else outer(ctx.withPhase(thisTransform)).path(clazz) transformFollowingDeep(qual.select(sym)) } private def proxyRef(sym: Symbol)(implicit ctx: Context, info: TransformerInfo): Tree = { - val psym = proxy(sym) + val psym = proxy(sym)(ctx.withPhase(thisTransform)) transformFollowingDeep(if (psym.owner.isTerm) ref(psym) else memberRef(psym)) } @@ -368,7 +373,9 @@ class LambdaLift extends MiniPhaseTransform with IdentityDenotTransformer { this val sym = tree.symbol val proxyHolder = sym.skipConstructor if (needsLifting(proxyHolder)) { - val paramsAdded = addFreeParams(tree, proxies(proxyHolder)).asInstanceOf[DefDef] + var paramsAdded = addFreeParams(tree, proxies(proxyHolder)).asInstanceOf[DefDef] + if (sym.is(JavaStatic) && !paramsAdded.mods.is(JavaStatic)) + paramsAdded = cpy.DefDef(paramsAdded)(mods = paramsAdded.mods | JavaStatic) if (sym.isConstructor) paramsAdded else liftDef(paramsAdded) } else tree |