1use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum IrError {
7 #[error("Einsum spec cannot be empty")]
8 EmptyEinsumSpec,
9 #[error("Invalid einsum spec '{spec}': {reason}")]
10 InvalidEinsumSpec { spec: String, reason: String },
11 #[error("Input tensor index {index} out of bounds (max: {max})")]
12 TensorIndexOutOfBounds { index: usize, max: usize },
13 #[error("Output index {index} out of bounds (max: {max})")]
14 OutputIndexOutOfBounds { index: usize, max: usize },
15 #[error("Node {node}: {message}")]
16 NodeValidation { node: usize, message: String },
17 #[error("Predicate {name} not found in signature registry")]
18 PredicateNotFound { name: String },
19 #[error("Predicate {name} arity mismatch: expected {expected}, got {actual}")]
20 ArityMismatch {
21 name: String,
22 expected: usize,
23 actual: usize,
24 },
25 #[error(
26 "Predicate {name} type mismatch at argument {arg_index}: expected {expected}, got {actual}"
27 )]
28 TypeMismatch {
29 name: String,
30 arg_index: usize,
31 expected: String,
32 actual: String,
33 },
34 #[error("Unbound variable {var} in expression")]
35 UnboundVariable { var: String },
36 #[error("Variable {var} used with inconsistent types: {type1} and {type2}")]
37 InconsistentTypes {
38 var: String,
39 type1: String,
40 type2: String,
41 },
42 #[error("Domain {name} not found in registry")]
43 DomainNotFound { name: String },
44 #[error("Domain {name} already exists in registry")]
45 DomainAlreadyExists { name: String },
46 #[error("Domain incompatibility: {domain1} and {domain2} are not compatible")]
47 DomainIncompatible { domain1: String, domain2: String },
48 #[error("Variable {var} domain mismatch: expected {expected}, got {actual}")]
49 VariableDomainMismatch {
50 var: String,
51 expected: String,
52 actual: String,
53 },
54 #[error("Aggregation operation {op} not supported")]
55 UnsupportedAggregation { op: String },
56 #[error("Graph contains a cycle and cannot be topologically sorted")]
57 CyclicGraph,
58 #[error("Type unification failed: cannot unify {type1} with {type2}")]
59 UnificationFailure { type1: String, type2: String },
60 #[error("Occurs check failed: type variable {var} occurs in {ty}")]
61 OccursCheckFailure { var: String, ty: String },
62 #[error("Kind mismatch: expected {expected}, got {actual}")]
63 KindMismatch { expected: String, actual: String },
64 #[error("Linearity violation: {0}")]
65 LinearityViolation(String),
66 #[error("Serialization error: {0}")]
67 SerializationError(String),
68 #[error("Domain mismatch: expected {expected}, found {found}")]
69 DomainMismatch { expected: String, found: String },
70 #[error("Constraint violation: {message}")]
71 ConstraintViolation { message: String },
72 #[error("Formatting error: {0}")]
73 FormattingError(#[from] std::fmt::Error),
74}