use crate::ir_inner::model::program::Program;
pub use vyre_spec::CpuFn;
pub trait CpuOp {
fn cpu(input: &[u8], output: &mut Vec<u8>);
}
pub trait CategoryAOp {
fn program() -> Program;
}
#[deprecated(
note = "structured_intrinsic_cpu is a panicking fallback. Implement typed GPU lowering for the op."
)]
pub fn structured_intrinsic_cpu(input: &[u8], output: &mut Vec<u8>) {
output.clear();
panic!(
"structured intrinsic CPU adapter received {} flat input bytes, but no typed reference implementation is registered for this op. Fix: implement the op's typed reference in vyre-reference and dispatch via DialectRegistry::get_lowering(ReferenceBackend); production execution must select a concrete GPU/backend lowering before launch.",
input.len()
);
}
#[must_use]
pub fn is_cpu_reference_sentinel(f: CpuFn) -> bool {
#[allow(deprecated)]
std::ptr::fn_addr_eq(f, structured_intrinsic_cpu as CpuFn)
}
#[deprecated(
note = "use is_cpu_reference_sentinel; CPU reference sentinels are explicit oracles, not runtime fallbacks"
)]
#[must_use]
pub fn is_fallback_cpu_ref(f: CpuFn) -> bool {
is_cpu_reference_sentinel(f)
}
#[cfg(test)]
#[allow(deprecated)]
mod tests {
use super::*;
#[test]
fn is_cpu_reference_sentinel_detects_structured_intrinsic() {
assert!(is_cpu_reference_sentinel(structured_intrinsic_cpu));
}
#[test]
fn is_cpu_reference_sentinel_rejects_other_fn() {
#[allow(clippy::ptr_arg)] fn custom_cpu(_input: &[u8], _output: &mut Vec<u8>) {}
assert!(!is_cpu_reference_sentinel(custom_cpu));
}
#[test]
fn structured_intrinsic_clears_output_and_panics() {
let mut output = vec![1, 2, 3];
let panic = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
structured_intrinsic_cpu(b"input", &mut output);
}))
.expect_err("structured intrinsic CPU sentinel must not return normally");
assert!(output.is_empty());
let message = panic
.downcast_ref::<String>()
.map(String::as_str)
.or_else(|| panic.downcast_ref::<&str>().copied())
.expect("Fix: structured intrinsic CPU sentinel panic should carry a message");
assert!(message.contains("no typed reference implementation is registered"));
assert!(
message.contains("production execution must select a concrete GPU/backend lowering")
);
}
}