2024-10-04 19:48:11 +00:00
|
|
|
pub(crate) trait Counter: ra_salsa::Database {
|
2024-02-07 15:29:46 +00:00
|
|
|
fn increment(&self) -> usize;
|
|
|
|
}
|
|
|
|
|
2024-10-04 19:48:11 +00:00
|
|
|
#[ra_salsa::query_group(GroupStruct)]
|
2024-02-07 15:29:46 +00:00
|
|
|
pub(crate) trait Database: Counter {
|
|
|
|
fn memoized(&self) -> usize;
|
|
|
|
fn volatile(&self) -> usize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Because this query is memoized, we only increment the counter
|
|
|
|
/// the first time it is invoked.
|
|
|
|
fn memoized(db: &dyn Database) -> usize {
|
|
|
|
db.volatile()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Because this query is volatile, each time it is invoked,
|
|
|
|
/// we will increment the counter.
|
|
|
|
fn volatile(db: &dyn Database) -> usize {
|
|
|
|
db.salsa_runtime().report_untracked_read();
|
|
|
|
db.increment()
|
|
|
|
}
|