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(
98 "externally defined scalar {dtype:?} reached {site} without a canonical program \
99identity; a contribution must declare a stable scalar identity before a traced program can \
100carry it"
101 )]
102 ExternalScalarWithoutIdentity {
103 dtype: tenferro_tensor::DType,
105 site: &'static str,
107 },
108 #[error("semantic aliases must cover {expected} outputs exactly once, got {actual}")]
110 AliasCoverage {
111 expected: usize,
113 actual: usize,
115 },
116}
117
118#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
120pub enum ProgramQueryError {
121 #[error("value does not belong to this semantic program")]
123 ForeignValue,
124}
125
126#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
128#[non_exhaustive]
129pub enum ProgramStructuralError {
130 #[error("semantic operation references a value outside the program")]
132 InvalidValueReference,
133 #[error("semantic operation outputs violate SSA ordering")]
135 InvalidSsaOrder,
136}
137
138#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
140#[non_exhaustive]
141pub enum ProgramBindingError {
142 #[error("tensor binding target is not a semantic-program input")]
144 InvalidTarget,
145 #[error("tensor binding dtype mismatch: expected {expected:?}, got {actual:?}")]
147 DTypeMismatch {
148 expected: tenferro_tensor::DType,
150 actual: tenferro_tensor::DType,
152 },
153 #[error("tensor binding rank mismatch: expected {expected}, got {actual}")]
155 RankMismatch {
156 expected: usize,
158 actual: usize,
160 },
161 #[error("tensor binding extent mismatch at axis {axis}: expected {expected}, got {actual}")]
163 ExactExtentMismatch {
164 axis: usize,
166 expected: usize,
168 actual: usize,
170 },
171 #[error(
173 "tensor binding extent exceeds upper bound at axis {axis}: bound {bound}, got {actual}"
174 )]
175 UpperBoundExceeded {
176 axis: usize,
178 bound: usize,
180 actual: usize,
182 },
183}
184
185#[derive(Debug, thiserror::Error)]
187#[non_exhaustive]
188pub enum ProgramFinishError {
189 #[error("program output does not belong to this semantic-program builder")]
191 ForeignOutput,
192 #[error("semantic-program structural validation failed: {source}")]
194 StructuralValidation {
195 #[source]
197 source: ProgramStructuralError,
198 },
199 #[error("semantic-program binding finalization failed: {source}")]
201 BindingFinalization {
202 #[source]
204 source: ProgramBindingError,
205 },
206}
207
208#[derive(Debug, thiserror::Error)]
210#[non_exhaustive]
211pub enum SemanticTransformError {
212 #[error(transparent)]
214 Build(#[from] ProgramBuildError),
215 #[error(transparent)]
217 Finish(#[from] ProgramFinishError),
218 #[error("semantic transform returned a foreign destination value")]
220 ForeignReturnedValue,
221 #[error("semantic transform discarded one or more tensor bindings")]
223 DroppedBindings,
224 #[error("semantic transform rejected the input")]
226 Rejected,
227}
228
229#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
231pub enum EffectResourceError {
232 #[error("effect resource family must be a nonempty versioned identifier")]
234 InvalidFamily,
235}