@@ -470,7 +470,7 @@ object Objects:
470
470
471
471
/** Store the heap as a mutable field to avoid threading it through the program. */
472
472
class MutableData (private [Heap ] var heap : Data ):
473
- private [Heap ] def update (addr : Addr , value : Value ): Unit =
473
+ private [Heap ] def writeJoin (addr : Addr , value : Value ): Unit =
474
474
heap.get(addr) match
475
475
case None =>
476
476
heap = heap.updated(addr, value)
@@ -479,7 +479,7 @@ object Objects:
479
479
val value2 = value.join(current)
480
480
if value2 != current then
481
481
heap = heap.updated(addr, value2)
482
-
482
+ end MutableData
483
483
484
484
def empty (): MutableData = new MutableData (Map .empty)
485
485
@@ -489,8 +489,8 @@ object Objects:
489
489
def read (addr : Addr )(using mutable : MutableData ): Value =
490
490
mutable.heap(addr)
491
491
492
- def write (addr : Addr , value : Value )(using mutable : MutableData ): Unit =
493
- mutable.update (addr, value)
492
+ def writeJoin (addr : Addr , value : Value )(using mutable : MutableData ): Unit =
493
+ mutable.writeJoin (addr, value)
494
494
495
495
def localVarAddr (regions : Regions .Data , sym : Symbol , owner : ClassSymbol ): Addr =
496
496
LocalVarAddr (regions, sym, owner)
@@ -616,7 +616,7 @@ object Objects:
616
616
* @param superType The type of the super in a super call. NoType for non-super calls.
617
617
* @param needResolve Whether the target of the call needs resolution?
618
618
*/
619
- def call (value : Value , meth : Symbol , args : List [ArgInfo ], receiver : Type , superType : Type , needResolve : Boolean = true ): Contextual [Value ] = log(" call " + meth.show + " , args = " + args.map(_.value.show), printer, (_ : Value ).show) {
619
+ def call (value : Value , meth : Symbol , args : List [ArgInfo ], receiver : Type , superType : Type , needResolve : Boolean = true ): Contextual [Value ] = log(" call " + meth.show + " , this = " + value.show + " , args = " + args.map(_.value.show), printer, (_ : Value ).show) {
620
620
value match
621
621
case Cold =>
622
622
report.warning(" Using cold alias. Calling trace:\n " + Trace .show, Trace .position)
@@ -639,7 +639,7 @@ object Objects:
639
639
if arr.addr.owner != State .currentObject then
640
640
errorMutateOtherStaticObject(State .currentObject, arr.addr.owner)
641
641
else
642
- Heap .write (arr.addr, args.tail.head.value)
642
+ Heap .writeJoin (arr.addr, args.tail.head.value)
643
643
Bottom
644
644
else
645
645
// Array.length is OK
@@ -658,7 +658,11 @@ object Objects:
658
658
resolve(ref.klass, meth)
659
659
660
660
if target.isOneOf(Flags .Method ) then
661
- if target.hasSource then
661
+ if target.owner == defn.ArrayModuleClass && target.name == nme.apply then
662
+ val arr = OfArray (State .currentObject, summon[Regions .Data ])
663
+ Heap .writeJoin(arr.addr, args.map(_.value).join)
664
+ arr
665
+ else if target.hasSource then
662
666
val cls = target.owner.enclosingClass.asClass
663
667
val ddef = target.defTree.asInstanceOf [DefDef ]
664
668
val meth = ddef.symbol
@@ -842,7 +846,7 @@ object Objects:
842
846
if addr.owner != State .currentObject then
843
847
errorMutateOtherStaticObject(State .currentObject, addr.owner)
844
848
else
845
- Heap .write (addr, rhs)
849
+ Heap .writeJoin (addr, rhs)
846
850
else
847
851
report.warning(" Mutating a field before its initialization: " + field.show + " . Calling trace:\n " + Trace .show, Trace .position)
848
852
end match
@@ -867,7 +871,7 @@ object Objects:
867
871
case outer : (Ref | Cold .type | Bottom .type ) =>
868
872
if klass == defn.ArrayClass then
869
873
val arr = OfArray (State .currentObject, summon[Regions .Data ])
870
- Heap .write (arr.addr, Bottom )
874
+ Heap .writeJoin (arr.addr, Bottom )
871
875
arr
872
876
else
873
877
// Widen the outer to finitize the domain. Arguments already widened in `evalArgs`.
@@ -903,7 +907,7 @@ object Objects:
903
907
if sym.is(Flags .Mutable ) then
904
908
val addr = Heap .localVarAddr(summon[Regions .Data ], sym, State .currentObject)
905
909
Env .setLocalVar(sym, addr)
906
- Heap .write (addr, value)
910
+ Heap .writeJoin (addr, value)
907
911
else
908
912
Env .setLocalVal(sym, value)
909
913
}
@@ -964,8 +968,8 @@ object Objects:
964
968
* @param value The value of the rhs of the assignment.
965
969
*/
966
970
def writeLocal (thisV : ThisValue , sym : Symbol , value : Value ): Contextual [Value ] = log(" write local " + sym.show + " with " + value.show, printer, (_ : Value ).show) {
967
-
968
971
assert(sym.is(Flags .Mutable ), " Writing to immutable variable " + sym.show)
972
+
969
973
Env .resolveEnv(sym.enclosingMethod, thisV, summon[Env .Data ]) match
970
974
case Some (thisV -> env) =>
971
975
given Env .Data = env
@@ -974,7 +978,7 @@ object Objects:
974
978
if addr.owner != State .currentObject then
975
979
errorMutateOtherStaticObject(State .currentObject, addr.owner)
976
980
else
977
- Heap .write (addr, value)
981
+ Heap .writeJoin (addr, value)
978
982
case _ =>
979
983
report.warning(" [Internal error] Variable not found " + sym.show + " \n env = " + env.show + " . Calling trace:\n " + Trace .show, Trace .position)
980
984
@@ -1537,7 +1541,7 @@ object Objects:
1537
1541
if acc.is(Flags .Mutable ) then
1538
1542
val addr = Heap .fieldVarAddr(summon[Regions .Data ], acc, State .currentObject)
1539
1543
thisV.initVar(acc, addr)
1540
- Heap .write (addr, value)
1544
+ Heap .writeJoin (addr, value)
1541
1545
else
1542
1546
thisV.initVal(acc, value)
1543
1547
printer.println(acc.show + " initialized with " + value)
@@ -1632,7 +1636,7 @@ object Objects:
1632
1636
if sym.is(Flags .Mutable ) then
1633
1637
val addr = Heap .fieldVarAddr(summon[Regions .Data ], sym, State .currentObject)
1634
1638
thisV.initVar(sym, addr)
1635
- Heap .write (addr, res)
1639
+ Heap .writeJoin (addr, res)
1636
1640
else
1637
1641
thisV.initVal(sym, res)
1638
1642
0 commit comments