use shape_value::{HeapKind, HeapValue, KindedSlot, NativeKind, VMError};
use std::sync::Arc;
#[inline]
fn type_error(msg: impl Into<String>) -> VMError {
VMError::RuntimeError(msg.into())
}
#[cold]
#[inline(never)]
fn ckpt3_surface(op: &'static str, args: &[KindedSlot]) -> VMError {
let receiver_kind = if args.is_empty() {
"<no args>".to_string()
} else {
format!("{:?}", args[0].kind)
};
VMError::NotImplemented(format!(
"{op}: SURFACE — V3-S5 ckpt-3 consumer-cascade tier 2 surface. \
`TypedArrayData` enum DELETED at ckpt-1 (2026-05-15) per W12-\
typed-array-data-deletion audit §3.5 + ADR-006 §2.7.24 Q25.A \
SUPERSEDED. The previous `Arc<TypedArrayData>` receiver-recovery \
+ per-variant match-arm dispatch path (~105 references across \
8 public builtins in this file) cascade-broke at the enum \
deletion site (`crates/shape-value/src/heap_value.rs:3944`). \
Post-deletion target is the v2-raw `TypedArray<T>` flat-struct \
carrier per audit §1.2 + §A.3 + §3.1 scalar recipe + §2.2 \
heap-element variants; per-T monomorphization landing across \
ckpt-3 (this file plus typed_array_methods/iterator_methods/\
array_sort/concat/property_access/array_query) + ckpt-4 \
(Buf<T> / HeapValue::TypedArray arm / HeapKind::TypedArray \
ordinal) + ckpt-5 (wire/json/marshal + 4-table lockstep) + \
ckpt-6 (JIT FFI). Receiver kind: {kind}. UNREACHABLE until ckpt-6 \
STRICT close. REFUSED ON SIGHT: TypedArrayData resurrection under \
any rename (Refusal #1, W12 audit §7).",
op = op,
kind = receiver_kind,
))
}
pub(in crate::executor) fn slot_to_heap_arc(slot: &KindedSlot) -> Result<Arc<HeapValue>, VMError> {
match slot.kind {
NativeKind::Int64 => {
let i = slot.as_i64().expect("kind=Int64");
Ok(Arc::new(HeapValue::BigInt(Arc::new(i))))
}
NativeKind::Float64 => Err(type_error(
"array element of kind Float64 cannot be heap-wrapped (use v2-raw TypedArray<f64> instead)",
)),
NativeKind::Bool => Err(type_error(
"array element of kind Bool cannot be heap-wrapped (use v2-raw TypedArray<u8> instead)",
)),
NativeKind::String => match slot.slot.as_heap_value() {
HeapValue::String(s) => Ok(Arc::new(HeapValue::String(Arc::clone(s)))),
_ => Err(type_error("KindedSlot kind=String but heap arm mismatched")),
},
NativeKind::Ptr(_) => {
let hv: &HeapValue = slot.slot.as_heap_value();
Ok(Arc::new(hv.clone()))
}
_ => Err(type_error(format!(
"array element of kind {:?} cannot be stored in heterogeneous array",
slot.kind
))),
}
}
pub(in crate::executor) fn builtin_push(args: &[KindedSlot]) -> Result<KindedSlot, VMError> {
if args.len() != 2 {
return Err(type_error("push() requires 2 arguments (array, value)"));
}
Err(ckpt3_surface("push", args))
}
pub(in crate::executor) fn builtin_pop(args: &[KindedSlot]) -> Result<KindedSlot, VMError> {
if args.len() != 1 {
return Err(type_error("pop() requires 1 argument (array)"));
}
Err(ckpt3_surface("pop", args))
}
pub(in crate::executor) fn builtin_first(args: &[KindedSlot]) -> Result<KindedSlot, VMError> {
if args.len() != 1 {
return Err(type_error("first() requires 1 argument"));
}
Err(ckpt3_surface("first", args))
}
pub(in crate::executor) fn builtin_last(args: &[KindedSlot]) -> Result<KindedSlot, VMError> {
if args.len() != 1 {
return Err(type_error("last() requires 1 argument"));
}
Err(ckpt3_surface("last", args))
}
pub(in crate::executor) fn builtin_zip(args: &[KindedSlot]) -> Result<KindedSlot, VMError> {
if args.len() != 2 {
return Err(type_error("zip() requires 2 arguments"));
}
Err(ckpt3_surface("zip", args))
}
pub(in crate::executor) fn builtin_filled(args: &[KindedSlot]) -> Result<KindedSlot, VMError> {
if args.len() != 2 {
return Err(type_error("Array.filled() requires 2 arguments (size, value)"));
}
Err(ckpt3_surface("filled", args))
}
pub(in crate::executor) fn builtin_range(args: &[KindedSlot]) -> Result<KindedSlot, VMError> {
if args.is_empty() || args.len() > 3 {
return Err(type_error("range() requires 1, 2, or 3 arguments"));
}
Err(ckpt3_surface("range", args))
}
pub(in crate::executor) fn builtin_slice(args: &[KindedSlot]) -> Result<KindedSlot, VMError> {
if args.len() < 2 || args.len() > 3 {
return Err(type_error(
"slice() requires 2 or 3 arguments (array, start, [end])",
));
}
let _ = HeapKind::TypedArray; Err(ckpt3_surface("slice", args))
}