diff --git a/components/salsa-macros/src/lib.rs b/components/salsa-macros/src/lib.rs index a744473c..43d94092 100644 --- a/components/salsa-macros/src/lib.rs +++ b/components/salsa-macros/src/lib.rs @@ -7,8 +7,6 @@ extern crate proc_macro2; #[macro_use] extern crate quote; -mod hygiene; - use proc_macro::TokenStream; macro_rules! parse_quote { @@ -42,6 +40,7 @@ mod accumulator; mod db; mod db_lifetime; mod debug; +mod hygiene; mod input; mod interned; mod options; @@ -50,6 +49,7 @@ mod tracked; mod tracked_fn; mod tracked_struct; mod update; +mod xform; #[proc_macro_attribute] pub fn accumulator(args: TokenStream, input: TokenStream) -> TokenStream { diff --git a/components/salsa-macros/src/tracked_fn.rs b/components/salsa-macros/src/tracked_fn.rs index c77c4ead..31e95b30 100644 --- a/components/salsa-macros/src/tracked_fn.rs +++ b/components/salsa-macros/src/tracked_fn.rs @@ -2,7 +2,7 @@ use proc_macro2::{Span, TokenStream}; use quote::ToTokens; use syn::{spanned::Spanned, ItemFn}; -use crate::{db_lifetime, hygiene::Hygiene, options::Options}; +use crate::{db_lifetime, hygiene::Hygiene, options::Options, xform::ChangeLt}; // Source: // @@ -65,7 +65,7 @@ impl Macro { let db_lt = db_lifetime::db_lifetime(&item.sig.generics); let input_ids = self.input_ids(&item); let input_tys = self.input_tys(&item)?; - let output_ty = self.output_ty(&item)?; + let output_ty = self.output_ty(&db_lt, &item)?; let (cycle_recovery_fn, cycle_recovery_strategy) = self.cycle_recovery(); let mut inner_fn = item.clone(); @@ -293,10 +293,14 @@ impl Macro { .collect() } - fn output_ty<'item>(&self, item: &'item ItemFn) -> syn::Result { + fn output_ty<'item>( + &self, + db_lt: &syn::Lifetime, + item: &'item ItemFn, + ) -> syn::Result { match &item.sig.output { syn::ReturnType::Default => Ok(parse_quote!(())), - syn::ReturnType::Type(_, ty) => Ok(syn::Type::clone(ty)), + syn::ReturnType::Type(_, ty) => Ok(ChangeLt::elided_to(&db_lt).in_type(&ty)), } } diff --git a/components/salsa-macros/src/xform.rs b/components/salsa-macros/src/xform.rs index 9097d617..43ffa046 100644 --- a/components/salsa-macros/src/xform.rs +++ b/components/salsa-macros/src/xform.rs @@ -6,27 +6,12 @@ pub(crate) struct ChangeLt<'a> { } impl<'a> ChangeLt<'a> { - pub fn elided_to_static() -> Self { - ChangeLt { - from: Some("_"), - to: "static".to_string(), - } - } - pub fn elided_to(db_lt: &syn::Lifetime) -> Self { ChangeLt { from: Some("_"), to: db_lt.ident.to_string(), } } - - pub fn to_elided() -> Self { - ChangeLt { - from: None, - to: "_".to_string(), - } - } - pub fn in_type(mut self, ty: &syn::Type) -> syn::Type { let mut ty = ty.clone(); self.visit_type_mut(&mut ty); diff --git a/examples/calc/main.rs b/examples/calc/main.rs index 75eeab5c..4be984f8 100644 --- a/examples/calc/main.rs +++ b/examples/calc/main.rs @@ -1,30 +1,5 @@ use ir::{Diagnostics, SourceProgram}; - -// ANCHOR: jar_struct -#[salsa::jar(db = Db)] -pub struct Jar( - crate::compile::compile, - crate::ir::SourceProgram, - crate::ir::Program<'_>, - crate::ir::VariableId<'_>, - crate::ir::FunctionId<'_>, - crate::ir::Function<'_>, - crate::ir::Diagnostics, - crate::ir::Span<'_>, - crate::parser::parse_statements, - crate::type_check::type_check_program, - crate::type_check::type_check_function, - crate::type_check::find_function, -); -// ANCHOR_END: jar_struct - -// ANCHOR: jar_db -pub trait Db: salsa::DbWithJar {} -// ANCHOR_END: jar_db - -// ANCHOR: jar_db_impl -impl Db for DB where DB: ?Sized + salsa::DbWithJar {} -// ANCHOR_END: jar_db_impl +use salsa::Database as Db; mod compile; mod db; diff --git a/examples/lazy-input/main.rs b/examples/lazy-input/main.rs index ff305d5e..e9850842 100644 --- a/examples/lazy-input/main.rs +++ b/examples/lazy-input/main.rs @@ -8,7 +8,6 @@ use notify_debouncer_mini::{ notify::{RecommendedWatcher, RecursiveMode}, DebounceEventResult, Debouncer, }; -use salsa::DebugWithDb; // ANCHOR: main fn main() -> Result<()> { @@ -61,9 +60,6 @@ fn main() -> Result<()> { } // ANCHOR_END: main -#[salsa::jar(db = Db)] -struct Jar(Diagnostic, File, ParsedFile<'_>, compile, parse, sum); - // ANCHOR: db #[salsa::input] struct File { @@ -72,11 +68,12 @@ struct File { contents: String, } -trait Db: salsa::DbWithJar { +#[salsa::db] +trait Db: salsa::Database { fn input(&self, path: PathBuf) -> Result; } -#[salsa::db(Jar)] +#[salsa::db] struct Database { storage: salsa::Storage, logs: Mutex>, @@ -96,6 +93,7 @@ impl Database { } } +#[salsa::db] impl Db for Database { fn input(&self, path: PathBuf) -> Result { let path = path @@ -123,14 +121,12 @@ impl Db for Database { } // ANCHOR_END: db +#[salsa::db] impl salsa::Database for Database { fn salsa_event(&self, event: salsa::Event) { // don't log boring events if let salsa::EventKind::WillExecute { .. } = event.kind { - self.logs - .lock() - .unwrap() - .push(format!("{:?}", event.debug(self))); + self.logs.lock().unwrap().push(format!("{:?}", event)); } } }