mirror of
https://github.com/salsa-rs/salsa.git
synced 2024-12-04 05:29:44 +00:00
add debugging APIs -- just is_constant
for now
This commit is contained in:
parent
15faf43071
commit
16d151e4c8
4 changed files with 49 additions and 0 deletions
28
src/debug.rs
Normal file
28
src/debug.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
//! Debugging APIs: these are meant for use when unit-testing or
|
||||
//! debugging your application but aren't ordinarily needed.
|
||||
|
||||
use crate::Database;
|
||||
use crate::Query;
|
||||
use crate::QueryStorageOps;
|
||||
use crate::QueryTable;
|
||||
|
||||
pub trait DebugQueryTable {
|
||||
type Key;
|
||||
|
||||
/// True if salsa thinks that the value for `key` is a
|
||||
/// **constant**, meaning that it can never change, no matter what
|
||||
/// values the inputs take on from this point.
|
||||
fn is_constant(&self, key: Self::Key) -> bool;
|
||||
}
|
||||
|
||||
impl<DB, Q> DebugQueryTable for QueryTable<'_, DB, Q>
|
||||
where
|
||||
DB: Database,
|
||||
Q: Query<DB>,
|
||||
{
|
||||
type Key = Q::Key;
|
||||
|
||||
fn is_constant(&self, key: Q::Key) -> bool {
|
||||
self.storage.is_constant(self.db, &key)
|
||||
}
|
||||
}
|
|
@ -396,6 +396,15 @@ where
|
|||
|
||||
true
|
||||
}
|
||||
|
||||
fn is_constant(&self, _db: &DB, key: &Q::Key) -> bool {
|
||||
let map_read = self.map.read();
|
||||
match map_read.get(key) {
|
||||
None => false,
|
||||
Some(QueryState::InProgress) => panic!("query in progress"),
|
||||
Some(QueryState::Memoized(memo)) => memo.changed_at.is_constant(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB, Q, MP> UncheckedMutQueryStorageOps<DB, Q> for DerivedStorage<DB, Q, MP>
|
||||
|
|
|
@ -177,6 +177,14 @@ where
|
|||
|
||||
changed_at.changed_since(revision)
|
||||
}
|
||||
|
||||
fn is_constant(&self, _db: &DB, key: &Q::Key) -> bool {
|
||||
let map_read = self.map.read();
|
||||
map_read
|
||||
.get(key)
|
||||
.map(|v| v.changed_at.is_constant())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
||||
impl<DB, Q> InputQueryStorageOps<DB, Q> for InputStorage<DB, Q>
|
||||
|
|
|
@ -12,6 +12,7 @@ use std::fmt::Display;
|
|||
use std::fmt::Write;
|
||||
use std::hash::Hash;
|
||||
|
||||
pub mod debug;
|
||||
pub mod derived;
|
||||
pub mod input;
|
||||
pub mod runtime;
|
||||
|
@ -119,6 +120,9 @@ where
|
|||
key: &Q::Key,
|
||||
descriptor: &DB::QueryDescriptor,
|
||||
) -> bool;
|
||||
|
||||
/// Check if `key` is (currently) believed to be a constant.
|
||||
fn is_constant(&self, db: &DB, key: &Q::Key) -> bool;
|
||||
}
|
||||
|
||||
/// An optional trait that is implemented for "user mutable" storage:
|
||||
|
|
Loading…
Reference in a new issue