mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-12 16:35:21 +00:00
Add test for cycle detection
This commit is contained in:
parent
803095f13d
commit
5b43da0cd2
1 changed files with 73 additions and 0 deletions
73
tests/cycles.rs
Normal file
73
tests/cycles.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
#![feature(crate_visibility_modifier)]
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct QueryContextImpl {
|
||||
runtime: salsa::runtime::Runtime<QueryContextImpl>,
|
||||
}
|
||||
|
||||
impl salsa::QueryContext for QueryContextImpl {
|
||||
fn salsa_runtime(&self) -> &salsa::runtime::Runtime<QueryContextImpl> {
|
||||
&self.runtime
|
||||
}
|
||||
}
|
||||
|
||||
salsa::query_context_storage! {
|
||||
pub struct QueryContextImplStorage for QueryContextImpl {
|
||||
impl QueryContext {
|
||||
fn memoized_a() for MemoizedA;
|
||||
fn memoized_b() for MemoizedB;
|
||||
fn volatile_a() for VolatileA;
|
||||
fn volatile_b() for VolatileB;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait QueryContext: salsa::QueryContext {
|
||||
salsa::query_prototype! {
|
||||
// `a` and `b` depend on each other and form a cycle
|
||||
fn memoized_a() for MemoizedA;
|
||||
fn memoized_b() for MemoizedB;
|
||||
fn volatile_a() for VolatileA;
|
||||
fn volatile_b() for VolatileB;
|
||||
}
|
||||
}
|
||||
|
||||
salsa::query_definition! {
|
||||
crate MemoizedA(query: &impl QueryContext, (): ()) -> () {
|
||||
query.memoized_b().get(())
|
||||
}
|
||||
}
|
||||
|
||||
salsa::query_definition! {
|
||||
crate MemoizedB(query: &impl QueryContext, (): ()) -> () {
|
||||
query.memoized_a().get(())
|
||||
}
|
||||
}
|
||||
|
||||
salsa::query_definition! {
|
||||
#[storage(volatile)]
|
||||
crate VolatileA(query: &impl QueryContext, (): ()) -> () {
|
||||
query.volatile_b().get(())
|
||||
}
|
||||
}
|
||||
|
||||
salsa::query_definition! {
|
||||
#[storage(volatile)]
|
||||
crate VolatileB(query: &impl QueryContext, (): ()) -> () {
|
||||
query.volatile_a().get(())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "cycle detected")]
|
||||
fn cycle_memoized() {
|
||||
let query = QueryContextImpl::default();
|
||||
query.memoized_a().get(());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "cycle detected")]
|
||||
fn cycle_volatile() {
|
||||
let query = QueryContextImpl::default();
|
||||
query.volatile_a().get(());
|
||||
}
|
Loading…
Reference in a new issue