expand incremental tests

This commit is contained in:
Niko Matsakis 2018-09-30 07:32:24 -04:00
parent 9bfd8ebbfa
commit 1fef80d659
3 changed files with 27 additions and 3 deletions

View file

@ -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)
}
}

View file

@ -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
}
}

View file

@ -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(&[]);
}