interp: serialize runtime values without recursive JSON nesting

This commit is contained in:
dev committed 2026-10-10 00:01:40 +03:00
1 parent 6353ab5f5d
commit c9064418bd
6 files changed
+422 -55

No files matched your search

+2
View File
@@ -482,3 +482,5 @@ The [storage/value-copy increment](runtime-value-depth-audit.md#storagevalue-cop
The [sharing-preserving copy increment](runtime-value-depth-audit.md#sharing-preserving-copy-repair) removes recursive collector/result copying while retaining forwarded identities, backing storage, cycles, slice paths/ranges, buffer metadata, race shadows and mutex views. Deep verified runs now pass ordinary and per-instruction collection, with unchanged fuel boundaries and returned payload lifetimes. Follow-up CLI probes independently confirm valueBytes native-stack exhaustion on own.new and output failure at std.json.Stringify's fixed nesting stack. The latter is not yet evidence of writeValue native-stack overflow. Q-060 stays open for sizing and serialization; no normative depth limit, feature or trap is introduced.
The [runtime value-size increment](runtime-value-depth-audit.md#runtime-value-size-repair) iterates fixed-array first-element chains with constant state, preserving zero-sized leaves, checked overflow, nominal maximum payloads and the element-before-dynamic-count rule. The previously crashing 32,768-level own.new probe now returns normally with the original one-byte charge; zero authority takes the original failure edge. Deep verified fuel/collection tests, nested-quota AIR/source runs and an independent allocation-size oracle constrain compatibility. Q-060 remains open for output serialization; there is no new normative limit or trap, and Q-059's nominal-query audit remains separate.
The [runtime value JSON increment](runtime-value-depth-audit.md#runtime-value-json-repair) removes recursive value serialization and bypasses the outer stringify's fixed nesting table for internal payloads. Exact encoding/options, outer-container state, writer/allocation failure and deep returned-payload lifetimes are tested; the formerly failing CLI now emits a complete record in deterministic and hosted profiles. All five confirmed Q-060 failure paths have repairs, without a new limit or trap. Q-060 remains open for closing call-path checks, including the inspection-only cache-free public verification/runtime entry path and its connection to Q-059's uncached nominal queries; no verified failure on that path is claimed yet.
+15 -1
View File
@@ -21,7 +21,7 @@ Every array length is one. The accounted value/frame size is one byte, and `aji
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, collection, value sizing and output serialization. Q-060 remains open for output serialization; the earlier increments record the failures that led to each repair.
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, collection, value sizing and output serialization. All five confirmed failure paths now have iterative repairs. Q-060 remains open for the closing call-path audit; the earlier increments record the failures that led to each repair.
## Zero-materialization repair
@@ -78,3 +78,17 @@ Unit tests compare scalar/nominal/built-in/capability/iref leaves under mixed ar
Validation: unit/format checks, test-extended and all 1,789 ordinary conformance cases pass. Ten old/new quota records for the new AIR/source pair are identical. Another 426 generated runs independently compute expected charges for scalar/record/enum contents, mixed fixed arrays, individual/repeated/zero-count owners and island/arc headers; every boundary outcome matches that oracle and the old interpreter's record. These are generated runtime robustness inputs, not model-evaluation or held-out tasks. The earlier full per-instruction collector conformance run remains additional validation in progress.
Q-060 remains open for output serialization at the fixed std.json.Stringify nesting stack and the still-recursive writeValue traversal. Q-059's uncached nominal query audit is separate; this repair does not claim to close it.
## Runtime value JSON repair
WriteValue now emits the complete value through a raw-value boundary in the outer std.json.Stringify. An explicit pending-sequence stack traverses arrays, record fields and enum payloads; the outer stringify never stores their nesting in its fixed 256-level table. Field order, variant/payload shape, decimal integer representation, escaping, whitespace and opaque handles retain their existing encoding (spec 07a, Run result). The public writer API and diagnostic schema are unchanged.
The invariant is byte-identical encoding of existing runtime values without traversing opaque identity handles or mutating returned payloads. Traversal metadata lives in a temporary host arena, released on success and failure; it adds no Aji allocation, authority, effect, fuel charge or collection point. Writer errors propagate as before; metadata allocation failure uses the existing WriteFailed interface. No recovery after partial output is promised. The CLI still buffers a complete run record before publishing it. Verifier rules are unchanged: the new returned_mixed_json AIR/source pair returns an enum containing records, nested arrays, signed integers and empty values; the existing source borrow_returns/main_return rejection retains E7006. No new rejection, trap, feature, depth limit or normative/bundle text is introduced.
Unit tests compare exact bytes with the ordinary Zig encoder in 112 combinations of whitespace, Unicode escaping, string-array, nonportable-number and optional-field options, wrapped between other fields in an outer object. Existing Aji raw decimal integers are preserved even when string mode for nonportable numbers is selected. A codec-only 32,768-level mixed record/variant/array value checks pending siblings and empty leaves against independently constructed bytes; it is not claimed as an executed source programme. Allocation failures check temporary-arena cleanup, and fixed-capacity writers fail at every byte boundary with the exact expected prefix. Another test fills the outer stringify's 256-level table, writes a nested runtime value and then continues and closes the outer containers.
The verified 32,768-level returned-array programme now produces the complete 65,568-byte CLI record, including its newline, in both deterministic and hosted profiles under fuel 8. Unit tests write its outcome after execution-heap release under ordinary and per-instruction collection. Hosted tests also compare both new shallow examples with the old CLI, using fuel rather than wall-clock termination.
Validation: all units, format checks, test-extended and the complete current set of 1,791 ordinary conformance cases pass (the prior 1,789-case full run plus the two added cases). Both added cases pass in Debug with collection before every instruction. Forty-four old/new shallow run records are byte-identical. The earlier full Debug per-step collector run ended without a completion result after 785 passing records; its missing process handle and process inventory were checked before starting a replacement full ReleaseSafe run. The replacement retains safety checks and is still in progress; neither incomplete run is counted as a full pass.
Q-060 remains open for a closing call-path audit. Inspection shows that the public verify wrapper returns diagnostics without replacing the caller's module with verifyModule's derived-cache result, while interp.run accepts a verified module without rebuilding those caches. Runtime nominal size queries can therefore reach the uncached fallback tracked by Q-059. Whether this yields a failure on a verified cache-free library input is unverified; the mixed codec test above is not evidence for that path. No fresh Claude review was available for this increment.