Skip to content

Commit 63c14c6

Browse files
committed
Experiment: Remove database usage from remove_stale_output
1 parent 14c37fd commit 63c14c6

File tree

6 files changed

+20
-69
lines changed

6 files changed

+20
-69
lines changed

src/function/diff_outputs.rs

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

77
impl<C> IngredientImpl<C>
@@ -56,6 +56,6 @@ where
5656
})
5757
});
5858

59-
output.remove_stale_output(zalsa, db.as_dyn_database(), key);
59+
output.remove_stale_output(zalsa);
6060
}
6161
}

src/ingredient.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,8 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
7575
/// revision, but was NOT output in the current revision.
7676
///
7777
/// This hook is used to clear out the stale value so others cannot read it.
78-
fn remove_stale_output(
79-
&self,
80-
db: &dyn Database,
81-
executor: DatabaseKeyIndex,
82-
stale_output_key: Id,
83-
) {
84-
let _ = (db, executor, stale_output_key);
78+
fn remove_stale_output(&self, zalsa: &Zalsa, stale_output_key: Id) {
79+
let _ = (zalsa, stale_output_key);
8580
unreachable!("only tracked struct ingredients can have stale outputs")
8681
}
8782

src/key.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@ impl OutputDependencyIndex {
3636
}
3737
}
3838

39-
pub(crate) fn remove_stale_output(
40-
&self,
41-
zalsa: &Zalsa,
42-
db: &dyn Database,
43-
executor: DatabaseKeyIndex,
44-
) {
39+
pub(crate) fn remove_stale_output(&self, zalsa: &Zalsa) {
4540
zalsa
4641
.lookup_ingredient(self.ingredient_index)
47-
.remove_stale_output(db, executor, self.key_index)
42+
.remove_stale_output(zalsa, self.key_index)
4843
}
4944

5045
pub(crate) fn mark_validated_output(

src/table/memo.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -221,30 +221,22 @@ impl MemoTable {
221221
///
222222
/// The caller needs to make sure to not call this function until no more references into
223223
/// the database exist as there may be outstanding borrows into the pointer contents.
224-
pub(crate) unsafe fn into_memos(
225-
self,
226-
) -> impl Iterator<Item = (MemoIngredientIndex, Box<dyn Memo>)> {
224+
pub(crate) unsafe fn into_memos(self) -> impl Iterator<Item = Box<dyn Memo>> {
227225
self.memos
228226
.into_inner()
229227
.into_iter()
230-
.zip(0..)
231-
.filter_map(|(mut memo, index)| memo.data.take().map(|d| (d, index)))
228+
.filter_map(|mut memo| memo.data.take())
232229
.map(
233-
|(
234-
MemoEntryData {
235-
type_id: _,
236-
to_dyn_fn,
237-
atomic_memo,
238-
},
239-
index,
240-
)| {
230+
|MemoEntryData {
231+
type_id: _,
232+
to_dyn_fn,
233+
atomic_memo,
234+
}| {
241235
// SAFETY: The `atomic_memo` field is never null.
242236
let memo =
243237
unsafe { to_dyn_fn(NonNull::new_unchecked(atomic_memo.into_inner())) };
244238
// SAFETY: The caller guarantees that there are no outstanding borrows into the `Box` contents.
245-
let memo = unsafe { Box::from_raw(memo.as_ptr()) };
246-
247-
(MemoIngredientIndex::from_usize(index), memo)
239+
unsafe { Box::from_raw(memo.as_ptr()) }
248240
},
249241
)
250242
}

src/tracked_struct.rs

+6-28
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
salsa_struct::SalsaStructInDb,
1414
table::{memo::MemoTable, sync::SyncTable, Slot, Table},
1515
zalsa::{IngredientIndex, Zalsa},
16-
Database, Durability, Event, EventKind, Id, Revision,
16+
Database, Durability, Id, Revision,
1717
};
1818

1919
pub mod tracked_field;
@@ -584,14 +584,7 @@ where
584584
/// Using this method on an entity id that MAY be used in the current revision will lead to
585585
/// unspecified results (but not UB). See [`InternedIngredient::delete_index`] for more
586586
/// discussion and important considerations.
587-
pub(crate) fn delete_entity(&self, db: &dyn crate::Database, id: Id) {
588-
db.salsa_event(&|| {
589-
Event::new(crate::EventKind::DidDiscard {
590-
key: self.database_key_index(id),
591-
})
592-
});
593-
594-
let zalsa = db.zalsa();
587+
pub(crate) fn delete_entity(&self, zalsa: &Zalsa, id: Id) {
595588
let current_revision = zalsa.current_revision();
596589
let data = Self::data_raw(zalsa.table(), id);
597590

@@ -618,19 +611,9 @@ where
618611

619612
// SAFETY: We have verified that no more references to these memos exist and so we are good
620613
// to drop them.
621-
for (memo_ingredient_index, memo) in unsafe { memo_table.into_memos() } {
622-
let ingredient_index =
623-
zalsa.ingredient_index_for_memo(self.ingredient_index, memo_ingredient_index);
624-
625-
let executor = DatabaseKeyIndex {
626-
ingredient_index,
627-
key_index: id,
628-
};
629-
630-
db.salsa_event(&|| Event::new(EventKind::DidDiscard { key: executor }));
631-
614+
for memo in unsafe { memo_table.into_memos() } {
632615
for stale_output in memo.origin().outputs() {
633-
stale_output.remove_stale_output(zalsa, db, executor);
616+
stale_output.remove_stale_output(zalsa);
634617
}
635618
}
636619

@@ -756,17 +739,12 @@ where
756739
// FIXME: delete this method
757740
}
758741

759-
fn remove_stale_output(
760-
&self,
761-
db: &dyn Database,
762-
_executor: DatabaseKeyIndex,
763-
stale_output_key: crate::Id,
764-
) {
742+
fn remove_stale_output(&self, zalsa: &Zalsa, stale_output_key: crate::Id) {
765743
// This method is called when, in prior revisions,
766744
// `executor` creates a tracked struct `salsa_output_key`,
767745
// but it did not in the current revision.
768746
// In that case, we can delete `stale_output_key` and any data associated with it.
769-
self.delete_entity(db, stale_output_key);
747+
self.delete_entity(zalsa, stale_output_key);
770748
}
771749

772750
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {

src/zalsa.rs

-9
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,6 @@ impl Zalsa {
220220
.as_ref()
221221
}
222222

223-
pub(crate) fn ingredient_index_for_memo(
224-
&self,
225-
struct_ingredient_index: IngredientIndex,
226-
memo_ingredient_index: MemoIngredientIndex,
227-
) -> IngredientIndex {
228-
self.memo_ingredient_indices.read()[struct_ingredient_index.as_usize()]
229-
[memo_ingredient_index.as_usize()]
230-
}
231-
232223
/// Starts unwinding the stack if the current revision is cancelled.
233224
///
234225
/// This method can be called by query implementations that perform

0 commit comments

Comments
 (0)