@@ -163,10 +163,10 @@ object Objects:
163
163
*
164
164
* @param owner The static object whose initialization creates the array.
165
165
*/
166
- case class OfArray (owner : ClassSymbol )(using @ constructorOnly ctx : Context )
166
+ case class OfArray (owner : ClassSymbol , regions : Regions . Data )(using @ constructorOnly ctx : Context )
167
167
extends Ref (valsMap = mutable.Map .empty, varsMap = mutable.Map .empty, outersMap = mutable.Map .empty):
168
168
val klass : ClassSymbol = defn.ArrayClass
169
- val addr : Heap .Addr = Heap .arrayAddr(this , owner)
169
+ val addr : Heap .Addr = Heap .arrayAddr(regions , owner)
170
170
def show (using Context ) = " OfArray(owner = " + owner.show + " )"
171
171
172
172
/**
@@ -214,6 +214,7 @@ object Objects:
214
214
given Trace = Trace .empty.add(classSym.defTree)
215
215
given Env .Data = Env .emptyEnv(tpl.constr.symbol)
216
216
given Heap .MutableData = Heap .empty()
217
+ given regions : Regions .Data = Regions .empty // explicit name to avoid naming conflict
217
218
218
219
val obj = ObjectRef (classSym)
219
220
log(" Iteration " + count) {
@@ -281,7 +282,6 @@ object Objects:
281
282
/** Local environments can be deeply nested, therefore we need `outer`.
282
283
*
283
284
* For local variables in rhs of class field definitions, the `meth` is the primary constructor.
284
- *
285
285
*/
286
286
private case class LocalEnv
287
287
(private [Env ] val params : Map [Symbol , Value ], meth : Symbol , outer : Data )
@@ -407,10 +407,10 @@ object Objects:
407
407
def owner : ClassSymbol
408
408
409
409
/** The address for mutable fields of objects. */
410
- private case class FieldAddr (ref : Ref , field : Symbol , owner : ClassSymbol ) extends Addr
410
+ private case class FieldAddr (regions : Regions . Data , field : Symbol , owner : ClassSymbol ) extends Addr
411
411
412
412
/** The address for mutable local variables . */
413
- private case class LocalVarAddr (ref : Ref , env : Env .Data , sym : Symbol , owner : ClassSymbol ) extends Addr
413
+ private case class LocalVarAddr (regions : Regions .Data , sym : Symbol , owner : ClassSymbol ) extends Addr
414
414
415
415
/** Immutable heap data used in the cache.
416
416
*
@@ -444,14 +444,14 @@ object Objects:
444
444
def write (addr : Addr , value : Value )(using mutable : MutableData ): Unit =
445
445
mutable.update(addr, value)
446
446
447
- def localVarAddr (ref : Ref , env : Env .Data , sym : Symbol , owner : ClassSymbol ): Addr =
448
- LocalVarAddr (ref, env , sym, owner)
447
+ def localVarAddr (regions : Regions .Data , sym : Symbol , owner : ClassSymbol ): Addr =
448
+ LocalVarAddr (regions , sym, owner)
449
449
450
- def fieldVarAddr (ref : Ref , sym : Symbol , owner : ClassSymbol ): Addr =
451
- FieldAddr (ref , sym, owner)
450
+ def fieldVarAddr (regions : Regions . Data , sym : Symbol , owner : ClassSymbol ): Addr =
451
+ FieldAddr (regions , sym, owner)
452
452
453
- def arrayAddr (ref : Ref , owner : ClassSymbol ): Addr =
454
- FieldAddr (ref, NoSymbol , owner)
453
+ def arrayAddr (regions : Regions . Data , owner : ClassSymbol )( using Context ): Addr =
454
+ FieldAddr (regions, defn. ArrayClass , owner)
455
455
456
456
def getHeapData ()(using mutable : MutableData ): Data = mutable.heap
457
457
@@ -482,7 +482,7 @@ object Objects:
482
482
opaque type Data = List [SourcePosition ]
483
483
val empty : Data = Nil
484
484
def extend (pos : SourcePosition )(using data : Data ): Data = pos :: data
485
- def exists (pos : SourcePosition )(using data : Data ): Data = data.indexOf(pos) >= 0
485
+ def exists (pos : SourcePosition )(using data : Data ): Boolean = data.indexOf(pos) >= 0
486
486
487
487
inline def cache (using c : Cache .Data ): Cache .Data = c
488
488
@@ -735,7 +735,7 @@ object Objects:
735
735
// The outer can be a bottom value for top-level classes.
736
736
737
737
if klass == defn.ArrayClass then
738
- val arr = OfArray (State .currentObject)
738
+ val arr = OfArray (State .currentObject, summon[ Regions . Data ] )
739
739
Heap .write(arr.addr, Bottom )
740
740
arr
741
741
else
@@ -761,7 +761,7 @@ object Objects:
761
761
762
762
def initLocal (ref : Ref , sym : Symbol , value : Value ): Contextual [Unit ] = log(" initialize local " + sym.show + " with " + value.show, printer) {
763
763
if sym.is(Flags .Mutable ) then
764
- val addr = Heap .localVarAddr(ref, summon[Env .Data ], sym, State .currentObject)
764
+ val addr = Heap .localVarAddr(summon[Regions .Data ], sym, State .currentObject)
765
765
Env .setLocalVar(sym, addr)
766
766
Heap .write(addr, value)
767
767
else
@@ -1161,7 +1161,7 @@ object Objects:
1161
1161
klass.paramGetters.foreach { acc =>
1162
1162
val value = paramsMap(acc.name.toTermName)
1163
1163
if acc.is(Flags .Mutable ) then
1164
- val addr = Heap .fieldVarAddr(thisV , acc, State .currentObject)
1164
+ val addr = Heap .fieldVarAddr(summon[ Regions . Data ] , acc, State .currentObject)
1165
1165
thisV.initVar(acc, addr)
1166
1166
Heap .write(addr, value)
1167
1167
else
@@ -1256,7 +1256,7 @@ object Objects:
1256
1256
val res = eval(vdef.rhs, thisV, klass)
1257
1257
val sym = vdef.symbol
1258
1258
if sym.is(Flags .Mutable ) then
1259
- val addr = Heap .fieldVarAddr(thisV , sym, State .currentObject)
1259
+ val addr = Heap .fieldVarAddr(summon[ Regions . Data ] , sym, State .currentObject)
1260
1260
thisV.initVar(sym, addr)
1261
1261
Heap .write(addr, res)
1262
1262
else
0 commit comments