Expand description
Runtime detection and uniform access for v2 typed arrays.
v2 typed arrays are heap-allocated TypedArray<T> instances, where the
element type T is monomorphized at compile time. The bytecode compiler
emits typed allocation/push opcodes (e.g. NewTypedArrayF64,
TypedArrayPushF64) that create the right TypedArray<T> instantiation.
However, generic consumer-side opcodes (Length, GetProp, SetProp,
IterNext) and generic method dispatch (.len(), .first(), .last(),
.clone(), .sum(), .push(), .map(), .filter()) only have a runtime
(bits, NativeKind) pair to inspect — they need to recognize the v2 typed
array pointer and dispatch to a typed implementation based on the element
type.
§Element type encoding
The compile-time element type is preserved at runtime by stamping the
_pad byte (offset 7) of the HeapHeader with an ElemType discriminant.
This piggybacks on existing layout — no struct change required.
Allocation handlers in array.rs stamp the byte after allocating;
consumer paths in this module read the byte to dispatch.
§ADR-006 §2.7.7 / Wave 6.5 cluster D-v2-array-detect
API surface uses the kinded (u64, NativeKind) carrier shape. v2 typed
array pointers flow through the VM stack as raw *mut TypedArray<T> bits
tagged with NativeKind::UInt64 (no Arc, no refcount — see
v2_handlers/array.rs). Detection rejects any other kind. Element reads
return the element’s native bit pattern paired with the element’s
NativeKind (Float64 / Int64 / Int32 / Bool). Writes accept the same
pair, decode bits per kind, and reject incompatible kinds.
Structs§
Enums§
Constants§
- ELEM_
TYPE_ BOOL _pad-byte discriminant forTypedArray<u8>carryingboolelements.- ELEM_
TYPE_ CHAR _pad-byte discriminant forTypedArray<char>.- ELEM_
TYPE_ DECIMAL _pad-byte discriminant forTypedArray<*const DecimalObj>.- ELEM_
TYPE_ F32 _pad-byte discriminant forTypedArray<f32>.- ELEM_
TYPE_ F64 _pad-byte discriminant forTypedArray<f64>.- ELEM_
TYPE_ I8 _pad-byte discriminant forTypedArray<i8>.- ELEM_
TYPE_ I16 _pad-byte discriminant forTypedArray<i16>.- ELEM_
TYPE_ I32 _pad-byte discriminant forTypedArray<i32>.- ELEM_
TYPE_ I64 _pad-byte discriminant forTypedArray<i64>.- ELEM_
TYPE_ STRING _pad-byte discriminant forTypedArray<*const StringObj>.- ELEM_
TYPE_ TYPED_ OBJECT _pad-byte discriminant forTypedArray<*const TypedObjectStorage>.- ELEM_
TYPE_ U8 _pad-byte discriminant forTypedArray<u8>carryingu8elements.- ELEM_
TYPE_ U16 _pad-byte discriminant forTypedArray<u16>.- ELEM_
TYPE_ U32 _pad-byte discriminant forTypedArray<u32>.- ELEM_
TYPE_ UNKNOWN _pad-byte discriminant for an unstamped / unknown element type.
Functions§
- all_
elements - Check if all elements in a bool v2 typed array are true.
- allocate_
empty_ typed_ array - Allocate an empty
TypedArray<T>for the givenV2ElemType, initialised withcapacityslots, length zero, and stamped with the matching element-type discriminant byte (§2.7.5 producer-side stamp). Returns the raw*mut u8carrier pointer for wrapping into aPtr(HeapKind::TypedArray)KindedSlot. Subsequentpush_elementcalls grow the array. - any_
elements - Check if any element in a bool v2 typed array is true.
- as_
v2_ typed_ array - Try to interpret a
(bits, kind)pair as a v2 typed array pointer. - avg_
elements - Compute the average (mean) of all elements of a numeric v2 typed array.
Returns NaN for empty arrays. Returns
(bits, NativeKind::Float64)always (mean of integer arrays is a float). - clone_
array - Allocate a fresh v2 typed array, copy all elements from
view, stamp elem_type, and return its raw pointer. - cmp_
element_ natural - Compare two elements of the SAME view by natural ordering.
- concat_
arrays - Concatenate two v2 typed arrays of the same element type. Returns the
raw pointer to a freshly-allocated
TypedArray<T>witha.len + b.lenelements. ReturnsErron element-type mismatch (per ADR-006 §2.7.5 stamp-at-compile-time: mixed-kind concat is structurally rejected, no coercion). - contains_
element - Return
trueiff any element ofviewequalsneedle_bitsunder the element-type’s equality. - count_
true_ elements - Count
truevalues in a bool v2 typed array. Returns(count, Int64). - diff_
f64 - Stride-1 consecutive differences (
out[i] = src[i+1] - src[i]) over a v2 F64 typed array. Returns a fresh v2TypedArray<f64>of lengthview.len - 1(empty forlen < 2). SIMD-accelerated viaf64x4for sufficiently large inputs (PC.2). - dot_
elements - Compute the dot product of two float v2 typed arrays.
- drop_
array_ n arr.drop(n)— all elements except the firstn.nclamped to[0, view.len]. Nameddrop_array_nto avoid collision withTypedArray::drop_array(the allocator destructor).- eq_
element - Per-kind value equality for the
(bits, kind)carrier shape. - max_
elements - Compute the maximum element of a numeric v2 typed array.
- min_
elements - Compute the minimum element of a numeric v2 typed array.
- native_
kind_ to_ v2_ elem_ type - Map a
NativeKindto its correspondingV2ElemTypefor HOF-builder output-array allocation. ReturnsNonefor kinds with no monomorphizedTypedArray<T>carrier (e.g.Null,Ptr(Closure), genericPtr(HeapKind::HashMap)). Pairs withallocate_empty_typed_array+push_elementto build a result array element-by-element. - norm_
elements - Compute the Euclidean norm of a float v2 typed array.
- permute_
array - Materialize a permutation of
viewinto a freshTypedArray<T>of the same element kind.indices[i]selects the source element at positioniof the output. Indices out of range[0, view.len)are skipped (defensive — callers should validate up front; out-of-range indices indicate a sort comparator bug, not a user-input edge). - pop_
element - Pop the last element from a v2 typed array, returning
(bits, NativeKind). - position_
of - Return the first index
iwhereview[i] == needleunder the element-type’s equality, orNoneif no element matches. - push_
element - Append
(bits, kind)to a v2 typed array. - read_
element - Read element
indexfrom a v2 typed array, returning(bits, NativeKind). - reverse_
array - Produce a reversed copy of
view. Kind-generic over the 14V2ElemTypevariants. For heap-element variants (String / Decimal / TypedObject) the new array’s pointers share the same heap targets as the source; each is retained per-element so both arrays own valid shares. - slice_
array arr.slice(start, end)— bounded copy of[start..end).startandendare clamped to[0, view.len]; ifstart >= end, the result is empty. Mirrors Rust’sslice::get(range)clamping behaviour.- stamp_
elem_ ⚠type - Stamp the element type byte (
_padat offset 7 of the HeapHeader) on a freshly-allocated v2 typed array. - std_
elements - Compute the sample standard deviation of a float v2 typed array.
- sum_
elements - Sum all elements of a numeric (F64/I64/I32) v2 typed array.
- take_
array arr.take(n)— firstnelements.nclamped to[0, view.len].- unary_
f64_ transform - Apply a unary element-wise f64 transform to
view, returning a newly allocated v2TypedArray<f64>pointer withELEM_TYPE_F64stamped. - variance_
elements - Compute the sample variance of a float v2 typed array. Returns NaN for arrays with fewer than 2 elements. Always returns Float64.
- write_
element - Write
(bits, kind)to elementindexof a v2 typed array.