Allow interned values as tracked function arguments

This commit is contained in:
Micha Reiser 2024-07-20 09:03:57 +02:00
parent 1c69d3ba7b
commit 9ba36ebf7e
No known key found for this signature in database
3 changed files with 35 additions and 10 deletions

View file

@ -93,6 +93,12 @@ macro_rules! setup_interned_struct {
}
}
impl<$db_lt> $zalsa::LookupId<$db_lt> for $Struct<$db_lt> {
fn lookup_id(id: salsa::Id, db: &$db_lt dyn $zalsa::Database) -> Self {
$Configuration::ingredient(db).interned_value(id)
}
}
unsafe impl Send for $Struct<'_> {}
unsafe impl Sync for $Struct<'_> {}

View file

@ -1,13 +1,3 @@
error[E0277]: the trait bound `MyInterned<'_>: LookupId<'_>` is not satisfied
--> tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.rs:15:1
|
15 | #[salsa::tracked(specify)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromId` is not implemented for `MyInterned<'_>`, which is required by `MyInterned<'_>: LookupId<'_>`
|
= help: the trait `LookupId<'db>` is implemented for `MyTracked<'db>`
= note: required for `MyInterned<'_>` to implement `LookupId<'_>`
= note: this error originates in the macro `salsa::plumbing::setup_tracked_fn` which comes from the expansion of the attribute macro `salsa::tracked` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `MyInterned<'_>: TrackedStructInDb` is not satisfied
--> tests/compile-fail/specify-does-not-work-if-the-key-is-a-salsa-interned.rs:15:1
|

View file

@ -0,0 +1,29 @@
//! Test that a `tracked` fn on a `salsa::interned`
//! compiles and executes successfully.
#[salsa::interned]
struct Name<'db> {
name: String,
}
#[salsa::tracked]
fn tracked_fn<'db>(db: &'db dyn salsa::Database, name: Name<'db>) -> String {
name.name(db).clone()
}
#[salsa::db]
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
}
#[salsa::db]
impl salsa::Database for Database {}
#[test]
fn execute() {
let db = Database::default();
let name = Name::new(&db, "Salsa".to_string());
assert_eq!(tracked_fn(&db, name), "Salsa");
}