mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-12 08:30:51 +00:00
Merge pull request #58 from kleimkuhler/issue-56-remove-eq-bound
[WIP] Removal of Eq bound on `Q::Val`
This commit is contained in:
commit
df320c71dd
4 changed files with 27 additions and 13 deletions
|
@ -44,7 +44,7 @@ need.
|
|||
The `HelloWorldDatabase` trait has one supertrait:
|
||||
`salsa::Database`. If we were defining more query groups in our
|
||||
application, and we wanted to invoke some of those queries from within
|
||||
this query group, we might list those query groupes here. You can also
|
||||
this query group, we might list those query groups here. You can also
|
||||
list any other traits you want, so long as your final database type
|
||||
implements them (this lets you add custom state and so forth to your
|
||||
database).
|
||||
|
|
|
@ -53,6 +53,8 @@ where
|
|||
{
|
||||
fn should_memoize_value(key: &Q::Key) -> bool;
|
||||
|
||||
fn memoized_value_eq(old_value: &Q::Value, new_value: &Q::Value) -> bool;
|
||||
|
||||
fn should_track_inputs(key: &Q::Key) -> bool;
|
||||
}
|
||||
|
||||
|
@ -60,12 +62,17 @@ pub enum AlwaysMemoizeValue {}
|
|||
impl<DB, Q> MemoizationPolicy<DB, Q> for AlwaysMemoizeValue
|
||||
where
|
||||
Q: QueryFunction<DB>,
|
||||
Q::Value: Eq,
|
||||
DB: Database,
|
||||
{
|
||||
fn should_memoize_value(_key: &Q::Key) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn memoized_value_eq(old_value: &Q::Value, new_value: &Q::Value) -> bool {
|
||||
old_value == new_value
|
||||
}
|
||||
|
||||
fn should_track_inputs(_key: &Q::Key) -> bool {
|
||||
true
|
||||
}
|
||||
|
@ -81,6 +88,10 @@ where
|
|||
false
|
||||
}
|
||||
|
||||
fn memoized_value_eq(_old_value: &Q::Value, _new_value: &Q::Value) -> bool {
|
||||
panic!("cannot reach since we never memoize")
|
||||
}
|
||||
|
||||
fn should_track_inputs(_key: &Q::Key) -> bool {
|
||||
true
|
||||
}
|
||||
|
@ -101,6 +112,10 @@ where
|
|||
true
|
||||
}
|
||||
|
||||
fn memoized_value_eq(_old_value: &Q::Value, _new_value: &Q::Value) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn should_track_inputs(_key: &Q::Key) -> bool {
|
||||
false
|
||||
}
|
||||
|
@ -243,7 +258,7 @@ where
|
|||
match map.insert(key.clone(), QueryState::in_progress(runtime.id())) {
|
||||
Some(QueryState::Memoized(old_memo)) => Some(old_memo),
|
||||
Some(QueryState::InProgress { .. }) => unreachable!(),
|
||||
None => None
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -262,13 +277,7 @@ where
|
|||
let changed_at = memo.changed_at;
|
||||
|
||||
let new_value = StampedValue { value, changed_at };
|
||||
self.overwrite_placeholder(
|
||||
runtime,
|
||||
descriptor,
|
||||
key,
|
||||
old_memo.unwrap(),
|
||||
&new_value,
|
||||
);
|
||||
self.overwrite_placeholder(runtime, descriptor, key, old_memo.unwrap(), &new_value);
|
||||
return Ok(new_value);
|
||||
}
|
||||
}
|
||||
|
@ -299,9 +308,11 @@ where
|
|||
// "backdate" its `changed_at` revision to be the same as the
|
||||
// old value.
|
||||
if let Some(old_memo) = &old_memo {
|
||||
if old_memo.value.as_ref() == Some(&stamped_value.value) {
|
||||
assert!(old_memo.changed_at <= stamped_value.changed_at);
|
||||
stamped_value.changed_at = old_memo.changed_at;
|
||||
if let Some(old_value) = &old_memo.value {
|
||||
if MP::memoized_value_eq(&old_value, &stamped_value.value) {
|
||||
assert!(old_memo.changed_at <= stamped_value.changed_at);
|
||||
stamped_value.changed_at = old_memo.changed_at;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ struct IsConstant(bool);
|
|||
impl<DB, Q> InputStorage<DB, Q>
|
||||
where
|
||||
Q: Query<DB>,
|
||||
Q::Value: Eq,
|
||||
DB: Database,
|
||||
Q::Value: Default,
|
||||
{
|
||||
|
@ -137,6 +138,7 @@ where
|
|||
impl<DB, Q> QueryStorageOps<DB, Q> for InputStorage<DB, Q>
|
||||
where
|
||||
Q: Query<DB>,
|
||||
Q::Value: Eq,
|
||||
DB: Database,
|
||||
Q::Value: Default,
|
||||
{
|
||||
|
@ -197,6 +199,7 @@ where
|
|||
impl<DB, Q> InputQueryStorageOps<DB, Q> for InputStorage<DB, Q>
|
||||
where
|
||||
Q: Query<DB>,
|
||||
Q::Value: Eq,
|
||||
DB: Database,
|
||||
Q::Value: Default,
|
||||
{
|
||||
|
|
|
@ -56,7 +56,7 @@ pub trait ParallelDatabase: Database + Send {
|
|||
|
||||
pub trait Query<DB: Database>: Debug + Default + Sized + 'static {
|
||||
type Key: Clone + Debug + Hash + Eq;
|
||||
type Value: Clone + Debug + Hash + Eq;
|
||||
type Value: Clone + Debug;
|
||||
type Storage: plumbing::QueryStorageOps<DB, Self> + Send + Sync;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue