Remove ops_salsa_runtime_mut, replace it with direct synthetic_write API
This commit is contained in:
parent
543d7e98db
commit
f89d17b426
@ -17,7 +17,7 @@ impl RootDatabase {
|
|||||||
pub fn request_cancellation(&mut self) {
|
pub fn request_cancellation(&mut self) {
|
||||||
let _p =
|
let _p =
|
||||||
tracing::span!(tracing::Level::INFO, "RootDatabase::request_cancellation").entered();
|
tracing::span!(tracing::Level::INFO, "RootDatabase::request_cancellation").entered();
|
||||||
self.salsa_runtime_mut().synthetic_write(Durability::LOW);
|
self.synthetic_write(Durability::LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_change(&mut self, change: Change) {
|
pub fn apply_change(&mut self, change: Change) {
|
||||||
|
@ -154,8 +154,8 @@ fn ops_salsa_runtime(&self) -> &salsa::Runtime {
|
|||||||
self.#db_storage_field.salsa_runtime()
|
self.#db_storage_field.salsa_runtime()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ops_salsa_runtime_mut(&mut self) -> &mut salsa::Runtime {
|
fn synthetic_write(&mut self, durability: salsa::Durability) {
|
||||||
self.#db_storage_field.salsa_runtime_mut()
|
self.#db_storage_field.salsa_runtime_mut().synthetic_write(durability)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fmt_index(
|
fn fmt_index(
|
||||||
|
@ -96,11 +96,16 @@ fn salsa_runtime(&self) -> &Runtime {
|
|||||||
self.ops_salsa_runtime()
|
self.ops_salsa_runtime()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gives access to the underlying salsa runtime.
|
/// A "synthetic write" causes the system to act *as though* some
|
||||||
|
/// input of durability `durability` has changed. This is mostly
|
||||||
|
/// useful for profiling scenarios.
|
||||||
///
|
///
|
||||||
/// This method should not be overridden by `Database` implementors.
|
/// **WARNING:** Just like an ordinary write, this method triggers
|
||||||
fn salsa_runtime_mut(&mut self) -> &mut Runtime {
|
/// cancellation. If you invoke it while a snapshot exists, it
|
||||||
self.ops_salsa_runtime_mut()
|
/// will block until that snapshot is dropped -- if that snapshot
|
||||||
|
/// is owned by the current thread, this could trigger deadlock.
|
||||||
|
fn synthetic_write(&mut self, durability: Durability) {
|
||||||
|
plumbing::DatabaseOps::synthetic_write(self, durability)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,15 @@ pub trait DatabaseOps {
|
|||||||
/// Gives access to the underlying salsa runtime.
|
/// Gives access to the underlying salsa runtime.
|
||||||
fn ops_salsa_runtime(&self) -> &Runtime;
|
fn ops_salsa_runtime(&self) -> &Runtime;
|
||||||
|
|
||||||
/// Gives access to the underlying salsa runtime.
|
/// A "synthetic write" causes the system to act *as though* some
|
||||||
fn ops_salsa_runtime_mut(&mut self) -> &mut Runtime;
|
/// input of durability `durability` has changed. This is mostly
|
||||||
|
/// useful for profiling scenarios.
|
||||||
|
///
|
||||||
|
/// **WARNING:** Just like an ordinary write, this method triggers
|
||||||
|
/// cancellation. If you invoke it while a snapshot exists, it
|
||||||
|
/// will block until that snapshot is dropped -- if that snapshot
|
||||||
|
/// is owned by the current thread, this could trigger deadlock.
|
||||||
|
fn synthetic_write(&mut self, durability: Durability);
|
||||||
|
|
||||||
/// Formats a database key index in a human readable fashion.
|
/// Formats a database key index in a human readable fashion.
|
||||||
fn fmt_index(
|
fn fmt_index(
|
||||||
|
@ -58,7 +58,7 @@ fn revalidate() {
|
|||||||
|
|
||||||
// Second generation: volatile will change (to 1) but memoized1
|
// Second generation: volatile will change (to 1) but memoized1
|
||||||
// will not (still 0, as 1/2 = 0)
|
// will not (still 0, as 1/2 = 0)
|
||||||
query.salsa_runtime_mut().synthetic_write(Durability::LOW);
|
query.synthetic_write(Durability::LOW);
|
||||||
query.memoized2();
|
query.memoized2();
|
||||||
query.assert_log(&["Volatile invoked", "Memoized1 invoked"]);
|
query.assert_log(&["Volatile invoked", "Memoized1 invoked"]);
|
||||||
query.memoized2();
|
query.memoized2();
|
||||||
@ -67,7 +67,7 @@ fn revalidate() {
|
|||||||
// Third generation: volatile will change (to 2) and memoized1
|
// Third generation: volatile will change (to 2) and memoized1
|
||||||
// will too (to 1). Therefore, after validating that Memoized1
|
// will too (to 1). Therefore, after validating that Memoized1
|
||||||
// changed, we now invoke Memoized2.
|
// changed, we now invoke Memoized2.
|
||||||
query.salsa_runtime_mut().synthetic_write(Durability::LOW);
|
query.synthetic_write(Durability::LOW);
|
||||||
|
|
||||||
query.memoized2();
|
query.memoized2();
|
||||||
query.assert_log(&["Volatile invoked", "Memoized1 invoked", "Memoized2 invoked"]);
|
query.assert_log(&["Volatile invoked", "Memoized1 invoked", "Memoized2 invoked"]);
|
||||||
|
@ -111,7 +111,7 @@ fn on_demand_input_durability() {
|
|||||||
}
|
}
|
||||||
"#]].assert_debug_eq(&events);
|
"#]].assert_debug_eq(&events);
|
||||||
|
|
||||||
db.salsa_runtime_mut().synthetic_write(Durability::LOW);
|
db.synthetic_write(Durability::LOW);
|
||||||
events.replace(vec![]);
|
events.replace(vec![]);
|
||||||
assert_eq!(db.c(1), 10);
|
assert_eq!(db.c(1), 10);
|
||||||
assert_eq!(db.c(2), 20);
|
assert_eq!(db.c(2), 20);
|
||||||
@ -128,7 +128,7 @@ fn on_demand_input_durability() {
|
|||||||
}
|
}
|
||||||
"#]].assert_debug_eq(&events);
|
"#]].assert_debug_eq(&events);
|
||||||
|
|
||||||
db.salsa_runtime_mut().synthetic_write(Durability::HIGH);
|
db.synthetic_write(Durability::HIGH);
|
||||||
events.replace(vec![]);
|
events.replace(vec![]);
|
||||||
assert_eq!(db.c(1), 10);
|
assert_eq!(db.c(1), 10);
|
||||||
assert_eq!(db.c(2), 20);
|
assert_eq!(db.c(2), 20);
|
||||||
|
@ -20,7 +20,7 @@ fn volatile_twice() {
|
|||||||
let v2 = db.volatile(); // volatiles are cached, so 2nd read returns the same
|
let v2 = db.volatile(); // volatiles are cached, so 2nd read returns the same
|
||||||
assert_eq!(v1, v2);
|
assert_eq!(v1, v2);
|
||||||
|
|
||||||
db.salsa_runtime_mut().synthetic_write(Durability::LOW); // clears volatile caches
|
db.synthetic_write(Durability::LOW); // clears volatile caches
|
||||||
|
|
||||||
let v3 = db.volatile(); // will re-increment the counter
|
let v3 = db.volatile(); // will re-increment the counter
|
||||||
let v4 = db.volatile(); // second call will be cached
|
let v4 = db.volatile(); // second call will be cached
|
||||||
@ -40,7 +40,7 @@ fn intermingled() {
|
|||||||
assert_eq!(v1, v3);
|
assert_eq!(v1, v3);
|
||||||
assert_eq!(v2, v4);
|
assert_eq!(v2, v4);
|
||||||
|
|
||||||
db.salsa_runtime_mut().synthetic_write(Durability::LOW); // clears volatile caches
|
db.synthetic_write(Durability::LOW); // clears volatile caches
|
||||||
|
|
||||||
let v5 = db.memoized(); // re-executes volatile, caches new result
|
let v5 = db.memoized(); // re-executes volatile, caches new result
|
||||||
let v6 = db.memoized(); // re-use cached result
|
let v6 = db.memoized(); // re-use cached result
|
||||||
|
Loading…
Reference in New Issue
Block a user