mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-15 01:39:25 +00:00
rename Ingredients to Routes
The old name makes it sound like it contains the actual ingredients, but really it just contains the routes we use to find them at runtime.
This commit is contained in:
parent
00d95436e0
commit
9229b1a23a
11 changed files with 36 additions and 36 deletions
|
@ -112,11 +112,11 @@ fn ingredients_for_impl(args: &Args, struct_ty: &syn::Type, data_ty: &syn::Type)
|
|||
type Ingredients = salsa::accumulator::AccumulatorIngredient<#data_ty>;
|
||||
type Jar = #jar_ty;
|
||||
|
||||
fn create_ingredients<DB>(ingredients: &mut salsa::routes::Ingredients<DB>) -> Self::Ingredients
|
||||
fn create_ingredients<DB>(routes: &mut salsa::routes::Routes<DB>) -> Self::Ingredients
|
||||
where
|
||||
DB: salsa::DbWithJar<Self::Jar> + salsa::storage::JarFromJars<Self::Jar>,
|
||||
{
|
||||
let index = ingredients.push_mut(
|
||||
let index = routes.push_mut(
|
||||
|jars| {
|
||||
let jar = <DB as salsa::storage::JarFromJars<Self::Jar>>::jar_from_jars(jars);
|
||||
<_ as salsa::storage::HasIngredientsFor<Self>>::ingredient(jar)
|
||||
|
|
|
@ -97,10 +97,10 @@ fn has_jars_impl(args: &Args, input: &syn::ItemStruct, storage: &syn::Ident) ->
|
|||
self.#storage.jars_mut()
|
||||
}
|
||||
|
||||
fn create_jars(ingredients: &mut salsa::routes::Ingredients<Self>) -> Self::Jars {
|
||||
fn create_jars(routes: &mut salsa::routes::Routes<Self>) -> Self::Jars {
|
||||
(
|
||||
#(
|
||||
<#jar_paths as salsa::jar::Jar>::create_jar(ingredients),
|
||||
<#jar_paths as salsa::jar::Jar>::create_jar(routes),
|
||||
)*
|
||||
)
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ impl SalsaStruct {
|
|||
);
|
||||
|
||||
fn create_ingredients<DB>(
|
||||
ingredients: &mut salsa::routes::Ingredients<DB>,
|
||||
routes: &mut salsa::routes::Routes<DB>,
|
||||
) -> Self::Ingredients
|
||||
where
|
||||
DB: salsa::DbWithJar<Self::Jar> + salsa::storage::JarFromJars<Self::Jar>,
|
||||
|
@ -141,7 +141,7 @@ impl SalsaStruct {
|
|||
(
|
||||
#(
|
||||
{
|
||||
let index = ingredients.push(
|
||||
let index = routes.push(
|
||||
|jars| {
|
||||
let jar = <DB as salsa::storage::JarFromJars<Self::Jar>>::jar_from_jars(jars);
|
||||
let ingredients = <_ as salsa::storage::HasIngredientsFor<Self>>::ingredient(jar);
|
||||
|
@ -152,7 +152,7 @@ impl SalsaStruct {
|
|||
},
|
||||
)*
|
||||
{
|
||||
let index = ingredients.push(
|
||||
let index = routes.push(
|
||||
|jars| {
|
||||
let jar = <DB as salsa::storage::JarFromJars<Self::Jar>>::jar_from_jars(jars);
|
||||
let ingredients = <_ as salsa::storage::HasIngredientsFor<Self>>::ingredient(jar);
|
||||
|
|
|
@ -114,12 +114,12 @@ impl SalsaStruct {
|
|||
type Ingredients = salsa::interned::InternedIngredient<#id_ident, #data_ident>;
|
||||
|
||||
fn create_ingredients<DB>(
|
||||
ingredients: &mut salsa::routes::Ingredients<DB>,
|
||||
routes: &mut salsa::routes::Routes<DB>,
|
||||
) -> Self::Ingredients
|
||||
where
|
||||
DB: salsa::storage::JarFromJars<Self::Jar>,
|
||||
{
|
||||
let index = ingredients.push(
|
||||
let index = routes.push(
|
||||
|jars| {
|
||||
let jar = <DB as salsa::storage::JarFromJars<Self::Jar>>::jar_from_jars(jars);
|
||||
<_ as salsa::storage::HasIngredientsFor<Self>>::ingredient(jar)
|
||||
|
|
|
@ -106,12 +106,12 @@ pub(crate) fn jar_impl(
|
|||
impl<'salsa_db> salsa::jar::Jar<'salsa_db> for #jar_struct {
|
||||
type DynDb = dyn #jar_trait + 'salsa_db;
|
||||
|
||||
fn create_jar<DB>(ingredients: &mut salsa::routes::Ingredients<DB>) -> Self
|
||||
fn create_jar<DB>(routes: &mut salsa::routes::Routes<DB>) -> Self
|
||||
where
|
||||
DB: salsa::storage::JarFromJars<Self> + salsa::storage::DbWithJar<Self>,
|
||||
{
|
||||
#(
|
||||
let #field_var_names = <#field_tys as salsa::storage::IngredientsFor>::create_ingredients(ingredients);
|
||||
let #field_var_names = <#field_tys as salsa::storage::IngredientsFor>::create_ingredients(routes);
|
||||
)*
|
||||
Self(#(#field_var_names),*)
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ fn ingredients_for_impl(
|
|||
let intern_map: syn::Expr = if requires_interning(item_fn) {
|
||||
parse_quote! {
|
||||
{
|
||||
let index = ingredients.push(|jars| {
|
||||
let index = routes.push(|jars| {
|
||||
let jar = <DB as salsa::storage::JarFromJars<Self::Jar>>::jar_from_jars(jars);
|
||||
let ingredients =
|
||||
<_ as salsa::storage::HasIngredientsFor<Self::Ingredients>>::ingredient(jar);
|
||||
|
@ -226,7 +226,7 @@ fn ingredients_for_impl(
|
|||
type Ingredients = Self;
|
||||
type Jar = #jar_ty;
|
||||
|
||||
fn create_ingredients<DB>(ingredients: &mut salsa::routes::Ingredients<DB>) -> Self::Ingredients
|
||||
fn create_ingredients<DB>(routes: &mut salsa::routes::Routes<DB>) -> Self::Ingredients
|
||||
where
|
||||
DB: salsa::DbWithJar<Self::Jar> + salsa::storage::JarFromJars<Self::Jar>,
|
||||
{
|
||||
|
@ -234,7 +234,7 @@ fn ingredients_for_impl(
|
|||
intern_map: #intern_map,
|
||||
|
||||
function: {
|
||||
let index = ingredients.push(|jars| {
|
||||
let index = routes.push(|jars| {
|
||||
let jar = <DB as salsa::storage::JarFromJars<Self::Jar>>::jar_from_jars(jars);
|
||||
let ingredients =
|
||||
<_ as salsa::storage::HasIngredientsFor<Self::Ingredients>>::ingredient(jar);
|
||||
|
|
|
@ -154,7 +154,7 @@ impl SalsaStruct {
|
|||
);
|
||||
|
||||
fn create_ingredients<DB>(
|
||||
ingredients: &mut salsa::routes::Ingredients<DB>,
|
||||
routes: &mut salsa::routes::Routes<DB>,
|
||||
) -> Self::Ingredients
|
||||
where
|
||||
DB: salsa::DbWithJar<Self::Jar> + salsa::storage::JarFromJars<Self::Jar>,
|
||||
|
@ -162,7 +162,7 @@ impl SalsaStruct {
|
|||
(
|
||||
#(
|
||||
{
|
||||
let index = ingredients.push(
|
||||
let index = routes.push(
|
||||
|jars| {
|
||||
let jar = <DB as salsa::storage::JarFromJars<Self::Jar>>::jar_from_jars(jars);
|
||||
let ingredients = <_ as salsa::storage::HasIngredientsFor<Self>>::ingredient(jar);
|
||||
|
@ -173,7 +173,7 @@ impl SalsaStruct {
|
|||
},
|
||||
)*
|
||||
{
|
||||
let index = ingredients.push_mut(
|
||||
let index = routes.push_mut(
|
||||
|jars| {
|
||||
let jar = <DB as salsa::storage::JarFromJars<Self::Jar>>::jar_from_jars(jars);
|
||||
let ingredients = <_ as salsa::storage::HasIngredientsFor<Self>>::ingredient(jar);
|
||||
|
|
|
@ -26,7 +26,7 @@ pub trait Ingredient<DB: ?Sized> {
|
|||
|
||||
/// Optional trait for ingredients that wish to be notified when new revisions are
|
||||
/// about to occur. If ingredients wish to receive these method calls,
|
||||
/// they need to indicate that by invoking [`Ingredients::push_mut`] during initialization.
|
||||
/// they need to indicate that by invoking [`Routes::push_mut`] during initialization.
|
||||
pub trait MutIngredient<DB: ?Sized>: Ingredient<DB> {
|
||||
/// Invoked when a new revision is about to start. This gives ingredients
|
||||
/// a chance to flush data and so forth.
|
||||
|
|
|
@ -3,12 +3,12 @@ use crate::{
|
|||
Database, DbWithJar,
|
||||
};
|
||||
|
||||
use super::routes::Ingredients;
|
||||
use super::routes::Routes;
|
||||
|
||||
pub trait Jar<'db>: Sized {
|
||||
type DynDb: ?Sized + HasJar<Self> + Database + 'db;
|
||||
|
||||
fn create_jar<DB>(ingredients: &mut Ingredients<DB>) -> Self
|
||||
fn create_jar<DB>(routes: &mut Routes<DB>) -> Self
|
||||
where
|
||||
DB: JarFromJars<Self> + DbWithJar<Self>;
|
||||
}
|
||||
|
|
|
@ -41,14 +41,14 @@ pub type DynRoute<DB: HasJars> = dyn Fn(&DB::Jars) -> (&dyn Ingredient<DB>) + Se
|
|||
pub type DynMutRoute<DB: HasJars> =
|
||||
dyn Fn(&mut DB::Jars) -> (&mut dyn MutIngredient<DB>) + Send + Sync;
|
||||
|
||||
/// The "ingredients" structure is used to navigate the database.
|
||||
/// The "routes" structure is used to navigate the database.
|
||||
/// The database contains a number of jars, and each jar contains a number of ingredients.
|
||||
/// When the database is created, it creates each jar in turn.
|
||||
/// Each jar then creates its ingredients.
|
||||
/// Each ingredient is registered with the database by invoking the [`Ingredients::push`] method.
|
||||
/// Each ingredient is registered with the database by invoking the [`Routes::push`] method.
|
||||
/// This method assigns it a unique [`IngredientIndex`] and stores some callbacks indicating
|
||||
/// how to find the ingredient later based only on the index.
|
||||
pub struct Ingredients<DB: HasJars> {
|
||||
pub struct Routes<DB: HasJars> {
|
||||
/// Vector indexed by ingredient index. Yields the `DynRoute`,
|
||||
/// a function which can be applied to the `DB::Jars` to yield
|
||||
/// the `dyn Ingredient.
|
||||
|
@ -61,10 +61,10 @@ pub struct Ingredients<DB: HasJars> {
|
|||
mut_routes: Vec<Box<DynMutRoute<DB>>>,
|
||||
}
|
||||
|
||||
impl<DB: HasJars> Ingredients<DB> {
|
||||
impl<DB: HasJars> Routes<DB> {
|
||||
/// Construct an empty ingredients listing.
|
||||
pub(super) fn new() -> Self {
|
||||
Ingredients {
|
||||
Routes {
|
||||
routes: vec![],
|
||||
mut_routes: vec![],
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::runtime::local_state::QueryInputs;
|
|||
use crate::runtime::Runtime;
|
||||
use crate::{Database, DatabaseKeyIndex, IngredientIndex};
|
||||
|
||||
use super::routes::Ingredients;
|
||||
use super::routes::Routes;
|
||||
use super::{ParallelDatabase, Revision};
|
||||
|
||||
/// The "storage" struct stores all the data for the jars.
|
||||
|
@ -22,7 +22,7 @@ pub struct Storage<DB: HasJars> {
|
|||
/// The "ingredients" structure stores the information about how to find each ingredient in the database.
|
||||
/// It allows us to take the [`IngredientIndex`] assigned to a particular ingredient
|
||||
/// and get back a [`dyn Ingredient`][`Ingredient`] for the struct that stores its data.
|
||||
ingredients: Arc<Ingredients<DB>>,
|
||||
routes: Arc<Routes<DB>>,
|
||||
|
||||
/// The runtime for this particular salsa database handle.
|
||||
/// Each handle gets its own runtime, but the runtimes have shared state between them.s
|
||||
|
@ -48,14 +48,14 @@ where
|
|||
DB: HasJars,
|
||||
{
|
||||
fn default() -> Self {
|
||||
let mut ingredients = Ingredients::new();
|
||||
let jars = DB::create_jars(&mut ingredients);
|
||||
let mut routes = Routes::new();
|
||||
let jars = DB::create_jars(&mut routes);
|
||||
Self {
|
||||
shared: Arc::new(Shared {
|
||||
jars,
|
||||
cvar: Default::default(),
|
||||
}),
|
||||
ingredients: Arc::new(ingredients),
|
||||
routes: Arc::new(routes),
|
||||
runtime: Runtime::default(),
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ where
|
|||
{
|
||||
Self {
|
||||
shared: self.shared.clone(),
|
||||
ingredients: self.ingredients.clone(),
|
||||
routes: self.routes.clone(),
|
||||
runtime: self.runtime.snapshot(),
|
||||
}
|
||||
}
|
||||
|
@ -92,9 +92,9 @@ where
|
|||
self.cancel_other_workers();
|
||||
self.runtime.new_revision();
|
||||
|
||||
let ingredients = self.ingredients.clone();
|
||||
let routes = self.routes.clone();
|
||||
let shared = Arc::get_mut(&mut self.shared).unwrap();
|
||||
for route in ingredients.mut_routes() {
|
||||
for route in routes.mut_routes() {
|
||||
route(&mut shared.jars).reset_for_new_revision();
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ where
|
|||
}
|
||||
|
||||
pub fn ingredient(&self, ingredient_index: IngredientIndex) -> &dyn Ingredient<DB> {
|
||||
let route = self.ingredients.route(ingredient_index);
|
||||
let route = self.routes.route(ingredient_index);
|
||||
route(&self.shared.jars)
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ pub trait HasJars: HasJarsDyn + Sized {
|
|||
/// and it will also cancel any ongoing work in the current revision.
|
||||
fn jars_mut(&mut self) -> (&mut Self::Jars, &mut Runtime);
|
||||
|
||||
fn create_jars(ingredients: &mut Ingredients<Self>) -> Self::Jars;
|
||||
fn create_jars(routes: &mut Routes<Self>) -> Self::Jars;
|
||||
}
|
||||
|
||||
pub trait DbWithJar<J>: HasJar<J> + Database {
|
||||
|
@ -193,7 +193,7 @@ pub trait IngredientsFor {
|
|||
type Jar;
|
||||
type Ingredients;
|
||||
|
||||
fn create_ingredients<DB>(ingredients: &mut Ingredients<DB>) -> Self::Ingredients
|
||||
fn create_ingredients<DB>(routes: &mut Routes<DB>) -> Self::Ingredients
|
||||
where
|
||||
DB: DbWithJar<Self::Jar> + JarFromJars<Self::Jar>;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue