use crate::{ cycle::CycleRecoveryStrategy, ingredient::{Ingredient, IngredientRequiresReset}, key::{DatabaseKeyIndex, DependencyIndex}, runtime::{local_state::QueryOrigin, Runtime}, AsId, IngredientIndex, Revision, }; pub trait InputId: AsId {} impl InputId for T {} pub struct InputIngredient where Id: InputId, { ingredient_index: IngredientIndex, counter: u32, _phantom: std::marker::PhantomData, } impl InputIngredient where Id: InputId, { pub fn new(index: IngredientIndex) -> Self { Self { ingredient_index: index, counter: Default::default(), _phantom: std::marker::PhantomData, } } pub fn database_key_index(&self, id: Id) -> DatabaseKeyIndex { DatabaseKeyIndex { ingredient_index: self.ingredient_index, key_index: id.as_id(), } } pub fn new_input(&mut self, _runtime: &mut Runtime) -> Id { let next_id = self.counter; self.counter += 1; Id::from_id(crate::Id::from_u32(next_id)) } } impl Ingredient for InputIngredient where Id: InputId, { 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. false } fn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy { CycleRecoveryStrategy::Panic } fn origin(&self, _key_index: crate::Id) -> Option { None } fn mark_validated_output( &self, _db: &DB, executor: DatabaseKeyIndex, output_key: Option, ) { unreachable!( "mark_validated_output({:?}, {:?}): input cannot be the output of a tracked function", executor, output_key ); } fn remove_stale_output( &self, _db: &DB, executor: DatabaseKeyIndex, stale_output_key: Option, ) { unreachable!( "remove_stale_output({:?}, {:?}): input cannot be the output of a tracked function", executor, stale_output_key ); } fn reset_for_new_revision(&mut self) { panic!("unexpected call to `reset_for_new_revision`") } fn salsa_struct_deleted(&self, _db: &DB, _id: crate::Id) { panic!( "unexpected call: input ingredients do not register for salsa struct deletion events" ); } } impl IngredientRequiresReset for InputIngredient where Id: InputId, { const RESET_ON_NEW_REVISION: bool = false; }