mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-24 05:42:58 +00:00
389aa66bcf
In a previous PR we added the `include_all_fields` parameter to `DebugWithDb` to allow it to not create spurious dependencies. This PR takes a different approach: we simply ignore the dependencies created during debug operations. This is risky as it can create incorrect dependencies, but it is way more convenient and seems like what users probably want. It also means that `DebugWithDb` has a simpler signature that matches the `Debug` trait again, which seems good to me.
68 lines
1.7 KiB
Rust
68 lines
1.7 KiB
Rust
use expect_test::expect;
|
|
use salsa::{Database as SalsaDatabase, DebugWithDb};
|
|
use salsa_2022_tests::{HasLogger, Logger};
|
|
|
|
#[salsa::jar(db = Db)]
|
|
struct Jar(MyInput, MyTracked, tracked_fn, tracked_fn_extra);
|
|
|
|
trait Db: salsa::DbWithJar<Jar> + HasLogger {}
|
|
|
|
#[salsa::input(jar = Jar)]
|
|
struct MyInput {
|
|
field: u32,
|
|
}
|
|
|
|
#[salsa::tracked(jar = Jar)]
|
|
struct MyTracked {
|
|
field: u32,
|
|
}
|
|
|
|
#[salsa::tracked(jar = Jar)]
|
|
fn tracked_fn(db: &dyn Db, input: MyInput) -> u32 {
|
|
db.push_log(format!("tracked_fn({:?})", input.debug(db)));
|
|
let t = MyTracked::new(db, input.field(db) * 2);
|
|
tracked_fn_extra::specify(db, t, 2222);
|
|
tracked_fn_extra(db, t)
|
|
}
|
|
|
|
#[salsa::tracked(jar = Jar, specify)]
|
|
fn tracked_fn_extra(db: &dyn Db, input: MyTracked) -> u32 {
|
|
db.push_log(format!("tracked_fn_extra({:?})", input.debug(db)));
|
|
0
|
|
}
|
|
|
|
#[salsa::db(Jar)]
|
|
#[derive(Default)]
|
|
struct Database {
|
|
storage: salsa::Storage<Self>,
|
|
logger: Logger,
|
|
}
|
|
|
|
impl salsa::Database for Database {}
|
|
|
|
impl Db for Database {}
|
|
|
|
impl HasLogger for Database {
|
|
fn logger(&self) -> &Logger {
|
|
&self.logger
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn execute() {
|
|
let mut db = Database::default();
|
|
let input = MyInput::new(&db, 22);
|
|
assert_eq!(tracked_fn(&db, input), 2222);
|
|
db.assert_logs(expect![[r#"
|
|
[
|
|
"tracked_fn(MyInput { [salsa id]: 0, field: 22 })",
|
|
]"#]]);
|
|
|
|
// A "synthetic write" causes the system to act *as though* some
|
|
// input of durability `durability` has changed.
|
|
db.synthetic_write(salsa::Durability::LOW);
|
|
|
|
// Re-run the query on the original input. Nothing re-executes!
|
|
assert_eq!(tracked_fn(&db, input), 2222);
|
|
db.assert_logs(expect!["[]"]);
|
|
}
|