hax_types/diagnostics/
message.rs

1use crate::cli_options::Backend;
2use crate::prelude::*;
3
4#[derive_group(Serializers)]
5#[derive(Debug, Clone, JsonSchema)]
6#[repr(u8)]
7pub enum HaxMessage {
8    Diagnostic {
9        diagnostic: super::Diagnostics,
10        working_dir: PathBuf,
11    } = 254,
12    EngineNotFound {
13        is_opam_setup_correctly: bool,
14    } = 0,
15    ProducedFile {
16        path: PathBuf,
17        wrote: bool,
18    } = 1,
19    HaxEngineFailure {
20        exit_code: i32,
21    } = 2,
22    CargoBuildFailure = 3,
23    WarnExperimentalBackend {
24        backend: Backend<()>,
25    } = 4,
26    ProfilingData(crate::engine_api::ProfilingData) = 5,
27    Stats {
28        errors_per_item: Vec<(hax_frontend_exporter::DefId, usize)>,
29    } = 6,
30}
31
32impl HaxMessage {
33    // https://doc.rust-lang.org/reference/items/enumerations.html#pointer-casting
34    pub fn discriminant(&self) -> u16 {
35        unsafe { *(self as *const Self as *const u16) }
36    }
37
38    pub fn code(&self) -> String {
39        match self {
40            HaxMessage::Diagnostic { diagnostic, .. } => diagnostic.kind.code(),
41            _ => format!("CARGOHAX{:0>4}", self.discriminant()),
42        }
43    }
44}