Skip to main content

salsa_macro_rules/
setup_tracked_method_body.rs

1#[macro_export]
2macro_rules! setup_tracked_method_body {
3    (
4        salsa_tracked_attr: #[$salsa_tracked_attr:meta],
5        self: $self:ident,
6        self_ty: $self_ty:ty,
7        db_lt: $($db_lt:lifetime)?,
8        db: $db:ident,
9        db_ty: ($($db_ty:tt)*),
10        input_ids: [$($input_id:ident),*],
11        input_tys: [$($input_ty:ty),*],
12        output_ty: $output_ty:ty,
13        inner_fn_name: $inner_fn_name:ident,
14        inner_fn: $inner_fn:item,
15
16        // Annoyingly macro-rules hygiene does not extend to items defined in the macro.
17        // We have the procedural macro generate names for those items that are
18        // not used elsewhere in the user's code.
19        unused_names: [
20            $InnerTrait:ident,
21        ]
22    ) => {
23        {
24            trait $InnerTrait<$($db_lt)?> {
25                fn $inner_fn_name($self, db: $($db_ty)*, $($input_id: $input_ty),*) -> $output_ty;
26            }
27
28            impl<$($db_lt)?> $InnerTrait<$($db_lt)?> for $self_ty {
29                $inner_fn
30            }
31
32            #[$salsa_tracked_attr]
33            fn $inner_fn_name<$($db_lt)?>(db: $($db_ty)*, this: $self_ty, $($input_id: $input_ty),*) -> $output_ty {
34                <$self_ty as $InnerTrait>::$inner_fn_name(this, db, $($input_id),*)
35            }
36
37            $inner_fn_name($db, $self, $($input_id),*)
38        }
39    };
40}