Skip to content

Commit

Permalink
Merge pull request #485 from nikomatsakis/issue-484
Browse files Browse the repository at this point in the history
update tracked struct `created_at` when validated
  • Loading branch information
nikomatsakis authored Apr 5, 2024
2 parents 45fd941 + b12ff32 commit 3257fa9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/salsa-2022/src/tracked_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
48 changes: 48 additions & 0 deletions salsa-2022-tests/tests/tracked-struct-unchanged-in-new-rev.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 3257fa9

Please sign in to comment.