Skip to content

Commit

Permalink
WIP: add tracing for cycle iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed Oct 24, 2024
1 parent 7fcfd7f commit f700c39
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/function/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,24 @@ where
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: \
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) {
tracing::debug!(
"{database_key_index:?}: execute: not converged, calling cycle_fn"
);
// 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(
Expand All @@ -98,6 +109,9 @@ where
continue;
}
crate::CycleRecoveryAction::Fallback(fallback_value) => {
tracing::debug!(
"{database_key_index:?}: execute: fall back to {fallback_value:#?}"
);
new_value = fallback_value;
}
}
Expand All @@ -106,7 +120,7 @@ where
}
// This is no longer a provisional result, it's our final result, so remove ourself
// from the cycle heads, and iterate one last time to remove ourself from all other
// results in the cycle as well.
// results in the cycle as well and turn them into usable cached results.
revisions.cycle_heads.remove(&database_key_index);
revisions.cycle_ignore = false;
self.insert_memo(
Expand All @@ -116,6 +130,9 @@ where
);
continue;
}

tracing::debug!("{database_key_index:?}: execute: result.revisions = {revisions:#?}");

return self.insert_memo(
zalsa,
id,
Expand Down

0 comments on commit f700c39

Please sign in to comment.