1use crate::ast::*;
2use derive_generic_visitor::{Drive, DriveMut, DriveTwo};
3use macros::EnumIsA;
4use macros::VariantName;
5use serde_state::DeserializeState;
6use serde_state::SerializeState;
7
8#[derive(
10 Debug, PartialEq, Eq, Clone, SerializeState, DeserializeState, Drive, DriveMut, DriveTwo,
11)]
12pub struct FunDecl {
13 pub def_id: FunDeclId,
14 pub item_meta: ItemMeta,
16 pub generics: GenericParams,
17 pub signature: Box<FunSig>,
19 pub src: FunSource,
21 pub body: Body,
23}
24
25#[derive(
27 Debug,
28 Clone,
29 PartialEq,
30 Eq,
31 PartialOrd,
32 Ord,
33 Hash,
34 SerializeState,
35 DeserializeState,
36 Drive,
37 DriveMut,
38 DriveTwo,
39)]
40pub struct FunSig {
41 #[drive(skip)]
43 pub is_unsafe: bool,
44 #[drive(skip)]
46 pub abi: Abi,
47 #[drive(skip)]
49 pub is_variadic: bool,
50 pub inputs: Vec<Ty>,
51 pub output: Ty,
52}
53
54#[derive(
55 Debug,
56 Clone,
57 PartialEq,
58 Eq,
59 PartialOrd,
60 Ord,
61 Hash,
62 VariantName,
63 EnumIsA,
64 SerializeState,
65 DeserializeState,
66 Drive,
67 DriveMut,
68 DriveTwo,
69)]
70#[serde_state(stateless)]
71#[cfg_attr(feature = "charon_on_charon", charon::variants_prefix("Abi"))]
72pub enum Abi {
73 Rust,
74 C,
75 Other(#[drive(skip)] ustr::Ustr),
77}
78
79#[derive(
81 Debug, Clone, SerializeState, DeserializeState, Drive, DriveMut, DriveTwo, PartialEq, Eq,
82)]
83#[cfg_attr(feature = "charon_on_charon", charon::variants_suffix("Fun"))]
84pub enum FunSource {
85 Normal,
87 TraitDefault {
89 trait_ref: TraitDeclRef,
91 item_id: TraitMethodId,
94 },
95 TraitImpl {
97 impl_ref: TraitImplRef,
99 trait_ref: TraitDeclRef,
101 item_id: TraitMethodId,
104 #[drive(skip)]
107 reuses_default: bool,
108 },
109 VTableShim,
113 GlobalInitializer(GlobalDeclRef),
115 TargetDependent { dispatcher: FunDeclRef },
118}
119
120impl FunDecl {
121 pub fn substitute_params(self, subst: Binder<GenericArgs>) -> Self {
123 let FunDecl {
124 def_id,
125 item_meta,
126 generics: _,
127 signature,
128 src,
129 body,
130 } = self;
131 let signature = signature.substitute(&subst.skip_binder);
132 let src = src.substitute(&subst.skip_binder);
133 let body = body.substitute(&subst.skip_binder);
134 FunDecl {
135 def_id,
136 item_meta,
137 generics: subst.params,
138 signature,
139 src,
140 body,
141 }
142 }
143}
144
145impl Abi {
146 pub fn rust() -> Self {
147 Self::Rust
148 }
149
150 pub fn rust_name(&self) -> &str {
151 match self {
152 Self::Rust => "Rust",
153 Self::C => "C",
154 Self::Other(name) => name.as_str(),
155 }
156 }
157}