interp: calculate runtime value sizes without recursion

This commit is contained in:
dev committed 2026-10-09 22:55:04 +03:00
1 parent f92817b127
commit 6353ab5f5d
6 files changed
+276 -5

No files matched your search

+2
View File
@@ -480,3 +480,5 @@ The [zero-materialization increment](runtime-value-depth-audit.md#zero-materiali
The [storage/value-copy increment](runtime-value-depth-audit.md#storagevalue-copy-repair) removes recursion from deepCopy/copyAll while retaining per-occurrence payload independence, aggregate identities, shallow handles and failure publication rules. The previous 32,768-level local.load run now returns normally. An added local.store forces ordinary-threshold collection and independently confirms the remaining Copier.value/items native-stack failure, without collect-every-step instrumentation. Sharing-preserving collection/result copying, accounted-value queries and output serialization remain open; no accepted-depth or trap limit is introduced.
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.
+13 -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 the latter two failures.
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.
## Zero-materialization repair
@@ -66,3 +66,15 @@ Two follow-up failures are independently verified on the same ordinary native st
- Allocating an owner for the same loaded array using own.new with fuel 16 and an eight-byte heap grant aborts with exit -6, no JSON and 10,001 valueBytes frames. The value's accounted size is one byte. This confirms native recursion in runtime value sizing after zeroing, loading and collection now complete.
Q-060 remains open for valueBytes and output serialization. No normative or agent-bundle text changes in this increment.
## Runtime value-size repair
ValueBytes now iterates the first-element chain of fixed value arrays, composing their positive lengths into a checked factor. Scalar, capability, graph-reference, built-in enum and nominal leaf accounting remains unchanged; named types still delegate to the existing module size query. A zero-sized leaf yields zero even if the length factor overflows, matching the original inner-to-outer checked multiplication. A nonzero leaf with an overflowing factor still yields null. ArrayBytes continues to query the element before multiplying by the dynamic count, so a zero count cannot mask an overflowing element. The traversal uses constant state and allocates no temporary or payload storage.
The invariant is equality with spec 08 §7.1's static accounted size, including nominal maximum enum payloads, zero-sized records and overflow. The existing heap/region/graph charge, failure, release and sixteen-byte graph-header rules remain unchanged (spec 03 §18–§24); authority is still explicit. Fixed value arrays have positive lengths (spec 07 §8.8), and runtime-sized backing arrays are not allocatable SSA values (spec 03 §19.2). No verifier acceptance rule changes. The existing overflowing_array_chain AIR/source rejection pair still reports E5101. The new nested_allocation_quota AIR/source run pair returns 42: twelve-byte nested content fits exactly, a second live allocation fails budget_exceeded, zero-sized content still fits, and freeing restores authority for a repeated allocation. No new code, trap, effect, feature, semantic flag, accepted-depth limit or bundle text is introduced. Fuel, instruction count, collection safe points, ownership transfer and deterministic outcomes are unchanged.
Unit tests compare scalar/nominal/built-in/capability/iref leaves under mixed array lengths against static accounting, preserving inactive enum payload maxima. Query-only inputs cover 32,768 wrappers, overflowing factors with zero/nonzero leaves and zero dynamic counts; shared payloads compactly represent these queries without claiming verified exponential constructions. A verified 32,768-level own.new programme pins exact fuel 0–6 boundaries under ordinary and per-instruction collection. A one-byte grant takes success, a zero-byte grant takes the error edge, and both executions terminate with the original instruction counts. The formerly crashing CLI probe now returns null with grants one and eight; grant zero retains its explicit failure trap. The successful deep run and both new conformance examples pass with collection before every instruction.
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.
+6
View File
@@ -421,4 +421,10 @@ The [Q-060 sharing-preserving copy increment](../design/runtime-value-depth-audi
Units/format checks, test-extended and all 1,787 ordinary conformance cases pass. Per-step collection passes 57 focused run cases plus 26 phase-3 run cases with stress 16; 146 old/new mixed-value and identity/schedule records are identical. The full per-step conformance run is still running at this checkpoint. Follow-up probes independently confirm valueBytes recursion on own.new and JSON output failure at std.json.Stringify's fixed nesting stack. Q-060 and Phase 6 remain open. No fresh Claude review was available.
## P6-1 runtime value-size depth repair (2026-10-09)
The [Q-060 runtime value-size increment](../design/runtime-value-depth-audit.md#runtime-value-size-repair) replaces recursive array-value queries with a constant-state checked factor and unchanged leaf accounting. Zero-sized leaves, true overflow, maximum enum payloads and dynamic-count ordering retain their existing meanings; heap/region/graph charges and failure/release rules are unchanged. Deep verified allocation tests pin fuel 0–6 and zero/one-byte grant boundaries under ordinary/per-step collection. A nested-quota AIR/source pair checks exact charges, zero-sized contents, allocation failure and restored authority.
Units/format checks, test-extended and all 1,789 ordinary conformance cases pass; the deep allocation and new pair also pass per-step collection. Ten new-pair quota records and 426 generated allocation-oracle runs match the old interpreter exactly. The earlier full per-step collector suite remains in progress. No normative/bundle/feature/code change or accepted-depth limit; Q-060 remains open for serialization, and Phase 6/contract gates remain open. No fresh Claude review was available.
Both new copy cases also pass with collection before every instruction; their shallow sharing-preserving GC behavior is covered separately from the retained deep collector failure.