Skip to content

Commit 381c37c

Browse files
committed
Deduplicate via type alias
1 parent dfbfead commit 381c37c

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

Diff for: src/function.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ where
160160
/// only cleared with `&mut self`.
161161
unsafe fn extend_memo_lifetime<'this>(
162162
&'this self,
163-
memo: &memo::Memo<C::Lru, C::Output<'this>>,
164-
) -> &'this memo::Memo<C::Lru, C::Output<'this>> {
163+
memo: &memo::MemoConfigured<'this, C>,
164+
) -> &'this memo::MemoConfigured<'this, C> {
165165
std::mem::transmute(memo)
166166
}
167167

168168
fn insert_memo<'db>(
169169
&'db self,
170170
zalsa: &'db Zalsa,
171171
id: Id,
172-
memo: memo::Memo<C::Lru, C::Output<'db>>,
173-
) -> &'db memo::Memo<C::Lru, C::Output<'db>> {
172+
memo: memo::MemoConfigured<'db, C>,
173+
) -> &'db memo::MemoConfigured<'db, C> {
174174
let memo = Arc::new(memo);
175175
let db_memo = unsafe {
176176
// Unsafety conditions: memo must be in the map (it's not yet, but it will be by the time this

Diff for: src/function/backdate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::zalsa_local::QueryRevisions;
1+
use crate::{function::memo::MemoConfigured, zalsa_local::QueryRevisions};
22

3-
use super::{memo::Memo, Configuration, IngredientImpl, LruChoice};
3+
use super::{Configuration, IngredientImpl, LruChoice};
44

55
impl<C> IngredientImpl<C>
66
where
@@ -11,7 +11,7 @@ where
1111
/// on an old memo when a new memo has been produced to check whether there have been changed.
1212
pub(super) fn backdate_if_appropriate(
1313
&self,
14-
old_memo: &Memo<C::Lru, C::Output<'_>>,
14+
old_memo: &MemoConfigured<'_, C>,
1515
revisions: &mut QueryRevisions,
1616
value: &C::Output<'_>,
1717
) {

Diff for: src/function/diff_outputs.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::{memo::Memo, Configuration, IngredientImpl};
1+
use super::{Configuration, IngredientImpl};
22
use crate::{
3-
hash::FxHashSet, key::OutputDependencyIndex, zalsa_local::QueryRevisions, AsDynDatabase as _,
4-
DatabaseKeyIndex, Event, EventKind,
3+
function::memo::MemoConfigured, hash::FxHashSet, key::OutputDependencyIndex,
4+
zalsa_local::QueryRevisions, AsDynDatabase as _, DatabaseKeyIndex, Event, EventKind,
55
};
66

77
impl<C> IngredientImpl<C>
@@ -17,7 +17,7 @@ where
1717
&self,
1818
db: &C::DbView,
1919
key: DatabaseKeyIndex,
20-
old_memo: &Memo<C::Lru, C::Output<'_>>,
20+
old_memo: &MemoConfigured<'_, C>,
2121
revisions: &mut QueryRevisions,
2222
) {
2323
// Iterate over the outputs of the `old_memo` and put them into a hashset

Diff for: src/function/execute.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::sync::Arc;
22

33
use crate::{
4-
zalsa::ZalsaDatabase, zalsa_local::ActiveQueryGuard, Cycle, Database, Event, EventKind,
4+
function::memo::MemoConfigured, zalsa::ZalsaDatabase, zalsa_local::ActiveQueryGuard, Cycle,
5+
Database, Event, EventKind,
56
};
67

78
use super::{memo::Memo, Configuration, IngredientImpl, LruChoice};
@@ -23,8 +24,8 @@ where
2324
&'db self,
2425
db: &'db C::DbView,
2526
active_query: ActiveQueryGuard<'_>,
26-
opt_old_memo: Option<Arc<Memo<C::Lru, C::Output<'_>>>>,
27-
) -> &'db Memo<C::Lru, C::Output<'db>> {
27+
opt_old_memo: Option<Arc<MemoConfigured<'_, C>>>,
28+
) -> &'db MemoConfigured<'db, C> {
2829
let zalsa = db.zalsa();
2930
let revision_now = zalsa.current_revision();
3031
let database_key_index = active_query.database_key_index;

Diff for: src/function/fetch.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use super::{memo::Memo, Configuration, IngredientImpl};
1+
use super::{Configuration, IngredientImpl};
22
use crate::{
33
accumulator::accumulated_map::InputAccumulatedValues, function::lru::LruChoice as _,
4-
runtime::StampedValue, zalsa::ZalsaDatabase, AsDynDatabase as _, Id,
4+
function::memo::MemoConfigured, runtime::StampedValue, zalsa::ZalsaDatabase,
5+
AsDynDatabase as _, Id,
56
};
67

78
impl<C> IngredientImpl<C>
@@ -41,7 +42,7 @@ where
4142
&'db self,
4243
db: &'db C::DbView,
4344
id: Id,
44-
) -> &'db Memo<C::Lru, C::Output<'db>> {
45+
) -> &'db MemoConfigured<'db, C> {
4546
loop {
4647
if let Some(memo) = self.fetch_hot(db, id).or_else(|| self.fetch_cold(db, id)) {
4748
return memo;
@@ -54,7 +55,7 @@ where
5455
&'db self,
5556
db: &'db C::DbView,
5657
id: Id,
57-
) -> Option<&'db Memo<C::Lru, C::Output<'db>>> {
58+
) -> Option<&'db MemoConfigured<'db, C>> {
5859
let zalsa = db.zalsa();
5960
let memo_guard = self.get_memo_from_table_for(zalsa, id);
6061
if let Some(memo) = &memo_guard {
@@ -73,7 +74,7 @@ where
7374
&'db self,
7475
db: &'db C::DbView,
7576
id: Id,
76-
) -> Option<&'db Memo<C::Lru, C::Output<'db>>> {
77+
) -> Option<&'db MemoConfigured<'db, C>> {
7778
let (zalsa, zalsa_local) = db.zalsas();
7879
let database_key_index = self.database_key_index(id);
7980

Diff for: src/function/maybe_changed_after.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use crate::{
22
accumulator::accumulated_map::InputAccumulatedValues,
3+
function::memo::MemoConfigured,
34
ingredient::MaybeChangedAfter,
45
key::DatabaseKeyIndex,
56
zalsa::{Zalsa, ZalsaDatabase},
67
zalsa_local::{ActiveQueryGuard, QueryEdge, QueryOrigin},
78
AsDynDatabase as _, Id, Revision,
89
};
910

10-
use super::{memo::Memo, Configuration, IngredientImpl, LruChoice};
11+
use super::{Configuration, IngredientImpl, LruChoice};
1112

1213
impl<C> IngredientImpl<C>
1314
where
@@ -117,7 +118,7 @@ where
117118
db: &C::DbView,
118119
zalsa: &Zalsa,
119120
database_key_index: DatabaseKeyIndex,
120-
memo: &Memo<C::Lru, C::Output<'_>>,
121+
memo: &MemoConfigured<'_, C>,
121122
) -> bool {
122123
let verified_at = memo.verified_at.load();
123124
let revision_now = zalsa.current_revision();
@@ -159,7 +160,7 @@ where
159160
pub(super) fn deep_verify_memo(
160161
&self,
161162
db: &C::DbView,
162-
old_memo: &Memo<C::Lru, C::Output<'_>>,
163+
old_memo: &MemoConfigured<'_, C>,
163164
active_query: &ActiveQueryGuard<'_>,
164165
) -> bool {
165166
let zalsa = db.zalsa();

Diff for: src/function/memo.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<C: Configuration> IngredientImpl<C> {
6767
/// or has values assigned as output of another query, this has no effect.
6868
pub(super) fn evict_value_from_memo_for(&self, table: &mut MemoTable) {
6969
C::Lru::if_enabled(|| {
70-
table.map_memo::<Memo<C::Lru, C::Output<'_>>>(self.memo_ingredient_index, |memo| {
70+
table.map_memo::<MemoConfigured<'_, C>>(self.memo_ingredient_index, |memo| {
7171
match &memo.revisions.origin {
7272
QueryOrigin::Assigned(_)
7373
| QueryOrigin::DerivedUntracked(_)
@@ -110,6 +110,10 @@ impl<C: Configuration> IngredientImpl<C> {
110110
}
111111
}
112112

113+
#[allow(type_alias_bounds)]
114+
pub(super) type MemoConfigured<'db, C: Configuration<Lru: LruChoice>> =
115+
Memo<C::Lru, C::Output<'db>>;
116+
113117
pub(super) struct Memo<L: LruChoice, V: Send + Sync> {
114118
/// The result of the query, if we decide to memoize it.
115119
pub(super) value: L::LruCtor<V>,

0 commit comments

Comments
 (0)