Debian Codegraph @

src/setup_accumulator_impl.rs

raw symbols SCIP
1 /// Macro for setting up a function that must intern its arguments.
2 #[macro_export]
3 macro_rules! setup_accumulator_impl {
4 (
5 // Name of the struct
6 Struct: $Struct:ident,
7
8 // Annoyingly macro-rules hygiene does not extend to items defined in the macro.
9 // We have the procedural macro generate names for those items that are
10 // not used elsewhere in the user's code.
11 unused_names: [
12 $zalsa:ident,
13 $zalsa_struct:ident,
14 $CACHE:ident,
15 $ingredient:ident,
16 ]
17 ) => {
18 #[allow(clippy::all)]
19 #[allow(dead_code)]
20 const _: () = {
21 use salsa::plumbing as $zalsa;
22 use salsa::plumbing::accumulator as $zalsa_struct;
23
24 impl $zalsa::HasJar for $Struct {
25 type Jar = $zalsa_struct::JarImpl<$Struct>;
26 const KIND: $zalsa::JarKind = $zalsa::JarKind::Struct;
27 }
28
29 $zalsa::register_jar! {
30 $zalsa::ErasedJar::erase::<$Struct>()
31 }
32
33 fn $ingredient(zalsa: &$zalsa::Zalsa) -> &$zalsa_struct::IngredientImpl<$Struct> {
34 static $CACHE: $zalsa::IngredientCache<$zalsa_struct::IngredientImpl<$Struct>> =
35 $zalsa::IngredientCache::new();
36
37 // SAFETY: `lookup_jar_by_type` returns a valid ingredient index, and the only
38 // ingredient created by our jar is the struct ingredient.
39 unsafe { $CACHE.get_or_create::<$zalsa_struct::JarImpl<$Struct>, 0>(zalsa) }
40 }
41
42 impl $zalsa::Accumulator for $Struct {
43 const DEBUG_NAME: &'static str = stringify!($Struct);
44
45 fn accumulate<Db>(self, db: &Db)
46 where
47 Db: ?Sized + $zalsa::Database,
48 {
49 let (zalsa, zalsa_local) = db.zalsas();
50 $ingredient(zalsa).push(zalsa_local, self);
51 }
52 }
53 };
54 };
55 }