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<DB>`! Not cool.
This commit is contained in:
Niko Matsakis 2019-09-27 05:50:16 -04:00
parent b9f00726da
commit 8c133e7a4d
8 changed files with 28 additions and 28 deletions

View file

@ -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);
});

View file

@ -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());

View file

@ -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);

View file

@ -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(

View file

@ -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);

View file

@ -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"]);

View file

@ -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);

View file

@ -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