allow to peek at values via debug query interface

This commit is contained in:
Aleksey Kladov 2019-01-22 23:33:22 +03:00
parent 15134a257c
commit a3bbba6187
4 changed files with 72 additions and 0 deletions

View file

@ -14,6 +14,9 @@ pub trait DebugQueryTable {
/// Key of this query.
type Key;
/// Value of this query.
type Value;
/// 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.
@ -23,6 +26,30 @@ pub trait DebugQueryTable {
fn keys<C>(&self) -> C
where
C: FromIterator<Self::Key>;
/// Get the (current) set of the entries in the query table.
fn entries<C>(&self) -> C
where
C: FromIterator<TableEntry<Self::Key, Self::Value>>;
}
/// An entry from a query table, for debugging and inspecting the table state.
pub struct TableEntry<K, V> {
/// key of the query
pub key: K,
/// value of the query, if it is stored
pub value: Option<V>,
_for_future_use: (),
}
impl<K, V> TableEntry<K, V> {
pub(crate) fn new(key: K, value: Option<V>) -> TableEntry<K, V> {
TableEntry {
key,
value,
_for_future_use: (),
}
}
}
impl<DB, Q> DebugQueryTable for QueryTable<'_, DB, Q>
@ -31,6 +58,7 @@ where
Q: Query<DB>,
{
type Key = Q::Key;
type Value = Q::Value;
fn is_constant(&self, key: Q::Key) -> bool {
self.storage.is_constant(self.db, &key)
@ -42,4 +70,11 @@ where
{
self.storage.keys(self.db)
}
fn entries<C>(&self) -> C
where
C: FromIterator<TableEntry<Self::Key, Self::Value>>,
{
self.storage.entries(self.db)
}
}

View file

@ -1,3 +1,4 @@
use crate::debug::TableEntry;
use crate::plumbing::CycleDetected;
use crate::plumbing::QueryDescriptor;
use crate::plumbing::QueryFunction;
@ -162,6 +163,13 @@ where
waiting: Default::default(),
}
}
fn value(&self) -> Option<Q::Value> {
match self {
QueryState::InProgress { .. } => None,
QueryState::Memoized(memo) => memo.value.clone(),
}
}
}
struct Memo<DB, Q>
@ -901,6 +909,16 @@ where
let map = self.map.read();
map.keys().cloned().collect()
}
fn entries<C>(&self, _db: &DB) -> C
where
C: std::iter::FromIterator<TableEntry<Q::Key, Q::Value>>,
{
let map = self.map.read();
map.iter()
.map(|(key, query_state)| TableEntry::new(key.clone(), query_state.value()))
.collect()
}
}
impl<DB, Q, MP> QueryStorageMassOps<DB> for DerivedStorage<DB, Q, MP>

View file

@ -1,3 +1,4 @@
use crate::debug::TableEntry;
use crate::plumbing::CycleDetected;
use crate::plumbing::InputQueryStorageOps;
use crate::plumbing::QueryStorageMassOps;
@ -200,6 +201,18 @@ where
let map = self.map.read();
map.keys().cloned().collect()
}
fn entries<C>(&self, _db: &DB) -> C
where
C: std::iter::FromIterator<TableEntry<Q::Key, Q::Value>>,
{
let map = self.map.read();
map.iter()
.map(|(key, stamped_value)| {
TableEntry::new(key.clone(), Some(stamped_value.value.clone()))
})
.collect()
}
}
impl<DB, Q> QueryStorageMassOps<DB> for InputStorage<DB, Q>

View file

@ -1,5 +1,6 @@
#![allow(missing_docs)]
use crate::debug::TableEntry;
use crate::Database;
use crate::Query;
use crate::QueryTable;
@ -133,6 +134,11 @@ where
fn keys<C>(&self, db: &DB) -> C
where
C: std::iter::FromIterator<Q::Key>;
/// Get the (current) set of the entries in the query storage
fn entries<C>(&self, db: &DB) -> C
where
C: std::iter::FromIterator<TableEntry<Q::Key, Q::Value>>;
}
/// An optional trait that is implemented for "user mutable" storage: