Skip to content

Commit 99ec0a4

Browse files
committed
remove table-wide dependencies
1 parent 254c749 commit 99ec0a4

15 files changed

+117
-226
lines changed

book/src/plumbing/jars_and_ingredients.md

-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ It combines an [`IngredientIndex`] with a `key_index`, which is a `salsa::Id`:
146146
{{#include ../../../src/key.rs:DatabaseKeyIndex}}
147147
```
148148

149-
A `DependencyIndex` is similar, but the `key_index` is optional.
150-
This is used when we sometimes wish to refer to the ingredient as a whole, and not any specific value within the ingredient.
151-
152149
These kinds of indices are used to store connetions between ingredients.
153150
For example, each memoized value has to track its inputs.
154151
Those inputs are stored as dependency indices.

src/accumulator.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,7 @@ impl<A: Accumulator> Ingredient for IngredientImpl<A> {
9797
self.index
9898
}
9999

100-
fn maybe_changed_after(
101-
&self,
102-
_db: &dyn Database,
103-
_input: Option<Id>,
104-
_revision: Revision,
105-
) -> bool {
100+
fn maybe_changed_after(&self, _db: &dyn Database, _input: Id, _revision: Revision) -> bool {
106101
panic!("nothing should ever depend on an accumulator directly")
107102
}
108103

@@ -118,15 +113,15 @@ impl<A: Accumulator> Ingredient for IngredientImpl<A> {
118113
&self,
119114
_db: &dyn Database,
120115
_executor: DatabaseKeyIndex,
121-
_output_key: Option<crate::Id>,
116+
_output_key: Id,
122117
) {
123118
}
124119

125120
fn remove_stale_output(
126121
&self,
127122
_db: &dyn Database,
128123
_executor: DatabaseKeyIndex,
129-
_stale_output_key: Option<crate::Id>,
124+
_stale_output_key: Id,
130125
) {
131126
}
132127

@@ -138,7 +133,7 @@ impl<A: Accumulator> Ingredient for IngredientImpl<A> {
138133
panic!("unexpected reset on accumulator")
139134
}
140135

141-
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
136+
fn fmt_index(&self, index: Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
142137
fmt_index(A::DEBUG_NAME, index, fmt)
143138
}
144139

src/active_query.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
accumulator::accumulated_map::AccumulatedMap,
77
durability::Durability,
88
hash::FxIndexSet,
9-
key::{DatabaseKeyIndex, DependencyIndex},
9+
key::DatabaseKeyIndex,
1010
tracked_struct::{Disambiguator, Identity},
1111
zalsa_local::EMPTY_DEPENDENCIES,
1212
Cycle, Id, Revision,
@@ -30,7 +30,7 @@ pub(crate) struct ActiveQuery {
3030
/// * tracked structs created
3131
/// * invocations of `specify`
3232
/// * accumulators pushed to
33-
input_outputs: FxIndexSet<(EdgeKind, DependencyIndex)>,
33+
input_outputs: FxIndexSet<(EdgeKind, DatabaseKeyIndex)>,
3434

3535
/// True if there was an untracked read.
3636
untracked_read: bool,
@@ -73,7 +73,7 @@ impl ActiveQuery {
7373

7474
pub(super) fn add_read(
7575
&mut self,
76-
input: DependencyIndex,
76+
input: DatabaseKeyIndex,
7777
durability: Durability,
7878
revision: Revision,
7979
) {
@@ -95,12 +95,12 @@ impl ActiveQuery {
9595
}
9696

9797
/// Adds a key to our list of outputs.
98-
pub(super) fn add_output(&mut self, key: DependencyIndex) {
98+
pub(super) fn add_output(&mut self, key: DatabaseKeyIndex) {
9999
self.input_outputs.insert((EdgeKind::Output, key));
100100
}
101101

102102
/// True if the given key was output by this query.
103-
pub(super) fn is_output(&self, key: DependencyIndex) -> bool {
103+
pub(super) fn is_output(&self, key: DatabaseKeyIndex) -> bool {
104104
self.input_outputs.contains(&(EdgeKind::Output, key))
105105
}
106106

@@ -142,7 +142,7 @@ impl ActiveQuery {
142142
/// Used during cycle recovery, see [`Runtime::unblock_cycle_and_maybe_throw`].
143143
pub(super) fn remove_cycle_participants(&mut self, cycle: &Cycle) {
144144
for p in cycle.participant_keys() {
145-
let p: DependencyIndex = p.into();
145+
let p: DatabaseKeyIndex = p.into();
146146
self.input_outputs.shift_remove(&(EdgeKind::Input, p));
147147
}
148148
}

src/database.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub trait Database: Send + AsDynDatabase + Any + ZalsaDatabase {
4545
/// which are the fine-grained components we use to track data. This is intended
4646
/// for debugging and the contents of the returned string are not semver-guaranteed.
4747
///
48-
/// Ingredient indices can be extracted from [`DependencyIndex`](`crate::DependencyIndex`) values.
48+
/// Ingredient indices can be extracted from [`DatabaseIndex`](`crate::DatabaseIndex`) values.
4949
fn ingredient_debug_name(&self, ingredient_index: IngredientIndex) -> Cow<'_, str> {
5050
Cow::Borrowed(
5151
self.zalsa()

src/event.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::thread::ThreadId;
22

3-
use crate::{key::DatabaseKeyIndex, key::DependencyIndex};
3+
use crate::key::DatabaseKeyIndex;
44

55
/// The `Event` struct identifies various notable things that can
66
/// occur during salsa execution. Instances of this struct are given
@@ -64,7 +64,7 @@ pub enum EventKind {
6464
execute_key: DatabaseKeyIndex,
6565

6666
/// Key for the query that is no longer output
67-
output_key: DependencyIndex,
67+
output_key: DatabaseKeyIndex,
6868
},
6969

7070
/// Tracked structs or memoized data were discarded (freed).
@@ -79,6 +79,6 @@ pub enum EventKind {
7979
executor_key: DatabaseKeyIndex,
8080

8181
/// Accumulator that was accumulated into
82-
accumulator: DependencyIndex,
82+
accumulator: DatabaseKeyIndex,
8383
},
8484
}

src/function.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,9 @@ where
189189
self.index
190190
}
191191

192-
fn maybe_changed_after(
193-
&self,
194-
db: &dyn Database,
195-
input: Option<Id>,
196-
revision: Revision,
197-
) -> bool {
198-
let key = input.unwrap();
192+
fn maybe_changed_after(&self, db: &dyn Database, input: Id, revision: Revision) -> bool {
199193
let db = db.as_view::<C::DbView>();
200-
self.maybe_changed_after(db, key, revision)
194+
self.maybe_changed_after(db, input, revision)
201195
}
202196

203197
fn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy {
@@ -208,21 +202,15 @@ where
208202
self.origin(db.zalsa(), key)
209203
}
210204

211-
fn mark_validated_output(
212-
&self,
213-
db: &dyn Database,
214-
executor: DatabaseKeyIndex,
215-
output_key: Option<crate::Id>,
216-
) {
217-
let output_key = output_key.unwrap();
205+
fn mark_validated_output(&self, db: &dyn Database, executor: DatabaseKeyIndex, output_key: Id) {
218206
self.validate_specified_value(db, executor, output_key);
219207
}
220208

221209
fn remove_stale_output(
222210
&self,
223211
_db: &dyn Database,
224212
_executor: DatabaseKeyIndex,
225-
_stale_output_key: Option<crate::Id>,
213+
_stale_output_key: Id,
226214
) {
227215
// This function is invoked when a query Q specifies the value for `stale_output_key` in rev 1,
228216
// but not in rev 2. We don't do anything in this case, we just leave the (now stale) memo.
@@ -237,7 +225,7 @@ where
237225
std::mem::take(&mut self.deleted_entries);
238226
}
239227

240-
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
228+
fn fmt_index(&self, index: Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
241229
fmt_index(C::DEBUG_NAME, index, fmt)
242230
}
243231

src/function/diff_outputs.rs

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

77
impl<C> IngredientImpl<C>
@@ -33,9 +33,9 @@ where
3333
// Remove the outputs that are no longer present in the current revision
3434
// to prevent that the next revision is seeded with a id mapping that no longer exists.
3535
revisions.tracked_struct_ids.retain(|k, value| {
36-
!old_outputs.contains(&DependencyIndex {
36+
!old_outputs.contains(&DatabaseKeyIndex {
3737
ingredient_index: k.ingredient_index(),
38-
key_index: Some(*value),
38+
key_index: *value,
3939
})
4040
});
4141
}
@@ -45,7 +45,7 @@ where
4545
}
4646
}
4747

48-
fn report_stale_output(db: &C::DbView, key: DatabaseKeyIndex, output: DependencyIndex) {
48+
fn report_stale_output(db: &C::DbView, key: DatabaseKeyIndex, output: DatabaseKeyIndex) {
4949
let db = db.as_dyn_database();
5050

5151
db.salsa_event(&|| Event {

src/ingredient.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
3636
fn maybe_changed_after<'db>(
3737
&'db self,
3838
db: &'db dyn Database,
39-
input: Option<Id>,
39+
input: Id,
4040
revision: Revision,
4141
) -> bool;
4242

@@ -60,7 +60,7 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
6060
&'db self,
6161
db: &'db dyn Database,
6262
executor: DatabaseKeyIndex,
63-
output_key: Option<Id>,
63+
output_key: Id,
6464
);
6565

6666
/// Invoked when the value `stale_output` was output by `executor` in a previous
@@ -71,7 +71,7 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
7171
&self,
7272
db: &dyn Database,
7373
executor: DatabaseKeyIndex,
74-
stale_output_key: Option<Id>,
74+
stale_output_key: Id,
7575
);
7676

7777
/// Returns the [`IngredientIndex`] of this ingredient.
@@ -98,7 +98,7 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
9898
/// [`IngredientRequiresReset::RESET_ON_NEW_REVISION`] to true.
9999
fn reset_for_new_revision(&mut self);
100100

101-
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
101+
fn fmt_index(&self, index: Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result;
102102
}
103103

104104
impl dyn Ingredient {
@@ -138,14 +138,6 @@ impl dyn Ingredient {
138138
}
139139

140140
/// A helper function to show human readable fmt.
141-
pub(crate) fn fmt_index(
142-
debug_name: &str,
143-
id: Option<Id>,
144-
fmt: &mut fmt::Formatter<'_>,
145-
) -> fmt::Result {
146-
if let Some(i) = id {
147-
write!(fmt, "{debug_name}({i:?})")
148-
} else {
149-
write!(fmt, "{debug_name}()")
150-
}
141+
pub(crate) fn fmt_index(debug_name: &str, id: Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
142+
write!(fmt, "{debug_name}({id:?})")
151143
}

src/input.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
cycle::CycleRecoveryStrategy,
1212
id::{AsId, FromId},
1313
ingredient::{fmt_index, Ingredient},
14-
key::{DatabaseKeyIndex, DependencyIndex},
14+
key::DatabaseKeyIndex,
1515
plumbing::{Jar, JarAux, Stamp},
1616
table::{memo::MemoTable, sync::SyncTable, Slot, Table},
1717
zalsa::{IngredientIndex, Zalsa},
@@ -182,9 +182,9 @@ impl<C: Configuration> IngredientImpl<C> {
182182
let value = Self::data(zalsa, id);
183183
let stamp = &value.stamps[field_index];
184184
zalsa_local.report_tracked_read(
185-
DependencyIndex {
185+
DatabaseKeyIndex {
186186
ingredient_index: field_ingredient_index,
187-
key_index: Some(id),
187+
key_index: id,
188188
},
189189
stamp.durability,
190190
stamp.changed_at,
@@ -207,12 +207,7 @@ impl<C: Configuration> Ingredient for IngredientImpl<C> {
207207
self.ingredient_index
208208
}
209209

210-
fn maybe_changed_after(
211-
&self,
212-
_db: &dyn Database,
213-
_input: Option<Id>,
214-
_revision: Revision,
215-
) -> bool {
210+
fn maybe_changed_after(&self, _db: &dyn Database, _input: Id, _revision: Revision) -> bool {
216211
// Input ingredients are just a counter, they store no data, they are immortal.
217212
// Their *fields* are stored in function ingredients elsewhere.
218213
false
@@ -230,7 +225,7 @@ impl<C: Configuration> Ingredient for IngredientImpl<C> {
230225
&self,
231226
_db: &dyn Database,
232227
executor: DatabaseKeyIndex,
233-
output_key: Option<Id>,
228+
output_key: Id,
234229
) {
235230
unreachable!(
236231
"mark_validated_output({:?}, {:?}): input cannot be the output of a tracked function",
@@ -242,7 +237,7 @@ impl<C: Configuration> Ingredient for IngredientImpl<C> {
242237
&self,
243238
_db: &dyn Database,
244239
executor: DatabaseKeyIndex,
245-
stale_output_key: Option<Id>,
240+
stale_output_key: Id,
246241
) {
247242
unreachable!(
248243
"remove_stale_output({:?}, {:?}): input cannot be the output of a tracked function",
@@ -258,7 +253,7 @@ impl<C: Configuration> Ingredient for IngredientImpl<C> {
258253
panic!("unexpected call to `reset_for_new_revision`")
259254
}
260255

261-
fn fmt_index(&self, index: Option<Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
256+
fn fmt_index(&self, index: Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
262257
fmt_index(C::DEBUG_NAME, index, fmt)
263258
}
264259

src/input/input_field.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,8 @@ where
4949
CycleRecoveryStrategy::Panic
5050
}
5151

52-
fn maybe_changed_after(
53-
&self,
54-
db: &dyn Database,
55-
input: Option<Id>,
56-
revision: Revision,
57-
) -> bool {
52+
fn maybe_changed_after(&self, db: &dyn Database, input: Id, revision: Revision) -> bool {
5853
let zalsa = db.zalsa();
59-
let input = input.unwrap();
6054
let value = <IngredientImpl<C>>::data(zalsa, input);
6155
value.stamps[self.field_index].changed_at > revision
6256
}
@@ -69,15 +63,15 @@ where
6963
&self,
7064
_db: &dyn Database,
7165
_executor: DatabaseKeyIndex,
72-
_output_key: Option<Id>,
66+
_output_key: Id,
7367
) {
7468
}
7569

7670
fn remove_stale_output(
7771
&self,
7872
_db: &dyn Database,
7973
_executor: DatabaseKeyIndex,
80-
_stale_output_key: Option<Id>,
74+
_stale_output_key: Id,
8175
) {
8276
}
8377

@@ -89,7 +83,7 @@ where
8983
panic!("unexpected call: input fields don't register for resets");
9084
}
9185

92-
fn fmt_index(&self, index: Option<crate::Id>, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
86+
fn fmt_index(&self, index: Id, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
9387
fmt_index(C::FIELD_DEBUG_NAMES[self.field_index], index, fmt)
9488
}
9589

0 commit comments

Comments
 (0)