meta_language/translation/ir/
declarations.rs1use super::{Binder, Expr, Guard, Proof, Prop, Span, Type};
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
6pub struct Field {
7 pub name: String,
8 #[serde(rename = "type")]
9 pub ty: Type,
10}
11
12#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
13pub struct Ctor {
14 pub name: String,
15 pub fields: Vec<Field>,
16}
17
18#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
19pub struct Param {
20 pub name: String,
21 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
23 pub optional: bool,
24 #[serde(rename = "type")]
25 pub ty: Type,
26 #[serde(default)]
28 pub guard: Option<Guard>,
29 #[serde(default, rename = "default")]
30 pub default_value: Option<crate::translation::surface::SExpr>,
31}
32
33#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
35#[serde(rename_all = "camelCase")]
36pub struct LambdaParam {
37 pub name: String,
38 #[serde(rename = "type")]
39 pub ty: Type,
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 pub span: Option<Span>,
42 #[serde(default, rename = "default", skip_serializing_if = "Option::is_none")]
43 pub default_value: Option<crate::translation::surface::SExpr>,
44 #[serde(default, skip_serializing_if = "Option::is_none")]
45 pub guard: Option<Guard>,
46 #[serde(default, skip_serializing_if = "Option::is_none")]
47 pub rocq_type: Option<String>,
48}
49
50#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
51#[serde(rename_all = "camelCase")]
52pub struct DataDecl {
53 pub name: String,
54 pub ctors: Vec<Ctor>,
55 #[serde(default)]
56 pub span: Option<Span>,
57 pub full_name: String,
58 pub module_path: Vec<String>,
59 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
60 pub generated: bool,
61 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
63 pub output: bool,
64 #[serde(default, skip_serializing_if = "Option::is_none")]
66 pub source_unit_clone_derivation: Option<serde_json::Value>,
67}
68
69#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
70#[serde(rename_all = "camelCase")]
71pub struct FnDecl {
72 #[serde(default, skip_serializing_if = "Option::is_none")]
74 pub source_pure_unit: Option<serde_json::Value>,
75 pub name: String,
76 pub params: Vec<Param>,
77 pub ret: Type,
78 #[serde(
80 default,
81 skip_serializing_if = "Option::is_none",
82 deserialize_with = "crate::translation::present_type::read_present_type"
83 )]
84 pub semantic_ret: Option<Type>,
85 #[serde(
87 default,
88 skip_serializing_if = "Option::is_none",
89 deserialize_with = "crate::translation::present_type::read_present_type"
90 )]
91 pub annotated_ret: Option<Type>,
92 pub body: Expr,
93 #[serde(default)]
94 pub span: Option<Span>,
95 pub full_name: String,
96 pub module_path: Vec<String>,
97 pub recursive: bool,
98 pub decreasing: Option<usize>,
100 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
101 pub mutual: bool,
102 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
104 pub generated: bool,
105 #[serde(default, skip_serializing_if = "Option::is_none")]
107 pub source_signature: Option<crate::translation::source_signatures::SourceSignature>,
108 #[serde(default, skip_serializing_if = "Option::is_none")]
110 pub source_primitive_owners: Option<serde_json::Value>,
111 #[serde(default, skip_serializing_if = "Option::is_none")]
113 pub source_empty_option: Option<serde_json::Value>,
114 #[serde(default, skip_serializing_if = "Option::is_none")]
116 pub source_type_namespace: Option<serde_json::Value>,
117 #[serde(default, skip_serializing_if = "Option::is_none")]
119 pub source_local_state: Option<serde_json::Value>,
120 #[serde(default, skip_serializing_if = "Option::is_none")]
122 pub source_const_function: Option<serde_json::Value>,
123 #[serde(
125 default,
126 skip_serializing_if = "Option::is_none",
127 deserialize_with = "crate::translation::source_diagnostic_attributes::read_present_facet"
128 )]
129 pub source_diagnostic_attributes: Option<serde_json::Value>,
130 #[serde(
132 default,
133 rename = "sourceLoop",
134 skip_serializing_if = "Option::is_none"
135 )]
136 pub source_loop: Option<crate::translation::source_loops::SourceLoop>,
137}
138
139#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
140#[serde(rename_all = "camelCase")]
141pub struct TheoremDecl {
142 pub name: String,
143 pub binders: Vec<Binder>,
144 pub prop: Prop,
145 pub proof: Proof,
146 #[serde(default)]
147 pub span: Option<Span>,
148 pub full_name: String,
149 pub module_path: Vec<String>,
150}
151
152#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
153#[serde(tag = "k", rename_all = "camelCase")]
154#[allow(clippy::large_enum_variant)] pub enum Decl {
156 Data(DataDecl),
157 Fn(FnDecl),
158 Theorem(TheoremDecl),
159}
160
161impl Decl {
162 #[must_use]
163 pub fn name(&self) -> &str {
164 match self {
165 Self::Data(decl) => &decl.name,
166 Self::Fn(decl) => &decl.name,
167 Self::Theorem(decl) => &decl.name,
168 }
169 }
170
171 #[must_use]
172 pub fn full_name(&self) -> &str {
173 match self {
174 Self::Data(decl) => &decl.full_name,
175 Self::Fn(decl) => &decl.full_name,
176 Self::Theorem(decl) => &decl.full_name,
177 }
178 }
179
180 #[must_use]
181 pub fn module_path(&self) -> &[String] {
182 match self {
183 Self::Data(decl) => &decl.module_path,
184 Self::Fn(decl) => &decl.module_path,
185 Self::Theorem(decl) => &decl.module_path,
186 }
187 }
188
189 #[must_use]
190 pub const fn span(&self) -> Option<Span> {
191 match self {
192 Self::Data(decl) => decl.span,
193 Self::Fn(decl) => decl.span,
194 Self::Theorem(decl) => decl.span,
195 }
196 }
197
198 #[must_use]
200 pub const fn kind(&self) -> &'static str {
201 match self {
202 Self::Data(_) => "data",
203 Self::Fn(_) => "fn",
204 Self::Theorem(_) => "theorem",
205 }
206 }
207}