Skip to content

Commit 8a4fe78

Browse files
committed
Commit cache to stable on error
This is important because we don't revert the heap on error. Therefore, the stable cache has to be updated. Otherwise, a warm object might be initialized twice, violating invariants.
1 parent 2849052 commit 8a4fe78

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,29 +314,24 @@ object Semantic {
314314
end if
315315

316316
actual
317+
end assume
317318

318-
def remove(value: Value, expr: Tree) =
319-
current.remove(value, expr)
319+
/** Commit current cache to stable cache. */
320+
def commit() =
321+
current.foreach { (v, m) =>
322+
m.iterator.foreach { (e, res) =>
323+
stable.put(v, e, res)
324+
}
325+
}
326+
current = mutable.Map.empty
320327

321328
/** Prepare cache for the next iteration
322329
*
323-
* - Commit current cache to stable cache if unchanged.
324330
* - Reset changed flag
325331
* - Reset current cache (last cache already synced in `assume`)
326-
*
327-
* Precondition: the current cache reaches fixed point.
328332
*/
329333
def iterate() = {
330-
if !changed then
331-
current.foreach { (v, m) =>
332-
m.iterator.foreach { (e, res) =>
333-
stable.put(v, e, res)
334-
}
335-
}
336-
end if
337-
338334
changed = false
339-
340335
current = mutable.Map.empty
341336
}
342337
}
@@ -846,6 +841,7 @@ object Semantic {
846841
// discard heap changes
847842
heap.restore(heapBefore)
848843
else
844+
cache.commit()
849845
pendingTasks = rest
850846

851847
cache.iterate()

0 commit comments

Comments
 (0)