mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-23 13:10:19 +00:00
introduce cycle_recovery_strategy
function
Find the cycle recovery strategy for a given DatabaseKey.
This commit is contained in:
parent
853006fccf
commit
e49088644d
5 changed files with 22 additions and 2 deletions
|
@ -117,6 +117,8 @@ where
|
|||
Q: QueryFunction,
|
||||
MP: MemoizationPolicy<Q>,
|
||||
{
|
||||
const CYCLE_STRATEGY: crate::plumbing::CycleRecoveryStrategy = Q::CYCLE_STRATEGY;
|
||||
|
||||
fn new(group_index: u16) -> Self {
|
||||
DerivedStorage {
|
||||
group_index,
|
||||
|
|
|
@ -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<Q> QueryStorageOps<Q> for InputStorage<Q>
|
|||
where
|
||||
Q: Query,
|
||||
{
|
||||
const CYCLE_STRATEGY: crate::plumbing::CycleRecoveryStrategy = CycleRecoveryStrategy::Panic;
|
||||
|
||||
fn new(group_index: u16) -> Self {
|
||||
InputStorage {
|
||||
group_index,
|
||||
|
|
|
@ -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<Key = Q::Value, Value = Q::Key, Storage = InternedStorage<IQ>>,
|
||||
for<'d> Q: EqualDynDb<'d, IQ>,
|
||||
{
|
||||
const CYCLE_STRATEGY: CycleRecoveryStrategy = CycleRecoveryStrategy::Panic;
|
||||
|
||||
fn new(_group_index: u16) -> Self {
|
||||
LookupInternedStorage {
|
||||
phantom: std::marker::PhantomData,
|
||||
|
|
|
@ -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`.
|
||||
|
|
|
@ -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: &<Self as QueryDb<'_>>::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.
|
||||
|
|
Loading…
Reference in a new issue