mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-11-29 02:50:55 +00:00
move durability
to its own module and make part of public API
This commit is contained in:
parent
8b7808c6ae
commit
880b29a640
7 changed files with 46 additions and 25 deletions
|
@ -2,6 +2,7 @@ use crate::debug::TableEntry;
|
|||
use crate::dependency::DatabaseSlot;
|
||||
use crate::dependency::Dependency;
|
||||
use crate::derived::MemoizationPolicy;
|
||||
use crate::durability::Durability;
|
||||
use crate::lru::LruIndex;
|
||||
use crate::lru::LruNode;
|
||||
use crate::plumbing::CycleDetected;
|
||||
|
@ -9,7 +10,6 @@ use crate::plumbing::GetQueryTable;
|
|||
use crate::plumbing::HasQueryGroup;
|
||||
use crate::plumbing::QueryFunction;
|
||||
use crate::revision::Revision;
|
||||
use crate::runtime::Durability;
|
||||
use crate::runtime::FxIndexSet;
|
||||
use crate::runtime::Runtime;
|
||||
use crate::runtime::RuntimeId;
|
||||
|
|
33
src/durability.rs
Normal file
33
src/durability.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
/// Describes how likely a value is to change -- how "durable" it is.
|
||||
/// By default, inputs have `Durability::LOW` and interned values have
|
||||
/// `Durability::HIGH`. But inputs can be explicitly set with other
|
||||
/// durabilities.
|
||||
///
|
||||
/// We use durabilities to optimize the work of "revalidating" a query
|
||||
/// after some input has changed. Ordinarily, in a new revision,
|
||||
/// queries have to trace all their inputs back to the base inputs to
|
||||
/// determine if any of those inputs have changed. But if we know that
|
||||
/// the only changes were to inputs of low durability (the common
|
||||
/// case), and we know that the query only used inputs of medium
|
||||
/// durability or higher, then we can skip that enumeration.
|
||||
///
|
||||
/// Typically, one assigns low durabilites to inputs that the user is
|
||||
/// frequently editing. Medium or high durabilities are used for
|
||||
/// configuration, the source from library crates, or other things
|
||||
/// that are unlikely to be edited.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Durability(u8);
|
||||
|
||||
impl Durability {
|
||||
pub const LOW: Durability = Durability(0);
|
||||
pub const MEDIUM: Durability = Durability(1);
|
||||
pub const HIGH: Durability = Durability(2);
|
||||
|
||||
pub(crate) fn new(v: usize) -> Durability {
|
||||
Durability(v as u8)
|
||||
}
|
||||
|
||||
pub(crate) fn index(self) -> usize {
|
||||
self.0 as usize
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
use crate::debug::TableEntry;
|
||||
use crate::dependency::DatabaseSlot;
|
||||
use crate::durability::Durability;
|
||||
use crate::plumbing::CycleDetected;
|
||||
use crate::plumbing::InputQueryStorageOps;
|
||||
use crate::plumbing::QueryStorageMassOps;
|
||||
use crate::plumbing::QueryStorageOps;
|
||||
use crate::revision::Revision;
|
||||
use crate::runtime::Durability;
|
||||
use crate::runtime::StampedValue;
|
||||
use crate::Database;
|
||||
use crate::Event;
|
||||
|
@ -187,7 +187,7 @@ where
|
|||
fn set(&self, db: &DB, key: &Q::Key, database_key: &DB::DatabaseKey, value: Q::Value) {
|
||||
log::debug!("{:?}({:?}) = {:?}", Q::default(), key, value);
|
||||
|
||||
self.set_common(db, key, database_key, value, Durability::MUTABLE);
|
||||
self.set_common(db, key, database_key, value, Durability::LOW);
|
||||
}
|
||||
|
||||
fn set_constant(&self, db: &DB, key: &Q::Key, database_key: &DB::DatabaseKey, value: Q::Value) {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use crate::debug::TableEntry;
|
||||
use crate::dependency::DatabaseSlot;
|
||||
use crate::durability::Durability;
|
||||
use crate::intern_id::InternId;
|
||||
use crate::plumbing::CycleDetected;
|
||||
use crate::plumbing::HasQueryGroup;
|
||||
use crate::plumbing::QueryStorageMassOps;
|
||||
use crate::plumbing::QueryStorageOps;
|
||||
use crate::revision::Revision;
|
||||
use crate::runtime::Durability;
|
||||
use crate::Query;
|
||||
use crate::{Database, DiscardIf, SweepStrategy};
|
||||
use crossbeam::atomic::AtomicCell;
|
||||
|
@ -324,7 +324,7 @@ where
|
|||
let changed_at = slot.interned_at;
|
||||
let index = slot.index;
|
||||
db.salsa_runtime()
|
||||
.report_query_read(slot, Durability::MUTABLE, changed_at);
|
||||
.report_query_read(slot, Durability::LOW, changed_at);
|
||||
Ok(<Q::Value>::from_intern_id(index))
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ where
|
|||
let value = slot.value.clone();
|
||||
let interned_at = slot.interned_at;
|
||||
db.salsa_runtime()
|
||||
.report_query_read(slot, Durability::MUTABLE, interned_at);
|
||||
.report_query_read(slot, Durability::LOW, interned_at);
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
mod dependency;
|
||||
mod derived;
|
||||
mod doctest;
|
||||
mod durability;
|
||||
mod input;
|
||||
mod intern_id;
|
||||
mod interned;
|
||||
|
@ -33,6 +34,7 @@ use derive_new::new;
|
|||
use std::fmt::{self, Debug};
|
||||
use std::hash::Hash;
|
||||
|
||||
pub use crate::durability::Durability;
|
||||
pub use crate::intern_id::InternId;
|
||||
pub use crate::interned::InternKey;
|
||||
pub use crate::runtime::Runtime;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::dependency::DatabaseSlot;
|
||||
use crate::dependency::Dependency;
|
||||
use crate::durability::Durability;
|
||||
use crate::revision::{AtomicRevision, Revision};
|
||||
use crate::{Database, Event, EventKind, SweepStrategy};
|
||||
use lock_api::{RawRwLock, RawRwLockRecursive};
|
||||
|
@ -146,7 +147,7 @@ where
|
|||
|
||||
/// Returns the max durability, used for constants.
|
||||
pub(crate) fn max_durability(&self) -> Durability {
|
||||
Durability((self.shared_state.revisions.len() - 1) as u8)
|
||||
Durability::new(self.shared_state.revisions.len() - 1)
|
||||
}
|
||||
|
||||
/// The unique identifier attached to this `SalsaRuntime`. Each
|
||||
|
@ -594,13 +595,13 @@ impl<DB: Database> ActiveQuery<DB> {
|
|||
set.insert(dependency);
|
||||
}
|
||||
|
||||
self.durability = self.durability.and(durability);
|
||||
self.durability = self.durability.min(durability);
|
||||
self.changed_at = self.changed_at.max(revision);
|
||||
}
|
||||
|
||||
fn add_untracked_read(&mut self, changed_at: Revision) {
|
||||
self.dependencies = None;
|
||||
self.durability = Durability::MUTABLE;
|
||||
self.durability = Durability::LOW;
|
||||
self.changed_at = changed_at;
|
||||
}
|
||||
|
||||
|
@ -617,21 +618,6 @@ pub struct RuntimeId {
|
|||
counter: usize,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(crate) struct Durability(u8);
|
||||
|
||||
impl Durability {
|
||||
pub(crate) const MUTABLE: Durability = Durability(0);
|
||||
|
||||
pub(crate) fn and(self, c: Durability) -> Durability {
|
||||
self.min(c)
|
||||
}
|
||||
|
||||
fn index(self) -> usize {
|
||||
self.0 as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct StampedValue<V> {
|
||||
pub(crate) value: V,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::dependency::Dependency;
|
||||
use crate::durability::Durability;
|
||||
use crate::runtime::ActiveQuery;
|
||||
use crate::runtime::Durability;
|
||||
use crate::runtime::Revision;
|
||||
use crate::Database;
|
||||
use std::cell::Ref;
|
||||
|
|
Loading…
Reference in a new issue