Skip to content

Commit f89d17b

Browse files
committed
Remove ops_salsa_runtime_mut, replace it with direct synthetic_write API
1 parent 543d7e9 commit f89d17b

File tree

7 files changed

+27
-15
lines changed

7 files changed

+27
-15
lines changed

crates/ide-db/src/apply_change.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl RootDatabase {
1717
pub fn request_cancellation(&mut self) {
1818
let _p =
1919
tracing::span!(tracing::Level::INFO, "RootDatabase::request_cancellation").entered();
20-
self.salsa_runtime_mut().synthetic_write(Durability::LOW);
20+
self.synthetic_write(Durability::LOW);
2121
}
2222

2323
pub fn apply_change(&mut self, change: Change) {

crates/salsa/salsa-macros/src/database_storage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ pub(crate) fn database(args: TokenStream, input: TokenStream) -> TokenStream {
154154
self.#db_storage_field.salsa_runtime()
155155
}
156156

157-
fn ops_salsa_runtime_mut(&mut self) -> &mut salsa::Runtime {
158-
self.#db_storage_field.salsa_runtime_mut()
157+
fn synthetic_write(&mut self, durability: salsa::Durability) {
158+
self.#db_storage_field.salsa_runtime_mut().synthetic_write(durability)
159159
}
160160

161161
fn fmt_index(

crates/salsa/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ pub trait Database: plumbing::DatabaseOps {
9696
self.ops_salsa_runtime()
9797
}
9898

99-
/// Gives access to the underlying salsa runtime.
99+
/// A "synthetic write" causes the system to act *as though* some
100+
/// input of durability `durability` has changed. This is mostly
101+
/// useful for profiling scenarios.
100102
///
101-
/// This method should not be overridden by `Database` implementors.
102-
fn salsa_runtime_mut(&mut self) -> &mut Runtime {
103-
self.ops_salsa_runtime_mut()
103+
/// **WARNING:** Just like an ordinary write, this method triggers
104+
/// cancellation. If you invoke it while a snapshot exists, it
105+
/// will block until that snapshot is dropped -- if that snapshot
106+
/// is owned by the current thread, this could trigger deadlock.
107+
fn synthetic_write(&mut self, durability: Durability) {
108+
plumbing::DatabaseOps::synthetic_write(self, durability)
104109
}
105110
}
106111

crates/salsa/src/plumbing.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ pub trait DatabaseOps {
3838
/// Gives access to the underlying salsa runtime.
3939
fn ops_salsa_runtime(&self) -> &Runtime;
4040

41-
/// Gives access to the underlying salsa runtime.
42-
fn ops_salsa_runtime_mut(&mut self) -> &mut Runtime;
41+
/// A "synthetic write" causes the system to act *as though* some
42+
/// input of durability `durability` has changed. This is mostly
43+
/// useful for profiling scenarios.
44+
///
45+
/// **WARNING:** Just like an ordinary write, this method triggers
46+
/// cancellation. If you invoke it while a snapshot exists, it
47+
/// will block until that snapshot is dropped -- if that snapshot
48+
/// is owned by the current thread, this could trigger deadlock.
49+
fn synthetic_write(&mut self, durability: Durability);
4350

4451
/// Formats a database key index in a human readable fashion.
4552
fn fmt_index(

crates/salsa/tests/incremental/memoized_volatile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn revalidate() {
5858

5959
// Second generation: volatile will change (to 1) but memoized1
6060
// will not (still 0, as 1/2 = 0)
61-
query.salsa_runtime_mut().synthetic_write(Durability::LOW);
61+
query.synthetic_write(Durability::LOW);
6262
query.memoized2();
6363
query.assert_log(&["Volatile invoked", "Memoized1 invoked"]);
6464
query.memoized2();
@@ -67,7 +67,7 @@ fn revalidate() {
6767
// Third generation: volatile will change (to 2) and memoized1
6868
// will too (to 1). Therefore, after validating that Memoized1
6969
// changed, we now invoke Memoized2.
70-
query.salsa_runtime_mut().synthetic_write(Durability::LOW);
70+
query.synthetic_write(Durability::LOW);
7171

7272
query.memoized2();
7373
query.assert_log(&["Volatile invoked", "Memoized1 invoked", "Memoized2 invoked"]);

crates/salsa/tests/on_demand_inputs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn on_demand_input_durability() {
111111
}
112112
"#]].assert_debug_eq(&events);
113113

114-
db.salsa_runtime_mut().synthetic_write(Durability::LOW);
114+
db.synthetic_write(Durability::LOW);
115115
events.replace(vec![]);
116116
assert_eq!(db.c(1), 10);
117117
assert_eq!(db.c(2), 20);
@@ -128,7 +128,7 @@ fn on_demand_input_durability() {
128128
}
129129
"#]].assert_debug_eq(&events);
130130

131-
db.salsa_runtime_mut().synthetic_write(Durability::HIGH);
131+
db.synthetic_write(Durability::HIGH);
132132
events.replace(vec![]);
133133
assert_eq!(db.c(1), 10);
134134
assert_eq!(db.c(2), 20);

crates/salsa/tests/storage_varieties/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn volatile_twice() {
2020
let v2 = db.volatile(); // volatiles are cached, so 2nd read returns the same
2121
assert_eq!(v1, v2);
2222

23-
db.salsa_runtime_mut().synthetic_write(Durability::LOW); // clears volatile caches
23+
db.synthetic_write(Durability::LOW); // clears volatile caches
2424

2525
let v3 = db.volatile(); // will re-increment the counter
2626
let v4 = db.volatile(); // second call will be cached
@@ -40,7 +40,7 @@ fn intermingled() {
4040
assert_eq!(v1, v3);
4141
assert_eq!(v2, v4);
4242

43-
db.salsa_runtime_mut().synthetic_write(Durability::LOW); // clears volatile caches
43+
db.synthetic_write(Durability::LOW); // clears volatile caches
4444

4545
let v5 = db.memoized(); // re-executes volatile, caches new result
4646
let v6 = db.memoized(); // re-use cached result

0 commit comments

Comments
 (0)