add a SalsaStructInDb trait

Not currently used anywhere,
but will be implemented by all salsa structs.
This commit is contained in:
Niko Matsakis 2022-08-08 00:11:28 -04:00
parent fc5e05fae0
commit 25e085fbdc
4 changed files with 21 additions and 1 deletions

View file

@ -39,6 +39,7 @@ impl TrackedStruct {
let id_struct = self.id_struct();
let inherent_impl = self.tracked_inherent_impl();
let ingredients_for_impl = self.tracked_struct_ingredients(&config_structs);
let salsa_struct_in_db_impl = self.salsa_struct_in_db_impl();
let tracked_struct_in_db_impl = self.tracked_struct_in_db_impl();
let as_id_impl = self.as_id_impl();
Ok(quote! {
@ -46,6 +47,7 @@ impl TrackedStruct {
#id_struct
#inherent_impl
#ingredients_for_impl
#salsa_struct_in_db_impl
#tracked_struct_in_db_impl
#as_id_impl
#(#config_impls)*
@ -205,6 +207,19 @@ impl TrackedStruct {
}
}
/// Implementation of `SalsaStructInDb`.
fn salsa_struct_in_db_impl(&self) -> syn::ItemImpl {
let ident = self.id_ident();
let jar_ty = self.jar_ty();
parse_quote! {
impl<DB> salsa::salsa_struct::SalsaStructInDb<DB> for #ident
where
DB: ?Sized + salsa::DbWithJar<#jar_ty>,
{
}
}
}
/// Implementation of `TrackedStructInDb`.
fn tracked_struct_in_db_impl(&self) -> syn::ItemImpl {
let ident = self.id_ident();

View file

@ -17,6 +17,7 @@ pub mod plumbing;
pub mod revision;
pub mod routes;
pub mod runtime;
pub mod salsa_struct;
pub mod storage;
#[doc(hidden)]
pub mod tracked_struct;

View file

@ -0,0 +1,3 @@
use crate::Database;
pub trait SalsaStructInDb<DB: ?Sized + Database> {}

View file

@ -4,6 +4,7 @@ use crate::{
interned::{InternedData, InternedId, InternedIngredient},
key::{DatabaseKeyIndex, DependencyIndex},
runtime::{local_state::QueryInputs, Runtime},
salsa_struct::SalsaStructInDb,
Database, IngredientIndex, Revision,
};
@ -13,7 +14,7 @@ impl<T: InternedId> TrackedStructId for T {}
pub trait TrackedStructData: InternedData {}
impl<T: InternedData> TrackedStructData for T {}
pub trait TrackedStructInDb<DB: ?Sized + Database> {
pub trait TrackedStructInDb<DB: ?Sized + Database>: SalsaStructInDb<DB> {
fn database_key_index(self, db: &DB) -> DatabaseKeyIndex;
}