Unnamed repository; edit this file 'description' to name the repository.
Remove ops_salsa_runtime_mut, replace it with direct synthetic_write API
Lukas Wirth 2024-02-22
parent 543d7e9 · commit f89d17b
-rw-r--r--crates/ide-db/src/apply_change.rs2
-rw-r--r--crates/salsa/salsa-macros/src/database_storage.rs4
-rw-r--r--crates/salsa/src/lib.rs13
-rw-r--r--crates/salsa/src/plumbing.rs11
-rw-r--r--crates/salsa/tests/incremental/memoized_volatile.rs4
-rw-r--r--crates/salsa/tests/on_demand_inputs.rs4
-rw-r--r--crates/salsa/tests/storage_varieties/tests.rs4
7 files changed, 27 insertions, 15 deletions
diff --git a/crates/ide-db/src/apply_change.rs b/crates/ide-db/src/apply_change.rs
index 1a214ef0bf..2b2df144d6 100644
--- a/crates/ide-db/src/apply_change.rs
+++ b/crates/ide-db/src/apply_change.rs
@@ -17,7 +17,7 @@ impl RootDatabase {
pub fn request_cancellation(&mut self) {
let _p =
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) {
diff --git a/crates/salsa/salsa-macros/src/database_storage.rs b/crates/salsa/salsa-macros/src/database_storage.rs
index 0ec75bb043..223da9b529 100644
--- a/crates/salsa/salsa-macros/src/database_storage.rs
+++ b/crates/salsa/salsa-macros/src/database_storage.rs
@@ -154,8 +154,8 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
self.#db_storage_field.salsa_runtime()
}
- fn ops_salsa_runtime_mut(&mut self) -> &mut salsa::Runtime {
- self.#db_storage_field.salsa_runtime_mut()
+ fn synthetic_write(&mut self, durability: salsa::Durability) {
+ self.#db_storage_field.salsa_runtime_mut().synthetic_write(durability)
}
fn fmt_index(
diff --git a/crates/salsa/src/lib.rs b/crates/salsa/src/lib.rs
index 48b5d633bd..98b3a48e37 100644
--- a/crates/salsa/src/lib.rs
+++ b/crates/salsa/src/lib.rs
@@ -96,11 +96,16 @@ pub trait Database: plumbing::DatabaseOps {
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.
- fn salsa_runtime_mut(&mut self) -> &mut Runtime {
- self.ops_salsa_runtime_mut()
+ /// **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) {
+ plumbing::DatabaseOps::synthetic_write(self, durability)
}
}
diff --git a/crates/salsa/src/plumbing.rs b/crates/salsa/src/plumbing.rs
index 71332e39ca..b8df87fd5e 100644
--- a/crates/salsa/src/plumbing.rs
+++ b/crates/salsa/src/plumbing.rs
@@ -38,8 +38,15 @@ pub trait DatabaseOps {
/// Gives access to the underlying salsa runtime.
fn ops_salsa_runtime(&self) -> &Runtime;
- /// Gives access to the underlying salsa runtime.
- fn ops_salsa_runtime_mut(&mut self) -> &mut 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.
+ ///
+ /// **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.
fn fmt_index(
diff --git a/crates/salsa/tests/incremental/memoized_volatile.rs b/crates/salsa/tests/incremental/memoized_volatile.rs
index 6dc5030063..3dcc32eece 100644
--- a/crates/salsa/tests/incremental/memoized_volatile.rs
+++ b/crates/salsa/tests/incremental/memoized_volatile.rs
@@ -58,7 +58,7 @@ fn revalidate() {
// Second generation: volatile will change (to 1) but memoized1
// will not (still 0, as 1/2 = 0)
- query.salsa_runtime_mut().synthetic_write(Durability::LOW);
+ query.synthetic_write(Durability::LOW);
query.memoized2();
query.assert_log(&["Volatile invoked", "Memoized1 invoked"]);
query.memoized2();
@@ -67,7 +67,7 @@ fn revalidate() {
// Third generation: volatile will change (to 2) and memoized1
// will too (to 1). Therefore, after validating that Memoized1
// changed, we now invoke Memoized2.
- query.salsa_runtime_mut().synthetic_write(Durability::LOW);
+ query.synthetic_write(Durability::LOW);
query.memoized2();
query.assert_log(&["Volatile invoked", "Memoized1 invoked", "Memoized2 invoked"]);
diff --git a/crates/salsa/tests/on_demand_inputs.rs b/crates/salsa/tests/on_demand_inputs.rs
index 5d0e486644..677d633ee7 100644
--- a/crates/salsa/tests/on_demand_inputs.rs
+++ b/crates/salsa/tests/on_demand_inputs.rs
@@ -111,7 +111,7 @@ fn on_demand_input_durability() {
}
"#]].assert_debug_eq(&events);
- db.salsa_runtime_mut().synthetic_write(Durability::LOW);
+ db.synthetic_write(Durability::LOW);
events.replace(vec![]);
assert_eq!(db.c(1), 10);
assert_eq!(db.c(2), 20);
@@ -128,7 +128,7 @@ fn on_demand_input_durability() {
}
"#]].assert_debug_eq(&events);
- db.salsa_runtime_mut().synthetic_write(Durability::HIGH);
+ db.synthetic_write(Durability::HIGH);
events.replace(vec![]);
assert_eq!(db.c(1), 10);
assert_eq!(db.c(2), 20);
diff --git a/crates/salsa/tests/storage_varieties/tests.rs b/crates/salsa/tests/storage_varieties/tests.rs
index f75c7c142f..8e2f9b03cb 100644
--- a/crates/salsa/tests/storage_varieties/tests.rs
+++ b/crates/salsa/tests/storage_varieties/tests.rs
@@ -20,7 +20,7 @@ fn volatile_twice() {
let v2 = db.volatile(); // volatiles are cached, so 2nd read returns the same
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 v4 = db.volatile(); // second call will be cached
@@ -40,7 +40,7 @@ fn intermingled() {
assert_eq!(v1, v3);
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 v6 = db.memoized(); // re-use cached result