From 7d12f4f93a443ecd1efb27585e3e54db5d4ae877 Mon Sep 17 00:00:00 2001 From: memoryruins Date: Sun, 27 Jan 2019 17:01:00 -0500 Subject: [PATCH] remove set_unchecked methods --- src/lib.rs | 22 ------------ tests/set_unchecked.rs | 81 ------------------------------------------ 2 files changed, 103 deletions(-) delete mode 100644 tests/set_unchecked.rs diff --git a/src/lib.rs b/src/lib.rs index 270a689b..462d20d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -471,28 +471,6 @@ where self.storage .set_constant(self.db, &key, &self.database_key(&key), value); } - - /// Assigns a value to the query **bypassing the normal - /// incremental checking** -- this value becomes the value for the - /// query in the current revision. This can even be used on - /// "derived" queries (so long as their results are memoized). - /// - /// Note that once `set_unchecked` is used, the result is - /// effectively "fixed" for all future revisions. This "mocking" - /// system is pretty primitive and subject to revision; see - /// [salsa-rs/salsa#34](https://github.com/salsa-rs/salsa/issues/34) - /// for more details. - /// - /// **This is only meant to be used for "mocking" purposes in - /// tests** -- when testing a given query, you can use - /// `set_unchecked` to assign the values for its various inputs - /// and thus control what it sees when it executes. - pub fn set_unchecked(&self, key: Q::Key, value: Q::Value) - where - Q::Storage: plumbing::UncheckedMutQueryStorageOps, - { - self.storage.set_unchecked(self.db, &key, value); - } } // Re-export the procedural macros. diff --git a/tests/set_unchecked.rs b/tests/set_unchecked.rs deleted file mode 100644 index bcb5fd35..00000000 --- a/tests/set_unchecked.rs +++ /dev/null @@ -1,81 +0,0 @@ -use salsa::Database; - -#[salsa::query_group(HelloWorldStruct)] -trait HelloWorldDatabase: salsa::Database { - #[salsa::input] - fn input(&self) -> String; - - fn length(&self) -> usize; - - fn double_length(&self) -> usize; -} - -fn length(db: &impl HelloWorldDatabase) -> usize { - let l = db.input().len(); - assert!(l > 0); // not meant to be invoked with no input - l -} - -fn double_length(db: &impl HelloWorldDatabase) -> usize { - db.length() * 2 -} - -#[salsa::database(HelloWorldStruct)] -#[derive(Default)] -struct DatabaseStruct { - runtime: salsa::Runtime, -} - -impl salsa::Database for DatabaseStruct { - fn salsa_runtime(&self) -> &salsa::Runtime { - &self.runtime - } -} - -#[test] -fn normal() { - let mut db = DatabaseStruct::default(); - db.query_mut(InputQuery).set((), format!("Hello, world")); - assert_eq!(db.double_length(), 24); - db.query_mut(InputQuery).set((), format!("Hello, world!")); - assert_eq!(db.double_length(), 26); -} - -#[test] -#[should_panic] -fn use_without_set() { - let db = DatabaseStruct::default(); - db.double_length(); -} - -#[test] -fn using_set_unchecked_on_input() { - let mut db = DatabaseStruct::default(); - db.query_mut(InputQuery) - .set_unchecked((), format!("Hello, world")); - assert_eq!(db.double_length(), 24); -} - -#[test] -fn using_set_unchecked_on_input_after() { - let mut db = DatabaseStruct::default(); - db.query_mut(InputQuery).set((), format!("Hello, world")); - assert_eq!(db.double_length(), 24); - - // If we use `set_unchecked`, we don't notice that `double_length` - // is out of date. Oh well, don't do that. - db.query_mut(InputQuery) - .set_unchecked((), format!("Hello, world!")); - assert_eq!(db.double_length(), 24); -} - -#[test] -fn using_set_unchecked() { - let mut db = DatabaseStruct::default(); - - // Use `set_unchecked` to intentionally set the wrong value, - // demonstrating that the code never runs. - db.query_mut(LengthQuery).set_unchecked((), 24); - - assert_eq!(db.double_length(), 48); -}