2024-02-07 15:29:46 +00:00
|
|
|
//! Test that transparent (uncached) queries work
|
|
|
|
|
2024-10-04 19:48:11 +00:00
|
|
|
#[ra_salsa::query_group(QueryGroupStorage)]
|
2024-02-07 15:29:46 +00:00
|
|
|
trait QueryGroup {
|
2024-10-04 19:48:11 +00:00
|
|
|
#[ra_salsa::input]
|
2024-02-07 15:29:46 +00:00
|
|
|
fn input(&self, x: u32) -> u32;
|
2024-10-04 19:48:11 +00:00
|
|
|
#[ra_salsa::transparent]
|
2024-02-07 15:29:46 +00:00
|
|
|
fn wrap(&self, x: u32) -> u32;
|
|
|
|
fn get(&self, x: u32) -> u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wrap(db: &dyn QueryGroup, x: u32) -> u32 {
|
|
|
|
db.input(x)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get(db: &dyn QueryGroup, x: u32) -> u32 {
|
|
|
|
db.wrap(x)
|
|
|
|
}
|
|
|
|
|
2024-10-04 19:48:11 +00:00
|
|
|
#[ra_salsa::database(QueryGroupStorage)]
|
2024-02-07 15:29:46 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
struct Database {
|
2024-10-04 19:48:11 +00:00
|
|
|
storage: ra_salsa::Storage<Self>,
|
2024-02-07 15:29:46 +00:00
|
|
|
}
|
|
|
|
|
2024-10-04 19:48:11 +00:00
|
|
|
impl ra_salsa::Database for Database {}
|
2024-02-07 15:29:46 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn transparent_queries_work() {
|
|
|
|
let mut db = Database::default();
|
|
|
|
|
|
|
|
db.set_input(1, 10);
|
|
|
|
assert_eq!(db.get(1), 10);
|
|
|
|
assert_eq!(db.get(1), 10);
|
|
|
|
|
|
|
|
db.set_input(1, 92);
|
|
|
|
assert_eq!(db.get(1), 92);
|
|
|
|
assert_eq!(db.get(1), 92);
|
|
|
|
}
|