Skip to content

Commit

Permalink
WIP: fail fast if we get an evicted provisional value
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Oct 24, 2024
1 parent f411766 commit e16055d
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/function/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,37 +80,36 @@ where
// Did the new result we got depend on our own provisional value, in a cycle?
if revisions.cycle_heads.contains(&database_key_index) {
if let Some(last_provisional) = opt_last_provisional {
if let Some(provisional_value) = &last_provisional.value {
tracing::debug!(
"{database_key_index:?}: execute: \
// Memo value can only be `None` if LRU evicted; TODO should we explicitly
// prevent LRU eviction of cycle-head provisional memos?
let provisional_value = last_provisional.value.as_ref().unwrap();
tracing::debug!(
"{database_key_index:?}: execute: \
I am a cycle head, comparing last provisional value \
{provisional_value:#?} with new value {new_value:#?}"
);
// If the new result is equal to the last provisional result, the cycle has
// converged and we are done.
if !C::values_equal(&new_value, provisional_value) {
// We are in a cycle that hasn't converged; ask the user's
// cycle-recovery function what to do:
match C::recover_from_cycle(db, &new_value, iteration_count) {
crate::CycleRecoveryAction::Iterate => {
tracing::debug!(
"{database_key_index:?}: execute: iterate again"
);
iteration_count += 1;
revisions.cycle_ignore = false;
opt_last_provisional = Some(self.insert_memo(
zalsa,
id,
Memo::new(Some(new_value), revision_now, revisions),
));
continue;
}
crate::CycleRecoveryAction::Fallback(fallback_value) => {
tracing::debug!(
);
// If the new result is equal to the last provisional result, the cycle has
// converged and we are done.
if !C::values_equal(&new_value, provisional_value) {
// We are in a cycle that hasn't converged; ask the user's
// cycle-recovery function what to do:
match C::recover_from_cycle(db, &new_value, iteration_count) {
crate::CycleRecoveryAction::Iterate => {
tracing::debug!("{database_key_index:?}: execute: iterate again");
iteration_count += 1;
revisions.cycle_ignore = false;
opt_last_provisional = Some(self.insert_memo(
zalsa,
id,
Memo::new(Some(new_value), revision_now, revisions),
));
continue;
}
crate::CycleRecoveryAction::Fallback(fallback_value) => {
tracing::debug!(
"{database_key_index:?}: execute: fall back to {fallback_value:#?}"
);
new_value = fallback_value;
}
new_value = fallback_value;
}
}
}
Expand Down

0 comments on commit e16055d

Please sign in to comment.