introduce ability to ask a table what keys it has

This commit is contained in:
Niko Matsakis 2018-10-24 04:38:30 -04:00
parent 649b1a6f99
commit 7f1d1995aa
4 changed files with 34 additions and 0 deletions

View file

@ -5,6 +5,7 @@ use crate::plumbing::QueryStorageOps;
use crate::Database;
use crate::Query;
use crate::QueryTable;
use std::iter::FromIterator;
pub trait DebugQueryTable {
type Key;
@ -13,6 +14,11 @@ pub trait DebugQueryTable {
/// **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;
/// Get the (current) set of the keys in the query table.
fn keys<C>(&self) -> C
where
C: FromIterator<Self::Key>;
}
impl<DB, Q> DebugQueryTable for QueryTable<'_, DB, Q>
@ -25,4 +31,11 @@ where
fn is_constant(&self, key: Q::Key) -> bool {
self.storage.is_constant(self.db, &key)
}
fn keys<C>(&self) -> C
where
C: FromIterator<Q::Key>,
{
self.storage.keys(self.db)
}
}

View file

@ -774,6 +774,14 @@ where
Some(QueryState::Memoized(memo)) => memo.inputs.is_constant(),
}
}
fn keys<C>(&self, _db: &DB) -> C
where
C: std::iter::FromIterator<Q::Key>,
{
let map = self.map.read();
map.keys().cloned().collect()
}
}
impl<DB, Q, MP> QueryStorageMassOps<DB> for DerivedStorage<DB, Q, MP>

View file

@ -199,6 +199,14 @@ where
.map(|v| v.changed_at.is_constant)
.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()
}
}
impl<DB, Q> QueryStorageMassOps<DB> for InputStorage<DB, Q>

View file

@ -105,6 +105,11 @@ where
/// Check if `key` is (currently) believed to be a constant.
fn is_constant(&self, db: &DB, key: &Q::Key) -> bool;
/// Check if `key` is (currently) believed to be a constant.
fn keys<C>(&self, db: &DB) -> C
where
C: std::iter::FromIterator<Q::Key>;
}
/// An optional trait that is implemented for "user mutable" storage: