Skip to content

Commit 0283619

Browse files
committed
Experiment: Remove database usage from mark_validated_output
1 parent 00382f9 commit 0283619

8 files changed

+25
-56
lines changed

src/function.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ where
237237

238238
fn mark_validated_output(
239239
&self,
240-
db: &dyn Database,
240+
zalsa: &Zalsa,
241241
executor: DatabaseKeyIndex,
242242
output_key: crate::Id,
243243
) {
244-
self.validate_specified_value(db, executor, output_key);
244+
self.validate_specified_value(zalsa, executor, output_key);
245245
}
246246

247247
fn requires_reset_for_new_revision(&self) -> bool {

src/function/fetch.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ where
5050
let memo_ingredient_index = self.memo_ingredient_index(zalsa, id);
5151
loop {
5252
if let Some(memo) = self
53-
.fetch_hot(zalsa, db, id, memo_ingredient_index)
53+
.fetch_hot(zalsa, id, memo_ingredient_index)
5454
.or_else(|| self.fetch_cold(zalsa, db, id, memo_ingredient_index))
5555
{
5656
return memo;
@@ -62,14 +62,13 @@ where
6262
fn fetch_hot<'db>(
6363
&'db self,
6464
zalsa: &'db Zalsa,
65-
db: &'db C::DbView,
6665
id: Id,
6766
memo_ingredient_index: MemoIngredientIndex,
6867
) -> Option<&'db Memo<C::Output<'db>>> {
6968
let memo_guard = self.get_memo_from_table_for(zalsa, id, memo_ingredient_index);
7069
if let Some(memo) = memo_guard {
7170
if memo.value.is_some()
72-
&& self.shallow_verify_memo(db, zalsa, self.database_key_index(id), memo)
71+
&& self.shallow_verify_memo(zalsa, self.database_key_index(id), memo)
7372
{
7473
// Unsafety invariant: memo is present in memo_map and we have verified that it is
7574
// still valid for the current revision.

src/function/maybe_changed_after.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where
3131
// Check if we have a verified version: this is the hot path.
3232
let memo_guard = self.get_memo_from_table_for(zalsa, id, memo_ingredient_index);
3333
if let Some(memo) = memo_guard {
34-
if self.shallow_verify_memo(db, zalsa, database_key_index, memo) {
34+
if self.shallow_verify_memo(zalsa, database_key_index, memo) {
3535
return if memo.revisions.changed_at > revision {
3636
MaybeChangedAfter::Yes
3737
} else {
@@ -118,7 +118,6 @@ where
118118
#[inline]
119119
pub(super) fn shallow_verify_memo(
120120
&self,
121-
db: &C::DbView,
122121
zalsa: &Zalsa,
123122
database_key_index: DatabaseKeyIndex,
124123
memo: &Memo<C::Output<'_>>,
@@ -146,13 +145,8 @@ where
146145
);
147146
if last_changed <= verified_at {
148147
// No input of the suitable durability has changed since last verified.
149-
memo.mark_as_verified(
150-
db,
151-
revision_now,
152-
database_key_index,
153-
memo.revisions.accumulated_inputs.load(),
154-
);
155-
memo.mark_outputs_as_verified(zalsa, db.as_dyn_database(), database_key_index);
148+
memo.mark_as_verified(revision_now, memo.revisions.accumulated_inputs.load());
149+
memo.mark_outputs_as_verified(zalsa, database_key_index);
156150
return true;
157151
}
158152

@@ -181,7 +175,7 @@ where
181175
old_memo = old_memo.tracing_debug()
182176
);
183177

184-
if self.shallow_verify_memo(db, zalsa, database_key_index, old_memo) {
178+
if self.shallow_verify_memo(zalsa, database_key_index, old_memo) {
185179
return true;
186180
}
187181

@@ -241,16 +235,12 @@ where
241235
// by this function cannot be read until this function is marked green,
242236
// so even if we mark them as valid here, the function will re-execute
243237
// and overwrite the contents.
244-
dependency_index.mark_validated_output(
245-
zalsa,
246-
dyn_db,
247-
database_key_index,
248-
);
238+
dependency_index.mark_validated_output(zalsa, database_key_index);
249239
}
250240
}
251241
}
252242

253-
old_memo.mark_as_verified(db, zalsa.current_revision(), database_key_index, inputs);
243+
old_memo.mark_as_verified(zalsa.current_revision(), inputs);
254244
true
255245
}
256246
}

src/function/memo.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use crate::revision::AtomicRevision;
88
use crate::table::memo::MemoTable;
99
use crate::zalsa::MemoIngredientIndex;
1010
use crate::zalsa_local::QueryOrigin;
11-
use crate::{
12-
key::DatabaseKeyIndex, zalsa::Zalsa, zalsa_local::QueryRevisions, Event, EventKind, Id,
13-
Revision,
14-
};
11+
use crate::{key::DatabaseKeyIndex, zalsa::Zalsa, zalsa_local::QueryRevisions, Id, Revision};
1512

1613
use super::{Configuration, IngredientImpl};
1714

@@ -136,31 +133,22 @@ impl<V> Memo<V> {
136133

137134
/// Mark memo as having been verified in the `revision_now`, which should
138135
/// be the current revision.
139-
pub(super) fn mark_as_verified<Db: ?Sized + crate::Database>(
136+
pub(super) fn mark_as_verified(
140137
&self,
141-
db: &Db,
142138
revision_now: Revision,
143-
database_key_index: DatabaseKeyIndex,
144139
accumulated: InputAccumulatedValues,
145140
) {
146-
db.salsa_event(&|| {
147-
Event::new(EventKind::DidValidateMemoizedValue {
148-
database_key: database_key_index,
149-
})
150-
});
151-
152141
self.verified_at.store(revision_now);
153142
self.revisions.accumulated_inputs.store(accumulated);
154143
}
155144

156145
pub(super) fn mark_outputs_as_verified(
157146
&self,
158147
zalsa: &Zalsa,
159-
db: &dyn crate::Database,
160148
database_key_index: DatabaseKeyIndex,
161149
) {
162150
for output in self.revisions.origin.outputs() {
163-
output.mark_validated_output(zalsa, db, database_key_index);
151+
output.mark_validated_output(zalsa, database_key_index);
164152
}
165153
}
166154

src/function/specify.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::{
22
accumulator::accumulated_map::InputAccumulatedValues,
33
revision::AtomicRevision,
44
tracked_struct::TrackedStructInDb,
5-
zalsa::ZalsaDatabase,
5+
zalsa::{Zalsa, ZalsaDatabase},
66
zalsa_local::{QueryOrigin, QueryRevisions},
7-
AsDynDatabase as _, Database, DatabaseKeyIndex, Id,
7+
AsDynDatabase as _, DatabaseKeyIndex, Id,
88
};
99

1010
use super::{memo::Memo, Configuration, IngredientImpl};
@@ -103,11 +103,10 @@ where
103103
/// it would have specified `key` again.
104104
pub(super) fn validate_specified_value(
105105
&self,
106-
db: &dyn Database,
106+
zalsa: &Zalsa,
107107
executor: DatabaseKeyIndex,
108108
key: Id,
109109
) {
110-
let zalsa = db.zalsa();
111110
let memo_ingredient_index = self.memo_ingredient_index(zalsa, key);
112111

113112
let memo = match self.get_memo_from_table_for(zalsa, key, memo_ingredient_index) {
@@ -125,12 +124,6 @@ where
125124
),
126125
}
127126

128-
let database_key_index = self.database_key_index(key);
129-
memo.mark_as_verified(
130-
db,
131-
zalsa.current_revision(),
132-
database_key_index,
133-
InputAccumulatedValues::Empty,
134-
);
127+
memo.mark_as_verified(zalsa.current_revision(), InputAccumulatedValues::Empty);
135128
}
136129
}

src/ingredient.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
6565
/// Invoked when the value `output_key` should be marked as valid in the current revision.
6666
/// This occurs because the value for `executor`, which generated it, was marked as valid
6767
/// in the current revision.
68-
fn mark_validated_output<'db>(
69-
&'db self,
70-
db: &'db dyn Database,
68+
fn mark_validated_output(
69+
&self,
70+
zalsa: &Zalsa,
7171
executor: DatabaseKeyIndex,
7272
output_key: crate::Id,
7373
) {
74-
let _ = (db, executor, output_key);
74+
let _ = (zalsa, executor, output_key);
7575
unreachable!("only tracked struct and function ingredients can have validatable outputs")
7676
}
7777

src/key.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ impl OutputDependencyIndex {
4545
pub(crate) fn mark_validated_output(
4646
&self,
4747
zalsa: &Zalsa,
48-
db: &dyn Database,
4948
database_key_index: DatabaseKeyIndex,
5049
) {
5150
zalsa
5251
.lookup_ingredient(self.ingredient_index)
53-
.mark_validated_output(db, database_key_index, self.key_index)
52+
.mark_validated_output(zalsa, database_key_index, self.key_index)
5453
}
5554
}
5655

src/tracked_struct.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,9 @@ where
728728
MaybeChangedAfter::from(data.created_at > revision)
729729
}
730730

731-
fn mark_validated_output<'db>(
732-
&'db self,
733-
_db: &'db dyn Database,
731+
fn mark_validated_output(
732+
&self,
733+
_zalsa: &Zalsa,
734734
_executor: DatabaseKeyIndex,
735735
_output_key: crate::Id,
736736
) {

0 commit comments

Comments
 (0)