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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/// Errors that can occur in GAT operations.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum GatError {
/// A referenced sort was not found in the theory.
#[error("sort not found: {0}")]
SortNotFound(String),
/// A referenced operation was not found in the theory.
#[error("operation not found: {0}")]
OpNotFound(String),
/// A referenced theory was not found in the registry.
#[error("theory not found: {0}")]
TheoryNotFound(String),
/// Sort arity mismatch in a morphism or model.
#[error("sort arity mismatch for {sort}: expected {expected}, got {got}")]
SortArityMismatch {
/// The sort with mismatched arity.
sort: String,
/// Expected number of parameters.
expected: usize,
/// Actual number of parameters.
got: usize,
},
/// Operation type mismatch in a morphism or model.
#[error("operation type mismatch for {op}: {detail}")]
OpTypeMismatch {
/// The operation with mismatched types.
op: String,
/// Details about the mismatch.
detail: String,
},
/// An equation is not preserved by a morphism.
#[error("equation {equation} not preserved: {detail}")]
EquationNotPreserved {
/// The equation that failed preservation.
equation: String,
/// Details about the failure.
detail: String,
},
/// Sort conflict during colimit computation.
#[error("sort conflict in colimit: {name} has incompatible definitions")]
SortConflict {
/// The conflicting sort name.
name: String,
},
/// Operation conflict during colimit computation.
#[error("operation conflict in colimit: {name} has incompatible definitions")]
OpConflict {
/// The conflicting operation name.
name: String,
},
/// Equation conflict during colimit computation.
#[error("equation conflict in colimit: {name}")]
EqConflict {
/// The conflicting equation name.
name: String,
},
/// A morphism is missing a sort mapping.
#[error("morphism missing sort mapping for: {0}")]
MissingSortMapping(String),
/// A morphism is missing an operation mapping.
#[error("morphism missing operation mapping for: {0}")]
MissingOpMapping(String),
/// Cyclic dependency detected in theory extends chain.
#[error("cyclic dependency detected involving theory: {0}")]
CyclicDependency(String),
/// Model interpretation error.
#[error("model error: {0}")]
ModelError(String),
// --- Type-checking errors ---
/// A variable was not found in the typing context.
#[error("unbound variable: {0}")]
UnboundVariable(String),
/// An operation was applied to the wrong number of arguments.
#[error("arity mismatch for operation {op}: expected {expected} args, got {got}")]
TermArityMismatch {
/// The operation name.
op: String,
/// Expected number of arguments.
expected: usize,
/// Actual number of arguments.
got: usize,
},
/// An argument's sort doesn't match the operation's expected input sort.
#[error("type mismatch for {op} argument {arg_index}: expected {expected}, got {got}")]
ArgTypeMismatch {
/// The operation name.
op: String,
/// Zero-based argument index.
arg_index: usize,
/// Expected sort name.
expected: String,
/// Actual sort name.
got: String,
},
/// The two sides of an equation have different sorts.
#[error("equation {equation} sides have different sorts: lhs={lhs_sort}, rhs={rhs_sort}")]
EquationSortMismatch {
/// The equation name.
equation: String,
/// Sort of the left-hand side.
lhs_sort: String,
/// Sort of the right-hand side.
rhs_sort: String,
},
/// A variable is used at conflicting sorts across an equation.
#[error("variable {var} used at conflicting sorts: {sort1} and {sort2}")]
ConflictingVarSort {
/// The variable name.
var: String,
/// First inferred sort.
sort1: String,
/// Second (conflicting) inferred sort.
sort2: String,
},
// --- Natural transformation errors ---
/// Source and target morphisms of a natural transformation have different domains.
#[error(
"natural transformation domain mismatch: {source_morphism} and {target_morphism} have different domains"
)]
NatTransDomainMismatch {
/// Source morphism name.
source_morphism: String,
/// Target morphism name.
target_morphism: String,
},
/// A natural transformation is missing a component for a sort.
#[error("missing natural transformation component for sort: {0}")]
MissingNatTransComponent(String),
/// A natural transformation component is invalid.
#[error("invalid natural transformation component for sort {sort}: {detail}")]
NatTransComponentInvalid {
/// The sort name.
sort: String,
/// Details about the invalidity.
detail: String,
},
/// The naturality condition is violated for an operation.
#[error("naturality violated for operation {op}")]
NaturalityViolation {
/// The operation where naturality fails.
op: String,
/// LHS of the naturality square.
lhs: String,
/// RHS of the naturality square.
rhs: String,
},
/// Natural transformation composition mismatch.
#[error("cannot compose: alpha target {alpha_target} != beta source {beta_source}")]
NatTransComposeMismatch {
/// Target morphism of first nat trans.
alpha_target: String,
/// Source morphism of second nat trans.
beta_source: String,
},
// --- Quotient errors ---
/// Identified elements are incompatible for quotienting.
#[error("cannot identify {name_a} and {name_b}: {detail}")]
QuotientIncompatible {
/// First element name.
name_a: String,
/// Second element name.
name_b: String,
/// Reason for incompatibility.
detail: String,
},
}