remove debug keys in favor of entries

This commit is contained in:
Aleksey Kladov 2019-01-23 14:21:54 +03:00
parent a3bbba6187
commit a5349b8330
8 changed files with 35 additions and 60 deletions

View file

@ -22,11 +22,6 @@ pub trait DebugQueryTable {
/// values the inputs take on from this point.
fn is_constant(&self, key: Self::Key) -> bool;
/// Get the (current) set of the keys in the query table.
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
@ -34,6 +29,7 @@ pub trait DebugQueryTable {
}
/// An entry from a query table, for debugging and inspecting the table state.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct TableEntry<K, V> {
/// key of the query
pub key: K,
@ -64,13 +60,6 @@ where
self.storage.is_constant(self.db, &key)
}
fn keys<C>(&self) -> C
where
C: FromIterator<Q::Key>,
{
self.storage.keys(self.db)
}
fn entries<C>(&self) -> C
where
C: FromIterator<TableEntry<Self::Key, Self::Value>>,

View file

@ -902,14 +902,6 @@ where
}
}
fn keys<C>(&self, _db: &DB) -> C
where
C: std::iter::FromIterator<Q::Key>,
{
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>>,

View file

@ -194,14 +194,6 @@ where
.unwrap_or(false)
}
fn keys<C>(&self, _db: &DB) -> C
where
C: std::iter::FromIterator<Q::Key>,
{
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>>,

View file

@ -130,11 +130,6 @@ where
/// Check if `key` is (currently) believed to be a constant.
fn is_constant(&self, db: &DB, key: &Q::Key) -> bool;
/// Get the (current) set of the keys in the query storage
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

View file

@ -3,16 +3,6 @@ use crate::group::*;
use salsa::debug::DebugQueryTable;
use salsa::{Database, SweepStrategy};
macro_rules! assert_keys {
($db:expr, $($query:expr => ($($key:expr),*),)*) => {
$(
let mut keys = $db.query($query).keys::<Vec<_>>();
keys.sort();
assert_eq!(keys, vec![$($key),*], "query {:?} had wrong keys", $query);
)*
};
}
#[test]
fn compute_one() {
let mut db = db::DatabaseImpl::default();

View file

@ -9,7 +9,7 @@ fn sweep_default() {
db.fibonacci(5);
let k: Vec<_> = db.query(FibonacciQuery).keys();
let k: Vec<_> = db.query(FibonacciQuery).entries();
assert_eq!(k.len(), 6);
db.salsa_runtime().next_revision();
@ -20,9 +20,10 @@ fn sweep_default() {
// fibonacci is a constant, so it will not be invalidated,
// hence we keep 3 and 5 but remove the rest.
db.sweep_all(SweepStrategy::default());
let mut k: Vec<_> = db.query(FibonacciQuery).keys();
k.sort();
assert_eq!(k, vec![3, 5]);
assert_keys! {
db,
FibonacciQuery => (3, 5),
}
// Even though we ran the sweep, 5 is still in cache
db.clear_log();
@ -31,9 +32,11 @@ fn sweep_default() {
// Same but we discard values this time.
db.sweep_all(SweepStrategy::default().discard_values());
let mut k: Vec<_> = db.query(FibonacciQuery).keys();
k.sort();
assert_eq!(k, vec![3, 5]);
db.sweep_all(SweepStrategy::default());
assert_keys! {
db,
FibonacciQuery => (3, 5),
}
// Now we have to recompute
db.clear_log();

View file

@ -1,3 +1,14 @@
macro_rules! assert_keys {
($db:expr, $($query:expr => ($($key:expr),*),)*) => {
$(
let entries = $db.query($query).entries::<Vec<_>>();
let mut keys = entries.into_iter().map(|e| e.key).collect::<Vec<_>>();
keys.sort();
assert_eq!(keys, vec![$($key),*], "query {:?} had wrong keys", $query);
)*
};
}
mod db;
mod derived_tests;
mod discard_values;

View file

@ -13,7 +13,7 @@ fn one_rev() {
db.fibonacci(5);
let k: Vec<_> = db.query(FibonacciQuery).keys();
let k: Vec<_> = db.query(FibonacciQuery).entries();
assert_eq!(k.len(), 6);
// Everything was used in this revision, so
@ -28,7 +28,7 @@ fn two_rev_nothing() {
db.fibonacci(5);
let k: Vec<_> = db.query(FibonacciQuery).keys();
let k: Vec<_> = db.query(FibonacciQuery).entries();
assert_eq!(k.len(), 6);
db.salsa_runtime().next_revision();
@ -37,7 +37,7 @@ fn two_rev_nothing() {
// everything gets collected.
db.sweep_all(SweepStrategy::default());
let k: Vec<_> = db.query(FibonacciQuery).keys();
let k: Vec<_> = db.query(FibonacciQuery).entries();
assert_eq!(k.len(), 0);
}
@ -47,7 +47,7 @@ fn two_rev_one_use() {
db.fibonacci(5);
let k: Vec<_> = db.query(FibonacciQuery).keys();
let k: Vec<_> = db.query(FibonacciQuery).entries();
assert_eq!(k.len(), 6);
db.salsa_runtime().next_revision();
@ -58,8 +58,10 @@ fn two_rev_one_use() {
// hence we keep `fibonacci(5)` but remove 0..=4.
db.sweep_all(SweepStrategy::default());
let k: Vec<_> = db.query(FibonacciQuery).keys();
assert_eq!(k, vec![5]);
assert_keys! {
db,
FibonacciQuery => (5),
}
}
#[test]
@ -68,7 +70,7 @@ fn two_rev_two_uses() {
db.fibonacci(5);
let k: Vec<_> = db.query(FibonacciQuery).keys();
let k: Vec<_> = db.query(FibonacciQuery).entries();
assert_eq!(k.len(), 6);
db.salsa_runtime().next_revision();
@ -80,7 +82,8 @@ fn two_rev_two_uses() {
// hence we keep 3 and 5 but remove the rest.
db.sweep_all(SweepStrategy::default());
let mut k: Vec<_> = db.query(FibonacciQuery).keys();
k.sort();
assert_eq!(k, vec![3, 5]);
assert_keys! {
db,
FibonacciQuery => (3, 5),
}
}