use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaUid")]
pub struct ItemUid {
pub uid: String,
}
impl std::fmt::Display for ItemUid {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.uid, f)
}
}
impl ItemUid {
pub fn fresh() -> Self {
use uuid::Uuid;
let uid = format!("{}", Uuid::new_v4().simple());
ItemUid { uid }
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaItemStatus")]
pub enum ItemStatus {
Included {
late_skip: bool,
},
Excluded { modeled_by: Option<String> },
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaAssocRole")]
pub enum AssociationRole {
Requires,
Ensures,
Decreases,
SMTPat,
Refine,
ItemQuote,
ProcessRead,
ProcessWrite,
ProcessInit,
ProtocolMessages,
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaItemQuotePosition")]
pub enum ItemQuotePosition {
Before,
After,
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaItemQuoteFStarOpts")]
pub struct ItemQuoteFStarOpts {
pub intf: bool,
pub r#impl: bool,
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaItemQuote")]
pub struct ItemQuote {
pub position: ItemQuotePosition,
pub fstar_options: Option<ItemQuoteFStarOpts>,
}
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaProofMethod")]
pub enum ProofMethod {
BvDecide,
Grind,
}
#[derive(Debug, Clone, Serialize, Deserialize, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(rename = "HaPayload")]
pub enum AttrPayload {
ItemStatus(ItemStatus),
AssociatedItem {
role: AssociationRole,
item: ItemUid,
},
Uid(ItemUid),
ItemQuote(ItemQuote),
NeverErased,
NewtypeAsRefinement,
Lemma,
Language,
ProcessRead,
ProcessWrite,
ProcessInit,
Proof(String),
PureRequiresProof(String),
PureEnsuresProof(String),
ProofMethod(ProofMethod),
ProtocolMessages,
PVConstructor,
PVHandwritten,
TraitMethodNoPrePost,
Erased,
Order(i32),
}
pub const HAX_TOOL: &str = "_hax";
pub const HAX_CFG_OPTION_NAME: &str = "hax_compilation";
pub struct HaxTool;
pub struct HaxCfgOptionName;
pub struct DebugOrHaxCfgExpr;
impl ToTokens for HaxTool {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
format_ident!("{}", HAX_TOOL).to_tokens(tokens)
}
}
impl ToTokens for HaxCfgOptionName {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
format_ident!("{}", HAX_CFG_OPTION_NAME).to_tokens(tokens)
}
}
impl ToTokens for DebugOrHaxCfgExpr {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
quote! {any(#HaxCfgOptionName, debug_assertions)}.to_tokens(tokens)
}
}
use quote::*;
impl From<&AttrPayload> for proc_macro2::TokenStream {
fn from(payload: &AttrPayload) -> Self {
let payload: String = serde_json::to_string(payload).unwrap();
quote! {#[cfg_attr(#HaxCfgOptionName, #HaxTool::json(#payload))]}
}
}
impl ToTokens for AttrPayload {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
proc_macro2::TokenStream::from(self).to_tokens(tokens)
}
}