diff --git a/src/event.rs b/src/event.rs index d2d72dc85..8cbe56bf1 100644 --- a/src/event.rs +++ b/src/event.rs @@ -59,6 +59,13 @@ pub enum EventKind { database_key: DatabaseKeyIndex, }, + WillIterateCycle { + /// The database-key for the cycle head. Implements `Debug`. + database_key: DatabaseKeyIndex, + iteration_count: u32, + fell_back: bool, + }, + /// Indicates that `unwind_if_cancelled` was called and salsa will check if /// the current revision has been cancelled. WillCheckCancellation, diff --git a/src/function/execute.rs b/src/function/execute.rs index c8c2e3237..557463817 100644 --- a/src/function/execute.rs +++ b/src/function/execute.rs @@ -123,6 +123,13 @@ where if iteration_count > MAX_ITERATIONS { panic!("{database_key_index:?}: execute: too many cycle iterations"); } + db.salsa_event(&|| { + Event::new(EventKind::WillIterateCycle { + database_key: database_key_index, + iteration_count, + fell_back, + }) + }); revisions .cycle_heads .update_iteration_count(database_key_index, iteration_count); diff --git a/tests/common/mod.rs b/tests/common/mod.rs index bfc5429fa..5597a2fb3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -128,6 +128,7 @@ impl Database for ExecuteValidateLoggerDatabase { let event = event(); match event.kind { salsa::EventKind::WillExecute { .. } + | salsa::EventKind::WillIterateCycle { .. } | salsa::EventKind::DidValidateMemoizedValue { .. } => { self.push_log(format!("salsa_event({:?})", event.kind)); } diff --git a/tests/cycle.rs b/tests/cycle.rs index 596c51256..25702a153 100644 --- a/tests/cycle.rs +++ b/tests/cycle.rs @@ -871,7 +871,7 @@ fn cycle_unchanged() { a.assert_value(&db, 59); b.assert_value(&db, 60); - db.assert_logs_len(4); + db.assert_logs_len(5); // next revision, we change only A, which is not part of the cycle and the cycle does not // depend on. @@ -917,7 +917,7 @@ fn cycle_unchanged_nested() { a.assert_value(&db, 59); b.assert_value(&db, 60); - db.assert_logs_len(10); + db.assert_logs_len(13); // next revision, we change only A, which is not part of the cycle and the cycle does not // depend on. @@ -984,7 +984,7 @@ fn cycle_unchanged_nested_intertwined() { e.assert_value(&db, 60); } - db.assert_logs_len(12 + i); + db.assert_logs_len(15 + i); // next revision, we change only A, which is not part of the cycle and the cycle does not // depend on. @@ -1031,6 +1031,7 @@ fn repeat_provisional_query() { "salsa_event(WillExecute { database_key: min_iterate(Id(0)) })", "salsa_event(WillExecute { database_key: min_panic(Id(1)) })", "salsa_event(WillExecute { database_key: min_panic(Id(2)) })", + "salsa_event(WillIterateCycle { database_key: min_iterate(Id(0)), iteration_count: 1, fell_back: false })", "salsa_event(WillExecute { database_key: min_panic(Id(1)) })", "salsa_event(WillExecute { database_key: min_panic(Id(2)) })", ]"#]]); diff --git a/tests/cycle_tracked.rs b/tests/cycle_tracked.rs index 11abd27ec..fdf42cad4 100644 --- a/tests/cycle_tracked.rs +++ b/tests/cycle_tracked.rs @@ -163,6 +163,7 @@ fn main() { "WillExecute { database_key: cost_to_start(Id(401)) }", "WillCheckCancellation", "WillCheckCancellation", + "WillIterateCycle { database_key: cost_to_start(Id(403)), iteration_count: 1, fell_back: false }", "WillCheckCancellation", "WillCheckCancellation", "WillCheckCancellation",