From 59f094f5127404c4187459e15c761f194b636280 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Sun, 8 Oct 2023 20:40:52 +0200 Subject: [PATCH] Provide public API to get `IngredientIndex` --- components/salsa-2022/src/accumulator.rs | 4 ++++ components/salsa-2022/src/function.rs | 4 ++++ components/salsa-2022/src/ingredient.rs | 5 ++++- components/salsa-2022/src/input.rs | 4 ++++ components/salsa-2022/src/input_field.rs | 4 ++++ components/salsa-2022/src/interned.rs | 4 ++++ components/salsa-2022/src/tracked_struct.rs | 4 ++++ 7 files changed, 28 insertions(+), 1 deletion(-) diff --git a/components/salsa-2022/src/accumulator.rs b/components/salsa-2022/src/accumulator.rs index 69ea998c..af22ac84 100644 --- a/components/salsa-2022/src/accumulator.rs +++ b/components/salsa-2022/src/accumulator.rs @@ -103,6 +103,10 @@ where DB: crate::Database, Data: Clone, { + fn ingredient_index(&self) -> IngredientIndex { + self.index + } + fn maybe_changed_after(&self, _db: &DB, _input: DependencyIndex, _revision: Revision) -> bool { panic!("nothing should ever depend on an accumulator directly") } diff --git a/components/salsa-2022/src/function.rs b/components/salsa-2022/src/function.rs index 4879a522..41b25c0a 100644 --- a/components/salsa-2022/src/function.rs +++ b/components/salsa-2022/src/function.rs @@ -213,6 +213,10 @@ where DB: ?Sized + DbWithJar, C: Configuration, { + fn ingredient_index(&self) -> IngredientIndex { + self.index + } + fn maybe_changed_after(&self, db: &DB, input: DependencyIndex, revision: Revision) -> bool { let key = C::key_from_id(input.key_index.unwrap()); let db = db.as_jar_db(); diff --git a/components/salsa-2022/src/ingredient.rs b/components/salsa-2022/src/ingredient.rs index 5d051289..dc8f2b90 100644 --- a/components/salsa-2022/src/ingredient.rs +++ b/components/salsa-2022/src/ingredient.rs @@ -2,7 +2,7 @@ use std::fmt; use crate::{ cycle::CycleRecoveryStrategy, key::DependencyIndex, runtime::local_state::QueryOrigin, - DatabaseKeyIndex, Id, + DatabaseKeyIndex, Id, IngredientIndex, }; use super::Revision; @@ -17,6 +17,9 @@ use super::Revision; /// [`IngredientsFor`](`crate::storage::IngredientsFor`) implementations generated by the /// macro. pub trait Ingredient { + /// Returns the [`IngredientIndex`] of this ingredient. + fn ingredient_index(&self) -> IngredientIndex; + /// If this ingredient is a participant in a cycle, what is its cycle recovery strategy? /// (Really only relevant to [`crate::function::FunctionIngredient`], /// since only function ingredients push themselves onto the active query stack.) diff --git a/components/salsa-2022/src/input.rs b/components/salsa-2022/src/input.rs index a1624832..6c6900c0 100644 --- a/components/salsa-2022/src/input.rs +++ b/components/salsa-2022/src/input.rs @@ -68,6 +68,10 @@ impl Ingredient for InputIngredient where Id: InputId, { + fn ingredient_index(&self) -> IngredientIndex { + self.ingredient_index + } + fn maybe_changed_after(&self, _db: &DB, _input: DependencyIndex, _revision: Revision) -> bool { // Input ingredients are just a counter, they store no data, they are immortal. // Their *fields* are stored in function ingredients elsewhere. diff --git a/components/salsa-2022/src/input_field.rs b/components/salsa-2022/src/input_field.rs index f9b4f16a..fcd9c706 100644 --- a/components/salsa-2022/src/input_field.rs +++ b/components/salsa-2022/src/input_field.rs @@ -116,6 +116,10 @@ impl Ingredient for InputFieldIngredient where K: AsId, { + fn ingredient_index(&self) -> IngredientIndex { + self.index + } + fn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy { CycleRecoveryStrategy::Panic } diff --git a/components/salsa-2022/src/interned.rs b/components/salsa-2022/src/interned.rs index 8fd00349..80d78f87 100644 --- a/components/salsa-2022/src/interned.rs +++ b/components/salsa-2022/src/interned.rs @@ -194,6 +194,10 @@ where Id: InternedId, Data: InternedData, { + fn ingredient_index(&self) -> IngredientIndex { + self.ingredient_index + } + fn maybe_changed_after(&self, _db: &DB, _input: DependencyIndex, revision: Revision) -> bool { revision < self.reset_at } diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index 8c64daa5..ac0b39c2 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -137,6 +137,10 @@ where Data: TrackedStructData, DB: crate::Database, { + fn ingredient_index(&self) -> IngredientIndex { + self.interned.ingredient_index() + } + fn maybe_changed_after(&self, db: &DB, input: DependencyIndex, revision: Revision) -> bool { self.interned.maybe_changed_after(db, input, revision) }