From 1fef80d659921d77770949418cd38eb7a1d7366c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 30 Sep 2018 07:32:24 -0400 Subject: [PATCH] expand incremental tests --- src/runtime.rs | 2 +- tests/incremental/queries.rs | 2 +- tests/incremental/tests.rs | 26 +++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/runtime.rs b/src/runtime.rs index abdaf65c..4e6fbd4e 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -202,7 +202,7 @@ impl Revision { impl std::fmt::Debug for Revision { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(fmt, "R({})", self.generation) + write!(fmt, "R{}", self.generation) } } diff --git a/tests/incremental/queries.rs b/tests/incremental/queries.rs index 65ac9d69..328adfbd 100644 --- a/tests/incremental/queries.rs +++ b/tests/incremental/queries.rs @@ -25,7 +25,7 @@ salsa::query_definition! { crate Memoized1(query: &impl QueryContext, (): ()) -> usize { query.log().add("Memoized1 invoked"); let v = query.volatile().of(()); - v / 3 + v / 2 } } diff --git a/tests/incremental/tests.rs b/tests/incremental/tests.rs index ac516ad5..f4cbacb6 100644 --- a/tests/incremental/tests.rs +++ b/tests/incremental/tests.rs @@ -40,8 +40,16 @@ fn volatile_x2() { query.assert_log(&["Volatile invoked", "Volatile invoked"]); } +/// Test that: +/// +/// - On the first run of R0, we recompute everything. +/// - On the second run of R1, we recompute nothing. +/// - On the first run of R1, we recompute Memoized1 but not Memoized2 (since Memoized1 result +/// did not change). +/// - On the second run of R1, we recompute nothing. +/// - On the first run of R2, we recompute everything (since Memoized1 result *did* change). #[test] -fn foo() { +fn revalidate() { env_logger::init(); let query = QueryContextImpl::default(); @@ -52,8 +60,24 @@ fn foo() { query.memoized2().of(()); query.assert_log(&[]); + // Second generation: volatile will change (to 1) but memoized1 + // will not (still 0, as 1/2 = 0) query.salsa_runtime().next_revision(); query.memoized2().of(()); query.assert_log(&["Memoized1 invoked", "Volatile invoked"]); + + query.memoized2().of(()); + query.assert_log(&[]); + + // Third generation: volatile will change (to 2) and memoized1 + // will too (to 1). Therefore, after validating that Memoized1 + // changed, we now invoke Memoized2. + query.salsa_runtime().next_revision(); + + query.memoized2().of(()); + query.assert_log(&["Memoized1 invoked", "Volatile invoked", "Memoized2 invoked"]); + + query.memoized2().of(()); + query.assert_log(&[]); }