Skip to content

Commit 7ffa829

Browse files
committed
.
1 parent 93df94f commit 7ffa829

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

src/function/accumulated.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ where
9595
db: &'db C::DbView,
9696
key: Id,
9797
) -> (Option<&'db AccumulatedMap>, InputAccumulatedValues) {
98-
// NEXT STEP: stash and refactor `fetch` to return an `&Memo` so we can make this work
99-
let memo = self.refresh_memo(db, db.zalsa(), key);
98+
// NEXT STEP: stash and refactor `fetch` to return an `&Memo` so we can make this work'
99+
let (zalsa, zalsa_local) = db.zalsas();
100+
let memo = self.refresh_memo(db, zalsa, zalsa_local, key);
100101
(
101102
memo.revisions.accumulated.as_deref(),
102103
memo.revisions.accumulated_inputs.load(),

src/function/fetch.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::function::memo::Memo;
33
use crate::function::sync::ClaimResult;
44
use crate::function::{Configuration, IngredientImpl, VerifyResult};
55
use crate::loom::sync::AtomicMut;
6+
use crate::plumbing::ZalsaLocal;
67
use crate::zalsa::{MemoIngredientIndex, Zalsa, ZalsaDatabase};
78
use crate::zalsa_local::QueryRevisions;
89
use crate::Id;
@@ -15,7 +16,7 @@ where
1516
let (zalsa, zalsa_local) = db.zalsas();
1617
zalsa.unwind_if_revision_cancelled(zalsa_local);
1718

18-
let memo = self.refresh_memo(db, zalsa, id);
19+
let memo = self.refresh_memo(db, zalsa, zalsa_local, id);
1920
// SAFETY: We just refreshed the memo so it is guaranteed to contain a value now.
2021
let memo_value = unsafe { memo.value.as_ref().unwrap_unchecked() };
2122

@@ -38,13 +39,14 @@ where
3839
&'db self,
3940
db: &'db C::DbView,
4041
zalsa: &'db Zalsa,
42+
zalsa_local: &'db ZalsaLocal,
4143
id: Id,
4244
) -> &'db Memo<C::Output<'db>> {
4345
let memo_ingredient_index = self.memo_ingredient_index(zalsa, id);
4446
loop {
4547
if let Some(memo) = self
4648
.fetch_hot(zalsa, id, memo_ingredient_index)
47-
.or_else(|| self.fetch_cold(zalsa, db, id, memo_ingredient_index))
49+
.or_else(|| self.fetch_cold(db, zalsa, zalsa_local, id, memo_ingredient_index))
4850
{
4951
// If we get back a provisional cycle memo, and it's provisional on any cycle heads
5052
// that are claimed by a different thread, we can't propagate the provisional memo
@@ -91,8 +93,9 @@ where
9193
#[inline(never)]
9294
fn fetch_cold<'db>(
9395
&'db self,
94-
zalsa: &'db Zalsa,
9596
db: &'db C::DbView,
97+
zalsa: &'db Zalsa,
98+
zalsa_local: &'db ZalsaLocal,
9699
id: Id,
97100
memo_ingredient_index: MemoIngredientIndex,
98101
) -> Option<&'db Memo<C::Output<'db>>> {
@@ -120,7 +123,7 @@ where
120123
}
121124
// no provisional value; create/insert/return initial provisional value
122125
return match C::CYCLE_STRATEGY {
123-
CycleRecoveryStrategy::Panic => db.zalsa_local().with_query_stack(|stack| {
126+
CycleRecoveryStrategy::Panic => zalsa_local.with_query_stack(|stack| {
124127
panic!(
125128
"dependency graph cycle when querying {database_key_index:#?}, \
126129
set cycle_fn/cycle_initial to fixpoint iterate.\n\
@@ -147,7 +150,7 @@ where
147150
tracing::debug!(
148151
"hit a `FallbackImmediate` cycle at {database_key_index:#?}"
149152
);
150-
let active_query = db.zalsa_local().push_query(database_key_index, 0);
153+
let active_query = zalsa_local.push_query(database_key_index, 0);
151154
let fallback_value = self.initial_value(db, id).expect(
152155
"`CycleRecoveryStrategy::FallbackImmediate` should have initial_value",
153156
);
@@ -171,9 +174,13 @@ where
171174
let opt_old_memo = self.get_memo_from_table_for(zalsa, id, memo_ingredient_index);
172175
if let Some(old_memo) = opt_old_memo {
173176
if old_memo.value.is_some() {
174-
if let VerifyResult::Unchanged(_, cycle_heads) =
175-
self.deep_verify_memo(db, zalsa, old_memo, self.database_key_index(id))
176-
{
177+
if let VerifyResult::Unchanged(_, cycle_heads) = self.deep_verify_memo(
178+
db,
179+
zalsa,
180+
zalsa_local,
181+
old_memo,
182+
self.database_key_index(id),
183+
) {
177184
if cycle_heads.is_empty() {
178185
// SAFETY: memo is present in memo_map and we have verified that it is
179186
// still valid for the current revision.
@@ -185,7 +192,7 @@ where
185192

186193
let memo = self.execute(
187194
db,
188-
db.zalsa_local().push_query(self.database_key_index(id), 0),
195+
zalsa_local.push_query(self.database_key_index(id), 0),
189196
opt_old_memo,
190197
);
191198

src/function/maybe_changed_after.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ where
107107
}
108108

109109
if let Some(mcs) = self.maybe_changed_after_cold(
110-
zalsa,
111110
db,
111+
zalsa,
112+
zalsa_local,
112113
id,
113114
revision,
114115
memo_ingredient_index,
@@ -122,37 +123,41 @@ where
122123
}
123124

124125
#[inline(never)]
126+
#[allow(clippy::too_many_arguments)]
125127
fn maybe_changed_after_cold<'db>(
126128
&'db self,
127-
zalsa: &Zalsa,
128129
db: &'db C::DbView,
130+
zalsa: &Zalsa,
131+
zalsa_local: &ZalsaLocal,
129132
key_index: Id,
130133
revision: Revision,
131134
memo_ingredient_index: MemoIngredientIndex,
132135
in_cycle: bool,
133136
) -> Option<VerifyResult> {
134-
let database_key_index = self.database_key_index(key_index);
135-
136137
let _claim_guard = match self.sync_table.try_claim(zalsa, key_index) {
137138
ClaimResult::Retry => return None,
138139
ClaimResult::Cycle => match C::CYCLE_STRATEGY {
139-
CycleRecoveryStrategy::Panic => db.zalsa_local().with_query_stack(|stack| {
140-
panic!(
141-
"dependency graph cycle when validating {database_key_index:#?}, \
140+
CycleRecoveryStrategy::Panic => {
141+
let database_key_index = self.database_key_index(key_index);
142+
zalsa_local.with_query_stack(|stack| {
143+
panic!(
144+
"dependency graph cycle when validating {database_key_index:#?}, \
142145
set cycle_fn/cycle_initial to fixpoint iterate.\n\
143146
Query stack:\n{stack:#?}",
144-
);
145-
}),
147+
);
148+
})
149+
}
146150
CycleRecoveryStrategy::FallbackImmediate => {
147151
return Some(VerifyResult::unchanged());
148152
}
149153
CycleRecoveryStrategy::Fixpoint => {
150154
tracing::debug!(
151-
"hit cycle at {database_key_index:?} in `maybe_changed_after`, returning fixpoint initial value",
155+
"hit cycle at {:?} in `maybe_changed_after`, returning fixpoint initial value",
156+
self.database_key_index(key_index)
152157
);
153158
return Some(VerifyResult::Unchanged(
154159
InputAccumulatedValues::Empty,
155-
CycleHeads::initial(database_key_index),
160+
CycleHeads::initial(self.database_key_index(key_index)),
156161
));
157162
}
158163
},
@@ -165,13 +170,20 @@ where
165170
};
166171

167172
tracing::debug!(
168-
"{database_key_index:?}: maybe_changed_after_cold, successful claim, \
173+
"{:?}: maybe_changed_after_cold, successful claim, \
169174
revision = {revision:?}, old_memo = {old_memo:#?}",
170-
old_memo = old_memo.tracing_debug()
175+
self.database_key_index(key_index),
176+
old_memo = old_memo.tracing_debug(),
171177
);
172178

173179
// Check if the inputs are still valid. We can just compare `changed_at`.
174-
let deep_verify = self.deep_verify_memo(db, zalsa, old_memo, database_key_index);
180+
let deep_verify = self.deep_verify_memo(
181+
db,
182+
zalsa,
183+
zalsa_local,
184+
old_memo,
185+
self.database_key_index(key_index),
186+
);
175187
if deep_verify.is_unchanged() {
176188
return Some(if old_memo.revisions.changed_at > revision {
177189
VerifyResult::Changed(deep_verify.into_cycle_heads())
@@ -194,7 +206,7 @@ where
194206
// `in_cycle` tracks if the enclosing query is in a cycle. `deep_verify.cycle_heads` tracks
195207
// if **this query** encountered a cycle (which means there's some provisional value somewhere floating around).
196208
if old_memo.value.is_some() && !in_cycle && deep_verify.cycle_heads().is_empty() {
197-
let active_query = db.zalsa_local().push_query(database_key_index, 0);
209+
let active_query = zalsa_local.push_query(self.database_key_index(key_index), 0);
198210
let memo = self.execute(db, active_query, Some(old_memo));
199211
let changed_at = memo.revisions.changed_at;
200212

@@ -375,6 +387,7 @@ where
375387
&self,
376388
db: &C::DbView,
377389
zalsa: &Zalsa,
390+
zalsa_local: &ZalsaLocal,
378391
old_memo: &Memo<C::Output<'_>>,
379392
database_key_index: DatabaseKeyIndex,
380393
) -> VerifyResult {
@@ -386,12 +399,7 @@ where
386399
let shallow_update = self.shallow_verify_memo(zalsa, database_key_index, old_memo);
387400
let shallow_update_possible = shallow_update.is_some();
388401
if let Some(shallow_update) = shallow_update {
389-
if self.validate_may_be_provisional(
390-
zalsa,
391-
db.zalsa_local(),
392-
database_key_index,
393-
old_memo,
394-
) {
402+
if self.validate_may_be_provisional(zalsa, zalsa_local, database_key_index, old_memo) {
395403
self.update_shallow(zalsa, database_key_index, old_memo, shallow_update);
396404

397405
return VerifyResult::unchanged();

0 commit comments

Comments
 (0)