-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tracked struct
created_at
when validated
Fixes #484
- Loading branch information
1 parent
45fd941
commit f4a8ed6
Showing
2 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
salsa-2022-tests/tests/tracked-struct-unchanged-in-new-rev.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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); | ||
|
||
tracked2.field(&db); | ||
} |