diff --git a/components/salsa-2022-macros/src/tracked_struct.rs b/components/salsa-2022-macros/src/tracked_struct.rs index 03621e00..273b4be7 100644 --- a/components/salsa-2022-macros/src/tracked_struct.rs +++ b/components/salsa-2022-macros/src/tracked_struct.rs @@ -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 salsa::salsa_struct::SalsaStructInDb 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(); diff --git a/components/salsa-2022/src/lib.rs b/components/salsa-2022/src/lib.rs index 4aeca354..fe903c1a 100644 --- a/components/salsa-2022/src/lib.rs +++ b/components/salsa-2022/src/lib.rs @@ -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; diff --git a/components/salsa-2022/src/salsa_struct.rs b/components/salsa-2022/src/salsa_struct.rs new file mode 100644 index 00000000..62a7a84b --- /dev/null +++ b/components/salsa-2022/src/salsa_struct.rs @@ -0,0 +1,3 @@ +use crate::Database; + +pub trait SalsaStructInDb {} diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index 8f6a820f..939f3749 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -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 TrackedStructId for T {} pub trait TrackedStructData: InternedData {} impl TrackedStructData for T {} -pub trait TrackedStructInDb { +pub trait TrackedStructInDb: SalsaStructInDb { fn database_key_index(self, db: &DB) -> DatabaseKeyIndex; }