2022-08-28 22:28:30 +00:00
|
|
|
//! Test that a `tracked` fn on a `salsa::input`
|
|
|
|
//! compiles and executes successfully.
|
|
|
|
#![allow(warnings)]
|
|
|
|
|
2022-09-03 14:44:56 +00:00
|
|
|
trait TrackedTrait {
|
2024-07-17 11:49:46 +00:00
|
|
|
fn tracked_trait_fn(self, db: &dyn salsa::Database) -> u32;
|
2022-09-03 14:44:56 +00:00
|
|
|
}
|
|
|
|
|
2022-08-31 22:30:49 +00:00
|
|
|
#[salsa::input]
|
2022-08-28 22:28:30 +00:00
|
|
|
struct MyInput {
|
|
|
|
field: u32,
|
|
|
|
}
|
|
|
|
|
2022-08-31 22:30:49 +00:00
|
|
|
#[salsa::tracked]
|
2022-08-28 22:28:30 +00:00
|
|
|
impl MyInput {
|
2022-08-31 22:30:49 +00:00
|
|
|
#[salsa::tracked]
|
2024-07-18 09:59:43 +00:00
|
|
|
fn tracked_fn(self, db: &dyn salsa::Database) -> u32 {
|
2022-08-28 22:28:30 +00:00
|
|
|
self.field(db) * 2
|
|
|
|
}
|
|
|
|
|
2022-08-31 22:30:49 +00:00
|
|
|
#[salsa::tracked(return_ref)]
|
2024-07-18 09:59:43 +00:00
|
|
|
fn tracked_fn_ref(self, db: &dyn salsa::Database) -> u32 {
|
2022-08-28 22:28:30 +00:00
|
|
|
self.field(db) * 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 14:44:56 +00:00
|
|
|
#[salsa::tracked]
|
|
|
|
impl TrackedTrait for MyInput {
|
|
|
|
#[salsa::tracked]
|
2024-07-18 09:59:43 +00:00
|
|
|
fn tracked_trait_fn(self, db: &dyn salsa::Database) -> u32 {
|
2022-09-03 14:44:56 +00:00
|
|
|
self.field(db) * 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-28 22:28:30 +00:00
|
|
|
#[test]
|
|
|
|
fn execute() {
|
2024-07-27 12:29:41 +00:00
|
|
|
let mut db = salsa::DatabaseImpl::new();
|
2022-08-28 22:28:30 +00:00
|
|
|
let object = MyInput::new(&mut db, 22);
|
2024-07-18 09:59:43 +00:00
|
|
|
// assert_eq!(object.tracked_fn(&db), 44);
|
|
|
|
// assert_eq!(*object.tracked_fn_ref(&db), 66);
|
2022-09-03 14:44:56 +00:00
|
|
|
assert_eq!(object.tracked_trait_fn(&db), 88);
|
2022-08-28 22:28:30 +00:00
|
|
|
}
|