From 59f094f5127404c4187459e15c761f194b636280 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Sun, 8 Oct 2023 20:40:52 +0200 Subject: [PATCH 1/3] 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) } From b295f5aef7dae5ca4b90fbfed065a39b145b25d7 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Sun, 8 Oct 2023 20:41:55 +0200 Subject: [PATCH 2/3] Remove unnecessary `mut` from `make_fn_return_ref` --- components/salsa-2022-macros/src/tracked_fn.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index b458332e..b15d6ae6 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -740,7 +740,7 @@ fn specify_fn( /// Given a function def tagged with `#[return_ref]`, modifies `fn_sig` so that /// it returns an `&Value` instead of `Value`. May introduce a name for the /// database lifetime if required. -fn make_fn_return_ref(mut fn_sig: &mut syn::Signature) -> syn::Result<()> { +fn make_fn_return_ref(fn_sig: &mut syn::Signature) -> syn::Result<()> { // An input should be a `&dyn Db`. // We need to ensure it has a named lifetime parameter. let (db_lifetime, _) = db_lifetime_and_ty(fn_sig)?; From d0ca81e58f57e6cea1578432328024c5c0a27245 Mon Sep 17 00:00:00 2001 From: Yoshitomo Nakanishi Date: Sun, 8 Oct 2023 21:47:01 +0200 Subject: [PATCH 3/3] Update macro test fixtures to reflect rustc diagnostics updates --- .../specify-does-not-work-if-the-key-is-a-salsa-input.stderr | 3 +++ ...specify-does-not-work-if-the-key-is-a-salsa-interned.stderr | 3 +++ 2 files changed, 6 insertions(+) diff --git a/salsa-2022-tests/tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-input.stderr b/salsa-2022-tests/tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-input.stderr index 4709cac6..84d11e22 100644 --- a/salsa-2022-tests/tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-input.stderr +++ b/salsa-2022-tests/tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-input.stderr @@ -8,6 +8,9 @@ error[E0277]: the trait bound `MyInput: TrackedStructInDb` is not satisf note: required by a bound in `function::specify::>::specify_and_record` --> $WORKSPACE/components/salsa-2022/src/function/specify.rs | + | pub fn specify_and_record<'db>(&self, db: &'db DynDb<'db, C>, key: C::Key, value: C::Value) + | ------------------ required by a bound in this associated function + | where | C::Key: TrackedStructInDb>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `function::specify::>::specify_and_record` = note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/salsa-2022-tests/tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.stderr b/salsa-2022-tests/tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.stderr index 0dbe09c6..b6efedf6 100644 --- a/salsa-2022-tests/tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.stderr +++ b/salsa-2022-tests/tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.stderr @@ -8,6 +8,9 @@ error[E0277]: the trait bound `MyInterned: TrackedStructInDb` is not sat note: required by a bound in `function::specify::>::specify_and_record` --> $WORKSPACE/components/salsa-2022/src/function/specify.rs | + | pub fn specify_and_record<'db>(&self, db: &'db DynDb<'db, C>, key: C::Key, value: C::Value) + | ------------------ required by a bound in this associated function + | where | C::Key: TrackedStructInDb>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `function::specify::>::specify_and_record` = note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)