mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-07-07 21:35:17 +00:00

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.
25 lines
561 B
Rust
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);
|
|
}
|