salsa/tests/cycle_result_dependencies.rs
Chayim Refael Friedman 05b4faddb5
Add a third cycle mode, equivalent to old Salsa cycle behavior (#801)
That is, directly set a value for all queries that have fallbacks, and ignore all other queries in the cycle.

Unlike old Salsa, we still need all cycle heads to be marked, and we still execute the queries to completion, but we throw their result.
2025-04-22 10:35:43 +00:00

25 lines
561 B
Rust

use salsa::{Database, Setter};
#[salsa::input]
struct Input {
value: i32,
}
#[salsa::tracked(cycle_result=cycle_result)]
fn has_cycle(db: &dyn Database, input: Input) -> i32 {
has_cycle(db, input)
}
fn cycle_result(db: &dyn Database, input: Input) -> i32 {
input.value(db)
}
#[test]
fn cycle_result_dependencies_are_recorded() {
let mut db = salsa::DatabaseImpl::default();
let input = Input::new(&db, 123);
assert_eq!(has_cycle(&db, input), 123);
input.set_value(&mut db).to(456);
assert_eq!(has_cycle(&db, input), 456);
}