Skip to content

Commit 9527eac

Browse files
committed
Address review comments
1 parent ca724f7 commit 9527eac

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
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
@@ -49,7 +49,7 @@ class Checker extends MiniPhase {
4949
import semantic._
5050
val tpl = tree.rhs.asInstanceOf[Template]
5151
val thisRef = ThisRef(cls)
52-
val obj = Objekt(cls, fields = mutable.Map.empty, outers = mutable.Map.empty)
52+
val obj = Objekt(cls, fields = mutable.Map.empty, outers = mutable.Map(cls -> Hot))
5353
given Promoted = Promoted.empty
5454
given Trace = Trace.empty
5555
heap.update(thisRef, obj)

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class Semantic {
103103
*
104104
* As in the OOPSLA paper, the abstract heap is monotonistic.
105105
*
106-
* This is only one object we need to care about, hence it's just `Objekt`.
107106
*/
108107
object Heap {
109108
opaque type Heap = mutable.Map[Addr, Objekt]
@@ -119,9 +118,17 @@ class Semantic {
119118
end extension
120119

121120
extension (ref: Addr)
121+
/** Update field value of the abstract object
122+
*
123+
* Invariant: fields are immutable and only set once from `init`
124+
*/
122125
def updateField(field: Symbol, value: Value): Contextual[Unit] =
123126
heap(ref).fields(field) = value
124127

128+
/** Update the immediate outer of the given `klass` of the abstract object
129+
*
130+
* Invariant: outers are immutable and only set once from `init`
131+
*/
125132
def updateOuter(klass: ClassSymbol, value: Value): Contextual[Unit] =
126133
heap(ref).outers(klass) = value
127134
end extension
@@ -316,7 +323,7 @@ class Semantic {
316323
val cls = target.owner.enclosingClass.asClass
317324
if target.isPrimaryConstructor then
318325
val tpl = cls.defTree.asInstanceOf[TypeDef].rhs.asInstanceOf[Template]
319-
eval(tpl, addr, cls, cacheResult = true)(using ctx, trace.add(tpl), promoted)
326+
eval(tpl, addr, cls, cacheResult = true)(using ctx, trace.add(cls.defTree), promoted)
320327
else
321328
val rhs = target.defTree.asInstanceOf[ValOrDefDef].rhs
322329
eval(rhs, addr, cls, cacheResult = true)
@@ -777,9 +784,9 @@ class Semantic {
777784
else if target.is(Flags.Package) || target.isStaticOwner then Hot
778785
else
779786
thisV match
780-
case Hot | _: ThisRef => Hot
781-
case warm: Warm =>
782-
val obj = heap(warm)
787+
case Hot => Hot
788+
case addr: Addr =>
789+
val obj = heap(addr)
783790
val outerCls = klass.owner.enclosingClass.asClass
784791
resolveThis(target, obj.outers(klass), outerCls, source)
785792
case RefSet(refs) =>

0 commit comments

Comments
 (0)