salsa/tests/hello_world_tracked_fn.rs
Niko Matsakis dde7341f97 create macro-rules macros to encapsulate output
This is a new idea for how to manage procedural
macros, which I kind of hate.
2024-07-13 05:45:22 -04:00

62 lines
1.3 KiB
Rust

//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.
mod common;
use common::{HasLogger, Logger};
use expect_test::expect;
use test_log::test;
#[salsa::db]
trait Db: salsa::Database + HasLogger {}
#[salsa::db]
#[derive(Default)]
struct Database {
storage: salsa::Storage<Self>,
logger: Logger,
}
#[salsa::db]
impl salsa::Database for Database {}
#[salsa::db]
impl Db for Database {}
impl HasLogger for Database {
fn logger(&self) -> &Logger {
&self.logger
}
}
// #[salsa::tracked]
// fn final_result(db: &dyn Db, input: i32, (b, c): (i32, i32)) -> i32 {
// db.push_log(format!("final_result({:?})", input));
// input
// }
salsa::plumbing::setup_interned_fn!(
vis: ,
fn_name: identity,
db_lt: 'db,
Db: Db,
db: dbx,
input_ids: [input1, input2],
input_pats: [a, (b, c)],
input_tys: [i32, (i32, i32)],
output_ty: i32,
body: {
dbx.push_log(format!("final_result({a}, {b}, {c})"));
a + b * c
},
cycle_recovery_fn: (salsa::plumbing::unexpected_cycle_recovery!),
cycle_recovery_strategy: Panic,
unused_names: [
zalsa1,
Configuration1,
InternedData1,
FN_CACHE1,
INTERN_CACHE1,
inner1,
]
);