@@ -275,51 +275,51 @@ object Semantic {
275
275
opaque type CacheStore = mutable.Map [Value , EqHashMap [Tree , Value ]]
276
276
277
277
class Cache {
278
- private val in : CacheStore = mutable.Map .empty
279
- private var out : CacheStore = mutable.Map .empty
278
+ private val last : CacheStore = mutable.Map .empty
279
+ private var current : CacheStore = mutable.Map .empty
280
280
private val stable : CacheStore = mutable.Map .empty
281
281
private var changed : Boolean = false
282
282
283
283
def hasChanged = changed
284
284
285
285
def contains (value : Value , expr : Tree ) =
286
- out .contains(value, expr) || stable.contains(value, expr)
286
+ current .contains(value, expr) || stable.contains(value, expr)
287
287
288
288
def apply (value : Value , expr : Tree ) =
289
- if out .contains(value, expr) then out (value)(expr)
289
+ if current .contains(value, expr) then current (value)(expr)
290
290
else stable(value)(expr)
291
291
292
- def assume (value : Value , expr : Tree )(fun : => Result ): Result =
292
+ def assume (value : Value , expr : Tree , cacheResult : Boolean )(fun : => Result ): Result =
293
293
val assumeValue =
294
- if in .contains(value, expr) then
295
- in .get(value, expr)
294
+ if last .contains(value, expr) then
295
+ last .get(value, expr)
296
296
else
297
- in .put(value, expr, Hot )
297
+ last .put(value, expr, Hot )
298
298
Hot
299
- out .put(value, expr, assumeValue)
299
+ current .put(value, expr, assumeValue)
300
300
301
301
val actual = fun
302
302
if actual.value != assumeValue then
303
303
this .changed = true
304
- in .put(value, expr, actual.value)
305
- out .put(value, expr, actual.value)
304
+ last .put(value, expr, actual.value)
305
+ current .put(value, expr, actual.value)
306
306
307
307
actual
308
308
309
309
def remove (value : Value , expr : Tree ) =
310
- out .remove(value, expr)
310
+ current .remove(value, expr)
311
311
312
312
/** Prepare cache for the next iteration
313
313
*
314
- * - Commit out cache to stable cache if unchanged.
314
+ * - Commit current cache to stable cache if unchanged.
315
315
* - Reset changed flag
316
- * - Reset out cache
316
+ * - Reset current cache (last cache already synced in `assume`)
317
317
*
318
- * Precondition: the out cache reaches fixed point.
318
+ * Precondition: the current cache reaches fixed point.
319
319
*/
320
320
def iterate () = {
321
321
if ! changed then
322
- out .foreach { (v, m) =>
322
+ current .foreach { (v, m) =>
323
323
m.iterator.foreach { (e, res) =>
324
324
stable.put(v, e, res)
325
325
}
@@ -328,7 +328,7 @@ object Semantic {
328
328
329
329
changed = false
330
330
331
- out = mutable.Map .empty
331
+ current = mutable.Map .empty
332
332
}
333
333
}
334
334
@@ -834,7 +834,7 @@ object Semantic {
834
834
res.errors.foreach(_.issue)
835
835
836
836
if cache.hasChanged && res.errors.isEmpty then
837
- // discard heap changes and copy cache.out to cache.in
837
+ // discard heap changes
838
838
heap.restore(heapBefore)
839
839
else
840
840
pendingTasks = rest
@@ -911,7 +911,7 @@ object Semantic {
911
911
*/
912
912
def eval (expr : Tree , thisV : Ref , klass : ClassSymbol , cacheResult : Boolean = false ): Contextual [Result ] = log(" evaluating " + expr.show + " , this = " + thisV.show, printer, (_ : Result ).show) {
913
913
if (cache.contains(thisV, expr)) Result (cache(thisV, expr), Errors .empty)
914
- else cache.assume(thisV, expr) { cases(expr, thisV, klass) }
914
+ else cache.assume(thisV, expr, cacheResult ) { cases(expr, thisV, klass) }
915
915
}
916
916
917
917
/** Evaluate a list of expressions */
0 commit comments