add debugging APIs -- just is_constant for now

This commit is contained in:
Niko Matsakis 2018-10-11 04:37:29 -04:00
parent 15faf43071
commit 16d151e4c8
4 changed files with 49 additions and 0 deletions

28
src/debug.rs Normal file
View 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)
}
}

View file

@ -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>

View file

@ -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>

View file

@ -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: