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 )
@@ -343,7 +339,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
343339 }
344340
345341 val retryCase = {
346- val caseSymbol = ctx.newSymbol(methodSymbol, nme.DEFAULT_EXCEPTION_NAME , Flags . Synthetic , defn.ThrowableType )
342+ val caseSymbol = ctx.newSymbol(methodSymbol, nme.DEFAULT_EXCEPTION_NAME , Synthetic , defn.ThrowableType )
347343 val triggerRetry = setFlagState.appliedTo(thiz, offset, initState, fieldId)
348344 CaseDef (
349345 Bind (caseSymbol, ref(caseSymbol)),
@@ -373,7 +369,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
373369 }
374370
375371 def transformMemberDefVolatile (x : ValOrDefDef )(implicit ctx : Context ): Thicket = {
376- assert(! (x.symbol is Flags . Mutable ))
372+ assert(! (x.symbol is Mutable ))
377373
378374 val tpe = x.tpe.widen.resultType.widen
379375 val claz = x.symbol.owner.asClass
@@ -384,9 +380,9 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
384380 var flag : Tree = EmptyTree
385381 var ord = 0
386382
387- def offsetName (id : Int ) = (StdNames .nme.LAZY_FIELD_OFFSET + (if (x.symbol.owner.is(Flags . Module )) " _m_" else " " ) + id.toString).toTermName
383+ def offsetName (id : Int ) = (StdNames .nme.LAZY_FIELD_OFFSET + (if (x.symbol.owner.is(Module )) " _m_" else " " ) + id.toString).toTermName
388384
389- // compute or create appropriate offsetSymol , bitmap and bits used by current ValDef
385+ // compute or create appropriate offsetSymbol , bitmap and bits used by current ValDef
390386 appendOffsetDefs.get(claz) match {
391387 case Some (info) =>
392388 val flagsPerLong = (64 / dotty.runtime.LazyVals .BITS_PER_LAZY_VAL ).toInt
@@ -396,10 +392,10 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
396392 val offsetById = offsetName(id)
397393 if (ord != 0 ) { // there are unused bits in already existing flag
398394 offsetSymbol = claz.info.decl(offsetById)
399- .suchThat(sym => (sym is Flags . Synthetic ) && sym.isTerm)
395+ .suchThat(sym => (sym is Synthetic ) && sym.isTerm)
400396 .symbol.asTerm
401397 } else { // need to create a new flag
402- offsetSymbol = ctx.newSymbol(claz, offsetById, Flags . Synthetic , defn.LongType ).enteredAfter(this )
398+ offsetSymbol = ctx.newSymbol(claz, offsetById, Synthetic , defn.LongType ).enteredAfter(this )
403399 offsetSymbol.addAnnotation(Annotation (defn.ScalaStaticAnnot ))
404400 val flagName = (StdNames .nme.BITMAP_PREFIX + id.toString).toTermName
405401 val flagSymbol = ctx.newSymbol(claz, flagName, containerFlags, defn.LongType ).enteredAfter(this )
@@ -409,7 +405,7 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
409405 }
410406
411407 case None =>
412- offsetSymbol = ctx.newSymbol(claz, offsetName(0 ), Flags . Synthetic , defn.LongType ).enteredAfter(this )
408+ offsetSymbol = ctx.newSymbol(claz, offsetName(0 ), Synthetic , defn.LongType ).enteredAfter(this )
413409 offsetSymbol.addAnnotation(Annotation (defn.ScalaStaticAnnot ))
414410 val flagName = (StdNames .nme.BITMAP_PREFIX + " 0" ).toTermName
415411 val flagSymbol = ctx.newSymbol(claz, flagName, containerFlags, defn.LongType ).enteredAfter(this )
@@ -429,9 +425,8 @@ class LazyVals extends MiniPhase with IdentityDenotTransformer {
429425 val wait = Select (ref(helperModule), lazyNme.RLazyVals .wait4Notification)
430426 val state = Select (ref(helperModule), lazyNme.RLazyVals .state)
431427 val cas = Select (ref(helperModule), lazyNme.RLazyVals .cas)
432- val nullables = nullableFor(x.symbol)
433428
434- val accessor = mkThreadSafeDef(x.symbol.asTerm, claz, ord, containerSymbol, x.rhs, tpe, offset, getFlag, state, cas, setFlag, wait, nullables )
429+ val accessor = mkThreadSafeDef(x.symbol.asTerm, claz, ord, containerSymbol, x.rhs, tpe, offset, getFlag, state, cas, setFlag, wait)
435430 if (flag eq EmptyTree )
436431 Thicket (containerTree, accessor)
437432 else Thicket (containerTree, flag, accessor)
0 commit comments