refactor(compiler)!: migrate SDK to minimal storage ISA
Test / Tests and coverage
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good

Replace retired guards and publication opcodes with SDK checks, neutral TRAP and sequential List/Linked mutations with explicit failure phases. Preserve snapshot cursors and import schema 2 metadata with the delivered provider pin.

Include common/source/installed conformance, debug and release evidence, synchronized specs and the consolidated lesson. Runtime checkout remains unchanged.
This commit is contained in:
2026-10-24 01:35:42 +01:00
parent 77aada6259
commit 632ba6d0d6
51 changed files with 2688 additions and 711 deletions
@@ -44,10 +44,11 @@ references. Producer checks validate proven carrier facts; runtime admission
and execution remain authoritative for reference identity, session ownership,
platform availability and traps. Unsupported carrier tokens MUST fail explicitly.
Static intrinsic String facts MUST follow the provider verifier's String-only
mask: a proven null is rejected at load time. The dispatcher's acceptance of
null for the String ABI does not broaden that static rule. Random's static
reference mask includes null; native handle validity is still checked at runtime.
Intrinsic arguments MUST use each schema-2 entry's ordered nullable mask.
A proven null is admitted for hash.string's String slot; older String entries
remain non-nullable. Random nullable reference admission does not remove runtime
receiver/provenance checks. Do not infer nullable admission from carrier width,
name, determinism or a different entry using the same ABI atom.
Determinism MUST NOT be interpreted as purity. In particular, all Random calls
mutate guest state. Reachable calls cannot be removed, merged or reordered in a
@@ -57,6 +58,30 @@ base cost 4, cost 8 per attempt and a maximum of 64 attempts in the selected
contract. The runtime performs charging; Java metadata does not implement a
second scheduler or random algorithm.
## Schema 2 invocation and cost metadata
Every entry MUST preserve all 25 CSV columns, including schema_version=2,
arg_nullable, invocation_model, scratch_model, context_access, cost_arg_index and
cost_per_byte in addition to the original 18 fields. Nullable bits are lowercase
booleans in flattened argument order, exactly one per slot; zero arguments use
an empty mask. Numeric carriers cannot be nullable.
Supported coherent profiles are host_buffered_v1/existing_contract_v1/host,
vm_owned_v1/existing_contract_v1/vm_state and borrowed_inline_v1/none/none.
The borrowed profile requires its separately declared deterministic/nonallocating/
nonmutating effects; existing Host/VM entries do not acquire borrowed semantics.
Unsupported schemas, models, profiles and incoherent layouts, masks, indices or
cost parameters MUST fail explicitly.
Fixed costs have no argument index, zero per-byte/attempt cost and zero attempts.
random_rejection_v1 retains base 4, attempt cost 8 and at most 64 draws with the
VM-owned profile. argument_utf8_bytes_v1 selects String argument zero with the
borrowed profile, base 8, one cycle per UTF-8 byte and zero attempt fields. Empty
or null String costs base 8 and remains subject to that entry's nullable mask.
No consumer-side scheduler or hash implementation is added by importing metadata.
All 108 provider entries, including hash.i64/hash.float/hash.string, are represented;
metadata parity does not declare PBS hashing facades delivered.
## Constants
Builtin constants have their own lookup identity `(target, name, version)` and
@@ -188,93 +188,66 @@ tracked separately in AGD75; passing common conformance does not claim complete
PBS lowering or complete Studio/runtime integration.
## Generic logical guards and atomic storage publication
## Minimal typed storage and 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.
The supported collection storage operations are STRUCT_NEW/GET/SET (0xA0–0xA2),
ARRAY_NEW/LEN/GET/SET (0xA3–0xA6) and ARRAY_COPY (0xA9). Logical bounds and
multi-owner collection algorithms belong to producers. Encodings 0xA7, 0xA8,
0xAA and 0xAB MUST be rejected at actual instruction positions, including dead
code; identical bytes in immediates or data are not opcodes. No guard, publication
schema, batch transaction or atomic region replaces the retired instructions.
| 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 |
ARRAY_COPY encodes u16 LE 0xA9 followed by Array TypeId u32 LE. Its five operands,
bottom to top, are source, sourceStart, target, targetStart and count, with no
result. Receivers MUST match the exact Array descriptor; offsets/count MUST use
Int64. Ranges are physical, nonnegative and strict; an empty range may start at
length. Snapshot source groups before writing for overlap. Preserve complete
presence tags, immutable boxes, native owners and identities without unpacking
and repacking existing values.
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.
Reserve the complete TemporaryBytes scratch before writing and release it on
success or failure. A refused instruction preserves its own operands, complete
destinations and owners. No callback, GC or scheduler interleaves its preparation
and commit. This guarantee covers that instruction only, not earlier instructions
in a source method.
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.
For N=count and Registry-derived element width W, attempted work is C=4+2*N*W.
With five temporary operands and exact Int64 N in 0..u32::MAX, precharge the whole
representable C before receiver/range/group/scratch validation and retain it on
refusal. Underflow, wrong count carrier or count outside that interval costs base
4 and follows ordinary fault precedence, without reading frame locals or
converting N. Checked C overflow costs 4 and raises SizeOverflow before ordinary
validation. Above-u32 N is not automatically an allocation SizeOverflow.
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.
Otherwise fault order is height, source, target, offset/count carriers in source
order, source range, target range, scratch reservation, source groups in order.
N=0 still validates receivers/ranges and costs 4; aliases give no discount.
N=10/W=1 costs 24 on success or receiver/range/scratch refusal. Zero budget does
nothing; positive budget admits the full instruction with overshoot. A failed
attempt reports Trap rather than BudgetExhausted and is not a successful step.
Optimizers MUST NOT erase empty-copy validation, faults or required charged work.
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.
## Neutral terminal failure and producer mutation boundaries
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.
Common executable IR and IRVM represent existing TRAP (0x05) as a zero-operand,
zero-result block terminator, preserving its source span. It raises
TRAP_EXPLICIT, distinct from a debugger breakpoint. It neither returns nor falls
through, and optimization MUST retain its observable failure. There is no new
runtime opcode or encoded error argument.
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.
Source producers implement logical checks with comparisons and branches. A
trusted private PBS SDK failure binding selects this terminal instruction, not
a backend-implemented bounds algorithm. Physical ARRAY operations retain their
own faults/resource context. Per-instruction cycle costs and real emitted work
apply; the retired guard costs are not simulated.
## 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.
Collection methods prepare bounds, next sizes, values, candidates and optional
results before the first visible mutation. A refusal before that boundary MUST
preserve the previous collection. A fault after it may leave earlier writes and
incomplete collection invariants; no whole-method rollback, retry or safe-reuse
guarantee exists. Successful methods MUST restore all published invariants.
Prepare-before-mutation does not prove every later operand/call/store infallible.
BudgetExhausted and debugger pauses can occur between instructions and resume at
the current PC; they neither roll back nor complete a method. No atomic observation
of source operations by host/debugger is promised. SDK methods introduce no user
callbacks or explicit suspension during the updates that complete their invariants.