2018-10-09 19:34:30 +00:00
|
|
|
pub(crate) trait Counter: salsa::Database {
|
2018-09-29 08:50:08 +00:00
|
|
|
fn increment(&self) -> usize;
|
|
|
|
}
|
|
|
|
|
2019-01-25 15:25:17 +00:00
|
|
|
#[salsa::query_group(GroupStruct)]
|
2019-01-12 10:11:59 +00:00
|
|
|
pub(crate) trait Database: Counter {
|
|
|
|
fn memoized(&self) -> usize;
|
|
|
|
fn volatile(&self) -> usize;
|
2018-09-29 08:50:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 09:51:18 +00:00
|
|
|
/// Because this query is memoized, we only increment the counter
|
|
|
|
/// the first time it is invoked.
|
2020-07-03 10:46:00 +00:00
|
|
|
fn memoized(db: &dyn Database) -> usize {
|
2018-10-19 01:26:48 +00:00
|
|
|
db.volatile()
|
2018-09-29 08:50:08 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 09:51:18 +00:00
|
|
|
/// Because this query is volatile, each time it is invoked,
|
|
|
|
/// we will increment the counter.
|
2020-07-03 10:46:00 +00:00
|
|
|
fn volatile(db: &dyn Database) -> usize {
|
2019-06-19 16:59:03 +00:00
|
|
|
db.salsa_runtime().report_untracked_read();
|
2018-10-05 14:30:17 +00:00
|
|
|
db.increment()
|
2018-09-29 08:50:08 +00:00
|
|
|
}
|