2019-01-25 15:25:17 +00:00
|
|
|
#[salsa::database(GroupStruct)]
|
2018-10-01 10:47:24 +00:00
|
|
|
#[derive(Default)]
|
2019-01-23 02:53:06 +00:00
|
|
|
struct DatabaseImpl {
|
2018-10-07 11:08:22 +00:00
|
|
|
runtime: salsa::Runtime<DatabaseImpl>,
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 08:54:51 +00:00
|
|
|
impl salsa::Database for DatabaseImpl {
|
2018-10-07 11:08:22 +00:00
|
|
|
fn salsa_runtime(&self) -> &salsa::Runtime<DatabaseImpl> {
|
2018-10-01 10:47:24 +00:00
|
|
|
&self.runtime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-25 15:25:17 +00:00
|
|
|
#[salsa::query_group(GroupStruct)]
|
2019-01-12 10:11:59 +00:00
|
|
|
trait Database: salsa::Database {
|
|
|
|
// `a` and `b` depend on each other and form a cycle
|
|
|
|
fn memoized_a(&self) -> ();
|
|
|
|
fn memoized_b(&self) -> ();
|
|
|
|
fn volatile_a(&self) -> ();
|
|
|
|
fn volatile_b(&self) -> ();
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 01:26:48 +00:00
|
|
|
fn memoized_a(db: &impl Database) -> () {
|
|
|
|
db.memoized_b()
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 01:26:48 +00:00
|
|
|
fn memoized_b(db: &impl Database) -> () {
|
|
|
|
db.memoized_a()
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 01:26:48 +00:00
|
|
|
fn volatile_a(db: &impl Database) -> () {
|
2019-06-19 16:59:03 +00:00
|
|
|
db.salsa_runtime().report_untracked_read();
|
2018-10-19 01:26:48 +00:00
|
|
|
db.volatile_b()
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-19 01:26:48 +00:00
|
|
|
fn volatile_b(db: &impl Database) -> () {
|
2019-06-19 16:59:03 +00:00
|
|
|
db.salsa_runtime().report_untracked_read();
|
2018-10-19 01:26:48 +00:00
|
|
|
db.volatile_a()
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic(expected = "cycle detected")]
|
|
|
|
fn cycle_memoized() {
|
2018-10-05 08:54:51 +00:00
|
|
|
let query = DatabaseImpl::default();
|
2018-10-19 01:26:48 +00:00
|
|
|
query.memoized_a();
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic(expected = "cycle detected")]
|
|
|
|
fn cycle_volatile() {
|
2018-10-05 08:54:51 +00:00
|
|
|
let query = DatabaseImpl::default();
|
2018-10-19 01:26:48 +00:00
|
|
|
query.volatile_a();
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|