Skip to content

Commit d5fb3e9

Browse files
committed
Add comment
1 parent f97dc02 commit d5fb3e9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,7 @@ object Semantic {
312312
*
313313
* 2. Reset current cache (last cache already synced in `assume`)
314314
*
315-
* 3. Recompute the newly created warm objects with the updated cache.
316-
*
317-
* The computation only covers class parameters and outers. Class
318-
* fields are ignored and are lazily evaluated and cached.
319-
*
320-
* This step should be after the first two steps so that the populated
321-
* parameter are re-computed from the updated input cache.
315+
* 3. Revert heap if instable.
322316
*
323317
*/
324318
def prepareForNextIteration(isStable: Boolean)(using State, Context) =
@@ -470,6 +464,12 @@ object Semantic {
470464
*/
471465
def updateField(field: Symbol, value: Value): Contextual[Unit] = log("set field " + field + " of " + ref + " to " + value) {
472466
val obj = objekt
467+
// We may reset the outers or params of a populated warm object.
468+
// This is the case if we need access the field of a warm object, which
469+
// requires population of parameters and outers; and later create an
470+
// instance of the exact warm object, which requires initialization check.
471+
//
472+
// See tests/init/neg/unsound1.scala
473473
assert(!obj.hasField(field) || field.is(Flags.ParamAccessor) && obj.field(field) == value, field.show + " already init, new = " + value + ", old = " + obj.field(field) + ", ref = " + ref)
474474
val obj2 = obj.copy(fields = obj.fields.updated(field, value))
475475
cache.updateObject(ref, obj2)
@@ -481,6 +481,7 @@ object Semantic {
481481
*/
482482
def updateOuter(klass: ClassSymbol, value: Value): Contextual[Unit] = log("set outer " + klass + " of " + ref + " to " + value) {
483483
val obj = objekt
484+
// See the comment in `updateField` for setting the value twice.
484485
assert(!obj.hasOuter(klass) || obj.outer(klass) == value, klass.show + " already has outer, new = " + value + ", old = " + obj.outer(klass) + ", ref = " + ref)
485486
val obj2 = obj.copy(outers = obj.outers.updated(klass, value))
486487
cache.updateObject(ref, obj2)

0 commit comments

Comments
 (0)