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

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

Has the value for input in this ingredient changed after revision?

What were the inputs (if any) that were used to create the value at key_index.

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.

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.

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.

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.

Implementors