1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
18#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
19#[serde(rename = "HaUid")]
20pub struct ItemUid {
21 pub uid: String,
23}
24
25impl std::fmt::Display for ItemUid {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 std::fmt::Display::fmt(&self.uid, f)
28 }
29}
30
31impl ItemUid {
32 pub fn fresh() -> Self {
33 use uuid::Uuid;
34 let uid = format!("{}", Uuid::new_v4().simple());
35 ItemUid { uid }
36 }
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
41#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
42#[serde(rename = "HaItemStatus")]
43pub enum ItemStatus {
44 Included {
46 late_skip: bool,
48 },
49 Excluded { modeled_by: Option<String> },
51}
52
53#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
57#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
58#[serde(rename = "HaAssocRole")]
59pub enum AssociationRole {
60 Requires,
61 Ensures,
62 Decreases,
63 SMTPat,
64 Refine,
65 ItemQuote,
68 ProcessRead,
69 ProcessWrite,
70 ProcessInit,
71 ProtocolMessages,
72}
73
74#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
76#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
77#[serde(rename = "HaItemQuotePosition")]
78pub enum ItemQuotePosition {
79 Before,
81 After,
83}
84
85#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
87#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
88#[serde(rename = "HaItemQuoteFStarOpts")]
89pub struct ItemQuoteFStarOpts {
90 pub intf: bool,
92 pub r#impl: bool,
94}
95
96#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
100#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
101#[serde(rename = "HaItemQuote")]
102pub struct ItemQuote {
103 pub position: ItemQuotePosition,
104 pub fstar_options: Option<ItemQuoteFStarOpts>,
105}
106
107#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
109#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
110#[serde(rename = "HaProofMethod")]
111pub enum ProofMethod {
112 BvDecide,
113 Grind,
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
120#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
121#[serde(rename = "HaPayload")]
122pub enum AttrPayload {
123 ItemStatus(ItemStatus),
124 AssociatedItem {
126 role: AssociationRole,
128 item: ItemUid,
130 },
131 Uid(ItemUid),
132 ItemQuote(ItemQuote),
134 NeverErased,
138 NewtypeAsRefinement,
139 Lemma,
141 Language,
142 ProcessRead,
143 ProcessWrite,
144 ProcessInit,
145 Proof(String),
146 PureRequiresProof(String),
147 PureEnsuresProof(String),
148 ProofMethod(ProofMethod),
149 ProtocolMessages,
150 PVConstructor,
151 PVHandwritten,
152 TraitMethodNoPrePost,
153 Erased,
155 Order(i32),
162}
163
164pub const HAX_TOOL: &str = "_hax";
165pub const HAX_CFG_OPTION_NAME: &str = "hax_compilation";
166
167pub struct HaxTool;
168pub struct HaxCfgOptionName;
169pub struct DebugOrHaxCfgExpr;
170impl ToTokens for HaxTool {
171 fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
172 format_ident!("{}", HAX_TOOL).to_tokens(tokens)
173 }
174}
175impl ToTokens for HaxCfgOptionName {
176 fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
177 format_ident!("{}", HAX_CFG_OPTION_NAME).to_tokens(tokens)
178 }
179}
180impl ToTokens for DebugOrHaxCfgExpr {
181 fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
182 quote! {any(#HaxCfgOptionName, debug_assertions)}.to_tokens(tokens)
183 }
184}
185
186use quote::*;
187
188impl From<&AttrPayload> for proc_macro2::TokenStream {
189 fn from(payload: &AttrPayload) -> Self {
190 let payload: String = serde_json::to_string(payload).unwrap();
191 quote! {#[cfg_attr(#HaxCfgOptionName, #HaxTool::json(#payload))]}
192 }
193}
194
195impl ToTokens for AttrPayload {
196 fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
197 proc_macro2::TokenStream::from(self).to_tokens(tokens)
198 }
199}