eliminate a built-in notion of constant durability

This commit is contained in:
Niko Matsakis 2019-06-25 05:44:37 -04:00
parent ccb85989bc
commit 8b7808c6ae
4 changed files with 29 additions and 15 deletions

View file

@ -362,7 +362,7 @@ where
QueryState::NotComputed => false,
QueryState::InProgress { .. } => panic!("query in progress"),
QueryState::Memoized(memo) => {
memo.durability.is_constant() && memo.is_still_constant(db)
db.salsa_runtime().is_constant(memo.durability) && memo.is_still_constant(db)
}
}
}

View file

@ -145,9 +145,12 @@ where
Ok(value)
}
fn is_constant(&self, _db: &DB, key: &Q::Key) -> bool {
fn is_constant(&self, db: &DB, key: &Q::Key) -> bool {
self.slot(key)
.map(|slot| slot.stamped_value.read().durability.is_constant())
.map(|slot| {
db.salsa_runtime()
.is_constant(slot.stamped_value.read().durability)
})
.unwrap_or(false)
}
@ -190,7 +193,8 @@ where
fn set_constant(&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::CONSTANT);
let durability = db.salsa_runtime().max_durability();
self.set_common(db, key, database_key, value, durability);
}
}

View file

@ -139,6 +139,16 @@ where
db.for_each_query(|query_storage| query_storage.sweep(db, strategy));
}
/// True if `d` represents the max durability level.
pub(crate) fn is_constant(&self, d: Durability) -> bool {
d == self.max_durability()
}
/// Returns the max durability, used for constants.
pub(crate) fn max_durability(&self) -> Durability {
Durability((self.shared_state.revisions.len() - 1) as u8)
}
/// The unique identifier attached to this `SalsaRuntime`. Each
/// snapshotted runtime has a distinct identifier.
#[inline]
@ -324,7 +334,8 @@ where
});
// Push the active query onto the stack.
let active_query = self.local_state.push_query(database_key);
let max_durability = self.max_durability();
let active_query = self.local_state.push_query(database_key, max_durability);
// Execute user's code, accumulating inputs etc.
let value = execute();
@ -569,10 +580,10 @@ pub(crate) struct ComputedQueryResult<DB: Database, V> {
}
impl<DB: Database> ActiveQuery<DB> {
fn new(database_key: DB::DatabaseKey) -> Self {
fn new(database_key: DB::DatabaseKey, max_durability: Durability) -> Self {
ActiveQuery {
database_key,
durability: Durability::CONSTANT,
durability: max_durability,
changed_at: Revision::start(),
dependencies: Some(FxIndexSet::default()),
}
@ -611,14 +622,9 @@ pub(crate) struct Durability(u8);
impl Durability {
pub(crate) const MUTABLE: Durability = Durability(0);
pub(crate) const CONSTANT: Durability = Durability(1);
pub(crate) fn is_constant(self) -> bool {
self == Self::CONSTANT
}
pub(crate) fn and(self, c: Durability) -> Durability {
Durability(self.0 & c.0)
self.min(c)
}
fn index(self) -> usize {

View file

@ -29,9 +29,13 @@ impl<DB: Database> Default for LocalState<DB> {
}
impl<DB: Database> LocalState<DB> {
pub(super) fn push_query(&self, database_key: &DB::DatabaseKey) -> ActiveQueryGuard<'_, DB> {
pub(super) fn push_query(
&self,
database_key: &DB::DatabaseKey,
max_durability: Durability,
) -> ActiveQueryGuard<'_, DB> {
let mut query_stack = self.query_stack.borrow_mut();
query_stack.push(ActiveQuery::new(database_key.clone()));
query_stack.push(ActiveQuery::new(database_key.clone(), max_durability));
ActiveQueryGuard {
local_state: self,
push_len: query_stack.len(),