From f4a8ed650f138666e93a468f8deeb59b58b6f245 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 5 Apr 2024 05:14:45 -0400 Subject: [PATCH] update tracked struct `created_at` when validated Fixes #484 --- components/salsa-2022/src/tracked_struct.rs | 9 ++-- .../tracked-struct-unchanged-in-new-rev.rs | 47 +++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 salsa-2022-tests/tests/tracked-struct-unchanged-in-new-rev.rs diff --git a/components/salsa-2022/src/tracked_struct.rs b/components/salsa-2022/src/tracked_struct.rs index 25589bc6..189e5c5c 100644 --- a/components/salsa-2022/src/tracked_struct.rs +++ b/components/salsa-2022/src/tracked_struct.rs @@ -287,11 +287,14 @@ where fn mark_validated_output( &self, - _db: &DB, + db: &DB, _executor: DatabaseKeyIndex, - _output_key: Option, + output_key: Option, ) { - // FIXME + let output_key = output_key.unwrap(); + let output_key: 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( diff --git a/salsa-2022-tests/tests/tracked-struct-unchanged-in-new-rev.rs b/salsa-2022-tests/tests/tracked-struct-unchanged-in-new-rev.rs new file mode 100644 index 00000000..7d38fc9f --- /dev/null +++ b/salsa-2022-tests/tests/tracked-struct-unchanged-in-new-rev.rs @@ -0,0 +1,47 @@ +use test_log::test; + +#[salsa::jar(db = Db)] +struct Jar(MyInput, MyTracked, tracked_fn); + +trait Db: salsa::DbWithJar {} + +#[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, +} + +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); + + tracked2.field(&db); +}