1- package dotty .tools .dotc
2- package transform
1+ package dotty .tools .dotc .transform
32
4- import dotty . tools . dotc . core . Annotations . Annotation
3+ import java . util . IdentityHashMap
54
6- import scala .collection .mutable
7- import core ._
8- import Contexts ._
9- import Symbols ._
10- import Decorators ._
11- import NameKinds ._
12- import Types ._
13- import Flags ._
14- import StdNames .nme
15- import dotty .tools .dotc .transform .MegaPhase ._
165import dotty .tools .dotc .ast .tpd
6+ import dotty .tools .dotc .core .Annotations .Annotation
177import dotty .tools .dotc .core .Constants .Constant
18- import dotty .tools .dotc .core .Types . MethodType
19- import SymUtils ._
8+ import dotty .tools .dotc .core .Contexts . Context
9+ import dotty . tools . dotc . core . Decorators ._
2010import dotty .tools .dotc .core .DenotTransformers .IdentityDenotTransformer
21- import Erasure .Boxing .adaptToType
11+ import dotty .tools .dotc .core .Flags ._
12+ import dotty .tools .dotc .core .NameKinds .{LazyBitMapName , LazyLocalInitName , LazyLocalName }
13+ import dotty .tools .dotc .core .StdNames .nme
14+ import dotty .tools .dotc .core .Symbols ._
15+ import dotty .tools .dotc .core .Types ._
16+ import dotty .tools .dotc .core .{Names , StdNames }
17+ import dotty .tools .dotc .transform .MegaPhase .MiniPhase
18+ import dotty .tools .dotc .transform .SymUtils ._
2219
23- import java . util . IdentityHashMap
20+ import scala . collection . mutable
2421
2522class LazyVals extends MiniPhase with IdentityDenotTransformer {
2623 import LazyVals ._
@@ -41,10 +38,10 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
4138
4239 def transformer : LazyVals = new LazyVals
4340
44- val containerFlags : FlagSet = Flags . Synthetic | Flags . Mutable | Flags . Lazy
45- val initFlags : FlagSet = Flags . Synthetic | Flags . Method
41+ val containerFlags : FlagSet = Synthetic | Mutable | Lazy
42+ val initFlags : FlagSet = Synthetic | Method
4643
47- val containerFlagsMask : FlagSet = Flags . Method | Flags . Lazy | Flags . Accessor | Flags . Module
44+ val containerFlagsMask : FlagSet = Method | Lazy | Accessor | Module
4845
4946 /** A map of lazy values to the fields they should null after initialization. */
5047 private [this ] var lazyValNullables : IdentityHashMap [Symbol , mutable.ListBuffer [Symbol ]] = _
@@ -72,22 +69,22 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
7269
7370 def transformLazyVal (tree : ValOrDefDef )(implicit ctx : Context ): Tree = {
7471 val sym = tree.symbol
75- if (! (sym is Flags . Lazy ) ||
76- sym.owner.is(Flags . Trait ) || // val is accessor, lazy field will be implemented in subclass
77- (sym.isStatic && sym.is(Flags . Module , butNot = Flags . Method ))) // static module vals are implemented in the JVM by lazy loading
72+ if (! (sym is Lazy ) ||
73+ sym.owner.is(Trait ) || // val is accessor, lazy field will be implemented in subclass
74+ (sym.isStatic && sym.is(Module , butNot = Method ))) // static module vals are implemented in the JVM by lazy loading
7875 tree
7976 else {
8077 val isField = sym.owner.isClass
8178 if (isField) {
8279 if (sym.isVolatile ||
83- (sym.is(Flags . Module )/* || ctx.scala2Mode*/ ) &&
80+ (sym.is(Module )/* || ctx.scala2Mode*/ ) &&
8481 // TODO assume @volatile once LazyVals uses static helper constructs instead of
8582 // ones in the companion object.
86- ! sym.is(Flags . Synthetic ))
83+ ! sym.is(Synthetic ))
8784 // module class is user-defined.
8885 // Should be threadsafe, to mimic safety guaranteed by global object
8986 transformMemberDefVolatile(tree)
90- else if (sym.is(Flags . Module )) // synthetic module
87+ else if (sym.is(Module )) // synthetic module
9188 transformSyntheticModule(tree)
9289 else
9390 transformMemberDefNonVolatile(tree)
@@ -123,7 +120,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
123120 def transformSyntheticModule (tree : ValOrDefDef )(implicit ctx : Context ): Thicket = {
124121 val sym = tree.symbol
125122 val holderSymbol = ctx.newSymbol(sym.owner, LazyLocalName .fresh(sym.asTerm.name),
126- Flags . Synthetic , sym.info.widen.resultType).enteredAfter(this )
123+ Synthetic , sym.info.widen.resultType).enteredAfter(this )
127124 val field = ValDef (holderSymbol, tree.rhs.changeOwnerAfter(sym, holderSymbol, this ))
128125 val getter = DefDef (sym.asTerm, ref(holderSymbol))
129126 Thicket (field, getter)
@@ -187,8 +184,8 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
187184 // need to bring containers to start of method
188185 val (holders, stats) =
189186 trees.partition {
190- _.symbol.flags.&~ (Flags . Touched ) == containerFlags
191- // Filtering out Flags. Touched is not required currently, as there are no LazyTypes involved here
187+ _.symbol.flags.&~ (Touched ) == containerFlags
188+ // Filtering out Touched is not required currently, as there are no LazyTypes involved here
192189 // but just to be more safe
193190 }
194191 holders::: stats
@@ -198,7 +195,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
198195 val nullConst = Literal (Constant (null ))
199196 nullables.map { field =>
200197 assert(field.isField)
201- field.setFlag(Flags . Mutable )
198+ field.setFlag(Mutable )
202199 ref(field).becomes(nullConst)
203200 }
204201 }
@@ -252,10 +249,10 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
252249 def transformMemberDefNonVolatile (x : ValOrDefDef )(implicit ctx : Context ): Thicket = {
253250 val claz = x.symbol.owner.asClass
254251 val tpe = x.tpe.widen.resultType.widen
255- assert(! (x.symbol is Flags . Mutable ))
252+ assert(! (x.symbol is Mutable ))
256253 val containerName = LazyLocalName .fresh(x.name.asTermName)
257254 val containerSymbol = ctx.newSymbol(claz, containerName,
258- x.symbol.flags &~ containerFlagsMask | containerFlags | Flags . Private ,
255+ x.symbol.flags &~ containerFlagsMask | containerFlags | Private ,
259256 tpe, coord = x.symbol.coord
260257 ).enteredAfter(this )
261258
@@ -266,7 +263,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
266263 }
267264 else {
268265 val flagName = LazyBitMapName .fresh(x.name.asTermName)
269- val flagSymbol = ctx.newSymbol(x.symbol.owner, flagName, containerFlags | Flags . Private , defn.BooleanType ).enteredAfter(this )
266+ val flagSymbol = ctx.newSymbol(x.symbol.owner, flagName, containerFlags | Private , defn.BooleanType ).enteredAfter(this )
270267 val flag = ValDef (flagSymbol, Literal (Constant (false )))
271268 Thicket (containerTree, flag, mkNonThreadSafeDef(x.symbol, flagSymbol, containerSymbol, x.rhs))
272269 }
@@ -314,13 +311,12 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
314311 stateMask : Tree ,
315312 casFlag : Tree ,
316313 setFlagState : Tree ,
317- waitOnLock : Tree ,
318- nullables : List [Symbol ])(implicit ctx : Context ): DefDef = {
314+ waitOnLock : Tree )(implicit ctx : Context ): DefDef = {
319315 val initState = Literal (Constant (0 ))
320316 val computeState = Literal (Constant (1 ))
321317 val computedState = Literal (Constant (3 ))
322318
323- val thiz = This (claz)(ctx.fresh.setOwner(claz))
319+ val thiz = This (claz)
324320 val fieldId = Literal (Constant (ord))
325321
326322 val flagSymbol = ctx.newSymbol(methodSymbol, lazyNme.flag, Synthetic , defn.LongType )
@@ -338,14 +334,14 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
338334 val resultRef = ref(resultSymbol)
339335 stats += ValDef (resultSymbol, rhs)
340336 stats += ref(target).becomes(resultRef)
341- stats ++= nullOut(nullables )
337+ stats ++= nullOut(nullableFor(methodSymbol) )
342338 stats += setFlagState.appliedTo(thiz, offset, computedState, fieldId)
343339
344340 Block (stats.toList, Return (resultRef, methodSymbol))
345341 }
346342
347343 val retryCase = {
348- val caseSymbol = ctx.newSymbol(methodSymbol, nme.DEFAULT_EXCEPTION_NAME , Flags . Synthetic , defn.ThrowableType )
344+ val caseSymbol = ctx.newSymbol(methodSymbol, nme.DEFAULT_EXCEPTION_NAME , Synthetic , defn.ThrowableType )
349345 val triggerRetry = setFlagState.appliedTo(thiz, offset, initState, fieldId)
350346 CaseDef (
351347 Bind (caseSymbol, ref(caseSymbol)),
@@ -375,7 +371,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
375371 }
376372
377373 def transformMemberDefVolatile (x : ValOrDefDef )(implicit ctx : Context ): Thicket = {
378- assert(! (x.symbol is Flags . Mutable ))
374+ assert(! (x.symbol is Mutable ))
379375
380376 val tpe = x.tpe.widen.resultType.widen
381377 val claz = x.symbol.owner.asClass
@@ -386,9 +382,9 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
386382 var flag : Tree = EmptyTree
387383 var ord = 0
388384
389- def offsetName (id : Int ) = (StdNames .nme.LAZY_FIELD_OFFSET + (if (x.symbol.owner.is(Flags . Module )) " _m_" else " " ) + id.toString).toTermName
385+ def offsetName (id : Int ) = (StdNames .nme.LAZY_FIELD_OFFSET + (if (x.symbol.owner.is(Module )) " _m_" else " " ) + id.toString).toTermName
390386
391- // compute or create appropriate offsetSymol , bitmap and bits used by current ValDef
387+ // compute or create appropriate offsetSymbol , bitmap and bits used by current ValDef
392388 appendOffsetDefs.get(claz) match {
393389 case Some (info) =>
394390 val flagsPerLong = (64 / dotty.runtime.LazyVals .BITS_PER_LAZY_VAL ).toInt
@@ -398,10 +394,10 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
398394 val offsetById = offsetName(id)
399395 if (ord != 0 ) { // there are unused bits in already existing flag
400396 offsetSymbol = claz.info.decl(offsetById)
401- .suchThat(sym => (sym is Flags . Synthetic ) && sym.isTerm)
397+ .suchThat(sym => (sym is Synthetic ) && sym.isTerm)
402398 .symbol.asTerm
403399 } else { // need to create a new flag
404- offsetSymbol = ctx.newSymbol(claz, offsetById, Flags . Synthetic , defn.LongType ).enteredAfter(this )
400+ offsetSymbol = ctx.newSymbol(claz, offsetById, Synthetic , defn.LongType ).enteredAfter(this )
405401 offsetSymbol.addAnnotation(Annotation (defn.ScalaStaticAnnot ))
406402 val flagName = (StdNames .nme.BITMAP_PREFIX + id.toString).toTermName
407403 val flagSymbol = ctx.newSymbol(claz, flagName, containerFlags, defn.LongType ).enteredAfter(this )
@@ -411,7 +407,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
411407 }
412408
413409 case None =>
414- offsetSymbol = ctx.newSymbol(claz, offsetName(0 ), Flags . Synthetic , defn.LongType ).enteredAfter(this )
410+ offsetSymbol = ctx.newSymbol(claz, offsetName(0 ), Synthetic , defn.LongType ).enteredAfter(this )
415411 offsetSymbol.addAnnotation(Annotation (defn.ScalaStaticAnnot ))
416412 val flagName = (StdNames .nme.BITMAP_PREFIX + " 0" ).toTermName
417413 val flagSymbol = ctx.newSymbol(claz, flagName, containerFlags, defn.LongType ).enteredAfter(this )
@@ -431,9 +427,8 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
431427 val wait = Select (ref(helperModule), lazyNme.RLazyVals .wait4Notification)
432428 val state = Select (ref(helperModule), lazyNme.RLazyVals .state)
433429 val cas = Select (ref(helperModule), lazyNme.RLazyVals .cas)
434- val nullables = nullableFor(x.symbol)
435430
436- val accessor = mkThreadSafeDef(x.symbol.asTerm, claz, ord, containerSymbol, x.rhs, tpe, offset, getFlag, state, cas, setFlag, wait, nullables )
431+ val accessor = mkThreadSafeDef(x.symbol.asTerm, claz, ord, containerSymbol, x.rhs, tpe, offset, getFlag, state, cas, setFlag, wait)
437432 if (flag eq EmptyTree )
438433 Thicket (containerTree, accessor)
439434 else Thicket (containerTree, flag, accessor)
0 commit comments