parse the lru option

This commit is contained in:
XFFXFF 2022-08-16 07:39:08 +08:00
parent 2778750fdf
commit 2d59df39af
5 changed files with 26 additions and 1 deletions

View file

@ -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(

View file

@ -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(

View file

@ -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<A: AllowedOptions> {
/// If this is `Some`, the value is the `<ident>`.
pub data: Option<syn::Ident>,
pub lru: Option<syn::LitInt>,
/// Remember the `A` parameter, which plays no role after parsing.
phantom: PhantomData<A>,
}
@ -61,6 +63,7 @@ impl<A: AllowedOptions> Default for Options<A> {
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<A: AllowedOptions> syn::parse::Parse for Options<A> {
"`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(),

View file

@ -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"];

View file

@ -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.