371: Ported LRU improvements from old salsa to salsa 2022 r=nikomatsakis a=OLUWAMUYIWA

## What?
In handling evictions from the LRU, I replaced the `delete_memo`  with `evict` in the while keeping the `delete_memo` intact. 

## How?
This mechanism was already implemented in old `salsa `. I only had to port it.

Fixes: #365

Co-authored-by: OLUWAMUYIWA <onigbindemy@gmail.com>
Co-authored-by: Onigbinde Oluwamuyiwa Elijah <onigbindemy@gmail.com>
Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
This commit is contained in:
bors[bot] 2022-08-24 10:47:28 +00:00 committed by GitHub
commit 5ce4662b81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 23 deletions

View file

@ -1,10 +1,6 @@
use arc_swap::Guard;
use crate::{
database::AsSalsaDatabase,
runtime::{local_state::QueryOrigin, StampedValue},
AsId, Database,
};
use crate::{database::AsSalsaDatabase, runtime::StampedValue, AsId, Database};
use super::{Configuration, DynDb, FunctionIngredient};
@ -94,23 +90,6 @@ where
}
fn evict(&self, key: C::Key) {
if let Some(memo) = self.memo_map.get(key) {
match memo.revisions.origin {
QueryOrigin::Assigned(_)
| QueryOrigin::DerivedUntracked(_)
| QueryOrigin::BaseInput
| QueryOrigin::Field => {
// Careful: Cannot evict memos whose values were
// assigned as output of another query
// or those with untracked inputs
// as their values cannot be reconstructed.
return;
}
QueryOrigin::Derived(_) => {
self.delete_memo(key);
}
}
}
self.memo_map.evict(key);
}
}

View file

@ -42,6 +42,40 @@ impl<K: AsId, V> MemoMap<K, V> {
pub(super) fn get(&self, key: K) -> Option<Guard<Arc<Memo<V>>>> {
self.map.get(&key).map(|v| v.load())
}
/// Evicts the existing memo for the given key, replacing it
/// with an equivalent memo that has no value. If the memo is untracked, BaseInput,
/// or has values assigned as output of another query, this has no effect.
pub(super) fn evict(&self, key: K) {
use crate::runtime::local_state::QueryOrigin;
use dashmap::mapref::entry::Entry::*;
if let Occupied(entry) = self.map.entry(key) {
let memo = entry.get().load();
match memo.revisions.origin {
QueryOrigin::Assigned(_)
| QueryOrigin::DerivedUntracked(_)
| QueryOrigin::BaseInput
| QueryOrigin::Field => {
// Careful: Cannot evict memos whose values were
// assigned as output of another query
// or those with untracked inputs
// as their values cannot be reconstructed.
return;
}
QueryOrigin::Derived(_) => {
let memo_evicted = Arc::new(Memo::new(
None::<V>,
memo.verified_at.load(),
memo.revisions.clone(),
));
entry.get().store(memo_evicted);
}
}
}
}
}
#[derive(Debug)]