Add generic logical guards and atomic storage publication
This commit is contained in:
@@ -161,3 +161,61 @@ Typed callable instructions are MAKE_CLOSURE `(FunctionId,FnTypeId)`, CALL_CLOSU
|
||||
## Random core integration
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
| 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 |
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
@@ -306,3 +306,12 @@ precedence, conversions, catalog metadata and producer examples.
|
||||
## Random core integration
|
||||
|
||||
[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
|
||||
|
||||
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.
|
||||
|
||||
@@ -221,3 +221,14 @@ Threshold GC opportunities are FRAME_SYNC and successful RET of the last root, a
|
||||
## Random core integration
|
||||
|
||||
[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
|
||||
|
||||
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).
|
||||
|
||||
Reference in New Issue
Block a user