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}