Skip to content

Commit 0f19e75

Browse files
committed
Handle cache in work list
1 parent 3614108 commit 0f19e75

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,25 @@ object Semantic {
268268
*
269269
*/
270270

271-
class Cache(val in: Cache.CacheIn, var out: Cache.CacheOut) {
272-
var changed: Boolean = false
273-
}
274-
275271
object Cache {
276272
opaque type CacheIn = mutable.Map[Value, EqHashMap[Tree, Value]]
277273
opaque type CacheOut = mutable.Map[Value, EqHashMap[Tree, Value]]
278274

275+
class Cache(val in: CacheIn, var out: CacheOut) {
276+
var changed: Boolean = false
277+
278+
/** Copy out to in and reset out to empty */
279+
def update() = {
280+
out.foreach { (v, m) =>
281+
m.iterator.foreach { (e, res) =>
282+
in.put(v, e, res)
283+
}
284+
}
285+
286+
out = mutable.Map.empty
287+
}
288+
}
289+
279290
val empty: Cache = new Cache(mutable.Map.empty, mutable.Map.empty)
280291

281292
extension (cache: CacheIn | CacheOut)
@@ -770,9 +781,15 @@ object Semantic {
770781
final def work()(using State, Context): Unit =
771782
pendingTasks match
772783
case task :: rest =>
773-
pendingTasks = rest
774-
checkedTasks = checkedTasks + task
775784
doTask(task)
785+
786+
if cache.changed then
787+
// discard heap changes and copy cache.out to cache.in
788+
cache.update()
789+
else
790+
pendingTasks = rest
791+
checkedTasks = checkedTasks + task
792+
776793
work()
777794
case _ =>
778795

0 commit comments

Comments
 (0)