From 9fb5f7a366ea462bce89011b4fe8fb31701ce4bf Mon Sep 17 00:00:00 2001 From: XFFXFF <1247714429@qq.com> Date: Tue, 9 Aug 2022 08:13:21 +0800 Subject: [PATCH] add some comments --- components/salsa-2022-macros/src/options.rs | 13 ++++++++----- components/salsa-2022-macros/src/tracked_fn.rs | 6 +++--- salsa-2022-tests/tests/cycles.rs | 6 ++++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/salsa-2022-macros/src/options.rs b/components/salsa-2022-macros/src/options.rs index 9d72b8dd..eb8bd937 100644 --- a/components/salsa-2022-macros/src/options.rs +++ b/components/salsa-2022-macros/src/options.rs @@ -27,22 +27,25 @@ pub(crate) struct Options { /// The `jar = ` option is used to indicate the jar; it defaults to `crate::jar`. /// - /// If this is `Some`, the value is the ``. + /// If this is `Some`, the value is the ``. pub jar_ty: Option, - /// The `db = ` option is used to indicate the db. + /// The `db = ` option is used to indicate the db. /// - /// If this is `Some`, the value is the ``. + /// If this is `Some`, the value is the ``. pub db_path: Option, + /// The `recovery_fn = ` option is used to indicate the recovery function. + /// + /// If this is `Some`, the value is the ``. + pub recovery_fn: Option, + /// The `data = ` option is used to define the name of the data type for an interned /// struct. /// /// If this is `Some`, the value is the ``. pub data: Option, - pub recovery_fn: Option, - /// Remember the `A` parameter, which plays no role after parsing. phantom: PhantomData, } diff --git a/components/salsa-2022-macros/src/tracked_fn.rs b/components/salsa-2022-macros/src/tracked_fn.rs index e52a34d8..f22dd213 100644 --- a/components/salsa-2022-macros/src/tracked_fn.rs +++ b/components/salsa-2022-macros/src/tracked_fn.rs @@ -136,9 +136,10 @@ fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration { let fn_ty = item_fn.sig.ident.clone(); - // FIXME: these are hardcoded for now let indices = (0..item_fn.sig.inputs.len() - 1).map(|i| Literal::usize_unsuffixed(i)); let (cycle_strategy, recover_fn) = if let Some(recovery_fn) = &args.recovery_fn { + // Create the `recover_from_cycle` function, which (a) maps from the interned id to the actual + // keys and then (b) invokes the recover function itself. let cycle_strategy = CycleRecoveryStrategy::Fallback; let cycle_fullback = parse_quote! { @@ -152,13 +153,12 @@ fn fn_configuration(args: &Args, item_fn: &syn::ItemFn) -> Configuration { }; (cycle_strategy, cycle_fullback) } else { + // When the `recovery_fn` attribute is not set, set `cycle_strategy` to `Panic` let cycle_strategy = CycleRecoveryStrategy::Panic; let cycle_panic = configuration::panic_cycle_recovery_fn(); (cycle_strategy, cycle_panic) }; - // let cycle_strategy = CycleRecoveryStrategy::Panic; - // let recover_fn = configuration::panic_cycle_recovery_fn(); let backdate_fn = configuration::should_backdate_value_fn(args.should_backdate()); // The type of the configuration struct; this has the same name as the fn itself. diff --git a/salsa-2022-tests/tests/cycles.rs b/salsa-2022-tests/tests/cycles.rs index 111a9685..5bd066ad 100644 --- a/salsa-2022-tests/tests/cycles.rs +++ b/salsa-2022-tests/tests/cycles.rs @@ -40,9 +40,11 @@ use salsa::storage::HasJarsDyn; // | Intra | Fallback | Both | Tracked | direct | cycle_revalidate | // | Intra | Fallback | New | Tracked | direct | cycle_appears | // | Intra | Fallback | Old | Tracked | direct | cycle_disappears | -// | Intra | Fallback | Old | Tracked | direct | cycle_disappears_durability | // | Intra | Mixed | N/A | Tracked | direct | cycle_mixed_1 | // | Intra | Mixed | N/A | Tracked | direct | cycle_mixed_2 | + +// TODO: The following tests are not yet ported. +// | Intra | Fallback | Old | Tracked | direct | cycle_disappears_durability | // | Cross | Fallback | N/A | Tracked | both | parallel/cycles.rs: recover_parallel_cycle | // | Cross | Panic | N/A | Tracked | both | parallel/cycles.rs: panic_parallel_cycle | @@ -257,7 +259,7 @@ fn cycle_recovery_unchanged_twice() { let abc = ABC::new(&mut db, CycleQuery::B, CycleQuery::A, CycleQuery::None); assert!(cycle_a(&db, abc).is_err()); - abc.set_c(&mut db, CycleQuery::A); // same value as default + abc.set_c(&mut db, CycleQuery::A); // force new revision assert!(cycle_a(&db, abc).is_err()); }