Merge pull request #461 from Y-Nak/provide-access-to-ingredient-index

Provide a public API to obtain `IngredientIndex`
This commit is contained in:
Niko Matsakis 2023-11-09 10:21:37 +00:00 committed by GitHub
commit 703794b1c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 2 deletions

View file

@ -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)?;

View file

@ -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")
}

View file

@ -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();

View file

@ -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<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.)

View file

@ -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.

View file

@ -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
}

View file

@ -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
}

View file

@ -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)
}

View file

@ -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)

View file

@ -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)