2018-10-24 08:38:38 +00:00
|
|
|
use crate::db;
|
2019-01-12 10:11:59 +00:00
|
|
|
use crate::group::{FibonacciQuery, GcDatabase};
|
2018-10-24 08:38:38 +00:00
|
|
|
use salsa::debug::DebugQueryTable;
|
2018-10-25 09:47:25 +00:00
|
|
|
use salsa::{Database, SweepStrategy};
|
2018-10-24 08:38:38 +00:00
|
|
|
|
|
|
|
// For constant values (like `fibonacci`), we only keep the values
|
|
|
|
// that were used in the latest revision, not the sub-values that
|
|
|
|
// they required to be computed.
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn one_rev() {
|
|
|
|
let db = db::DatabaseImpl::default();
|
|
|
|
|
|
|
|
db.fibonacci(5);
|
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
let k: Vec<_> = db.query(FibonacciQuery).keys();
|
2018-10-24 08:38:38 +00:00
|
|
|
assert_eq!(k.len(), 6);
|
|
|
|
|
|
|
|
// Everything was used in this revision, so
|
|
|
|
// nothing gets collected.
|
2018-10-25 09:47:25 +00:00
|
|
|
db.sweep_all(SweepStrategy::default());
|
2018-10-24 08:38:38 +00:00
|
|
|
assert_eq!(k.len(), 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn two_rev_nothing() {
|
|
|
|
let db = db::DatabaseImpl::default();
|
|
|
|
|
|
|
|
db.fibonacci(5);
|
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
let k: Vec<_> = db.query(FibonacciQuery).keys();
|
2018-10-24 08:38:38 +00:00
|
|
|
assert_eq!(k.len(), 6);
|
|
|
|
|
|
|
|
db.salsa_runtime().next_revision();
|
|
|
|
|
|
|
|
// Nothing was used in this revision, so
|
|
|
|
// everything gets collected.
|
2018-10-25 09:47:25 +00:00
|
|
|
db.sweep_all(SweepStrategy::default());
|
2018-10-24 08:38:38 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
let k: Vec<_> = db.query(FibonacciQuery).keys();
|
2018-10-24 08:38:38 +00:00
|
|
|
assert_eq!(k.len(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn two_rev_one_use() {
|
|
|
|
let db = db::DatabaseImpl::default();
|
|
|
|
|
|
|
|
db.fibonacci(5);
|
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
let k: Vec<_> = db.query(FibonacciQuery).keys();
|
2018-10-24 08:38:38 +00:00
|
|
|
assert_eq!(k.len(), 6);
|
|
|
|
|
|
|
|
db.salsa_runtime().next_revision();
|
|
|
|
|
|
|
|
db.fibonacci(5);
|
|
|
|
|
|
|
|
// fibonacci is a constant, so it will not be invalidated,
|
|
|
|
// hence we keep `fibonacci(5)` but remove 0..=4.
|
2018-10-25 09:47:25 +00:00
|
|
|
db.sweep_all(SweepStrategy::default());
|
2018-10-24 08:38:38 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
let k: Vec<_> = db.query(FibonacciQuery).keys();
|
2018-10-24 08:38:38 +00:00
|
|
|
assert_eq!(k, vec![5]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn two_rev_two_uses() {
|
|
|
|
let db = db::DatabaseImpl::default();
|
|
|
|
|
|
|
|
db.fibonacci(5);
|
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
let k: Vec<_> = db.query(FibonacciQuery).keys();
|
2018-10-24 08:38:38 +00:00
|
|
|
assert_eq!(k.len(), 6);
|
|
|
|
|
|
|
|
db.salsa_runtime().next_revision();
|
|
|
|
|
|
|
|
db.fibonacci(5);
|
|
|
|
db.fibonacci(3);
|
|
|
|
|
|
|
|
// fibonacci is a constant, so it will not be invalidated,
|
|
|
|
// hence we keep 3 and 5 but remove the rest.
|
2018-10-25 09:47:25 +00:00
|
|
|
db.sweep_all(SweepStrategy::default());
|
2018-10-24 08:38:38 +00:00
|
|
|
|
2019-01-12 10:11:59 +00:00
|
|
|
let mut k: Vec<_> = db.query(FibonacciQuery).keys();
|
2018-10-24 08:38:38 +00:00
|
|
|
k.sort();
|
|
|
|
assert_eq!(k, vec![3, 5]);
|
|
|
|
}
|