diff --git a/tests/incremental/constants.rs b/tests/incremental/constants.rs new file mode 100644 index 00000000..fa6ecae5 --- /dev/null +++ b/tests/incremental/constants.rs @@ -0,0 +1,43 @@ +use crate::implementation::{TestContext, TestContextImpl}; +use salsa::Database; + +salsa::query_group! { + pub(crate) trait ConstantsDatabase: TestContext { + fn constants_input(key: usize) -> usize { + type ConstantsInput; + storage input; + } + + fn constants_derived(key: usize) -> usize { + type ConstantsDerived; + } + } +} + +fn constants_derived(db: &impl ConstantsDatabase, key: usize) -> usize { + db.log().add(format!("constants_derived({}) invoked", key)); + db.constants_input(key) * 2 +} + +#[test] +#[should_panic] +fn invalidate_constant() { + let db = &TestContextImpl::default(); + db.query(ConstantsInput).set_constant(22, 44); + db.query(ConstantsInput).set_constant(22, 66); +} + +#[test] +#[should_panic] +fn invalidate_constant_1() { + let db = &TestContextImpl::default(); + + // Not constant: + db.query(ConstantsInput).set(22, 44); + + // Becomes constant: + db.query(ConstantsInput).set_constant(22, 44); + + // Invalidates: + db.query(ConstantsInput).set_constant(22, 66); +} diff --git a/tests/incremental/implementation.rs b/tests/incremental/implementation.rs index 868e49c9..8fba2ce7 100644 --- a/tests/incremental/implementation.rs +++ b/tests/incremental/implementation.rs @@ -1,3 +1,4 @@ +use crate::constants; use crate::counter::Counter; use crate::log::Log; use crate::memoized_dep_inputs; @@ -43,6 +44,11 @@ impl TestContextImpl { salsa::database_storage! { pub(crate) struct TestContextImplStorage for TestContextImpl { + impl constants::ConstantsDatabase { + fn constants_input() for constants::ConstantsInput; + fn constants_derived() for constants::ConstantsDerived; + } + impl memoized_dep_inputs::MemoizedDepInputsContext { fn dep_memoized2() for memoized_dep_inputs::Memoized2; fn dep_memoized1() for memoized_dep_inputs::Memoized1; diff --git a/tests/incremental/main.rs b/tests/incremental/main.rs index 33a623cd..bcd13c75 100644 --- a/tests/incremental/main.rs +++ b/tests/incremental/main.rs @@ -1,3 +1,4 @@ +mod constants; mod counter; mod implementation; mod log;