1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use petgraph::stable_graph::NodeIndex;

use crate::{EdgeInfo, OutputType};

/**
 * The name of an [`Operation`](crate::Operation)
 */
pub type OpName = String;

#[derive(Debug, Clone, PartialEq)]
/**
 * Represents an error that can occur in this crate.
 */
pub enum Error {
    /**
     * The given [`FheProgram`](crate::FheProgram) has
     * one or more errors. The inner value is the list of errors.
     */
    IRError(Vec<IRError>),

    /**
     * Attempted to deserialize and unknown scheme type.
     */
    InvalidSchemeType,
}

/**
 * An error in an [`FheProgram`](crate::FheProgram).
 */
#[derive(Debug, Clone, PartialEq)]
pub enum IRError {
    /**
     * The IR has a cycle.
     */
    IRHasCycles,

    /**
     * A node in the IR has an error.
     */
    NodeError(NodeIndex, OpName, NodeError),
}

/**
 * An error on a node in an [`FheProgram`](crate::FheProgram).
 */
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum NodeError {
    /**
     * The node is missing an expected operand of the contained type.
     */
    MissingOperand(EdgeInfo),

    /**
     * The parent node specified at the given [`EdgeInfo`] does not exist.
     */
    MissingParent(NodeIndex),

    /**
     * For the parent at EdgeInfo (first argument), the expected
     * output type (second argument) does not match the actual
     * (third argument) output type.
     */
    ParentHasIncorrectOutputType(EdgeInfo, OutputType, OutputType),

    /**
     * The node has expects a specific number of input operands (first argument),
     * but got some other number (second argument).
     */
    WrongOperandCount(usize, usize),
}

/**
 * Wrapper around [`Result`](std::result::Result) with this crate's error type.
 */
pub type Result<T> = std::result::Result<T, Error>;