mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-27 07:04:35 +00:00
introduce ability to ask a table what keys it has
This commit is contained in:
parent
649b1a6f99
commit
7f1d1995aa
4 changed files with 34 additions and 0 deletions
13
src/debug.rs
13
src/debug.rs
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue