Skip to content

Commit 13f2634

Browse files
committed
Create warm object in heap if absent
1 parent 7cf68c0 commit 13f2634

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

compiler/src/dotty/tools/dotc/transform/init/Checker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Checker extends MiniPhase {
5353
given Heap = Heap.empty
5454
given Promoted = Promoted.empty
5555
given Trace = Trace.empty
56-
heap.add(thisRef, obj)
56+
heap.update(thisRef, obj)
5757
val res = eval(tpl, thisRef, cls)
5858
res.errors.foreach(_.issue)
5959
}

compiler/src/dotty/tools/dotc/transform/init/Semantic.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ class Semantic {
112112
def empty: Heap = mutable.Map.empty
113113

114114
extension (heap: Heap)
115+
def contains(addr: Addr): Boolean = heap.contains(addr)
115116
def apply(addr: Addr): Objekt = heap(addr)
116-
def add(addr: Addr, obj: Objekt): Unit = heap(addr) = obj
117+
def update(addr: Addr, obj: Objekt): Unit =
118+
heap(addr) = obj
117119
end extension
118120

119121
extension (ref: Addr)
@@ -346,15 +348,18 @@ class Semantic {
346348
val error = CallCold(ctor, source, trace.toVector)
347349
Result(Hot, error :: Nil)
348350

349-
case thisRef: ThisRef =>
350-
val value = Warm(klass, outer = thisRef)
351-
val res = value.call(ctor, superType = NoType, source)
352-
Result(value, res.errors)
353-
354-
case warm: Warm =>
351+
case addr: Addr =>
355352
// widen the outer to finitize addresses
356-
val outer = if warm.outer.isInstanceOf[Warm] then warm.copy(outer = Cold) else warm
353+
val outer = addr match
354+
case _: ThisRef => addr
355+
case warm: Warm =>
356+
if warm.outer.isInstanceOf[Warm] then warm.copy(outer = Cold)
357+
else warm
358+
357359
val value = Warm(klass, outer)
360+
if !heap.contains(value) then
361+
val obj = Objekt(klass, fields = mutable.Map.empty, outers = mutable.Map(klass -> outer))
362+
heap.update(value, obj)
358363
val res = value.call(ctor, superType = NoType, source)
359364
Result(value, res.errors)
360365

0 commit comments

Comments
 (0)