Files
aji/docs/design/runtime-value-depth-audit.md
T

4.4 KiB

Runtime value-depth audit

Non-normative evidence at 53030ef, separate from Q-059's compiler type traversals. No acceptance limit or runtime rule is proposed here.

Generate TYPE as "array<" * 32768 + "u8" + ",1>" * 32768:

module depth.zero
air 0
lang 0.1
features [arrays, ownership]
fn @main() -> void
effects []
entry:
 %a = local.alloc TYPE
 local.zero %a
 ret

Every array length is one. The accounted value/frame size is one byte, and aji check accepts with no output. aji run --fuel 8 aborts with exit -6, no JSON run record and a symbolized traceback containing 9,997 zeroValue frames. The input has three instructions; the failure occurs inside materialization, not because fuel is exhausted. Tests use the ordinary 8-MiB native stack; only child core capture is disabled. No timeout ends the run.

This confirms native recursion in zeroValue on a verified input. An iterative fix must retain zero initialization, value shape, heap/root lifetimes, allocation failure handling, collection safety and instruction/fuel accounting. A new accepted-depth limit or trap would require a normative decision; none is added by compiler-side repairs.

At the initial baseline, deepCopy/copyAll, valueBytes and collection/serialization were inspection candidates only: the zero-materialization failure prevented probing them. The executed results below supersede that status for copying and collection. valueBytes and output serialization still need depth probes before claiming complete bounded native-stack behavior. Q-060 remains open.

Zero-materialization repair

The implementation now fills zeroable arrays and named structs in the original preorder, using explicit continuations only for pending siblings. Single-child edges need no continuation. Result payloads remain in the execution heap; temporary traversal metadata uses a separate host arena and is released before the next instruction safe point. A partially built value is not published to the local cell if an allocation fails.

The preserved invariant is complete initialization without aliasing independent array/struct payloads. Spec 07a's local.zero verifier rule (zeroable type, no live borrow) and spec 08 §13's whole-local initialization remain unchanged. All leaves have the same integer type/zero bits or false boolean, and aggregate declaration/variant identities and field/element order are unchanged. No runtime rule, Aji allocation authority, opcode, effect, feature, diagnostic code, trap, accepted-depth limit or fuel/scheduler event is introduced. Existing enum/capability zero rejects remain E1001 in AIR and E7006/zero_not_zeroable in source; the public zero_enum/capability_not_zeroable cases and their source analogues remain rejection examples.

Unit tests traverse 32,768 single-element arrays and a 32,768-declaration chain with heterogeneous pending siblings, empty-record leaves and three-byte arrays. A constrained payload allocator fails after allocating the root and proves that the old local value survives the failed instruction. The new zero_structure_siblings AIR/source pair checks complete mixed zeroing followed by a write and unchanged independent fields. Forty generated shallow mixed-type runs produce byte-identical old/new records.

An additional verified deep-program unit test pins fuel 0/1/2 as exact limit records and fuel 3 as successful completion, with matching instruction counts at the ordinary collection threshold.

The original 32,768-level input now returns {"status":"returned","value":null} under fuel 8 at the ordinary collection threshold. This is not a claim that all deep runtime paths work. Two follow-up probes are independently confirmed:

  • With collection before every instruction, the same program aborts without JSON inside Copier.value/items (4,997/4,998 symbolized frames). Its ordinary run succeeds, isolating the collector's recursive payload copy from zero construction.
  • Adding %v = local.load %a immediately after zeroing aborts without JSON inside deepCopy/copyAll (4,998 frames each), under the same fuel 8. Storage-to-SSA copying still requires its own iterative traversal.

Both probes retain the ordinary native stack limit and disable only child core capture, with no wall-clock termination. Evidence comes from the runner exit status and Zig's symbolized stderr, not a saved core dump. Q-060 stays open for copying, sharing-preserving collection/result copying, accounted-value queries and output serialization.