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("semantic control-flow construct {construct:?} is not supported")]
16 UnsupportedControlFlow {
17 construct: &'static str,
19 },
20 #[error("source semantic program is invalid for import: {source}")]
22 InvalidImport {
23 #[source]
24 source: ProgramStructuralError,
25 },
26 #[error("tensor bindings may target only semantic-program inputs")]
28 BindingTargetNotInput,
29 #[error("semantic shape guards may target only operation outputs")]
31 GuardTargetNotOperationOutput,
32 #[error("semantic-program input already has a tensor binding")]
34 DuplicateBinding,
35 #[error("semantic-program value count exceeds the supported u32 range")]
37 TooManyValues,
38 #[error("semantic operation expects {expected} inputs, got {actual}")]
40 Arity {
41 expected: usize,
43 actual: usize,
45 },
46 #[error("semantic operation metadata inference failed: {source}")]
48 Metadata {
49 #[source]
51 source: Box<crate::Error>,
52 },
53 #[error("semantic operation declares {expected} outputs, inferred {actual}")]
55 OutputMetadataCount {
56 expected: usize,
58 actual: usize,
60 },
61 #[error("extension family {family:?} has no semantic effect declaration")]
63 UndeclaredExtensionEffects {
64 family: &'static str,
66 },
67 #[error("extension family {family:?} has no semantic alias declaration")]
69 UndeclaredExtensionAliases {
70 family: &'static str,
72 },
73 #[error("extension family {family:?} declared an invalid effect resource: {source}")]
75 InvalidEffectResource {
76 family: &'static str,
78 #[source]
80 source: EffectResourceError,
81 },
82 #[error(
84 "semantic alias index is out of bounds: output {output}/{output_count}, input {input:?}/{input_count}"
85 )]
86 AliasOutOfBounds {
87 output: usize,
89 output_count: usize,
91 input: Option<usize>,
93 input_count: usize,
95 },
96 #[error("semantic aliases must cover {expected} outputs exactly once, got {actual}")]
98 AliasCoverage {
99 expected: usize,
101 actual: usize,
103 },
104}
105
106#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
108pub enum ProgramQueryError {
109 #[error("value does not belong to this semantic program")]
111 ForeignValue,
112}
113
114#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
116#[non_exhaustive]
117pub enum ProgramStructuralError {
118 #[error("semantic operation references a value outside the program")]
120 InvalidValueReference,
121 #[error("semantic operation outputs violate SSA ordering")]
123 InvalidSsaOrder,
124}
125
126#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
128#[non_exhaustive]
129pub enum ProgramBindingError {
130 #[error("tensor binding target is not a semantic-program input")]
132 InvalidTarget,
133 #[error("tensor binding dtype mismatch: expected {expected:?}, got {actual:?}")]
135 DTypeMismatch {
136 expected: tenferro_tensor::DType,
138 actual: tenferro_tensor::DType,
140 },
141 #[error("tensor binding rank mismatch: expected {expected}, got {actual}")]
143 RankMismatch {
144 expected: usize,
146 actual: usize,
148 },
149 #[error("tensor binding extent mismatch at axis {axis}: expected {expected}, got {actual}")]
151 ExactExtentMismatch {
152 axis: usize,
154 expected: usize,
156 actual: usize,
158 },
159 #[error(
161 "tensor binding extent exceeds upper bound at axis {axis}: bound {bound}, got {actual}"
162 )]
163 UpperBoundExceeded {
164 axis: usize,
166 bound: usize,
168 actual: usize,
170 },
171}
172
173#[derive(Debug, thiserror::Error)]
175#[non_exhaustive]
176pub enum ProgramFinishError {
177 #[error("program output does not belong to this semantic-program builder")]
179 ForeignOutput,
180 #[error("semantic-program structural validation failed: {source}")]
182 StructuralValidation {
183 #[source]
185 source: ProgramStructuralError,
186 },
187 #[error("semantic-program binding finalization failed: {source}")]
189 BindingFinalization {
190 #[source]
192 source: ProgramBindingError,
193 },
194}
195
196#[derive(Debug, thiserror::Error)]
198#[non_exhaustive]
199pub enum SemanticTransformError {
200 #[error(transparent)]
202 Build(#[from] ProgramBuildError),
203 #[error(transparent)]
205 Finish(#[from] ProgramFinishError),
206 #[error("semantic transform returned a foreign destination value")]
208 ForeignReturnedValue,
209 #[error("semantic transform discarded one or more tensor bindings")]
211 DroppedBindings,
212 #[error("semantic transform rejected the input")]
214 Rejected,
215}
216
217#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
219pub enum EffectResourceError {
220 #[error("effect resource family must be a nonempty versioned identifier")]
222 InvalidFamily,
223}