remove set_unchecked methods

This commit is contained in:
memoryruins 2019-01-27 17:01:00 -05:00
parent 1b9aaf2599
commit 7d12f4f93a
2 changed files with 0 additions and 103 deletions

View file

@ -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<DB, Q>,
{
self.storage.set_unchecked(self.db, &key, value);
}
}
// Re-export the procedural macros.

View file

@ -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<DatabaseStruct>,
}
impl salsa::Database for DatabaseStruct {
fn salsa_runtime(&self) -> &salsa::Runtime<DatabaseStruct> {
&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);
}