mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-14 17:18:20 +00:00
Merge pull request #485 from nikomatsakis/issue-484
update tracked struct `created_at` when validated
This commit is contained in:
commit
3257fa95a7
2 changed files with 54 additions and 3 deletions
|
@ -287,11 +287,14 @@ where
|
|||
|
||||
fn mark_validated_output(
|
||||
&self,
|
||||
_db: &DB,
|
||||
db: &DB,
|
||||
_executor: DatabaseKeyIndex,
|
||||
_output_key: Option<crate::Id>,
|
||||
output_key: Option<crate::Id>,
|
||||
) {
|
||||
// FIXME
|
||||
let output_key = output_key.unwrap();
|
||||
let output_key: C::Id = <C::Id>::from_id(output_key);
|
||||
let mut entity = self.entity_data.get_mut(&output_key).unwrap();
|
||||
entity.created_at = db.runtime().current_revision();
|
||||
}
|
||||
|
||||
fn remove_stale_output(
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
use test_log::test;
|
||||
|
||||
#[salsa::jar(db = Db)]
|
||||
struct Jar(MyInput, MyTracked, tracked_fn);
|
||||
|
||||
trait Db: salsa::DbWithJar<Jar> {}
|
||||
|
||||
#[salsa::input(jar = Jar)]
|
||||
struct MyInput {
|
||||
field: u32,
|
||||
}
|
||||
|
||||
#[salsa::tracked(jar = Jar)]
|
||||
struct MyTracked {
|
||||
field: u32,
|
||||
}
|
||||
|
||||
#[salsa::tracked(jar = Jar)]
|
||||
fn tracked_fn(db: &dyn Db, input: MyInput) -> MyTracked {
|
||||
MyTracked::new(db, input.field(db) / 2)
|
||||
}
|
||||
|
||||
#[salsa::db(Jar)]
|
||||
#[derive(Default)]
|
||||
struct Database {
|
||||
storage: salsa::Storage<Self>,
|
||||
}
|
||||
|
||||
impl salsa::Database for Database {}
|
||||
|
||||
impl Db for Database {}
|
||||
|
||||
#[test]
|
||||
fn execute() {
|
||||
let mut db = Database::default();
|
||||
|
||||
let input1 = MyInput::new(&db, 22);
|
||||
let input2 = MyInput::new(&db, 44);
|
||||
let _tracked1 = tracked_fn(&db, input1);
|
||||
let _tracked2 = tracked_fn(&db, input2);
|
||||
|
||||
// modify the input and change the revision
|
||||
input1.set_field(&mut db).to(24);
|
||||
let tracked2 = tracked_fn(&db, input2);
|
||||
|
||||
// this should not panic
|
||||
tracked2.field(&db);
|
||||
}
|
Loading…
Reference in a new issue