Skip to content

Commit

Permalink
Merge pull request #461 from Y-Nak/provide-access-to-ingredient-index
Browse files Browse the repository at this point in the history
Provide a public API to obtain `IngredientIndex`
  • Loading branch information
nikomatsakis authored Nov 9, 2023
2 parents 143cd8a + d0ca81e commit 703794b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/salsa-2022-macros/src/tracked_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
4 changes: 4 additions & 0 deletions components/salsa-2022/src/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
4 changes: 4 additions & 0 deletions components/salsa-2022/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ where
DB: ?Sized + DbWithJar<C::Jar>,
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();
Expand Down
5 changes: 4 additions & 1 deletion components/salsa-2022/src/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +17,9 @@ use super::Revision;
/// [`IngredientsFor`](`crate::storage::IngredientsFor`) implementations generated by the
/// macro.
pub trait Ingredient<DB: ?Sized> {
/// 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.)
Expand Down
4 changes: 4 additions & 0 deletions components/salsa-2022/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ impl<DB: ?Sized, Id> Ingredient<DB> for InputIngredient<Id>
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.
Expand Down
4 changes: 4 additions & 0 deletions components/salsa-2022/src/input_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ impl<DB: ?Sized, K, F> Ingredient<DB> for InputFieldIngredient<K, F>
where
K: AsId,
{
fn ingredient_index(&self) -> IngredientIndex {
self.index
}

fn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy {
CycleRecoveryStrategy::Panic
}
Expand Down
4 changes: 4 additions & 0 deletions components/salsa-2022/src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions components/salsa-2022/src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ error[E0277]: the trait bound `MyInput: TrackedStructInDb<dyn Db>` is not satisf
note: required by a bound in `function::specify::<impl FunctionIngredient<C>>::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<DynDb<'db, C>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `function::specify::<impl FunctionIngredient<C>>::specify_and_record`
= note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ error[E0277]: the trait bound `MyInterned: TrackedStructInDb<dyn Db>` is not sat
note: required by a bound in `function::specify::<impl FunctionIngredient<C>>::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<DynDb<'db, C>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `function::specify::<impl FunctionIngredient<C>>::specify_and_record`
= note: this error originates in the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit 703794b

Please sign in to comment.