summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/transform
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-09-15 15:18:30 +1000
committerGitHub <noreply@github.com>2016-09-15 15:18:30 +1000
commitbe43eb5fba5da844f664cca10783bb869c7b76e7 (patch)
tree225b1aecc8dcb6c77248e1c5a308c3151cd995c2 /src/compiler/scala/tools/nsc/transform
parent81effdb9a2cd9e94b88f18181b8405a32f883f71 (diff)
parenta5bb6e00f051bf93fe7df4a02583eba478fa5ca1 (diff)
downloadscala-be43eb5fba5da844f664cca10783bb869c7b76e7.tar.gz
scala-be43eb5fba5da844f664cca10783bb869c7b76e7.tar.bz2
scala-be43eb5fba5da844f664cca10783bb869c7b76e7.zip
Merge pull request #5398 from retronym/ticket/SD-225
SD-225 Use a "lzycompute" method for module initialization
Diffstat (limited to 'src/compiler/scala/tools/nsc/transform')
-rw-r--r--src/compiler/scala/tools/nsc/transform/Fields.scala6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Fields.scala b/src/compiler/scala/tools/nsc/transform/Fields.scala
index 10494f33d1..8ebfdcc647 100644
--- a/src/compiler/scala/tools/nsc/transform/Fields.scala
+++ b/src/compiler/scala/tools/nsc/transform/Fields.scala
@@ -22,7 +22,7 @@ import symtab.Flags._
* in the first (closest in the subclassing lattice) subclass (not a trait) of a trait.
*
* For lazy vals and modules, we emit accessors that using double-checked locking (DCL) to balance thread safety
- * and performance. A lazy val gets a compute method for the DCL's slow path, for a module it's all done in the accessor.
+ * and performance. For both lazy vals and modules, the a compute method contains the DCL's slow path.
*
* Local lazy vals do not receive bitmaps, but use a Lazy*Holder that has the volatile init bit and the computed value.
* See `mkLazyLocalDef`.
@@ -236,7 +236,9 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
*
* TODO: optimize using local variable?
*/
- Block(If(needsInit, gen.mkSynchronized(monitorHolder)(If(needsInit, init, EmptyTree)), EmptyTree) :: Nil, moduleVarRef)
+ val computeName = nme.newLazyValSlowComputeName(module.name)
+ val computeMethod = DefDef(NoMods, computeName, Nil, ListOfNil, TypeTree(UnitTpe), gen.mkSynchronized(monitorHolder)(If(needsInit, init, EmptyTree)))
+ Block(computeMethod :: If(needsInit, Apply(Ident(computeName), Nil), EmptyTree) :: Nil, moduleVarRef)
}
// NoSymbol for lazy accessor sym with unit result type