shape_vm/executor/utils/extraction_helpers.rs
1//! Extraction helpers for method handlers.
2//!
3//! Wave-β R-misc migration (per ADR-006 §2.7 + playbook §10
4//! `D-array-detect` / `D-v2-array-detect` template): the legacy v1
5//! ValueWord-shaped helpers (`require_any_array_arg`,
6//! `nb_to_string_coerce`, `check_arg_count`) depended on a stack of
7//! deleted carriers — `shape_value::ValueWord` / `ValueWordExt` (the v1
8//! dynamic-tag word, deleted), `shape_value::ArrayView` (the v1
9//! polymorphic array view, deleted alongside `as_any_array`), and the
10//! `as_str` / `as_f64` / `as_i64` / `as_bool` / `is_none` accessors on
11//! `&ValueWord` (all deleted by §2.7.6 — heap dispatch goes through
12//! `KindedSlot::slot.as_heap_value()` + `HeapValue` match per Q8).
13//!
14//! - `require_any_array_arg(&[ValueWord]) -> Result<ArrayView, _>` —
15//! deleted (no caller is reachable until D-array-detect /
16//! D-v2-array-detect rebuild lands the kinded array dispatch surface).
17//! Callers in `array_sort.rs` / `array_transform.rs` are pre-existing
18//! Wave-α-broken on `nb_to_string_coerce`; the array-view accessor
19//! itself has zero live callers.
20//! - `nb_to_string_coerce(&ValueWord) -> String` — deleted. Callers in
21//! `array_sort.rs` / `array_transform.rs` reach this via `array.iter()`
22//! on the deleted v1 array view; both consumer files are pre-existing
23//! Wave-α-broken and migrate together with the kinded array surface.
24//! - `check_arg_count(&[ValueWord], usize, &str, &str) -> Result<(), _>`
25//! — deleted. Zero live callers (verified via grep across `crates/`).
26//!
27//! `type_mismatch_error(method_name: &str, expected_type: &str) -> VMError`
28//! is preserved verbatim — its signature carries no `ValueWord`
29//! dependency and it is the only helper in this module with live
30//! callers (~80 sites across `priority_queue_methods.rs`,
31//! `deque_methods.rs`, and other `objects/*_methods.rs` files).
32
33use shape_value::VMError;
34
35/// Produce a `VMError::RuntimeError` of the form
36/// `"<method> called on non-<expected_type> value"`.
37///
38/// This consolidates the ~77 occurrences of that pattern across the
39/// collection method handlers. Used by every `*_methods.rs` consumer
40/// in `executor/objects/`.
41#[inline]
42pub(crate) fn type_mismatch_error(method_name: &str, expected_type: &str) -> VMError {
43 VMError::RuntimeError(format!(
44 "{} called on non-{} value",
45 method_name, expected_type
46 ))
47}
48
49// `check_arg_count`, `require_any_array_arg`, `nb_to_string_coerce` were
50// deleted as part of the Wave-β R-misc strict-typing migration. Their
51// signatures took `&[ValueWord]` / `&ValueWord` / returned `ArrayView`,
52// all of which were deleted with the v1 dynamic-tag carrier. The
53// post-§2.7.6 replacement dispatches on `KindedSlot.kind()` and uses
54// the per-variant `KindedSlot::as_*` accessors plus
55// `slot.as_heap_value()` for heap-arm dispatch. No live caller depends
56// on the deleted helpers; rebuild as needed once the kinded array
57// dispatch surface lands (D-array-detect / D-v2-array-detect).