From 8c133e7a4d6376ae95a991466461098350e6940f Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 27 Sep 2019 05:50:16 -0400 Subject: [PATCH] make `synthetic_write` require `&mut self` (breaking change!) This was an oversight before -- the current type implies that one introduce a synthetic write (and hence a new revision) from a `Frozen`! Not cool. --- src/runtime.rs | 2 +- tests/gc/derived_tests.rs | 8 ++++---- tests/gc/discard_values.rs | 4 ++-- tests/gc/interned.rs | 12 ++++++------ tests/gc/shallow_constant_tests.rs | 12 ++++++------ tests/incremental/memoized_volatile.rs | 6 +++--- tests/on_demand_inputs.rs | 4 ++-- tests/storage_varieties/tests.rs | 8 ++++---- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index d3200729..0539c399 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -143,7 +143,7 @@ where /// 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. - pub fn synthetic_write(&self, durability: Durability) { + pub fn synthetic_write(&mut self, durability: Durability) { self.with_incremented_revision(|guard| { guard.mark_durability_as_changed(durability); }); diff --git a/tests/gc/derived_tests.rs b/tests/gc/derived_tests.rs index 628c8948..83ab2dbb 100644 --- a/tests/gc/derived_tests.rs +++ b/tests/gc/derived_tests.rs @@ -11,7 +11,7 @@ fn compute_one_write_low() { db.set_use_triangular(5, false); db.compute(5); - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); assert_keys! { db, @@ -49,7 +49,7 @@ fn compute_one_write_high() { // Doing a synthetic write with durability *high* means that we // will revalidate the things `compute(5)` uses, and hence they // are not discarded. - db.salsa_runtime().synthetic_write(Durability::HIGH); + db.salsa_runtime_mut().synthetic_write(Durability::HIGH); assert_keys! { db, @@ -116,7 +116,7 @@ fn compute_switch() { } // Now run `compute` *again* in next revision. - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); assert_eq!(db.compute(5), 15); db.sweep_all(SweepStrategy::discard_outdated()); @@ -145,7 +145,7 @@ fn compute_all() { db.set_max(6); db.compute_all(); - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); db.compute_all(); db.sweep_all(SweepStrategy::discard_outdated()); diff --git a/tests/gc/discard_values.rs b/tests/gc/discard_values.rs index 9c38c313..b1a2d5aa 100644 --- a/tests/gc/discard_values.rs +++ b/tests/gc/discard_values.rs @@ -5,14 +5,14 @@ use salsa::{Database, Durability, SweepStrategy}; #[test] fn sweep_default() { - let db = db::DatabaseImpl::default(); + let mut db = db::DatabaseImpl::default(); db.fibonacci(5); let k: Vec<_> = db.query(FibonacciQuery).entries(); assert_eq!(k.len(), 6); - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); db.fibonacci(5); db.fibonacci(3); diff --git a/tests/gc/interned.rs b/tests/gc/interned.rs index 5772890b..9df73b88 100644 --- a/tests/gc/interned.rs +++ b/tests/gc/interned.rs @@ -74,13 +74,13 @@ fn discard_during_same_revision() { /// exercises precisely that scenario. #[test] fn discard_outdated() { - let db = db::DatabaseImpl::default(); + let mut db = db::DatabaseImpl::default(); let foo_from_rev0 = db.repeat_intern1("foo"); let bar_from_rev0 = db.repeat_intern1("bar"); // Trigger a new revision. - db.salsa_runtime().synthetic_write(Durability::HIGH); + db.salsa_runtime_mut().synthetic_write(Durability::HIGH); // In this revision, we use "bar". let bar_from_rev1 = db.repeat_intern1("bar"); @@ -117,7 +117,7 @@ fn discard_outdated() { /// keys (which are considered durability HIGH). #[test] fn discard_durability_after_synthetic_write_low() { - let db = db::DatabaseImpl::default(); + let mut db = db::DatabaseImpl::default(); // This will assign index 0 for "foo". let foo1a = db.repeat_intern1("foo"); @@ -127,7 +127,7 @@ fn discard_durability_after_synthetic_write_low() { ); // Trigger a new revision. - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); // If we are not careful, this would remove the interned key for // "foo". @@ -157,7 +157,7 @@ fn discard_durability_after_synthetic_write_low() { /// `Durability::HIGH`. #[test] fn discard_durability_after_synthetic_write_high() { - let db = db::DatabaseImpl::default(); + let mut db = db::DatabaseImpl::default(); // This will assign index 0 for "foo". let foo1a = db.repeat_intern1("foo"); @@ -167,7 +167,7 @@ fn discard_durability_after_synthetic_write_high() { ); // Trigger a new revision -- marking even high things as having changed. - db.salsa_runtime().synthetic_write(Durability::HIGH); + db.salsa_runtime_mut().synthetic_write(Durability::HIGH); // We are now able to collect "collect". db.query(InternStrQuery).sweep( diff --git a/tests/gc/shallow_constant_tests.rs b/tests/gc/shallow_constant_tests.rs index 1dd39be9..98782f00 100644 --- a/tests/gc/shallow_constant_tests.rs +++ b/tests/gc/shallow_constant_tests.rs @@ -24,14 +24,14 @@ fn one_rev() { #[test] fn two_rev_nothing() { - let db = db::DatabaseImpl::default(); + let mut db = db::DatabaseImpl::default(); db.fibonacci(5); let k: Vec<_> = db.query(FibonacciQuery).entries(); assert_eq!(k.len(), 6); - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); // Nothing was used in this revision, so // everything gets collected. @@ -43,14 +43,14 @@ fn two_rev_nothing() { #[test] fn two_rev_one_use() { - let db = db::DatabaseImpl::default(); + let mut db = db::DatabaseImpl::default(); db.fibonacci(5); let k: Vec<_> = db.query(FibonacciQuery).entries(); assert_eq!(k.len(), 6); - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); db.fibonacci(5); @@ -66,14 +66,14 @@ fn two_rev_one_use() { #[test] fn two_rev_two_uses() { - let db = db::DatabaseImpl::default(); + let mut db = db::DatabaseImpl::default(); db.fibonacci(5); let k: Vec<_> = db.query(FibonacciQuery).entries(); assert_eq!(k.len(), 6); - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); db.fibonacci(5); db.fibonacci(3); diff --git a/tests/incremental/memoized_volatile.rs b/tests/incremental/memoized_volatile.rs index e2ffcbff..ba7d0e66 100644 --- a/tests/incremental/memoized_volatile.rs +++ b/tests/incremental/memoized_volatile.rs @@ -48,7 +48,7 @@ fn volatile_x2() { /// - On the first run of R2, we recompute everything (since Memoized1 result *did* change). #[test] fn revalidate() { - let query = TestContextImpl::default(); + let mut query = TestContextImpl::default(); query.memoized2(); query.assert_log(&["Memoized2 invoked", "Memoized1 invoked", "Volatile invoked"]); @@ -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().synthetic_write(Durability::LOW); + query.salsa_runtime_mut().synthetic_write(Durability::LOW); query.memoized2(); query.assert_log(&["Memoized1 invoked", "Volatile 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().synthetic_write(Durability::LOW); + query.salsa_runtime_mut().synthetic_write(Durability::LOW); query.memoized2(); query.assert_log(&["Memoized1 invoked", "Volatile invoked", "Memoized2 invoked"]); diff --git a/tests/on_demand_inputs.rs b/tests/on_demand_inputs.rs index 536fbdda..4b3af6fb 100644 --- a/tests/on_demand_inputs.rs +++ b/tests/on_demand_inputs.rs @@ -100,13 +100,13 @@ fn on_demand_input_durability() { } })); - db.salsa_runtime().synthetic_write(Durability::LOW); + db.salsa_runtime_mut().synthetic_write(Durability::LOW); validated.set(0); assert_eq!(db.c(1), 10); assert_eq!(db.c(2), 20); assert_eq!(validated.get(), 2); - db.salsa_runtime().synthetic_write(Durability::HIGH); + db.salsa_runtime_mut().synthetic_write(Durability::HIGH); validated.set(0); assert_eq!(db.c(1), 10); assert_eq!(db.c(2), 20); diff --git a/tests/storage_varieties/tests.rs b/tests/storage_varieties/tests.rs index d765080c..f75c7c14 100644 --- a/tests/storage_varieties/tests.rs +++ b/tests/storage_varieties/tests.rs @@ -15,12 +15,12 @@ fn memoized_twice() { #[test] fn volatile_twice() { - let db = DatabaseImpl::default(); + let mut db = DatabaseImpl::default(); let v1 = db.volatile(); let v2 = db.volatile(); // volatiles are cached, so 2nd read returns the same assert_eq!(v1, v2); - db.salsa_runtime().synthetic_write(Durability::LOW); // clears volatile caches + db.salsa_runtime_mut().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 @@ -30,7 +30,7 @@ fn volatile_twice() { #[test] fn intermingled() { - let db = DatabaseImpl::default(); + let mut db = DatabaseImpl::default(); let v1 = db.volatile(); let v2 = db.memoized(); let v3 = db.volatile(); // cached @@ -40,7 +40,7 @@ fn intermingled() { assert_eq!(v1, v3); assert_eq!(v2, v4); - db.salsa_runtime().synthetic_write(Durability::LOW); // clears volatile caches + db.salsa_runtime_mut().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