Skip to content

Commit 6a63bff

Browse files
committed
Pass CompletedQuery to diff_outputs
1 parent 3d6ab1e commit 6a63bff

File tree

4 files changed

+38
-52
lines changed

4 files changed

+38
-52
lines changed

src/function/diff_outputs.rs

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use crate::active_query::CompletedQuery;
12
use crate::function::memo::Memo;
23
use crate::function::{Configuration, IngredientImpl};
34
use crate::hash::FxIndexSet;
45
use crate::zalsa::Zalsa;
5-
use crate::zalsa_local::{output_edges, QueryOriginRef, QueryRevisions};
6+
use crate::zalsa_local::{output_edges, QueryOriginRef};
67
use crate::{DatabaseKeyIndex, Event, EventKind};
78

89
impl<C> IngredientImpl<C>
@@ -16,54 +17,28 @@ where
1617
zalsa: &Zalsa,
1718
key: DatabaseKeyIndex,
1819
old_memo: &Memo<'_, C>,
19-
revisions: &QueryRevisions,
20-
stale_tracked_structs: Vec<DatabaseKeyIndex>,
20+
completed_query: &CompletedQuery,
2121
) {
2222
let (QueryOriginRef::Derived(edges) | QueryOriginRef::DerivedUntracked(edges)) =
2323
old_memo.revisions.origin.as_ref()
2424
else {
2525
return;
2626
};
2727

28-
let stale_outputs = output_edges(edges).collect::<FxIndexSet<_>>();
29-
30-
if stale_tracked_structs.is_empty() && stale_outputs.is_empty() {
31-
return;
28+
// Note that tracked structs are not stored as direct query outputs, but they are still outputs
29+
// that need to be reported as stale.
30+
for output in &completed_query.stale_tracked_structs {
31+
Self::report_stale_output(zalsa, key, *output);
3232
}
3333

34-
Self::diff_outputs_cold(zalsa, key, revisions, stale_outputs, stale_tracked_structs);
35-
}
36-
37-
#[cold]
38-
fn diff_outputs_cold(
39-
zalsa: &Zalsa,
40-
key: DatabaseKeyIndex,
41-
revisions: &QueryRevisions,
42-
mut stale_outputs: FxIndexSet<DatabaseKeyIndex>,
43-
mut stale_tracked_structs: Vec<DatabaseKeyIndex>,
44-
) {
45-
if !stale_tracked_structs.is_empty() {
46-
// Removing a stale tracked struct ID shows up in the event logs, so make sure
47-
// the order is stable here.
48-
stale_tracked_structs.sort_unstable_by(|a, b| {
49-
a.ingredient_index()
50-
.cmp(&b.ingredient_index())
51-
.then(a.key_index().cmp(&b.key_index()))
52-
});
53-
54-
// Note that tracked structs are not stored as direct query outputs, but they are still outputs
55-
// that need to be reported as stale.
56-
for output in stale_tracked_structs {
57-
Self::report_stale_output(zalsa, key, output);
58-
}
59-
}
34+
let mut stale_outputs = output_edges(edges).collect::<FxIndexSet<_>>();
6035

6136
if stale_outputs.is_empty() {
6237
return;
6338
}
6439

6540
// Preserve any outputs that were recreated in the current revision.
66-
for new_output in revisions.origin.as_ref().outputs() {
41+
for new_output in completed_query.revisions.origin.as_ref().outputs() {
6742
stale_outputs.swap_remove(&new_output);
6843
}
6944

src/function/execute.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,7 @@ where
107107

108108
// Diff the new outputs with the old, to discard any no-longer-emitted
109109
// outputs and update the tracked struct IDs for seeding the next revision.
110-
self.diff_outputs(
111-
zalsa,
112-
database_key_index,
113-
old_memo,
114-
&completed_query.revisions,
115-
completed_query.stale_tracked_structs,
116-
);
110+
self.diff_outputs(zalsa, database_key_index, old_memo, &completed_query);
117111
}
118112
self.insert_memo(
119113
zalsa,

src/function/specify.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[cfg(feature = "accumulator")]
22
use crate::accumulator::accumulated_map::InputAccumulatedValues;
3+
use crate::active_query::CompletedQuery;
34
use crate::function::memo::Memo;
45
use crate::function::{Configuration, IngredientImpl};
56
use crate::revision::AtomicRevision;
@@ -63,26 +64,34 @@ where
6364
// - a result that is NOT verified and has untracked inputs, which will re-execute (and likely panic)
6465

6566
let revision = zalsa.current_revision();
66-
let mut revisions = QueryRevisions {
67-
changed_at: current_deps.changed_at,
68-
durability: current_deps.durability,
69-
origin: QueryOrigin::assigned(active_query_key),
70-
#[cfg(feature = "accumulator")]
71-
accumulated_inputs: Default::default(),
72-
verified_final: AtomicBool::new(true),
73-
extra: QueryRevisionsExtra::default(),
67+
let mut completed_query = CompletedQuery {
68+
revisions: QueryRevisions {
69+
changed_at: current_deps.changed_at,
70+
durability: current_deps.durability,
71+
origin: QueryOrigin::assigned(active_query_key),
72+
#[cfg(feature = "accumulator")]
73+
accumulated_inputs: Default::default(),
74+
verified_final: AtomicBool::new(true),
75+
extra: QueryRevisionsExtra::default(),
76+
},
77+
stale_tracked_structs: Vec::new(),
7478
};
7579

7680
let memo_ingredient_index = self.memo_ingredient_index(zalsa, key);
7781
if let Some(old_memo) = self.get_memo_from_table_for(zalsa, key, memo_ingredient_index) {
78-
self.backdate_if_appropriate(old_memo, database_key_index, &mut revisions, &value);
79-
self.diff_outputs(zalsa, database_key_index, old_memo, &revisions, Vec::new());
82+
self.backdate_if_appropriate(
83+
old_memo,
84+
database_key_index,
85+
&mut completed_query.revisions,
86+
&value,
87+
);
88+
self.diff_outputs(zalsa, database_key_index, old_memo, &completed_query);
8089
}
8190

8291
let memo = Memo {
8392
value: Some(value),
8493
verified_at: AtomicRevision::from(revision),
85-
revisions,
94+
revisions: completed_query.revisions,
8695
};
8796

8897
crate::tracing::debug!(

src/tracked_struct.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,14 @@ impl IdentityMap {
347347
}
348348
}
349349

350+
// Removing a stale tracked struct ID shows up in the event logs, so make sure
351+
// the order is stable here.
352+
stale.sort_unstable_by(|a, b| {
353+
a.ingredient_index()
354+
.cmp(&b.ingredient_index())
355+
.then(a.key_index().cmp(&b.key_index()))
356+
});
357+
350358
(active, stale)
351359
}
352360

0 commit comments

Comments
 (0)