2018-10-01 10:47:24 +00:00
|
|
|
#![feature(crate_visibility_modifier)]
|
|
|
|
|
|
|
|
#[derive(Default)]
|
2018-10-05 08:54:51 +00:00
|
|
|
pub struct DatabaseImpl {
|
|
|
|
runtime: salsa::runtime::Runtime<DatabaseImpl>,
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-05 08:54:51 +00:00
|
|
|
impl salsa::Database for DatabaseImpl {
|
|
|
|
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<DatabaseImpl> {
|
2018-10-01 10:47:24 +00:00
|
|
|
&self.runtime
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 08:54:51 +00:00
|
|
|
salsa::database_storage! {
|
|
|
|
pub struct DatabaseImplStorage for DatabaseImpl {
|
|
|
|
impl Database {
|
2018-10-01 10:47:24 +00:00
|
|
|
fn memoized_a() for MemoizedA;
|
|
|
|
fn memoized_b() for MemoizedB;
|
|
|
|
fn volatile_a() for VolatileA;
|
|
|
|
fn volatile_b() for VolatileB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 00:42:41 +00:00
|
|
|
salsa::query_prototype! {
|
2018-10-05 08:54:51 +00:00
|
|
|
trait Database: salsa::Database {
|
2018-10-01 10:47:24 +00:00
|
|
|
// `a` and `b` depend on each other and form a cycle
|
|
|
|
fn memoized_a() for MemoizedA;
|
|
|
|
fn memoized_b() for MemoizedB;
|
|
|
|
fn volatile_a() for VolatileA;
|
|
|
|
fn volatile_b() for VolatileB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
salsa::query_definition! {
|
2018-10-05 08:54:51 +00:00
|
|
|
crate MemoizedA(db: &impl Database, (): ()) -> () {
|
|
|
|
db.memoized_b().get(())
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
salsa::query_definition! {
|
2018-10-05 08:54:51 +00:00
|
|
|
crate MemoizedB(db: &impl Database, (): ()) -> () {
|
|
|
|
db.memoized_a().get(())
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
salsa::query_definition! {
|
|
|
|
#[storage(volatile)]
|
2018-10-05 08:54:51 +00:00
|
|
|
crate VolatileA(db: &impl Database, (): ()) -> () {
|
|
|
|
db.volatile_b().get(())
|
2018-10-01 10:47:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
salsa::query_definition! {
|
|
|
|
#[storage(volatile)]
|
2018-10-05 08:54:51 +00:00
|
|
|
crate VolatileB(db: &impl Database, (): ()) -> () {
|
|
|
|
db.volatile_a().get(())
|
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-01 10:47:24 +00:00
|
|
|
query.memoized_a().get(());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[should_panic(expected = "cycle detected")]
|
|
|
|
fn cycle_volatile() {
|
2018-10-05 08:54:51 +00:00
|
|
|
let query = DatabaseImpl::default();
|
2018-10-01 10:47:24 +00:00
|
|
|
query.volatile_a().get(());
|
|
|
|
}
|