create remove_stale_output method on ingredients

but we are not doing anything in it, yet
This commit is contained in:
Niko Matsakis 2022-08-11 12:15:17 -04:00
parent 1e3272bc61
commit 8b7324dca8
9 changed files with 43 additions and 3 deletions

View file

@ -140,6 +140,12 @@ fn has_jars_dyn_impl(input: &syn::ItemStruct, storage: &syn::Ident) -> syn::Item
let ingredient = self.#storage.ingredient(index.ingredient_index());
ingredient.inputs(index.key_index())
}
fn remove_stale_output(&self, executor: salsa::DatabaseKeyIndex, stale_output: salsa::key::DependencyIndex) {
let ingredient = self.#storage.ingredient(stale_output.ingredient_index());
ingredient.remove_stale_output(executor, stale_output.key_index());
}
}
}
}

View file

@ -81,6 +81,10 @@ where
fn inputs(&self, _key_index: crate::Id) -> Option<QueryEdges> {
None
}
fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option<crate::Id>) {
// FIXME
}
}
impl<DB: ?Sized, Data> MutIngredient<DB> for AccumulatorIngredient<Data>

View file

@ -203,6 +203,11 @@ where
let key = C::key_from_id(key_index);
self.inputs(key)
}
fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option<crate::Id>) {
let stale_output_key = C::key_from_id(stale_output_key.unwrap());
// FIXME
}
}
impl<DB, C> MutIngredient<DB> for FunctionIngredient<C>

View file

@ -1,6 +1,6 @@
use crate::{
key::DependencyIndex, runtime::local_state::QueryRevisions, Database, DatabaseKeyIndex, Event,
EventKind,
key::DependencyIndex, runtime::local_state::QueryRevisions, storage::HasJarsDyn, Database,
DatabaseKeyIndex, Event, EventKind,
};
use super::{memo::Memo, Configuration, DynDb, FunctionIngredient};
@ -59,5 +59,7 @@ where
output_key: output,
},
});
db.remove_stale_output(key, output);
}
}

View file

@ -1,5 +1,6 @@
use crate::{
cycle::CycleRecoveryStrategy, key::DependencyIndex, runtime::local_state::QueryEdges, Id,
cycle::CycleRecoveryStrategy, key::DependencyIndex, runtime::local_state::QueryEdges,
DatabaseKeyIndex, Id,
};
use super::Revision;
@ -22,6 +23,12 @@ pub trait Ingredient<DB: ?Sized> {
/// What were the inputs (if any) that were used to create the value at `key_index`.
fn inputs(&self, key_index: Id) -> Option<QueryEdges>;
/// Invoked when the value `stale_output` was output by `executor` in a previous
/// revision, but was NOT output in the current revision.
///
/// This hook is used to clear out the stale value so others cannot read it.
fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option<Id>);
}
/// Optional trait for ingredients that wish to be notified when new revisions are

View file

@ -61,4 +61,8 @@ where
fn inputs(&self, _key_index: crate::Id) -> Option<QueryEdges> {
None
}
fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option<crate::Id>) {
unreachable!("input cannot be the output of a tracked function");
}
}

View file

@ -8,6 +8,7 @@ use crate::id::AsId;
use crate::key::DependencyIndex;
use crate::runtime::local_state::QueryEdges;
use crate::runtime::Runtime;
use crate::DatabaseKeyIndex;
use super::hash::FxDashMap;
use super::ingredient::Ingredient;
@ -197,6 +198,10 @@ where
fn inputs(&self, _key_index: crate::Id) -> Option<QueryEdges> {
None
}
fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option<crate::Id>) {
unreachable!("interned ids are not outputs");
}
}
pub struct IdentityInterner<Id: AsId> {

View file

@ -179,6 +179,8 @@ pub trait HasJarsDyn {
fn cycle_recovery_strategy(&self, input: IngredientIndex) -> CycleRecoveryStrategy;
fn inputs(&self, input: DatabaseKeyIndex) -> Option<QueryEdges>;
fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output: DependencyIndex);
}
pub trait HasIngredientsFor<I>

View file

@ -117,6 +117,11 @@ where
fn inputs(&self, _key_index: crate::Id) -> Option<QueryEdges> {
None
}
fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option<crate::Id>) {
let key: Id = Id::from_id(stale_output_key.unwrap());
// FIXME -- we can delete this entity
}
}
impl<DB: ?Sized, Id, Data> MutIngredient<DB> for TrackedStructIngredient<Id, Data>