From 8b7324dca886001df7e7bf7c45567520954fec6b Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 11 Aug 2022 12:15:17 -0400 Subject: [PATCH] create `remove_stale_output` method on ingredients but we are not doing anything in it, yet --- components/salsa-2022-macros/src/db.rs | 6 ++++++ components/salsa-2022/src/accumulator.rs | 4 ++++ components/salsa-2022/src/function.rs | 5 +++++ components/salsa-2022/src/function/diff_outputs.rs | 6 ++++-- components/salsa-2022/src/ingredient.rs | 9 ++++++++- components/salsa-2022/src/input.rs | 4 ++++ components/salsa-2022/src/interned.rs | 5 +++++ components/salsa-2022/src/storage.rs | 2 ++ components/salsa-2022/src/tracked_struct.rs | 5 +++++ 9 files changed, 43 insertions(+), 3 deletions(-) diff --git a/components/salsa-2022-macros/src/db.rs b/components/salsa-2022-macros/src/db.rs index 0d1151fc..74573df0 100644 --- a/components/salsa-2022-macros/src/db.rs +++ b/components/salsa-2022-macros/src/db.rs @@ -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()); + } + } } } diff --git a/components/salsa-2022/src/accumulator.rs b/components/salsa-2022/src/accumulator.rs index a685ef67..27f89a25 100644 --- a/components/salsa-2022/src/accumulator.rs +++ b/components/salsa-2022/src/accumulator.rs @@ -81,6 +81,10 @@ where fn inputs(&self, _key_index: crate::Id) -> Option { None } + + fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option) { + // FIXME + } } impl MutIngredient for AccumulatorIngredient diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index 8d543fbb..4c27987c 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -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) { + let stale_output_key = C::key_from_id(stale_output_key.unwrap()); + // FIXME + } } impl MutIngredient for FunctionIngredient diff --git a/components/salsa-2022/src/function/diff_outputs.rs b/components/salsa-2022/src/function/diff_outputs.rs index 24398746..81a67e67 100644 --- a/components/salsa-2022/src/function/diff_outputs.rs +++ b/components/salsa-2022/src/function/diff_outputs.rs @@ -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); } } diff --git a/components/salsa-2022/src/ingredient.rs b/components/salsa-2022/src/ingredient.rs index d2aef7b4..058a3fbe 100644 --- a/components/salsa-2022/src/ingredient.rs +++ b/components/salsa-2022/src/ingredient.rs @@ -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 { /// What were the inputs (if any) that were used to create the value at `key_index`. fn inputs(&self, key_index: Id) -> Option; + + /// 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); } /// Optional trait for ingredients that wish to be notified when new revisions are diff --git a/components/salsa-2022/src/input.rs b/components/salsa-2022/src/input.rs index 3fb7afc8..6b5737c6 100644 --- a/components/salsa-2022/src/input.rs +++ b/components/salsa-2022/src/input.rs @@ -61,4 +61,8 @@ where fn inputs(&self, _key_index: crate::Id) -> Option { None } + + fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option) { + unreachable!("input cannot be the output of a tracked function"); + } } diff --git a/components/salsa-2022/src/interned.rs b/components/salsa-2022/src/interned.rs index cf6c88fd..3e867a06 100644 --- a/components/salsa-2022/src/interned.rs +++ b/components/salsa-2022/src/interned.rs @@ -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 { None } + + fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option) { + unreachable!("interned ids are not outputs"); + } } pub struct IdentityInterner { diff --git a/components/salsa-2022/src/storage.rs b/components/salsa-2022/src/storage.rs index 5384a76a..8fab71e2 100644 --- a/components/salsa-2022/src/storage.rs +++ b/components/salsa-2022/src/storage.rs @@ -179,6 +179,8 @@ pub trait HasJarsDyn { fn cycle_recovery_strategy(&self, input: IngredientIndex) -> CycleRecoveryStrategy; fn inputs(&self, input: DatabaseKeyIndex) -> Option; + + fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output: DependencyIndex); } pub trait HasIngredientsFor diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index c57819cf..59550370 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -117,6 +117,11 @@ where fn inputs(&self, _key_index: crate::Id) -> Option { None } + + fn remove_stale_output(&self, executor: DatabaseKeyIndex, stale_output_key: Option) { + let key: Id = Id::from_id(stale_output_key.unwrap()); + // FIXME -- we can delete this entity + } } impl MutIngredient for TrackedStructIngredient