mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-23 13:10:19 +00:00
refactor Memo
to just be parameterized over V
This commit is contained in:
parent
75ee3edd2e
commit
891a866653
1 changed files with 13 additions and 15 deletions
|
@ -49,15 +49,12 @@ where
|
||||||
},
|
},
|
||||||
|
|
||||||
/// We have computed the query already, and here is the result.
|
/// We have computed the query already, and here is the result.
|
||||||
Memoized(Memo<Q>),
|
Memoized(Memo<Q::Value>),
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Memo<Q>
|
struct Memo<V> {
|
||||||
where
|
|
||||||
Q: QueryFunction,
|
|
||||||
{
|
|
||||||
/// The result of the query, if we decide to memoize it.
|
/// The result of the query, if we decide to memoize it.
|
||||||
value: Option<Q::Value>,
|
value: Option<V>,
|
||||||
|
|
||||||
/// Revision information
|
/// Revision information
|
||||||
revisions: MemoRevisions,
|
revisions: MemoRevisions,
|
||||||
|
@ -220,7 +217,9 @@ where
|
||||||
// first things first, let's walk over each of our previous
|
// first things first, let's walk over each of our previous
|
||||||
// inputs and check whether they are out of date.
|
// inputs and check whether they are out of date.
|
||||||
if let Some(memo) = &mut panic_guard.memo {
|
if let Some(memo) = &mut panic_guard.memo {
|
||||||
if let Some(value) = memo.validate_memoized_value(db, revision_now, &active_query) {
|
if let Some(value) =
|
||||||
|
memo.validate_memoized_value(db.ops_database(), revision_now, &active_query)
|
||||||
|
{
|
||||||
info!("{:?}: validated old memoized value", self,);
|
info!("{:?}: validated old memoized value", self,);
|
||||||
|
|
||||||
db.salsa_event(Event {
|
db.salsa_event(Event {
|
||||||
|
@ -649,7 +648,7 @@ where
|
||||||
{
|
{
|
||||||
database_key_index: DatabaseKeyIndex,
|
database_key_index: DatabaseKeyIndex,
|
||||||
slot: &'me Slot<Q, MP>,
|
slot: &'me Slot<Q, MP>,
|
||||||
memo: Option<Memo<Q>>,
|
memo: Option<Memo<Q::Value>>,
|
||||||
runtime: &'me Runtime,
|
runtime: &'me Runtime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -661,7 +660,7 @@ where
|
||||||
fn new(
|
fn new(
|
||||||
database_key_index: DatabaseKeyIndex,
|
database_key_index: DatabaseKeyIndex,
|
||||||
slot: &'me Slot<Q, MP>,
|
slot: &'me Slot<Q, MP>,
|
||||||
memo: Option<Memo<Q>>,
|
memo: Option<Memo<Q::Value>>,
|
||||||
runtime: &'me Runtime,
|
runtime: &'me Runtime,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -737,9 +736,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Q> Memo<Q>
|
impl<V> Memo<V>
|
||||||
where
|
where
|
||||||
Q: QueryFunction,
|
V: Clone,
|
||||||
{
|
{
|
||||||
/// Determines whether the memo is still valid in the current
|
/// Determines whether the memo is still valid in the current
|
||||||
/// revision. If needed, this will walk each dependency and
|
/// revision. If needed, this will walk each dependency and
|
||||||
|
@ -750,20 +749,19 @@ where
|
||||||
/// takes the `active_query` argument as evidence.
|
/// takes the `active_query` argument as evidence.
|
||||||
fn validate_memoized_value(
|
fn validate_memoized_value(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &<Q as QueryDb<'_>>::DynDb,
|
db: &dyn Database,
|
||||||
revision_now: Revision,
|
revision_now: Revision,
|
||||||
active_query: &ActiveQueryGuard<'_>,
|
active_query: &ActiveQueryGuard<'_>,
|
||||||
) -> Option<StampedValue<Q::Value>> {
|
) -> Option<StampedValue<V>> {
|
||||||
// If we don't have a memoized value, nothing to validate.
|
// If we don't have a memoized value, nothing to validate.
|
||||||
let value = match &self.value {
|
let value = match &self.value {
|
||||||
None => return None,
|
None => return None,
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
};
|
};
|
||||||
|
|
||||||
let dyn_db = db.ops_database();
|
|
||||||
if self
|
if self
|
||||||
.revisions
|
.revisions
|
||||||
.validate_memoized_value(dyn_db, revision_now, active_query)
|
.validate_memoized_value(db, revision_now, active_query)
|
||||||
{
|
{
|
||||||
Some(StampedValue {
|
Some(StampedValue {
|
||||||
durability: self.revisions.durability,
|
durability: self.revisions.durability,
|
||||||
|
|
Loading…
Reference in a new issue