docs(pbs): consolidate collection lessons and failure guarantees

This commit is contained in:
2026-10-27 13:40:38 +00:00
parent 0016d92ac3
commit eb7d6a2398
3 changed files with 326 additions and 118 deletions
@@ -3,7 +3,7 @@ id: LSN-0090
ticket: pbs-sdk-list
title: Mutable Lists and Stable Snapshot Cursors
created: 2026-10-22
tags: [compiler-pbs, collections, snapshot-cursor, atomic-publication, runtime-conformance]
tags: [compiler-pbs, collections, snapshot-cursor, failure-phases, runtime-conformance]
---
## Original problem and final result
@@ -19,8 +19,15 @@ PBS needed a resizable collection whose existing references remain valid, togeth
with a traversal that survives later collection edits. Both now live in the
executable SDK: ordinary generic `list<T>`, the shared `Cursor<T>` contract and
private snapshot nodes. The compiler provides trusted private bindings and source
projections; generic storage instructions support complete publication in the VM.
Linked, Set and Map remain separate discussions.
projections; ordinary typed storage and ARRAY_COPY preserve complete stored groups.
This lesson was reconciled during AGD89 closure on 2026-10-27 with accepted
DEC-0077 / PLN-0155, consolidated in
[LSN-0092](../DSC-0096-runtime-storage-isa-consumer-migration/LSN-0092-sequential-collection-mutations-need-explicit-failure-boundaries.md).
That migration replaced the original guard/publication instructions and universal
whole-method refusal guarantee. The current explanation below follows the
sequential-store contract; the original evidence remains explicitly historical.
Other collection APIs are documented in their own specifications and lessons.
## Separate collection identity, logical positions and physical storage
@@ -84,44 +91,47 @@ returns 42. Current still contains 22 afterwards.
The outer optional describes whether a node exists. A producer with optional T
must preserve `some(none)` as a present node whose payload is none. A synthetic
non-List producer qualifies that distinction independently of List's element rule.
Future Linked/Set producers use Cursor<T>; Map entries use Cursor<keyval<K,V>>.
Their construction rules and ordering guarantees belong to their own discussions.
Linked/Set produce Cursor<T>; Map entries use Cursor<keyval<K,V>>, and Stack/Queue
capture in removal order. Their construction rules and ordering guarantees belong
to their own specifications. These producers reuse the same Cursor state table.
## Prepare the whole mutation before publishing
## Prepare values, then perform sequential updates
An insert without growth can shift many slots and update size. A remove also
prepares an optional result and clears its old tail. Each operation needs a single
failure boundary for all observable changes.
Logical index/length checks are executable PBS comparisons and branches ending in
the trusted private terminal TRAP_EXPLICIT binding. They are not INDEX_GUARD or
ARRAY_CHECK_LENGTH instructions. ARRAY_COPY remains a neutral complete-group,
overlap-safe transfer; STORAGE_PUBLISH and FIELDS_PUBLISH were retired by the
migration in LSN-0092. No compound publication instruction is available.
The generic provider adds four operations, carried through common IR and PBX:
For insertion with growth, allocate a private candidate and copy prefix/suffix
directly into their final positions, including holes and presence tags. Store
the new value privately, then assign backing and length in sequence. Without
growth, first prepare the inserted stored group in a private one-slot array,
shift the suffix with ARRAY_COPY, copy the prepared slot and update length.
The temporary array and both copies retain ordinary allocation, scratch,
validation and charging costs, including empty copies.
| Operation | Purpose |
Removal prepares its optional return, shifts the suffix, clears the old tail and
updates length. Clear and in-capacity resize clear the selected interval in index
order before assigning length. Growing resize prepares/copies a candidate before
backing/length installation; reserve/trim prepare/copy candidates and replace only
backing. Indexed replacement/clearAt update one checked position. Complete stored
groups move without unpacking/reboxing every shifted element.
| Outcome | Current guarantee |
| --- | --- |
| INDEX_GUARD | Check a signed-long logical index against an exclusive limit |
| ARRAY_CHECK_LENGTH | Validate a structural length without allocating |
| ARRAY_COPY | Transfer complete stored groups with overlap-safe prestate semantics |
| STORAGE_PUBLISH | Prepare and commit source-selected copy/fill ranges and two typed fields |
| Logical rejection or preparation refusal before the first visible write | Previous backing, capacity, size and slots survive; argument effects and provisional allocations are not undone |
| Successful return | All collection, cleanup, identity, group and snapshot invariants hold |
| Internal/resource fault after visible writes start | Earlier writes may remain and invariants may be incomplete; no rollback, safe reuse, retry or recovery is promised |
The SDK chooses its indices, ranges, fill value, target backing and resulting size.
The generic layer validates those operands and resource charges. It snapshots
complete source groups into charged scratch before any write, then commits the
selected copy, fill and field updates without allocation, callbacks, scheduler or
GC interleaving. Its four immediate operands identify the Array/Struct types and
two distinct fields. There is no exported preparation token or general transaction
syntax.
Preparing values/returns does not make every subsequent instruction infallible.
A refused instruction preserves its own entry state, not earlier successful
stores. BudgetExhausted/debugger pauses are resumable boundaries; a method is not
an atomic host observation region. No callback or explicit suspension is inserted
between mutation updates. Candidates, temporary arrays and scratch follow normal
ownership/quotas; immediate GC or quota return is not promised.
For growth, a private candidate array is allocated and populated first. For a
no-growth edit, scratch and all argument/result carriers are prepared first.
`removeAt` obtains its previous optional value before publication. Raw transfer
keeps presence tags, full value groups and existing reference/carrier identity.
Per-element public optional unpack/repack would add failure points and allocation
costs while shifting.
Refusal leaves backing identity, capacity, size and complete stored groups
unchanged. Argument effects evaluated before the call remain ordinary source
effects. Unpublished candidates and scratch follow normal ownership and budgets.
The provider has no List/Cursor opcode, category or syscall; collection algorithms
remain in
The provider has no List/Cursor opcode, category or syscall; algorithms remain in
[SDK source](../../../prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/game/stdlib/1/sdk/collections/main.pbs).
## Compiler and tooling integration
@@ -140,41 +150,52 @@ tuples, nested arrays, contracts and function references.
List index/length arguments accept localized lossless int-to-long promotion.
Receiver and arguments execute once in source order, including named arguments.
General numeric conversion rules stay unchanged. Common aggregation, optimization,
emission and preload verification retain all four publication operands; malformed
types or fields are rejected even in unreachable instructions.
emission and preload verification carry ordinary typed stores, ARRAY_COPY and the
terminal operation. Retired encodings are rejected even in dead instructions;
matching byte values inside ordinary immediates are not retired instructions.
Editor projections show concrete public List/Cursor methods, optional results,
constructor overloads and SDK definitions. Hover/completion hide private adapters
and backing fields. Installed JAR tests load the actual packaged SDK, normative
spec and example outside the checkout, generate PBX and execute it in the provider.
## Evidence and practical limits
## Current qualification and historical evidence
The selected provider is clean commit
The current selected pin is [the catalog revision](../../../docs/vm-arch/runtime-catalog.properties),
`dcf6561ea73446e0a3e1cf1c73eda20923b38df0`. The
[migration evidence](../DSC-0096-runtime-storage-isa-consumer-migration/runtime-conformance-evidence.json)
qualifies sequential stores, logical traps and mutation phases. Later complete
[debug/release evidence](../DSC-0097-pbs-sdk-stack-queue/evidence/README.md) includes
the current List/Cursor corpus with both producers. This editorial reconciliation
does not rerun those suites or change their recorded scope.
The following table and the original JSON are historical delivery evidence for
the superseded storage design, not proof of whole-method preservation today.
The original selected provider was clean commit
`d9b9eeb171d2861ec660d4cf5703b0795eac49a9`. Studio changes were tested over base
`76a8b074e89e17c7425220888eeec38427261d46`. Qualification used macOS 27.0.1 arm64,
Rust 1.98.1/LLVM 22.1.8, the dev runtime profile with resource-diagnostics,
capabilities NONE, Gradle 9.3.1 and the repository's Java 21 toolchain
(Corretto 21.0.4). Ordinary and optimized producer paths were exercised.
| Gate | Observed result |
| Historical delivery gate | Result on the original pin |
| --- | --- |
| Provider bytecode and VM libraries | 6 + 302 passed; 2 existing measurement tests ignored |
| Full Studio regression and installed knowledge | Passed; existing skipped tests retained |
| Final frontend/editor, LSP, source generation and installed checks | Passed; both installed tests passed |
| PBS List/Cursor through production verifier/VM | 27 cases in each producer mode: 54 passed |
| Non-PBS common IR | 2 storage fixtures executed through production VM |
| Whole-operation quota refusals | 71 attempts; independently observed prior List state preserved |
| Compound-publication refusals, now retired | 71 attempts; prior List state preserved on the original pin |
| Cursor GC | Nodes/items: 1200/1200 → 1/1 → 1/1 → 0/0 |
| Reexports and installed example execution | Both passed; final captured value 22 retained |
| Provider catalogs and canonical mirrors | Clean pinned provider; catalog parity and all four mirrors match |
The refusal matrix lowers GuestBytes, HandleSlots, AuxiliaryBytes and TemporaryBytes
That historical refusal matrix lowered GuestBytes, HandleSlots, AuxiliaryBytes and TemporaryBytes
around candidate allocation, no-growth publication scratch, optional return
preparation, node creation and frame/operand preparation. It compares the typed
List fields and every backing group before and after each refusal, and verifies
resource accounting returns to zero after VM drop. Generic provider tests also
cover overlapping multi-slot transfers, late invalid fields/ranges, immutable
preparation, node creation and frame/operand preparation. It compared the typed
List fields and every backing group before and after each refusal, and verified
resource accounting returned to zero after VM drop. The original provider tests also
covered overlapping multi-slot transfers, late invalid fields/ranges, immutable
Dynamic-box identity and malformed encodings.
Controlled normal GC safepoints prove consumed-prefix reclamation, retention of
@@ -184,35 +205,37 @@ safepoints. Optional carriers and other legitimate owners still have their norma
allocation and retention costs. Capturing n positions with k present values takes
O(n) time and O(k) additional nodes; next follows one link in O(1).
[Machine-readable evidence](runtime-conformance-evidence.json) records commands,
[Historical machine-readable evidence](runtime-conformance-evidence.json) records commands,
source and PBX hashes, default ceilings, every lowered refusal quota, GC observations
and tested provenance. New cases are mandatory; missing fixtures fail the harness.
The full harness also reports two pre-existing response-schema gaps, LifecycleRole
and NonFiniteValue, with original payloads preserved. These were not changed by
this delivery. Qualification makes no release-profile or cross-platform claim.
this original delivery. That historical run makes no release-profile or cross-platform
claim; later debug/release qualification is linked separately above.
R1–R5 are covered by type/construction/bounds/mutation/capacity fixtures; R6–R9 by
snapshot states, identity, non-List optional production and GC; R10–R11 by direct
provider tests, common IR and the refusal matrix; R12 by editor/import/distribution
gates; R13 by resource accounting and retention observations; R14 by the mandatory
The original R1–R5 mapping used type/construction/bounds/mutation/capacity fixtures; R6–R9 used
snapshot states, identity, non-List optional production and GC; R10–R11 used direct
provider tests, common IR and the refusal matrix; R12 used editor/import/distribution
gates; R13 used resource accounting and retention observations; R14 used the mandatory
production corpus, full regressions and pinned provenance.
## Pitfalls to preserve in future work
- Treat logical size and capacity separately. An index inside physical capacity
can still require TRAP_OOB; a hole is an optional result only at a valid index.
can still fail the SDK's logical check with TRAP_EXPLICIT; a hole is an optional
result only at a valid index. Physical Array instructions retain their own faults.
- Keep faults distinct from absence. Long overflow, invalid bounds and resource
refusal cannot become none or a truncated index.
- Prepare optional returns and temporary groups before publication. Individual
Array instruction atomicity alone cannot prove whole-mutator atomicity.
- Prepare optional returns and temporary groups before visible writes. Preparation
and individual instruction preservation do not provide whole-method rollback.
- Preserve complete stored groups while shifting. Public optional reboxing can
change identity, roots, costs and refusal boundaries.
- Follow the Cursor state table. Never advance a nonempty cursor past its last
node or retain an initial-head root just to support an unrequested reset.
- Account for node and optional-carrier allocation. A linked snapshot has no
promise of lower memory use than an array or immediate quota recovery.
- Carry all publication operands through linking and optimization. A lost second
field identity can invalidate otherwise well-typed SDK calls after imports.
- Preserve source-selected store/copy order through linking and optimization, and
compare refusal observations with the successful prefix at the actual failure phase.
- Keep privileged bindings origin-based and private. Names and copied attributes
are insufficient authority.
@@ -220,15 +243,18 @@ production corpus, full regressions and pinned provenance.
- [List/Cursor specification](../../../docs/compiler/pbs/specs/sdk-list-and-cursor.md)
and [Array/optional foundation](../../../docs/compiler/pbs/specs/typed-arrays-and-optional-execution.md).
- [Common Registry/PBX specification](../../../docs/compiler/general/specs/typed-registry-and-pbx-v0.md)
and [canonical provider publication code](../../../../runtime/crates/console/prometeu-vm/src/virtual_machine/storage_publication.rs).
- [Common Registry/PBX specification](../../../docs/compiler/general/specs/typed-registry-and-pbx-v0.md),
[current provider copy code](../../../../runtime/crates/console/prometeu-vm/src/virtual_machine/array_copy.rs)
and [ordinary typed storage](../../../../runtime/crates/console/prometeu-vm/src/virtual_machine/collections.rs).
- [Source fixture generator](../../../prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsListCursorTest.java),
[neutral IR fixtures](../../../prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/registry/StoragePublicationPipelineTest.java)
and [production harness instructions](../../../tools/pbx-conformance/README.md).
- [Generic structs lesson](../DSC-0094-pbs-generic-structs/LSN-0089-concrete-generic-state-and-bodies.md)
- [Mutation-phase migration](../DSC-0096-runtime-storage-isa-consumer-migration/LSN-0092-sequential-collection-mutations-need-explicit-failure-boundaries.md),
[generic structs lesson](../DSC-0094-pbs-generic-structs/LSN-0089-concrete-generic-state-and-bodies.md)
and [generic contracts lesson](../DSC-0089-pbs-generic-contracts/LSN-0088-concrete-generic-contracts-from-source-to-vm.md).
Run `./gradlew test :prometeu-app:installedKnowledgeTest --console=plain` before
`python3 tools/pbx-conformance/run.py --runtime ../runtime` so the complete fixture
corpus, including the installed example, exists. Provider and catalog commands,
their working directories and the tested configuration are in the evidence file.
corpus, including the installed example, exists. Select the current pin and use
the migration/later evidence for current reproduction. The original JSON retains
its original provider, commands and configuration unchanged.