Skip to content

Commit

Permalink
Remove panicking paths from maybe_changed_after
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jan 5, 2025
1 parent 38ddd63 commit 1b51d4d
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 68 deletions.
7 changes: 1 addition & 6 deletions src/accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ impl<A: Accumulator> Ingredient for IngredientImpl<A> {
self.index
}

fn maybe_changed_after(
&self,
_db: &dyn Database,
_input: Option<Id>,
_revision: Revision,
) -> bool {
fn maybe_changed_after(&self, _db: &dyn Database, _input: Id, _revision: Revision) -> bool {
panic!("nothing should ever depend on an accumulator directly")
}

Expand Down
10 changes: 2 additions & 8 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,9 @@ where
self.index
}

fn maybe_changed_after(
&self,
db: &dyn Database,
input: Option<Id>,
revision: Revision,
) -> bool {
let key = input.unwrap();
fn maybe_changed_after(&self, db: &dyn Database, input: Id, revision: Revision) -> bool {
let db = db.as_view::<C::DbView>();
self.maybe_changed_after(db, key, revision)
self.maybe_changed_after(db, input, revision)
}

fn cycle_recovery_strategy(&self) -> CycleRecoveryStrategy {
Expand Down
2 changes: 1 addition & 1 deletion src/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait Ingredient: Any + std::fmt::Debug + Send + Sync {
fn maybe_changed_after<'db>(
&'db self,
db: &'db dyn Database,
input: Option<Id>,
input: Id,
revision: Revision,
) -> bool;

Expand Down
7 changes: 1 addition & 6 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,7 @@ impl<C: Configuration> Ingredient for IngredientImpl<C> {
self.ingredient_index
}

fn maybe_changed_after(
&self,
_db: &dyn Database,
_input: Option<Id>,
_revision: Revision,
) -> bool {
fn maybe_changed_after(&self, _db: &dyn Database, _input: Id, _revision: Revision) -> bool {
// Input ingredients are just a counter, they store no data, they are immortal.
// Their *fields* are stored in function ingredients elsewhere.
false
Expand Down
8 changes: 1 addition & 7 deletions src/input/input_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,8 @@ where
CycleRecoveryStrategy::Panic
}

fn maybe_changed_after(
&self,
db: &dyn Database,
input: Option<Id>,
revision: Revision,
) -> bool {
fn maybe_changed_after(&self, db: &dyn Database, input: Id, revision: Revision) -> bool {
let zalsa = db.zalsa();
let input = input.unwrap();
let value = <IngredientImpl<C>>::data(zalsa, input);
value.stamps[self.field_index].changed_at > revision
}
Expand Down
7 changes: 1 addition & 6 deletions src/interned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,7 @@ where
self.ingredient_index
}

fn maybe_changed_after(
&self,
_db: &dyn Database,
_input: Option<Id>,
revision: Revision,
) -> bool {
fn maybe_changed_after(&self, _db: &dyn Database, _input: Id, revision: Revision) -> bool {
revision < self.reset_at
}

Expand Down
11 changes: 8 additions & 3 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,14 @@ impl InputDependencyIndex {
db: &dyn Database,
last_verified_at: crate::Revision,
) -> bool {
db.zalsa()
.lookup_ingredient(self.ingredient_index)
.maybe_changed_after(db, self.key_index, last_verified_at)
match self.key_index {
Some(key_index) => db
.zalsa()
.lookup_ingredient(self.ingredient_index)
.maybe_changed_after(db, key_index, last_verified_at),
// Data in tables themselves remain valid until the table as a whole is reset.
None => false,
}
}

pub fn set_key_index(&mut self, key_index: Id) {
Expand Down
7 changes: 1 addition & 6 deletions src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,7 @@ where
self.ingredient_index
}

fn maybe_changed_after(
&self,
_db: &dyn Database,
_input: Option<Id>,
_revision: Revision,
) -> bool {
fn maybe_changed_after(&self, _db: &dyn Database, _input: Id, _revision: Revision) -> bool {
false
}

Expand Down
5 changes: 2 additions & 3 deletions src/tracked_struct/tracked_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ where
fn maybe_changed_after<'db>(
&'db self,
db: &'db dyn Database,
input: Option<Id>,
input: Id,
revision: crate::Revision,
) -> bool {
let zalsa = db.zalsa();
let id = input.unwrap();
let data = <super::IngredientImpl<C>>::data(zalsa.table(), id);
let data = <super::IngredientImpl<C>>::data(zalsa.table(), input);
let field_changed_at = data.revisions[self.field_index];
field_changed_at > revision
}
Expand Down
2 changes: 1 addition & 1 deletion src/zalsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl JarAux for JarAuxImpl<'_> {
memo_ingredients
} else {
memo_ingredients.resize_with(idx + 1, Vec::new);
memo_ingredients.get_mut(idx).unwrap()
&mut memo_ingredients[idx]
};
let mi = MemoIngredientIndex(u32::try_from(memo_ingredients.len()).unwrap());
memo_ingredients.push(ingredient_index);
Expand Down
30 changes: 9 additions & 21 deletions src/zalsa_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ impl ZalsaLocal {
c(self.query_stack.borrow_mut().as_mut())
}

fn query_in_progress(&self) -> bool {
self.with_query_stack(|stack| !stack.is_empty())
}

/// Returns the index of the active query along with its *current* durability/changed-at
/// information. As the query continues to execute, naturally, that information may change.
pub(crate) fn active_query(&self) -> Option<(DatabaseKeyIndex, StampedValue<()>)> {
Expand Down Expand Up @@ -239,13 +235,10 @@ impl ZalsaLocal {
/// * the disambiguator index
#[track_caller]
pub(crate) fn disambiguate(&self, key: IdentityHash) -> (StampedValue<()>, Disambiguator) {
assert!(
self.query_in_progress(),
"cannot create a tracked struct disambiguator outside of a tracked function"
);

self.with_query_stack(|stack| {
let top_query = stack.last_mut().unwrap();
let top_query = stack.last_mut().expect(
"cannot create a tracked struct disambiguator outside of a tracked function",
);
let disambiguator = top_query.disambiguate(key);
(
StampedValue {
Expand All @@ -260,25 +253,20 @@ impl ZalsaLocal {

#[track_caller]
pub(crate) fn tracked_struct_id(&self, identity: &Identity) -> Option<Id> {
debug_assert!(
self.query_in_progress(),
"cannot create a tracked struct disambiguator outside of a tracked function"
);

self.with_query_stack(|stack| {
let top_query = stack.last().unwrap();
let top_query = stack.last().expect(
"cannot create a tracked struct disambiguator outside of a tracked function",
);
top_query.tracked_struct_ids.get(identity).copied()
})
}

#[track_caller]
pub(crate) fn store_tracked_struct_id(&self, identity: Identity, id: Id) {
debug_assert!(
self.query_in_progress(),
"cannot create a tracked struct disambiguator outside of a tracked function"
);
self.with_query_stack(|stack| {
let top_query = stack.last_mut().unwrap();
let top_query = stack.last_mut().expect(
"cannot create a tracked struct disambiguator outside of a tracked function",
);
let old_id = top_query.tracked_struct_ids.insert(identity, id);
assert!(
old_id.is_none(),
Expand Down

0 comments on commit 1b51d4d

Please sign in to comment.