Skip to content

Commit

Permalink
Merge pull request #566 from MichaReiser/const-query
Browse files Browse the repository at this point in the history
Fix const queries with custom `Db` trait
  • Loading branch information
nikomatsakis authored Aug 20, 2024
2 parents d5018d5 + 3f93415 commit f608ff8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/salsa-macro-rules/src/setup_tracked_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ macro_rules! setup_tracked_fn {
fn id_to_input<$db_lt>(db: &$db_lt Self::DbView, key: salsa::Id) -> Self::Input<$db_lt> {
$zalsa::macro_if! {
if $needs_interner {
$Configuration::intern_ingredient(db).data(db, key).clone()
$Configuration::intern_ingredient(db).data(db.as_dyn_database(), key).clone()
} else {
$zalsa::FromId::from_id(key)
}
Expand Down
15 changes: 15 additions & 0 deletions tests/tracked_fn_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@
//! compiles and executes successfully.
#![allow(warnings)]

use crate::common::LogDatabase;

mod common;

#[salsa::tracked]
fn tracked_fn(db: &dyn salsa::Database) -> u32 {
44
}

#[salsa::tracked]
fn tracked_custom_db(db: &dyn LogDatabase) -> u32 {
44
}

#[test]
fn execute() {
let mut db = salsa::DatabaseImpl::new();
assert_eq!(tracked_fn(&db), 44);
}

#[test]
fn execute_custom() {
let mut db = common::LoggerDatabase::default();
assert_eq!(tracked_custom_db(&db), 44);
}

0 comments on commit f608ff8

Please sign in to comment.