@@ -26,7 +26,7 @@ import dotty.tools.dotc.core.SymDenotations.SymDenotation
26
26
import dotty .tools .dotc .core .DenotTransformers .{SymTransformer , IdentityDenotTransformer , DenotTransformer }
27
27
import Erasure .Boxing .adaptToType
28
28
29
- class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer with NeedsCompanions {
29
+ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
30
30
import LazyVals ._
31
31
32
32
import tpd ._
@@ -49,11 +49,6 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer with Nee
49
49
* before this phase starts processing same tree */
50
50
override def runsAfter = Set (classOf [Mixin ])
51
51
52
- def isCompanionNeeded (cls : ClassSymbol )(implicit ctx : Context ): Boolean = {
53
- def hasLazyVal (cls : ClassSymbol ) = cls.info.decls.exists(_.is(Flags .Lazy ))
54
- hasLazyVal(cls) || cls.mixins.exists(hasLazyVal)
55
- }
56
-
57
52
override def transformDefDef (tree : tpd.DefDef )(implicit ctx : Context , info : TransformerInfo ): tpd.Tree =
58
53
transformLazyVal(tree)
59
54
@@ -341,26 +336,28 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer with Nee
341
336
val tpe = x.tpe.widen.resultType.widen
342
337
val claz = x.symbol.owner.asClass
343
338
val thizClass = Literal (Constant (claz.info))
344
- val companion = claz.companionModule
345
339
val helperModule = ctx.requiredModule(" dotty.runtime.LazyVals" )
346
340
val getOffset = Select (ref(helperModule), lazyNme.RLazyVals .getOffset)
347
341
var offsetSymbol : TermSymbol = null
348
342
var flag : Tree = EmptyTree
349
343
var ord = 0
350
344
345
+ def offsetName (id : Int ) = (StdNames .nme.LAZY_FIELD_OFFSET + (if (x.symbol.owner.is(Flags .Module )) " _m_" else " " ) + id.toString).toTermName
346
+
351
347
// compute or create appropriate offsetSymol, bitmap and bits used by current ValDef
352
- appendOffsetDefs.get(companion.moduleClass ) match {
348
+ appendOffsetDefs.get(claz ) match {
353
349
case Some (info) =>
354
350
val flagsPerLong = (64 / dotty.runtime.LazyVals .BITS_PER_LAZY_VAL ).toInt
355
351
info.ord += 1
356
352
ord = info.ord % flagsPerLong
357
353
val id = info.ord / flagsPerLong
354
+ val offsetById = offsetName(id)
358
355
if (ord != 0 ) { // there are unused bits in already existing flag
359
- offsetSymbol = companion .moduleClass.info.decl(( StdNames .nme. LAZY_FIELD_OFFSET + id.toString).toTermName )
356
+ offsetSymbol = claz .moduleClass.info.decl(offsetById )
360
357
.suchThat(sym => (sym is Flags .Synthetic ) && sym.isTerm)
361
358
.symbol.asTerm
362
359
} else { // need to create a new flag
363
- offsetSymbol = ctx.newSymbol(companion.moduleClass, ( StdNames .nme. LAZY_FIELD_OFFSET + id.toString).toTermName , Flags .Synthetic , defn.LongType ).enteredAfter(this )
360
+ offsetSymbol = ctx.newSymbol(claz, offsetById , Flags .Synthetic , defn.LongType ).enteredAfter(this )
364
361
offsetSymbol.addAnnotation(Annotation (defn.ScalaStaticAnnot ))
365
362
val flagName = (StdNames .nme.BITMAP_PREFIX + id.toString).toTermName
366
363
val flagSymbol = ctx.newSymbol(claz, flagName, containerFlags, defn.LongType ).enteredAfter(this )
@@ -370,13 +367,13 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer with Nee
370
367
}
371
368
372
369
case None =>
373
- offsetSymbol = ctx.newSymbol(companion.moduleClass, ( StdNames .nme. LAZY_FIELD_OFFSET + " 0 " ).toTermName , Flags .Synthetic , defn.LongType ).enteredAfter(this )
370
+ offsetSymbol = ctx.newSymbol(claz, offsetName( 0 ) , Flags .Synthetic , defn.LongType ).enteredAfter(this )
374
371
offsetSymbol.addAnnotation(Annotation (defn.ScalaStaticAnnot ))
375
372
val flagName = (StdNames .nme.BITMAP_PREFIX + " 0" ).toTermName
376
373
val flagSymbol = ctx.newSymbol(claz, flagName, containerFlags, defn.LongType ).enteredAfter(this )
377
374
flag = ValDef (flagSymbol, Literal (Constants .Constant (0L )))
378
375
val offsetTree = ValDef (offsetSymbol, getOffset.appliedTo(thizClass, Literal (Constant (flagName.toString))))
379
- appendOffsetDefs += (companion.moduleClass -> new OffsetInfo (List (offsetTree), ord))
376
+ appendOffsetDefs += (claz -> new OffsetInfo (List (offsetTree), ord))
380
377
}
381
378
382
379
val containerName = ctx.freshName(x.name.asTermName.lazyLocalName).toTermName
0 commit comments