diff --git a/components/salsa-2022-macros/src/accumulator.rs b/components/salsa-2022-macros/src/accumulator.rs index cfc32c9e..26276398 100644 --- a/components/salsa-2022-macros/src/accumulator.rs +++ b/components/salsa-2022-macros/src/accumulator.rs @@ -32,6 +32,8 @@ impl crate::options::AllowedOptions for Accumulator { const DB: bool = false; const RECOVERY_FN: bool = false; + + const LRU: bool = false; } fn accumulator_contents( diff --git a/components/salsa-2022-macros/src/jar.rs b/components/salsa-2022-macros/src/jar.rs index 7a6498d4..5c582abd 100644 --- a/components/salsa-2022-macros/src/jar.rs +++ b/components/salsa-2022-macros/src/jar.rs @@ -41,6 +41,8 @@ impl crate::options::AllowedOptions for Jar { const DB: bool = true; const RECOVERY_FN: bool = false; + + const LRU: bool = false; } pub(crate) fn jar_struct_and_friends( diff --git a/components/salsa-2022-macros/src/options.rs b/components/salsa-2022-macros/src/options.rs index eb8bd937..bfbd4c26 100644 --- a/components/salsa-2022-macros/src/options.rs +++ b/components/salsa-2022-macros/src/options.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use syn::{ext::IdentExt, spanned::Spanned}; +use syn::{ext::IdentExt, spanned::Spanned, LitInt}; /// "Options" are flags that can be supplied to the various salsa related /// macros. They are listed like `(ref, no_eq, foo=bar)` etc. The commas @@ -46,6 +46,8 @@ pub(crate) struct Options { /// If this is `Some`, the value is the ``. pub data: Option, + pub lru: Option, + /// Remember the `A` parameter, which plays no role after parsing. phantom: PhantomData, } @@ -61,6 +63,7 @@ impl Default for Options { recovery_fn: Default::default(), data: Default::default(), phantom: Default::default(), + lru: Default::default(), } } } @@ -74,6 +77,7 @@ pub(crate) trait AllowedOptions { const DATA: bool; const DB: bool; const RECOVERY_FN: bool; + const LRU: bool; } type Equals = syn::Token![=]; @@ -195,6 +199,19 @@ impl syn::parse::Parse for Options { "`data` option not allowed here", )); } + } else if ident == "lru" { + if A::LRU { + let _eq = Equals::parse(input)?; + let lit: LitInt = input.parse()?; + if let Some(old) = std::mem::replace(&mut options.lru, Some(lit)) { + return Err(syn::Error::new(old.span(), "option `lru` provided twice")); + } + } else { + return Err(syn::Error::new( + ident.span(), + "`lru` option not allowed here", + )); + } } else { return Err(syn::Error::new( ident.span(), diff --git a/components/salsa-2022-macros/src/salsa_struct.rs b/components/salsa-2022-macros/src/salsa_struct.rs index beb7f0d2..48e4298f 100644 --- a/components/salsa-2022-macros/src/salsa_struct.rs +++ b/components/salsa-2022-macros/src/salsa_struct.rs @@ -50,6 +50,8 @@ impl crate::options::AllowedOptions for SalsaStruct { const DB: bool = false; const RECOVERY_FN: bool = false; + + const LRU: bool = false; } const BANNED_FIELD_NAMES: &[&str] = &["from", "new"]; diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index 8c0884e1..d5bcb940 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -72,6 +72,8 @@ impl crate::options::AllowedOptions for TrackedFn { const DB: bool = false; const RECOVERY_FN: bool = true; + + const LRU: bool = true; } /// Returns the key type for this tracked function.