Skip to content

Commit 87bf6b6

Browse files
authored
add WillIterateCycle event (#790)
* add WillIterateCycle event * add iteration_count and fell_back to event
1 parent b165ba7 commit 87bf6b6

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

src/event.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ pub enum EventKind {
5959
database_key: DatabaseKeyIndex,
6060
},
6161

62+
WillIterateCycle {
63+
/// The database-key for the cycle head. Implements `Debug`.
64+
database_key: DatabaseKeyIndex,
65+
iteration_count: u32,
66+
fell_back: bool,
67+
},
68+
6269
/// Indicates that `unwind_if_cancelled` was called and salsa will check if
6370
/// the current revision has been cancelled.
6471
WillCheckCancellation,

src/function/execute.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ where
123123
if iteration_count > MAX_ITERATIONS {
124124
panic!("{database_key_index:?}: execute: too many cycle iterations");
125125
}
126+
db.salsa_event(&|| {
127+
Event::new(EventKind::WillIterateCycle {
128+
database_key: database_key_index,
129+
iteration_count,
130+
fell_back,
131+
})
132+
});
126133
revisions
127134
.cycle_heads
128135
.update_iteration_count(database_key_index, iteration_count);

tests/common/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl Database for ExecuteValidateLoggerDatabase {
128128
let event = event();
129129
match event.kind {
130130
salsa::EventKind::WillExecute { .. }
131+
| salsa::EventKind::WillIterateCycle { .. }
131132
| salsa::EventKind::DidValidateMemoizedValue { .. } => {
132133
self.push_log(format!("salsa_event({:?})", event.kind));
133134
}

tests/cycle.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ fn cycle_unchanged() {
871871
a.assert_value(&db, 59);
872872
b.assert_value(&db, 60);
873873

874-
db.assert_logs_len(4);
874+
db.assert_logs_len(5);
875875

876876
// next revision, we change only A, which is not part of the cycle and the cycle does not
877877
// depend on.
@@ -917,7 +917,7 @@ fn cycle_unchanged_nested() {
917917
a.assert_value(&db, 59);
918918
b.assert_value(&db, 60);
919919

920-
db.assert_logs_len(10);
920+
db.assert_logs_len(13);
921921

922922
// next revision, we change only A, which is not part of the cycle and the cycle does not
923923
// depend on.
@@ -984,7 +984,7 @@ fn cycle_unchanged_nested_intertwined() {
984984
e.assert_value(&db, 60);
985985
}
986986

987-
db.assert_logs_len(12 + i);
987+
db.assert_logs_len(15 + i);
988988

989989
// next revision, we change only A, which is not part of the cycle and the cycle does not
990990
// depend on.
@@ -1031,6 +1031,7 @@ fn repeat_provisional_query() {
10311031
"salsa_event(WillExecute { database_key: min_iterate(Id(0)) })",
10321032
"salsa_event(WillExecute { database_key: min_panic(Id(1)) })",
10331033
"salsa_event(WillExecute { database_key: min_panic(Id(2)) })",
1034+
"salsa_event(WillIterateCycle { database_key: min_iterate(Id(0)), iteration_count: 1, fell_back: false })",
10341035
"salsa_event(WillExecute { database_key: min_panic(Id(1)) })",
10351036
"salsa_event(WillExecute { database_key: min_panic(Id(2)) })",
10361037
]"#]]);

tests/cycle_tracked.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ fn main() {
163163
"WillExecute { database_key: cost_to_start(Id(401)) }",
164164
"WillCheckCancellation",
165165
"WillCheckCancellation",
166+
"WillIterateCycle { database_key: cost_to_start(Id(403)), iteration_count: 1, fell_back: false }",
166167
"WillCheckCancellation",
167168
"WillCheckCancellation",
168169
"WillCheckCancellation",

0 commit comments

Comments
 (0)