From e49088644d9c83a39c794d92bddec316cb987c63 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 25 Oct 2021 05:09:53 -0400 Subject: [PATCH] introduce `cycle_recovery_strategy` function Find the cycle recovery strategy for a given DatabaseKey. --- src/derived.rs | 2 ++ src/input.rs | 3 +++ src/interned.rs | 5 +++++ src/lib.rs | 5 +++++ src/plumbing.rs | 9 +++++++-- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/derived.rs b/src/derived.rs index 3d144fad..93e0382b 100644 --- a/src/derived.rs +++ b/src/derived.rs @@ -117,6 +117,8 @@ where Q: QueryFunction, MP: MemoizationPolicy, { + const CYCLE_STRATEGY: crate::plumbing::CycleRecoveryStrategy = Q::CYCLE_STRATEGY; + fn new(group_index: u16) -> Self { DerivedStorage { group_index, diff --git a/src/input.rs b/src/input.rs index dea49843..b27c37ee 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,5 +1,6 @@ use crate::debug::TableEntry; use crate::durability::Durability; +use crate::plumbing::CycleRecoveryStrategy; use crate::plumbing::InputQueryStorageOps; use crate::plumbing::QueryStorageMassOps; use crate::plumbing::QueryStorageOps; @@ -56,6 +57,8 @@ impl QueryStorageOps for InputStorage where Q: Query, { + const CYCLE_STRATEGY: crate::plumbing::CycleRecoveryStrategy = CycleRecoveryStrategy::Panic; + fn new(group_index: u16) -> Self { InputStorage { group_index, diff --git a/src/interned.rs b/src/interned.rs index 6ad59998..5f3e251f 100644 --- a/src/interned.rs +++ b/src/interned.rs @@ -1,6 +1,7 @@ use crate::debug::TableEntry; use crate::durability::Durability; use crate::intern_id::InternId; +use crate::plumbing::CycleRecoveryStrategy; use crate::plumbing::HasQueryGroup; use crate::plumbing::QueryStorageMassOps; use crate::plumbing::QueryStorageOps; @@ -191,6 +192,8 @@ where Q: Query, Q::Value: InternKey, { + const CYCLE_STRATEGY: crate::plumbing::CycleRecoveryStrategy = CycleRecoveryStrategy::Panic; + fn new(group_index: u16) -> Self { InternedStorage { group_index, @@ -312,6 +315,8 @@ where IQ: Query>, for<'d> Q: EqualDynDb<'d, IQ>, { + const CYCLE_STRATEGY: CycleRecoveryStrategy = CycleRecoveryStrategy::Panic; + fn new(_group_index: u16) -> Self { LookupInternedStorage { phantom: std::marker::PhantomData, diff --git a/src/lib.rs b/src/lib.rs index 45246eb6..76064973 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -438,6 +438,11 @@ where { self.storage.purge(); } + + #[allow(dead_code)] // FIXME + pub(crate) fn cycle_recovery_strategy(&self) -> plumbing::CycleRecoveryStrategy { + Q::Storage::CYCLE_STRATEGY + } } /// Return value from [the `query_mut` method] on `Database`. diff --git a/src/plumbing.rs b/src/plumbing.rs index 237852fe..edd06b27 100644 --- a/src/plumbing.rs +++ b/src/plumbing.rs @@ -70,8 +70,7 @@ pub trait QueryStorageMassOps { pub trait DatabaseKey: Clone + Debug + Eq + Hash {} pub trait QueryFunction: Query { - /// Cycle recovery strategy: Is this query capable of recovering from - /// a cycle that results from executing the function? If so, how? + /// See `CycleRecoveryStrategy` const CYCLE_STRATEGY: CycleRecoveryStrategy; fn execute(db: &>::DynDb, key: Self::Key) -> Self::Value; @@ -86,6 +85,8 @@ pub trait QueryFunction: Query { } } +/// Cycle recovery strategy: Is this query capable of recovering from +/// a cycle that results from executing the function? If so, how? pub enum CycleRecoveryStrategy { /// Cannot recover from cycles: panic. /// @@ -98,6 +99,7 @@ pub enum CycleRecoveryStrategy { Panic, /// Recovers from cycles by storing a sentinel value. + /// /// This value is computed by the `QueryFunction::cycle_fallback` /// function. Fallback, @@ -148,6 +150,9 @@ where Self: QueryStorageMassOps, Q: Query, { + /// See CycleRecoveryStrategy + const CYCLE_STRATEGY: CycleRecoveryStrategy; + fn new(group_index: u16) -> Self; /// Format a database key index in a suitable way.