mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
Merge pull request #534 from salsa-rs/fix-synthetic-write
Bump revision in `db.synthetic_write`
This commit is contained in:
commit
49524367b7
2 changed files with 76 additions and 1 deletions
|
@ -21,7 +21,9 @@ pub trait Database: DatabaseGen {
|
||||||
/// will block until that snapshot is dropped -- if that snapshot
|
/// will block until that snapshot is dropped -- if that snapshot
|
||||||
/// is owned by the current thread, this could trigger deadlock.
|
/// is owned by the current thread, this could trigger deadlock.
|
||||||
fn synthetic_write(&mut self, durability: Durability) {
|
fn synthetic_write(&mut self, durability: Durability) {
|
||||||
self.runtime_mut().report_tracked_write(durability);
|
let runtime = self.runtime_mut();
|
||||||
|
runtime.new_revision();
|
||||||
|
runtime.report_tracked_write(durability);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reports that the query depends on some state unknown to salsa.
|
/// Reports that the query depends on some state unknown to salsa.
|
||||||
|
|
73
tests/synthetic_write.rs
Normal file
73
tests/synthetic_write.rs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
//! Test that a constant `tracked` fn (has no inputs)
|
||||||
|
//! compiles and executes successfully.
|
||||||
|
#![allow(warnings)]
|
||||||
|
|
||||||
|
mod common;
|
||||||
|
|
||||||
|
use common::{HasLogger, Logger};
|
||||||
|
use expect_test::expect;
|
||||||
|
use salsa::{Database as _, Durability, Event, EventKind};
|
||||||
|
|
||||||
|
#[salsa::db]
|
||||||
|
trait Db: salsa::Database + HasLogger {}
|
||||||
|
|
||||||
|
#[salsa::input]
|
||||||
|
struct MyInput {
|
||||||
|
field: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::tracked]
|
||||||
|
fn tracked_fn(db: &dyn Db, input: MyInput) -> u32 {
|
||||||
|
input.field(db) * 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::db]
|
||||||
|
#[derive(Default)]
|
||||||
|
struct Database {
|
||||||
|
storage: salsa::Storage<Self>,
|
||||||
|
logger: Logger,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::db]
|
||||||
|
impl salsa::Database for Database {
|
||||||
|
fn salsa_event(&self, event: Event) {
|
||||||
|
if let EventKind::WillExecute { .. } | EventKind::DidValidateMemoizedValue { .. } =
|
||||||
|
event.kind
|
||||||
|
{
|
||||||
|
self.push_log(format!("{:?}", event.kind));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HasLogger for Database {
|
||||||
|
fn logger(&self) -> &Logger {
|
||||||
|
&self.logger
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[salsa::db]
|
||||||
|
impl Db for Database {}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn execute() {
|
||||||
|
let mut db = Database::default();
|
||||||
|
|
||||||
|
let input = MyInput::new(&db, 22);
|
||||||
|
assert_eq!(tracked_fn(&db, input), 44);
|
||||||
|
|
||||||
|
db.assert_logs(expect![[r#"
|
||||||
|
[
|
||||||
|
"WillExecute { database_key: tracked_fn(0) }",
|
||||||
|
]"#]]);
|
||||||
|
|
||||||
|
// Bumps the revision
|
||||||
|
db.synthetic_write(Durability::LOW);
|
||||||
|
|
||||||
|
// Query should re-run
|
||||||
|
assert_eq!(tracked_fn(&db, input), 44);
|
||||||
|
|
||||||
|
db.assert_logs(expect![[r#"
|
||||||
|
[
|
||||||
|
"DidValidateMemoizedValue { database_key: tracked_fn(0) }",
|
||||||
|
]"#]]);
|
||||||
|
}
|
Loading…
Reference in a new issue