-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathdiff_outputs.rs
57 lines (50 loc) · 2.09 KB
/
diff_outputs.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use super::{Configuration, IngredientImpl};
use crate::{
function::memo::MemoConfigured, hash::FxHashSet, key::OutputDependencyIndex,
zalsa_local::QueryRevisions, AsDynDatabase as _, DatabaseKeyIndex, Event, EventKind,
};
impl<C> IngredientImpl<C>
where
C: Configuration,
{
/// Compute the old and new outputs and invoke the `clear_stale_output` callback
/// for each output that was generated before but is not generated now.
///
/// This function takes a `&mut` reference to `revisions` to remove outputs
/// that no longer exist in this revision from [`QueryRevisions::tracked_struct_ids`].
pub(super) fn diff_outputs(
&self,
db: &C::DbView,
key: DatabaseKeyIndex,
old_memo: &MemoConfigured<'_, C>,
revisions: &mut QueryRevisions,
) {
// Iterate over the outputs of the `old_memo` and put them into a hashset
let mut old_outputs: FxHashSet<_> = old_memo.revisions.origin.outputs().collect();
// Iterate over the outputs of the current query
// and remove elements from `old_outputs` when we find them
for new_output in revisions.origin.outputs() {
old_outputs.remove(&new_output);
}
if !old_outputs.is_empty() {
// Remove the outputs that are no longer present in the current revision
// to prevent that the next revision is seeded with a id mapping that no longer exists.
revisions.tracked_struct_ids.retain(|&k, &mut value| {
!old_outputs.contains(&OutputDependencyIndex::new(k.ingredient_index(), value))
});
}
for old_output in old_outputs {
Self::report_stale_output(db, key, old_output);
}
}
fn report_stale_output(db: &C::DbView, key: DatabaseKeyIndex, output: OutputDependencyIndex) {
let db = db.as_dyn_database();
db.salsa_event(&|| {
Event::new(EventKind::WillDiscardStaleOutput {
execute_key: key,
output_key: output,
})
});
output.remove_stale_output(db, key);
}
}