Trait salsa_2022::ingredient::Ingredient
source · [−]pub trait Ingredient<DB: ?Sized> {
fn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy;
fn maybe_changed_after(
&self,
db: &DB,
input: DependencyIndex,
revision: Revision
) -> bool;
fn origin(&self, key_index: Id) -> Option<QueryOrigin>;
fn mark_validated_output(
&self,
db: &DB,
executor: DatabaseKeyIndex,
output_key: Option<Id>
);
fn remove_stale_output(
&self,
db: &DB,
executor: DatabaseKeyIndex,
stale_output_key: Option<Id>
);
fn salsa_struct_deleted(&self, db: &DB, id: Id);
fn reset_for_new_revision(&mut self);
fn fmt_index(&self, index: Option<Id>, fmt: &mut Formatter<'_>) -> Result;
}
Expand description
“Ingredients” are the bits of data that are stored within the database to make salsa work.
Each jar will define some number of ingredients that it requires.
Each use salsa macro (e.g., #[salsa::tracked]
, #[salsa::interned]
) adds one or more
ingredients to the jar struct that together are used to create the salsa concept.
For example, a tracked struct defines a crate::interned::InternedIngredient
to store
its identity plus crate::function::FunctionIngredient
values to store its fields.
The exact ingredients are determined by
IngredientsFor
implementations generated by the
macro.
Required Methods
sourcefn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy
fn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy
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.)
sourcefn maybe_changed_after(
&self,
db: &DB,
input: DependencyIndex,
revision: Revision
) -> bool
fn maybe_changed_after(
&self,
db: &DB,
input: DependencyIndex,
revision: Revision
) -> bool
Has the value for input
in this ingredient changed after revision
?
sourcefn origin(&self, key_index: Id) -> Option<QueryOrigin>
fn origin(&self, key_index: Id) -> Option<QueryOrigin>
What were the inputs (if any) that were used to create the value at key_index
.
sourcefn mark_validated_output(
&self,
db: &DB,
executor: DatabaseKeyIndex,
output_key: Option<Id>
)
fn mark_validated_output(
&self,
db: &DB,
executor: DatabaseKeyIndex,
output_key: Option<Id>
)
Invoked when the value output_key
should be marked as valid in the current revision.
This occurs because the value for executor
, which generated it, was marked as valid
in the current revision.
sourcefn remove_stale_output(
&self,
db: &DB,
executor: DatabaseKeyIndex,
stale_output_key: Option<Id>
)
fn remove_stale_output(
&self,
db: &DB,
executor: DatabaseKeyIndex,
stale_output_key: Option<Id>
)
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.
sourcefn salsa_struct_deleted(&self, db: &DB, id: Id)
fn salsa_struct_deleted(&self, db: &DB, id: Id)
Informs the ingredient self
that the salsa struct with id id
has been deleted.
This gives self
a chance to remove any memoized data dependent on id
.
To receive this callback, self
must register itself as a dependent function using
SalsaStructInDb::register_dependent_fn
.
sourcefn reset_for_new_revision(&mut self)
fn reset_for_new_revision(&mut self)
Invoked when a new revision is about to start.
This moment is important because it means that we have an &mut
-reference to the
database, and hence any pre-existing &
-references must have expired.
Many ingredients, given an &'db
-reference to the database,
use unsafe code to return &'db
-references to internal values.
The backing memory for those values can only be freed once an &mut
-reference to the
database is created.
Important: to actually receive resets, the ingredient must set
IngredientRequiresReset::RESET_ON_NEW_REVISION
to true.