tenferro_runtime/program/
error.rs1#[derive(Debug, thiserror::Error)]
3#[non_exhaustive]
4pub enum ProgramBuildError {
5 #[error("value does not belong to this semantic-program builder")]
7 ForeignValue,
8 #[error("import root does not belong to the source semantic program")]
10 ForeignImportRoot,
11 #[error("import bindings do not belong to the source semantic program")]
13 ForeignBindings,
14 #[error("trace context is already borrowed by an operation in progress")]
16 ReentrantContextBorrow,
17 #[error("semantic control-flow construct {construct:?} is not supported")]
19 UnsupportedControlFlow {
20 construct: &'static str,
22 },
23 #[error("source semantic program is invalid for import: {source}")]
25 InvalidImport {
26 #[source]
27 source: ProgramStructuralError,
28 },
29 #[error("tensor bindings may target only semantic-program inputs")]
31 BindingTargetNotInput,
32 #[error("semantic shape guards may target only operation outputs")]
34 GuardTargetNotOperationOutput,
35 #[error("semantic-program input already has a tensor binding")]
37 DuplicateBinding,
38 #[error("semantic-program value count exceeds the supported u32 range")]
40 TooManyValues,
41 #[error("semantic operation expects {expected} inputs, got {actual}")]
43 Arity {
44 expected: usize,
46 actual: usize,
48 },
49 #[error("semantic operation metadata inference failed: {source}")]
51 Metadata {
52 #[source]
54 source: Box<crate::Error>,
55 },
56 #[error("semantic operation declares {expected} outputs, inferred {actual}")]
58 OutputMetadataCount {
59 expected: usize,
61 actual: usize,
63 },
64 #[error("extension family {family:?} has no semantic effect declaration")]
66 UndeclaredExtensionEffects {
67 family: &'static str,
69 },
70 #[error("extension family {family:?} has no semantic alias declaration")]
72 UndeclaredExtensionAliases {
73 family: &'static str,
75 },
76 #[error("extension family {family:?} declared an invalid effect resource: {source}")]
78 InvalidEffectResource {
79 family: &'static str,
81 #[source]
83 source: EffectResourceError,
84 },
85 #[error(
87 "semantic alias index is out of bounds: output {output}/{output_count}, input {input:?}/{input_count}"
88 )]
89 AliasOutOfBounds {
90 output: usize,
92 output_count: usize,
94 input: Option<usize>,
96 input_count: usize,
98 },
99 #[error(
101 "externally defined scalar {dtype:?} reached {site} without a canonical program \
102identity; a contribution must declare a stable scalar identity before a traced program can \
103carry it"
104 )]
105 ExternalScalarWithoutIdentity {
106 dtype: tenferro_tensor::DType,
108 site: &'static str,
110 },
111 #[error("semantic aliases must cover {expected} outputs exactly once, got {actual}")]
113 AliasCoverage {
114 expected: usize,
116 actual: usize,
118 },
119}
120
121#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
123pub enum ProgramQueryError {
124 #[error("value does not belong to this semantic program")]
126 ForeignValue,
127}
128
129#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
131#[non_exhaustive]
132pub enum ProgramStructuralError {
133 #[error("semantic operation references a value outside the program")]
135 InvalidValueReference,
136 #[error("semantic operation outputs violate SSA ordering")]
138 InvalidSsaOrder,
139}
140
141#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
143#[non_exhaustive]
144pub enum ProgramBindingError {
145 #[error("tensor binding target is not a semantic-program input")]
147 InvalidTarget,
148 #[error("tensor binding dtype mismatch: expected {expected:?}, got {actual:?}")]
150 DTypeMismatch {
151 expected: tenferro_tensor::DType,
153 actual: tenferro_tensor::DType,
155 },
156 #[error("tensor binding rank mismatch: expected {expected}, got {actual}")]
158 RankMismatch {
159 expected: usize,
161 actual: usize,
163 },
164 #[error("tensor binding extent mismatch at axis {axis}: expected {expected}, got {actual}")]
166 ExactExtentMismatch {
167 axis: usize,
169 expected: usize,
171 actual: usize,
173 },
174 #[error(
176 "tensor binding extent exceeds upper bound at axis {axis}: bound {bound}, got {actual}"
177 )]
178 UpperBoundExceeded {
179 axis: usize,
181 bound: usize,
183 actual: usize,
185 },
186}
187
188#[derive(Debug, thiserror::Error)]
190#[non_exhaustive]
191pub enum ProgramFinishError {
192 #[error("program output does not belong to this semantic-program builder")]
194 ForeignOutput,
195 #[error("snapshot rebuild failed: {source}")]
197 SnapshotRebuild {
198 #[source]
200 source: ProgramBuildError,
201 },
202 #[error("checkpoint alias substitution failed: {source}")]
204 AliasSubstitution {
205 #[source]
207 source: ProgramBuildError,
208 },
209 #[error("trace context is already borrowed by an operation in progress")]
211 ReentrantContextBorrow,
212 #[error("semantic-program structural validation failed: {source}")]
214 StructuralValidation {
215 #[source]
217 source: ProgramStructuralError,
218 },
219 #[error("semantic-program binding finalization failed: {source}")]
221 BindingFinalization {
222 #[source]
224 source: ProgramBindingError,
225 },
226}
227
228#[derive(Debug, thiserror::Error)]
230#[non_exhaustive]
231pub enum SemanticTransformError {
232 #[error(transparent)]
234 Build(#[from] ProgramBuildError),
235 #[error(transparent)]
237 Finish(#[from] ProgramFinishError),
238 #[error("semantic transform returned a foreign destination value")]
240 ForeignReturnedValue,
241 #[error("semantic transform discarded one or more tensor bindings")]
243 DroppedBindings,
244 #[error("semantic transform rejected the input")]
246 Rejected,
247}
248
249#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
251pub enum EffectResourceError {
252 #[error("effect resource family must be a nonempty versioned identifier")]
254 InvalidFamily,
255}