refactor(vm)!: remove publication and logical guard opcodes
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good

Remove INDEX_GUARD, ARRAY_CHECK_LENGTH, STORAGE_PUBLISH and FIELDS_PUBLISH
from decoding, metadata, tooling, verification and execution. Keep ARRAY_LEN
and overlap-safe ARRAY_COPY with complete-group ownership and early charging
of calculable copy work, including refused attempts.

Update specifications, producer handoff, qualification evidence and lessons.
Share collection test support and remove redundant Copy clones for Clippy.

Validation: make ci-domains passed with 1,095 workspace tests, five separately
executed debugger socket tests and all 15 unchanged coverage domain gates.
VM release, resource diagnostics and layer/quality suites also passed.

BREAKING CHANGE: PBX using opcodes 0xA7, 0xA8, 0xAA or 0xAB is rejected,
including unreachable instructions. Consumers must adapt their emission and
collection algorithms or operational guarantees.
This commit is contained in:
2026-10-23 23:37:56 +01:00
parent 69ad1931de
commit dcf6561ea7
27 changed files with 1407 additions and 1013 deletions
@@ -169,6 +169,16 @@ The [Dynamic/reference instruction table](02c-program-registry-and-pbx-v0.md#dyn
The [collection ISA table](02-vm-instruction-set.md#typed-collection-instructions) defines complete costs. Metadata widths determine costs independently of native sizeof, allocator, timing, optimizer and GC. Each decoded collection attempt is charged exactly once before validation/refusal. Fixed costs apply even to underflow, invalid receiver, bounds and rejected value groups. ARRAY_NEW charges 8 + N*w(E) whenever an available exact Int64 length is in 0..u32::MAX, including quota/allocation refusal; absent, wrong-carrier, negative or above-u32 length charges eight. Rejected loads execute and charge no guest instruction.
ARRAY_COPY charges C=4+2*N*W when all five temporary operands are available and
count is exact Int64 in 0..u32::MAX. W comes from immutable Registry element
storage. Charge C before receiver/range/group validation and scratch reservation,
retaining it on refusal. Otherwise charge base 4 and preserve ordinary fault
precedence. Checked cost overflow charges base 4 and traps SizeOverflow before
ordinary validation. Never inspect frame locals as missing operands. Empty copies
still validate and cost 4; identity/overlap give no discount. Ten one-slot elements
cost 24 on success, invalid receiver/range or scratch refusal. Full validation
order is defined in the [copy contract](02-vm-instruction-set.md#typed-array-range-copy).
Examples: empty Struct/Array costs eight; a Struct containing Int32, vec2 and Trait costs thirteen; ten vec2 elements cost twenty-eight even on quota refusal; pixel GET costs six including bounds failure; pixel SET costs seven including group rejection; LEN costs three including receiver failure. Charged cycles are never refunded by rollback.
Budget admission remains between instructions. Zero executes nothing. A positive remaining budget admits the entire next instruction, which may overshoot; continuation then returns BudgetExhausted before the following instruction. Thus ARRAY_NEW of ten vec2 under run_budget(1) consumes twenty-eight cycles. Trap takes priority on refusal, with the same cycle delta and no successful target step. steps_executed counts only successful steps; cycles_used includes failed attempts. Collection operations add no implicit frame sync, tick, GC or coroutine switch, no extra length cap and no cycle pre-admission rule.
+46 -84
View File
@@ -163,96 +163,58 @@ Typed callable instructions are MAKE_CLOSURE `(FunctionId,FnTypeId)`, CALL_CLOSU
INTRINSIC also dispatches the [VM-owned random operations](02e-vm-owned-random-core.md), IDs 0x4000–0x4003. NEW cannot construct Random. TRAP_RANDOM_REJECTION_LIMIT is 0x00000015.
## Logical guards and atomic storage publication
## Typed array range copy
The core includes the following generic operations, with u16 opcodes and
little-endian u32 immediates. They introduce no new Registry category, syscall,
source-language collection or ambient transaction. Operand order below is bottom
to top; all integer operands are Int64.
ARRAY_COPY uses little-endian u16 opcode 0xA9 followed by one little-endian u32
Array TypeId. It consumes five operands, bottom to top: source, sourceStart,
target, targetStart, count, and produces no result. Receivers require the exact
Array type; sourceStart, targetStart and count require exact Int64 carriers.
Ranges must be nonnegative and fit each physical array, without clamping,
truncation or coercion. An empty range may start at the physical length.
| Opcode | Immediate | Stack operands consumed |
| --- | --- | --- |
| INDEX_GUARD `0xA7` | none | index, exclusive limit |
| ARRAY_CHECK_LENGTH `0xA8` | Array TypeId | length |
| ARRAY_COPY `0xA9` | Array TypeId | source, sourceStart, target, targetStart, count |
| STORAGE_PUBLISH `0xAA` | Array TypeId, Struct TypeId, first field, second field | source, sourceStart, target, targetStart, count, fillStart, fillCount, element group, owner, first field group, second field group |
Loading validates Array identity/category even in unreachable code. Registry
verification requires five complete operands. The instruction may trap, but is
neither a branch, terminator nor safepoint. ARRAY_LEN (0xA4) remains the physical
length query. Logical collection limits and error paths belong to producers.
The encodings 0xA7, 0xA8, 0xAA and 0xAB are unsupported and reject at admission,
including in unreachable code. Bytes inside immediates or data are not opcodes.
There is no multi-owner publication, generic batch or atomic-region replacement.
All operations return no values. INDEX_GUARD accepts exactly
`0 <= index < limit`, otherwise TRAP_OOB. It does not use physical storage length.
ARRAY_CHECK_LENGTH accepts zero through u32::MAX without allocating. Negative
lengths produce TRAP_OOB; values above u32::MAX produce the same resource
SizeOverflow failure as ARRAY_NEW. This check does not reserve future allocation.
Copy preserves complete stored groups, including presence tags, immutable boxes,
native String owners, HeapRefs, traits and identities without boxing or payload
repacking. All source groups are captured before the first destination write,
so overlap observes the pre-attempt source sequence. All copy scratch is reserved
under TemporaryBytes before writing and released on success or failure. Original
operands remain roots throughout preparation. No guest object or request token
is allocated. Quota refusal does not trigger rescue GC.
ARRAY_COPY and STORAGE_PUBLISH require exact Array receiver identities and complete
stored groups. Every range must have nonnegative start/count and fit its physical
array; an empty range may start at length. Invalid ranges produce TRAP_OOB, never
clamping or truncation. Copy reads the pre-attempt source sequence, including for
overlapping source/target ranges. Presence tags, immutable boxes, native owners and
object identities are preserved without payload unpacking or repacking.
Validation, quota or recoverable allocation failure preserves operands and all
destinations/owners. Commit uses prevalidated infallible writes; no callback,
allocation, GC or scheduler boundary occurs inside the instruction. Consume the
five operands only after commit. Cycles and diagnostics retain the attempt.
This guarantee begins with prepared operands; it does not undo earlier source
calculations, allocations or callbacks, or make a sequence of stores transactional.
STORAGE_PUBLISH first copies the selected source range, then fills the selected
target range with the supplied element group, then writes the two selected fields
on the supplied Struct owner. Fields must be distinct valid indices on that Struct;
their types and widths come from the immutable Registry. Source code/producer owns
selection of every range, value, owner and field. The VM implements these generic
ordered effects and does not select collection algorithms.
Let N=count and W=element storage slots from the immutable validated Registry.
The planned cost is C=4+2*N*W. Charge base 4 for every admitted attempt. Only inspect
count for cost selection when all five operands are available in the temporary
stack region; frame locals are not operands. If N is exact Int64 in 0..u32::MAX,
charge representable C before validating receivers, offsets, ranges, source
groups or reserving scratch. Retain C on any later refusal. Otherwise retain base
4 and follow ordinary validation; count is neither converted nor accepted.
Checked overflow of C retains only base 4 and produces structured RESOURCE_LIMIT
with SizeOverflow before ordinary validation, without wrapping or saturation.
Loading validates all immediate identities/categories/fields even in unreachable
code. Verification requires complete typed operands. ARRAY_COPY consumes five
slots; STORAGE_PUBLISH consumes `8 + elementWidth + firstWidth + secondWidth`.
INDEX_GUARD consumes two slots and ARRAY_CHECK_LENGTH consumes one.
Execution validates all receivers, lengths/ranges, supplied groups and source
groups, and reserves the complete charged copy scratch before writing. Validation,
quota or host allocation refusal leaves all input operands and destinations
unchanged, including both fields and native owners. Scratch uses TemporaryBytes,
is refunded on success/refusal and does not relax any resource ceiling. Existing
operands remain roots during preparation. There is no GC, callback, scheduler or
other interleaving inside this single instruction. Commit uses already validated
complete groups, performs no fallible allocation and consumes operands only after
all selected effects have been published. No prepared token escapes the attempt.
Base cycle costs are 2 for either guard, 4 for ARRAY_COPY and 6 for STORAGE_PUBLISH.
Copy adds `2 * count * elementWidth`; publication additionally adds
`fillCount * elementWidth + firstWidth + secondWidth`. Work arithmetic is checked
before mutation. A refused preparation still charges the attempted work. Neither
operation is a safepoint. Consumers must prepare any potentially failing return
carrier and all call operands before publication; a series of ordinary stores is
not a substitute for whole-operation safety.
## Atomic publication of multiple Struct instances
FIELDS_PUBLISH (`0xAB`) has one little-endian u32 schema TypeId immediate. The
schema MUST be a Registry Struct whose ordered field types are all Struct types.
Names are descriptive only. The schema is declarative metadata; no request object,
new Registry category or preparation token is allocated or exposed.
For each schema entry, the operand stack supplies one nullable destination
reference followed by every destination field's complete typed value group, in
field declaration order. The stack effect is the sum, over entries, of one plus
the destination instance's initialization-slot count; no results are produced.
Null skips that destination, but every supplied field group is still validated.
Non-null destinations require exact concrete Struct identity and a live reference
of the current session/generation. Array, Trait, Fn and builtin schema entries are
invalid, including in unreachable instructions. The full schema and exact stack
height/groups are checked under normal Registry admission/work limits.
Validate all destinations and value groups before any shared write or operand
consumption. The original operands remain roots throughout preparation. Then write
all fields in schema order, without allocation, fallible validation, callbacks,
GC or scheduler interleaving, and consume the entire input. Input values are
captured before publication; repeated destinations use ordered last-write
semantics. Complete multi-slot/native/reference groups retain identity and normal
ownership. A failed attempt preserves every destination and the operand stack.
The operation allocates no publication scratch or guest object. Operand/frame and
source value preparation remain normally charged and may fail before publication.
Base cost is 6 cycles. After the stack-height check, precharge one cycle per schema
entry and one per destination field execution slot for the complete declared
attempt, including skipped destinations. Quotas are unchanged.
This is a generic typed storage mechanism; collection algorithms and node topology
remain source-owned, with no collection-specific VM instruction or syscall.
Early count inspection selects cost only. Apart from cost overflow, fault order
is temporary height, source receiver, target receiver, carriers of sourceStart,
targetStart and count, source range, target range, scratch reservation, then source
group reads/validation in order. Thus above-u32 count with otherwise valid inputs
fails physical bounds, not an allocation-size check. N=0 still validates receivers
and ranges and costs 4. Identity and overlap grant no discount. N=10/W=1 costs 24
on success, invalid receiver/range or scratch refusal. Zero budget executes no
attempt; a positive budget admits the whole instruction with overshoot. Trap
prevails over BudgetExhausted on failure, with no successful target step. Rejected
images execute no guest instruction and charge zero guest cycles.
## Identity and value hashing
@@ -308,13 +308,15 @@ precedence, conversions, catalog metadata and producer examples.
[Random](02e-vm-owned-random-core.md) adds BuiltinId 0x0016 and intrinsic IDs 0x4000–0x4003 using existing PBX v0 encoding. Registry categories remain unchanged; unsupported identities are rejected, without fallback.
## Logical guards and atomic storage publication
## Typed array range copy
INDEX_GUARD (0xA7), ARRAY_CHECK_LENGTH (0xA8), ARRAY_COPY (0xA9) and
STORAGE_PUBLISH (0xAA) provide generic logical validation, complete stored-group
transfer and prepared atomic publication. Their encoding, typed operands, exact
faults, overlap semantics, costs and preflight/commit guarantees are defined by
the [canonical instruction contract](02-vm-instruction-set.md#logical-guards-and-atomic-storage-publication). No new Registry category, syscall, collection algorithm or safepoint is introduced.
ARRAY_COPY (0xA9) uses one Array TypeId and five operands for complete stored-group
range transfer, with no new Registry category or PBX section. Encoding, exact
receivers, overlap, preparation, fault order and precharged attempt costs follow
the [instruction contract](02-vm-instruction-set.md#typed-array-range-copy).
Unsupported opcodes 0xA7, 0xA8, 0xAA and 0xAB reject during bounded instruction
admission even after a terminator. Immediate/data bytes are not instructions.
ARRAY_LEN remains 0xA4; physical allocation/access checks remain mandatory.
## Identity queries
@@ -223,15 +223,18 @@ Threshold GC opportunities are FRAME_SYNC and successful RET of the last root, a
[Random objects](02e-vm-owned-random-core.md) use ObjectKind tag 9 (tag 6 remains reserved), 32 logical payload bytes and quota-accounted headers/handles/auxiliary storage. They are opaque GC leaves; Dynamic holds their direct reference and exact TypeId.
## Prepared storage publication
## Prepared array range copy
Generic complete-group transfer/publication reserves its copy scratch against
TemporaryBytes before changing any destination. Source groups preserve Dynamic
presence tags and immutable box/native owner/reference identities. Operands remain
roots throughout preparation; the commit phase has no allocation, GC, scheduler or
callback boundary. Refusal changes neither destinations nor input groups, and
releases temporary reservations. Consumer return carriers must be prepared before
publication. See [the instruction contract](02c-program-registry-and-pbx-v0.md#logical-guards-and-atomic-storage-publication).
ARRAY_COPY reserves all copy scratch against TemporaryBytes and captures complete
source groups before changing any destination. Preserve Dynamic tags, immutable
boxes, native String owners, HeapRefs and trait groups without boxing or new guest
objects/request tokens. Operands remain roots; commit has no allocation, fallible
validation, callback, GC or scheduler boundary. No rescue GC is performed.
Failure preserves destinations and operands and releases provisional scratch;
success also releases scratch, then consumes the five operands. Charged cycles
are never refunded. Overlap reads the pre-attempt source sequence, without an
identity discount. Earlier instructions retain their effects; multiple ordinary
stores do not form a transaction. See [the instruction contract](02-vm-instruction-set.md#typed-array-range-copy).
## Borrowed intrinsic invocation