diff options
author | Paul Phillips <paulp@improving.org> | 2012-02-28 15:35:08 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-02-28 16:54:14 -0800 |
commit | fc2866efee1bcf17aee18d427ed41e172f440f62 (patch) | |
tree | 649322d0c27af4a5d6712bd60af69b5b4a4da2b3 /src/compiler/scala/tools/nsc/transform/UnCurry.scala | |
parent | 872c825192b30faa1b20f9cc2b1e3a0adeed8617 (diff) | |
download | scala-fc2866efee1bcf17aee18d427ed41e172f440f62.tar.gz scala-fc2866efee1bcf17aee18d427ed41e172f440f62.tar.bz2 scala-fc2866efee1bcf17aee18d427ed41e172f440f62.zip |
Reworking synchronized patch.
Eliminated annotation and custom phase. Kept SYNCHRONIZED flag.
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform/UnCurry.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/UnCurry.scala | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index b9b115b7c8..2af6192e42 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -451,6 +451,24 @@ abstract class UnCurry extends InfoTransform gen.mkZero(tree.tpe) setType tree.tpe } } + + private def isSelfSynchronized(ddef: DefDef) = ddef.rhs match { + case Apply(fn @ TypeApply(Select(sel, _), _), _) => + fn.symbol == Object_synchronized && sel.symbol == ddef.symbol.enclClass && !ddef.symbol.enclClass.isTrait + case _ => false + } + + /** If an eligible method is entirely wrapped in a call to synchronized + * locked on the same instance, remove the synchronized scaffolding and + * mark the method symbol SYNCHRONIZED for bytecode generation. + */ + private def translateSynchronized(tree: Tree) = tree match { + case dd @ DefDef(_, _, _, _, _, Apply(fn, body :: Nil)) if isSelfSynchronized(dd) => + log("Translating " + dd.symbol.defString + " into synchronized method") + dd.symbol setFlag SYNCHRONIZED + deriveDefDef(dd)(_ => body) + case _ => tree + } // ------ The tree transformers -------------------------------------------------------- @@ -495,9 +513,10 @@ abstract class UnCurry extends InfoTransform // breakage until a reasonable interface is settled upon. if ((sym ne null) && (sym.elisionLevel.exists (_ < settings.elidebelow.value || settings.noassertions.value))) replaceElidableTree(tree) - else tree match { + else translateSynchronized(tree) match { case dd @ DefDef(mods, name, tparams, vparamss, tpt, rhs) => if (dd.symbol hasAnnotation VarargsClass) saveRepeatedParams(dd) + withNeedLift(false) { if (dd.symbol.isClassConstructor) { atOwner(sym) { @@ -512,11 +531,11 @@ abstract class UnCurry extends InfoTransform treeCopy.Block(rhs, presupers ::: supercalls ::: others, transform(expr)) } treeCopy.DefDef( - tree, mods, name, transformTypeDefs(tparams), + dd, mods, name, transformTypeDefs(tparams), transformValDefss(vparamss), transform(tpt), rhs1) } } else { - super.transform(tree) + super.transform(dd) } } case ValDef(_, _, _, rhs) => |