feat(pbs): add Map and read-only Keyval associations
This commit is contained in:
+194
@@ -0,0 +1,194 @@
|
||||
---
|
||||
id: LSN-0094
|
||||
ticket: pbs-sdk-map-keyval
|
||||
title: Map presence, key identity and captured associations
|
||||
created: 2026-10-26
|
||||
tags: [compiler-pbs, collections, map, keyval, identity, optional, cursor]
|
||||
---
|
||||
|
||||
# Map presence, key identity and captured associations
|
||||
|
||||
**Worker:** Lesson Worker. **Owner domain:** `compiler/pbs`.
|
||||
**Discussion:** DSC-0093, accepted DEC-0079 implemented by PLN-0157 (R1–R12).
|
||||
The normative contract is [SDK Map and Keyval](../../../docs/compiler/pbs/specs/sdk-map-and-keyval.md).
|
||||
The [evidence record](evidence/README.md) preserves reproduction commands, source
|
||||
and fixture fingerprints, raw logs and requirement coverage after housekeeping.
|
||||
|
||||
## Original problem
|
||||
|
||||
Map needed to distinguish association existence from the content of its value,
|
||||
define which object represents an equivalent key, and transport read-only entries
|
||||
without exposing mutable hash storage. Set had already delivered reusable Identity
|
||||
and hashing, while List supplied a shared snapshot Cursor. Neither delivery
|
||||
automatically determined Map's API, representation or mutation guarantees.
|
||||
|
||||
The accepted result is a source SDK Map with its own bucket nodes, an ordinary
|
||||
generic Keyval association, optional lookup/previous-value results and independent
|
||||
entry snapshots. The implementation uses existing typed Registry/PBX/VM contracts;
|
||||
the runtime checkout was not modified.
|
||||
|
||||
## Separate presence from payload
|
||||
|
||||
`m[key]`, `put(entry)` and `remove(key)` return optional V. The outer optional
|
||||
answers whether an entry existed. V may itself be optional:
|
||||
|
||||
| Stored state | Lookup or previous-value result |
|
||||
| --- | --- |
|
||||
| No association | none |
|
||||
| Present association, V=none | some(none) |
|
||||
| Present association, V=some(42) | some(some(42)) |
|
||||
|
||||
For example, inside a function:
|
||||
|
||||
```pbs
|
||||
let scores = new map<str, optional int>();
|
||||
scores["pending"] = none;
|
||||
if scores.containsKey("pending") {
|
||||
if let payload = scores["pending"] {
|
||||
// payload is optional int and is currently none.
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Assigning none does not remove an entry. remove is the structural operation.
|
||||
Zero/false are present values, and faults never become none. K directly optional
|
||||
is rejected consistently with Set; independent `keyval<K,V>` remains an ordinary
|
||||
generic struct and can hold optional components. The restriction on
|
||||
`array<optional T>` does not prohibit a V field in a private node.
|
||||
|
||||
## Preserve the stored key representative
|
||||
|
||||
Default Identity follows the [Set policy](../../../docs/compiler/pbs/specs/sdk-set-and-identity.md):
|
||||
scalar/String values use their specified value domains; eligible objects use
|
||||
instance identity; contracts use their validated receiver. Unsupported defaults
|
||||
require an explicit Identity<K>. V needs no equality/hash capability.
|
||||
|
||||
A content strategy can consider distinct objects equivalent. If a map already
|
||||
stores object A and a write supplies equivalent object B, replacement changes
|
||||
only V. A remains the key returned by subsequent snapshots; size and capacity do
|
||||
not change. To make B the representative, remove and reinsert. This rule avoids
|
||||
silently replacing object identity while updating an association's value.
|
||||
|
||||
An explicit strategy must remain coherent and stable while keys are stored.
|
||||
Remove keys from affected collections before changing relevant content or policy
|
||||
configuration, then reinsert. Cached hashes do not repair unstable equality.
|
||||
|
||||
## Keyval is an association, not a storage node
|
||||
|
||||
`new keyval<K,V>(key, value)` constructs a normal generic SDK struct. It has private
|
||||
fields and only key()/value() accessors, with no mutators. Assignment shares its
|
||||
instance and payload references. Separately constructed keyvals remain distinct
|
||||
under default instance identity even when their components match.
|
||||
|
||||
Map.put reads those components and returns the previous V. It does not retain the
|
||||
input Keyval as an editable table node. Internal Map nodes store cached long hash,
|
||||
K, mutable V and next link. This keeps storage mutation private and avoids one
|
||||
public Keyval allocation per internally stored association.
|
||||
|
||||
Keyval is shallowly read-only: its association is fixed, but referenced objects
|
||||
remain shared and mutable. An old captured value does not follow replacement
|
||||
with a new object; mutating the old object itself is still visible through aliases.
|
||||
|
||||
## Share policies and helpers without a universal table
|
||||
|
||||
Map and Set share Identity, hash primitives, private bucket/size/growth arithmetic
|
||||
and the Cursor implementation. They retain separate node types and algorithms.
|
||||
Map is not implemented over Set or Linked, and there is no universal Element.
|
||||
|
||||
Empty Map construction is lazy. First inclusion creates 8 buckets, growth occurs
|
||||
above 3/4 occupancy and doubles up to Array's u32 structural maximum. Chaining may
|
||||
continue above that bucket count within checked signed-long size and provider
|
||||
quotas. Removal does not shrink; clear releases the table and restores lazy state.
|
||||
|
||||
Full signed-long hashes select buckets using remainder plus positive correction,
|
||||
without abs or int narrowing. Rehash copies independent topology using cached
|
||||
hashes and complete K/V groups; it never calls Identity or edits old published
|
||||
links during preparation. Old and candidate tables/nodes coexist under normal
|
||||
quota accounting. Search still has a linear worst case.
|
||||
|
||||
## Capture associations independently of later mutation
|
||||
|
||||
Map.cursor returns `Cursor<keyval<K,V>>`. Each association costs a new Keyval and
|
||||
an immutable private snapshot node, plus applicable carriers. Capture takes
|
||||
O(B+N) work and O(N) extra storage, returns only when complete, calls no strategies
|
||||
and retains no editable Map node or bucket position.
|
||||
|
||||
The [shared Cursor table](../../../docs/compiler/pbs/specs/sdk-list-and-cursor.md#cursor-protocol)
|
||||
is unchanged: current starts on the first captured entry; hasNext tests for a
|
||||
successor; next without one retains the last entry. Only an empty-born Cursor has
|
||||
absent current. Consume current before checking whether to advance.
|
||||
|
||||
Later insertion, replacement, removal, clear or rehash cannot rewrite captured
|
||||
associations. Order is unspecified. Consumed prefixes may become unreachable,
|
||||
while the final current remains retained until its Cursor releases it. The real
|
||||
GC corpus observes 1,200 -> 1 -> 1 -> 0 snapshot nodes and Keyvals, retaining
|
||||
2,400 -> 2 -> 2 -> 0 distinct key/value objects. The Map-node count is zero after
|
||||
capture ownership leaves the source collection, confirming no source-node link.
|
||||
|
||||
## Prepare even typed absence before structural writes
|
||||
|
||||
The quota corpus exposed an easy source-level mistake: `return none` can lower
|
||||
to instructions that allocate a private typed-default carrier. Returning it after
|
||||
inserting a node therefore introduced a fallible allocation after publication,
|
||||
despite the source text looking like a trivial constant.
|
||||
|
||||
The insertion path now prepares the typed absent previous value before structural
|
||||
writes and returns that prepared local afterward. Existing-entry put/remove also
|
||||
prepare their complete optional previous-value carriers before replacement or
|
||||
unlinking. Optimized and ordinary producers qualify these phases independently.
|
||||
|
||||
This preparation is not a transaction. Read/write indexing, containsKey, put and
|
||||
remove use a guard against Identity-driven reentry on the same Map, including
|
||||
aliases. clear is also blocked during callbacks; size/isEmpty/cursor may inspect
|
||||
the consistent prior structure. Normal returns release the guard. Callback faults
|
||||
may leave it installed while associations remain unchanged.
|
||||
|
||||
Before structural writes, refusal preserves old associations/topology but does
|
||||
not undo callbacks, arguments, guard writes or provisional allocation. After
|
||||
structural writes start, faults may retain earlier writes and incomplete
|
||||
invariants, with no rollback or safe-reuse guarantee. A separate test-only quota
|
||||
probe after candidate-table installation demonstrates table=16/nodes=7 while old
|
||||
size=6 and guard=true. It does not ship in the SDK or represent a natural refusal
|
||||
frequency. Budget/debugger pauses remain resumable instruction boundaries.
|
||||
|
||||
## Compiler and editor integration pitfalls
|
||||
|
||||
- Map keys are K, not positional long indices. Semantic analysis and lowering must
|
||||
select Map handling before Array/List/Linked promotion, passing every key slot.
|
||||
- Indexed reads are optional V while indexed assignment expects V. Contextual
|
||||
generic construction on a key/value expression must use that operand's expected
|
||||
application, not the outer lookup optional.
|
||||
- A chained `optionalCall().hasSome()` has a boolean outer context, but that must
|
||||
not erase the uniquely resolved optional return or change the receiver's lowering
|
||||
context. This front corrected both resolution and receiver lowering.
|
||||
- Keyval privacy must hold in completion, hover, navigation and signature help,
|
||||
while private `this` fields remain available inside their owner. Unknown editor
|
||||
receivers must produce no invented members or null-name resolution failures.
|
||||
- Contextual constructors record application provenance on the entire NewExpr
|
||||
span; signature help must resolve that concrete application as well as explicit
|
||||
angular type applications. Imported aliases keep original SDK definitions.
|
||||
- Generic default constructors must not invalidate explicit-strategy applications
|
||||
for keys without default Identity. Keep K and V restrictions independent.
|
||||
|
||||
## Qualification and maintenance references
|
||||
|
||||
The complete regression and installed-JAR gates passed. Both production runtime
|
||||
profiles executed all 88 mandatory Map PBX fixtures: 64 paired behavior/expected
|
||||
fault cases, 16 natural-resource fixtures, 2 separate injected-fault fixtures,
|
||||
4 GC fixtures covering both producers and 2 import/installed examples. Each profile
|
||||
observed 328 natural refusals before structural writes, 2 post-publication test
|
||||
injections, 8 snapshot GC observations and 10 collection GC observations.
|
||||
|
||||
Qualification is local macOS/arm64 against unchanged provider
|
||||
`dcf6561ea73446e0a3e1cf1c73eda20923b38df0`. It does not establish a performance
|
||||
threshold, other-host qualification or installed game readiness. Existing unrelated
|
||||
disabled JUnit cases and upstream headless-schema gaps remain explicit in the
|
||||
evidence and are not counted as new Map conformance.
|
||||
|
||||
- [Normative Map/Keyval specification](../../../docs/compiler/pbs/specs/sdk-map-and-keyval.md).
|
||||
- [Executable installed example](../../../prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/pbs-knowledge/examples/game/1/src/maps.pbs).
|
||||
- [SDK algorithms](../../../prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/game/stdlib/1/sdk/collections/main.pbs).
|
||||
- [Source-to-PBX qualification](../../../prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsMapKeyvalTest.java).
|
||||
- [Harness reproduction](../../../tools/pbx-conformance/README.md).
|
||||
- [Set/Identity predecessor](../DSC-0092-pbs-sdk-set/LSN-0093-reusable-identity-and-source-set-buckets.md).
|
||||
- [Sequential mutation boundaries](../DSC-0096-runtime-storage-isa-consumer-migration/LSN-0092-sequential-collection-mutations-need-explicit-failure-boundaries.md).
|
||||
@@ -0,0 +1,126 @@
|
||||
# Map/Keyval implementation and qualification evidence
|
||||
|
||||
Owner: `compiler/pbs`. Captured 2026-10-26 for accepted DEC-0079 / PLN-0157,
|
||||
with complete coverage of R1–R12. Studio baseline HEAD and host/tool versions are
|
||||
in [environment.json](environment.json). Runtime remained clean at
|
||||
`dcf6561ea73446e0a3e1cf1c73eda20923b38df0`; no runtime write or commit was made.
|
||||
|
||||
## Reproduction and results
|
||||
|
||||
From the Studio root:
|
||||
|
||||
```sh
|
||||
./gradlew test :prometeu-app:installedKnowledgeTest --console=plain
|
||||
CARGO_TARGET_DIR=/tmp/studio-pbx-map-target python3 tools/pbx-conformance/run.py --runtime ../runtime
|
||||
CARGO_TARGET_DIR=/tmp/studio-pbx-map-target python3 tools/pbx-conformance/run.py --runtime ../runtime --release
|
||||
git diff --check
|
||||
discussion validate
|
||||
```
|
||||
|
||||
All returned zero. The two complete VM runs include all Map cases and the existing
|
||||
Registry, catalog, math, Random, input, Array/optional, Struct/contract, generic,
|
||||
closure, storage/copy, List, Linked, Set, Identity/hash, admission and schema corpora.
|
||||
Focused `--map-only` runs were used during development; final evidence is from
|
||||
the complete harness built from the final source fingerprints.
|
||||
|
||||
Aggregated standard JUnit reports contain 1,079 cases: zero failures/errors,
|
||||
1,066 executed and 13 existing skips. The independent installed-knowledge task
|
||||
adds two passing cases outside the checkout using installed JARs. The final
|
||||
Gradle invocation completed in 15 seconds with 2 executed and 92 up-to-date tasks;
|
||||
unchanged suites retained valid prior successful results. Reported suites and
|
||||
individual skips are preserved in [gradle-results.json](gradle-results.json).
|
||||
Existing skips belong to BackendGateIIntegrationTest (8),
|
||||
MainProjectPipelineIntegrationTest (4) and ExternalSourceDevelopmentHostTest (1).
|
||||
None is a new Map test. Frontend totals are 305 and architecture totals are 127.
|
||||
|
||||
Each Rust profile uses both ordinary and optimized source producers, including
|
||||
the GC fixtures. Eighty-eight mandatory Map files are fingerprinted: 64 behavior
|
||||
and expected-fault cases, 16 resource fixtures, 2 distinct injection fixtures,
|
||||
4 GC fixtures and 2 real import/installed examples. Missing mandatory fixtures
|
||||
fail qualification. The full fixture directory contains 1,389 fingerprinted PBX
|
||||
files; a directory count is not itself a count of executed corpus cases.
|
||||
|
||||
| New observation per Rust profile | Count |
|
||||
| --- | ---: |
|
||||
| Behavior / expected callback and overflow faults | 64 |
|
||||
| Natural quota refusals with successful-prefix comparison | 328 |
|
||||
| Separate test-only post-publication quota injections | 2 |
|
||||
| Snapshot GC observations, ordinary + optimized | 8 |
|
||||
| Collection/replacement/removal GC observations, ordinary + optimized | 10 |
|
||||
| Import/reexport and installed-JAR example executions | 2 |
|
||||
|
||||
Known upstream headless-schema gaps for LifecycleRole and NonFiniteValue remain
|
||||
printed explicitly. Original provider payloads are preserved and those cases are
|
||||
not called conformance to the unmodified published enum. No new exception was
|
||||
introduced for Map. Qualification is local macOS/arm64, not a timing benchmark or
|
||||
other-host/deployed-game qualification.
|
||||
|
||||
## Resource and failure-phase observations
|
||||
|
||||
The paired producer paths and Rust profiles produced the same peak vectors.
|
||||
These are measured whole-fixture/session peaks including setup, wrappers and call
|
||||
preparation, not standalone Map object sizes.
|
||||
|
||||
| Operation | GuestBytes before → after | HandleSlots before → after | Peak Map nodes / tables | Natural refusals per producer |
|
||||
| --- | --- | --- | --- | ---: |
|
||||
| Growth 6 → 7 | 26,776 → 50,576 | 86 → 161 | 13 / 2 | 38 |
|
||||
| Add without growth | 21,848 → 27,688 | 70 → 89 | 6 / 1 | 25 |
|
||||
| Index replacement | 21,848 → 24,912 | 70 → 80 | 5 / 1 | 16 |
|
||||
| put replacement | 21,848 → 25,516 | 70 → 82 | 5 / 1 | 18 |
|
||||
| Remove | 21,848 → 25,540 | 70 → 82 | 5 / 1 | 16 |
|
||||
| Clear | 21,848 → 22,152 | 70 → 71 | 5 / 1 | 5 |
|
||||
| Cursor capture | 21,848 → 37,888 | 70 → 122 | 5 / 1 | 30 |
|
||||
| Read | 21,848 → 25,212 | 70 → 81 | 5 / 1 | 16 |
|
||||
|
||||
All 328 natural refusals in each final profile occurred before structural writes;
|
||||
an installed guard may remain. This does not prove post-write faults impossible
|
||||
or permit automatic safe reuse. The separate test-only probe after actual table
|
||||
installation retains 16 buckets, 7 nodes, old size 6 and active guard when the
|
||||
probe allocation fails, while the refused instruction preserves its own entry state.
|
||||
Production SDK source contains no such probe. The source prepares even typed none
|
||||
before publication because lowering that absence can materialize a private carrier.
|
||||
|
||||
Snapshot GC observes 1,200 -> 1 -> 1 -> 0 nodes and Keyvals and
|
||||
2,400 -> 2 -> 2 -> 0 distinct key/value Items, without retaining the source Map
|
||||
table/nodes. Collection GC observes 64 -> 64 -> 61 -> 0 -> 0 Map nodes and
|
||||
128 -> 128 -> 122 -> 0 -> 0 Items: overwritten values are reclaimed, removals
|
||||
release keys/values and clear releases all associations. Both producer variants
|
||||
pass these observations in both runtime profiles.
|
||||
|
||||
The eight peak vector components are GuestBytes, HandleSlots, AuxiliaryBytes,
|
||||
TemporaryBytes, StringBytes, StringAllocations, IndividualStringBytes and CallDepth.
|
||||
The complete vectors, refusal operation/resource/opcode records and GC counts are
|
||||
in [map-results.json](map-results.json) and the compressed raw logs.
|
||||
|
||||
## Requirement coverage retained after housekeeping
|
||||
|
||||
| Requirement | Final evidence |
|
||||
| --- | --- |
|
||||
| R1 Construction, nominal origin, invariance | Frontend Map tests, SDK interface gate, alias/reexport frame and installed source |
|
||||
| R2 API and evaluation | basic/scalars/evaluation source cases, typed string/object/tuple/native keys |
|
||||
| R3 Optional presence | optional source case, nested payloads, stored none/zero/false, actual installed example |
|
||||
| R4 Representative and previous values | content/basic cases, no-growth replacement resource baseline, snapshot independence |
|
||||
| R5 Identity policies | scalars/objects/references/random/tuple/native/pixel cases and nominal/default-strategy frontend negatives |
|
||||
| R6 Read-only Keyval | content case with distinct association instances and shared payloads; private-field semantic/editorial gates |
|
||||
| R7 Buckets, bounds, cleanup | collisions/arithmetic/overflow, structural validation of resource fixtures, collection GC |
|
||||
| R8 Reuse, rehash, memory | collision strategy counters, 13-node/2-table growth peak and full existing Set corpus |
|
||||
| R9 Entry snapshot | empty/single/multiple states, snapshots/content, callback reads, paired snapshot GC |
|
||||
| R10 Guard and failure phases | hash and equals callback fault matrices, successful-prefix quota comparison, separate post-publication injection |
|
||||
| R11 Groups, owners, LSP | tuple/native/pixel/contract/reference payloads, source-order checks, real GC and SDK provenance/privacy editor tests |
|
||||
| R12 Production qualification and distribution | Complete debug/release logs, both producer paths, isolated installed-JAR compilation/execution and regression reports |
|
||||
|
||||
## Files and workflow mechanics
|
||||
|
||||
- `regression.log.gz`, `conformance-debug.log.gz`, `conformance-release.log.gz`:
|
||||
complete final raw outputs.
|
||||
- `source.sha256`: all changed/new version-controlled surfaces at qualification.
|
||||
- `fixtures.sha256.gz`: actual generated PBX fingerprints, including installed examples.
|
||||
- `gradle-results.json`, `map-results.json`, `environment.json`: machine-readable results.
|
||||
- `workflow.txt`: completed plan, validation and housekeeping output.
|
||||
- `SHA256SUMS`: evidence file integrity manifest.
|
||||
|
||||
The CLI has no standalone lesson creation/next-ID query. LSN-0094 was read through
|
||||
the framework's read-only model accessor; `discussion housekeep` performs its
|
||||
registration, counter advancement, index updates and workflow artifact removal.
|
||||
The index was not edited manually. The English lesson preserves the operational
|
||||
knowledge; completed agenda/decision/plan files are disposable workflow scaffolding.
|
||||
@@ -0,0 +1,10 @@
|
||||
e00bd96cd1e689654be4d563b550e488265c8eaf2038734013219019c508e004 README.md
|
||||
08b3115f4dc03a2a637b4133fd4a7ec6a27395183b8de1d778953e71c2e7df9f conformance-debug.log.gz
|
||||
5efbde06fc26364560cf5e4e717d8023769ce322edb624b01d80e957dfe1a701 conformance-release.log.gz
|
||||
325cb8c0638609340e398352e1c7a006b232ad24c7f860958f84017193266576 environment.json
|
||||
8e8453dbd3b4e336d6fcf5d49337cb03ef2a3365d8e905f4db52d7ce6a8d1000 fixtures.sha256.gz
|
||||
effff1a1552e7210bdb0486e44996d668dfb1d1e1cd1c0f076fe7a47a837f0f6 gradle-results.json
|
||||
be95e4f4aa5c8d2718c8cc356b3eaa68cce050632f0ea6d1ed5051f482013b4e map-results.json
|
||||
5af47b805bcf2c794d95bfaf517fe592e6b24116ba87d1c46a490fbbc18fbce1 regression.log.gz
|
||||
8569d628c2e0305e403197ef8b7c92cb9156bae817529a01f828c7ef340ce3ea source.sha256
|
||||
e93ad3067041f75297210adbf1f6cfd6a30a090c44d74afaf0059b6a1bee1faf workflow.txt
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"captured": "2026-10-26",
|
||||
"owner": "compiler/pbs",
|
||||
"decision": "DEC-0079",
|
||||
"plan": "PLN-0157",
|
||||
"studio_baseline_head": "8105604f9210468fc61950b124cdd7adf58daaf0",
|
||||
"runtime_head": "dcf6561ea73446e0a3e1cf1c73eda20923b38df0",
|
||||
"runtime_working_tree": "",
|
||||
"host": "macOS-27.0.1-arm64-arm-64bit-Mach-O",
|
||||
"rust": "rustc 1.98.1 (48a229cea 2026-09-01)\nbinary: rustc\ncommit-hash: 48a229ceaefd4985c50990b14116b6d856af0985\ncommit-date: 2026-09-01\nhost: aarch64-apple-darwin\nrelease: 1.98.1\nLLVM version: 22.1.8",
|
||||
"map_fixture_count": 88,
|
||||
"all_fixture_count": 1389
|
||||
}
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,992 @@
|
||||
{
|
||||
"debug": {
|
||||
"behavior_and_expected_faults": 64,
|
||||
"phase_refusals": [
|
||||
{
|
||||
"operation": "growth",
|
||||
"refusals": 38,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "growth-optimized",
|
||||
"refusals": 38,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "add",
|
||||
"refusals": 25,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "add-optimized",
|
||||
"refusals": 25,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "replace",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "replace-optimized",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "put",
|
||||
"refusals": 18,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "put-optimized",
|
||||
"refusals": 18,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "remove",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "remove-optimized",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "clear",
|
||||
"refusals": 5,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "clear-optimized",
|
||||
"refusals": 5,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "cursor",
|
||||
"refusals": 30,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "cursor-optimized",
|
||||
"refusals": 30,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "read",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "read-optimized",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
}
|
||||
],
|
||||
"peaks": [
|
||||
{
|
||||
"operation": "growth",
|
||||
"nodes": 13,
|
||||
"tables": 2,
|
||||
"before": [
|
||||
26776,
|
||||
86,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
50576,
|
||||
161,
|
||||
18368,
|
||||
7680,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "growth-optimized",
|
||||
"nodes": 13,
|
||||
"tables": 2,
|
||||
"before": [
|
||||
26776,
|
||||
86,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
50576,
|
||||
161,
|
||||
18368,
|
||||
7680,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "add",
|
||||
"nodes": 6,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
27688,
|
||||
89,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "add-optimized",
|
||||
"nodes": 6,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
27688,
|
||||
89,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "replace",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
24912,
|
||||
80,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "replace-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
24912,
|
||||
80,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "put",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25516,
|
||||
82,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "put-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25516,
|
||||
82,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "remove",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25540,
|
||||
82,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "remove-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25540,
|
||||
82,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "clear",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
22152,
|
||||
71,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "clear-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
22152,
|
||||
71,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "cursor",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
37888,
|
||||
122,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "cursor-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
37888,
|
||||
122,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "read",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25212,
|
||||
81,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
7
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "read-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25212,
|
||||
81,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
7
|
||||
]
|
||||
}
|
||||
],
|
||||
"test_only_postpublication_injections": 2,
|
||||
"snapshot_gc_observations": 8,
|
||||
"collection_gc_observations": 10,
|
||||
"distribution_executions": 2,
|
||||
"known_upstream_schema_gaps": [
|
||||
"LifecycleRole missing from published enum; original payload preserved",
|
||||
"NonFiniteValue missing from published enum; original payload preserved"
|
||||
]
|
||||
},
|
||||
"release": {
|
||||
"behavior_and_expected_faults": 64,
|
||||
"phase_refusals": [
|
||||
{
|
||||
"operation": "growth",
|
||||
"refusals": 38,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "growth-optimized",
|
||||
"refusals": 38,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "add",
|
||||
"refusals": 25,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "add-optimized",
|
||||
"refusals": 25,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "replace",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "replace-optimized",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "put",
|
||||
"refusals": 18,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "put-optimized",
|
||||
"refusals": 18,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "remove",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "remove-optimized",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "clear",
|
||||
"refusals": 5,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "clear-optimized",
|
||||
"refusals": 5,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "cursor",
|
||||
"refusals": 30,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "cursor-optimized",
|
||||
"refusals": 30,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "read",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
},
|
||||
{
|
||||
"operation": "read-optimized",
|
||||
"refusals": 16,
|
||||
"after_structural": 0
|
||||
}
|
||||
],
|
||||
"peaks": [
|
||||
{
|
||||
"operation": "growth",
|
||||
"nodes": 13,
|
||||
"tables": 2,
|
||||
"before": [
|
||||
26776,
|
||||
86,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
50576,
|
||||
161,
|
||||
18368,
|
||||
7680,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "growth-optimized",
|
||||
"nodes": 13,
|
||||
"tables": 2,
|
||||
"before": [
|
||||
26776,
|
||||
86,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
50576,
|
||||
161,
|
||||
18368,
|
||||
7680,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "add",
|
||||
"nodes": 6,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
27688,
|
||||
89,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "add-optimized",
|
||||
"nodes": 6,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
27688,
|
||||
89,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "replace",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
24912,
|
||||
80,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "replace-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
24912,
|
||||
80,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "put",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25516,
|
||||
82,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "put-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25516,
|
||||
82,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
8
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "remove",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25540,
|
||||
82,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "remove-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25540,
|
||||
82,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "clear",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
22152,
|
||||
71,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "clear-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
22152,
|
||||
71,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "cursor",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
37888,
|
||||
122,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "cursor-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
37888,
|
||||
122,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "read",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25212,
|
||||
81,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
7
|
||||
]
|
||||
},
|
||||
{
|
||||
"operation": "read-optimized",
|
||||
"nodes": 5,
|
||||
"tables": 1,
|
||||
"before": [
|
||||
21848,
|
||||
70,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
6
|
||||
],
|
||||
"after": [
|
||||
25212,
|
||||
81,
|
||||
10688,
|
||||
3840,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
7
|
||||
]
|
||||
}
|
||||
],
|
||||
"test_only_postpublication_injections": 2,
|
||||
"snapshot_gc_observations": 8,
|
||||
"collection_gc_observations": 10,
|
||||
"distribution_executions": 2,
|
||||
"known_upstream_schema_gaps": [
|
||||
"LifecycleRole missing from published enum; original payload preserved",
|
||||
"NonFiniteValue missing from published enum; original payload preserved"
|
||||
]
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,34 @@
|
||||
08b3115f4dc03a2a637b4133fd4a7ec6a27395183b8de1d778953e71c2e7df9f discussion/lessons/DSC-0093-pbs-sdk-map-keyval/evidence/conformance-debug.log.gz
|
||||
5efbde06fc26364560cf5e4e717d8023769ce322edb624b01d80e957dfe1a701 discussion/lessons/DSC-0093-pbs-sdk-map-keyval/evidence/conformance-release.log.gz
|
||||
effff1a1552e7210bdb0486e44996d668dfb1d1e1cd1c0f076fe7a47a837f0f6 discussion/lessons/DSC-0093-pbs-sdk-map-keyval/evidence/gradle-results.json
|
||||
be95e4f4aa5c8d2718c8cc356b3eaa68cce050632f0ea6d1ed5051f482013b4e discussion/lessons/DSC-0093-pbs-sdk-map-keyval/evidence/map-results.json
|
||||
5af47b805bcf2c794d95bfaf517fe592e6b24116ba87d1c46a490fbbc18fbce1 discussion/lessons/DSC-0093-pbs-sdk-map-keyval/evidence/regression.log.gz
|
||||
8d5804910106bfa3f654edcefd2a7d196d70fdf19fd67b86bc80d8d766ffe25b docs/compiler/pbs/specs/generic-structs-and-free-functions.md
|
||||
c82af9031ddd0143e208869a807fff5c85ee71d35799b9c841efdf8e30ed4b19 docs/compiler/pbs/specs/sdk-list-and-cursor.md
|
||||
12135be9ff129493eb332f4bb9c05e36d7667e001f52669d03d90221d1232d9a docs/compiler/pbs/specs/sdk-map-and-keyval.md
|
||||
4af3aa15ce6da20ae83c39ab4fcca38beba6f634ee5e55bf5f6edb0b5018ad50 docs/compiler/pbs/specs/sdk-set-and-identity.md
|
||||
fe0e0d0eccfacd5b3f5ca220ec8c7a7c82f7bc527c5317d4b0651443b021f73e docs/compiler/pbs/specs/typed-arrays-and-optional-execution.md
|
||||
de20f955ac4e55b3845741ea0ed6631326b4b91997f78fe7151dc094c40fe100 prometeu-app/src/test/java/p/studio/app/compiler/CompilerProjectKnowledgeTest.java
|
||||
59d87f52a1d75bb2b873a5a0446ba00b50a2ae69b8e13f610467e8879ab0dbbe prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeProbe.java
|
||||
dd65d8a6f7912aa1ba853a6876bf198069a88fdd75fbf53f6e83e4a2cfd29ebd prometeu-app/src/test/java/p/studio/app/compiler/InstalledKnowledgeTest.java
|
||||
43fcb6def3cb51dd410d27baf67fc96f5c524d29633700d1c5192d0c7c64aabc prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsListCursorTest.java
|
||||
38412eaad67ca52b591a12bad0d22064b569b2944e29d5f49e243c6243487bc5 prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsMapKeyvalTest.java
|
||||
5254aad2e0001ce420fec865e518f41aeaa938e7271319a81da016aeed8ab48d prometeu-architecture-tests/src/test/java/p/studio/compiler/backend/irvm/PbsSetTest.java
|
||||
f8336f28708de962c6dbe6e7c4927accb01c3bdc4df1a70f53921e14cea04e9d prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/PbsGenericInstantiation.java
|
||||
4231b9b16aae5e81740299a0959ca0258dedc3724ee69e82174df8218bfddfed prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/PbsGenericTemplateValidator.java
|
||||
e486759ce7a8225fdab8c793b1305dda761c7f7dc9ea542feb832432fa98efec prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/PbsSdkCollections.java
|
||||
f7295c1d1430b24f3bc76f3b988c9bb19e6047334d73b274a9eca6ff2751e624 prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/lowering/PbsExecutableBodyLowerer.java
|
||||
e6101710926b3bb6b1d188544f505a6f6236c551c7c7667d7e0bf8cb68afeda5 prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/parser/PbsDeclarationParser.java
|
||||
452363ea506a17dabd68ff3bc1443066fbc9558877c8016df3fdb85465fa38dc prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/semantics/PbsEditorialSupportService.java
|
||||
e0cc2c6dbd0cd2c3acfe58ebc17dba8f9fe58dd76c7820212863f851afd7cd32 prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/semantics/PbsFlowSemanticSupport.java
|
||||
448ea7e5650ff101ae380d0fef3f5f925fea8687ec236f32fc95ddb2b79f57fb prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/java/p/studio/compiler/pbs/semantics/PbsFlowStructuralExpressionAnalyzer.java
|
||||
6fe7a8ed065c6df78af005320ece39425bb73eeb48e8451310866655ff109733 prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/game/stdlib/1/sdk/collections/main.pbs
|
||||
eedf6c88abc73535423edfeafa549d491c137d23f7532d3d9b72f0ca6622642c prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/game/stdlib/1/sdk/collections/mod.barrel
|
||||
25d85ee0698f6e5e0ffae561ebf639a5942b4c990418fcbd5d9a4992c37109ea prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/pbs-knowledge/examples/game/1/src/maps.pbs
|
||||
e3a5232997b2bdc2d249da07b186bbc6fb73eb8741aacd3aa00beda43537d2e6 prometeu-compiler/frontends/prometeu-frontend-pbs/src/main/resources/pbs-knowledge/examples/game/1/src/mod.barrel
|
||||
6ec188158133c4632bd15a42105a6b32a8c9b5963872bdd62e7a1cd3954a2893 prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/PbsGateUSdkInterfaceConformanceTest.java
|
||||
fd9dd09edbf272ce54cb59c633df481d1d72fd1e008992b93f4a5583747f578b prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/PbsMapKeyvalTest.java
|
||||
7a3ffc5e2a533966dbe069f8a5e1541005916d7be47aa65d0f4d605926945f71 prometeu-compiler/frontends/prometeu-frontend-pbs/src/test/java/p/studio/compiler/pbs/semantics/PbsMapKeyvalEditorialTest.java
|
||||
01311527195d9f8513c96907adf7eb501080cd073e56f3f71b6e6c690c800b94 tools/pbx-conformance/README.md
|
||||
2d3cfb43159a4c20f891562f2e196fd894e82e0d47124f09707b20f146ed505e tools/pbx-conformance/main.rs
|
||||
11ac435b7c1f7a0df1961975a537da4f491d4c6fd7feeb8b7b39183ecaf039e2 tools/pbx-conformance/run.py
|
||||
@@ -0,0 +1,23 @@
|
||||
Owner: compiler/pbs. Completed 2026-10-26. DEC-0079 / PLN-0157, R1–R12.
|
||||
Workers: Spec Editorial Worker, Code Implementation Worker, Lesson Worker.
|
||||
|
||||
discussion mark-plan PLN-0157 done --json
|
||||
{"discussion_id":"DSC-0093","plan_id":"PLN-0157","status":"done"}
|
||||
|
||||
discussion validate (before housekeeping)
|
||||
validation passed
|
||||
|
||||
discussion housekeep DSC-0093 --lesson discussion/lessons/DSC-0093-pbs-sdk-map-keyval/LSN-0094-map-presence-key-identity-and-captured-associations.md
|
||||
housekept DSC-0093
|
||||
removed workflow artifacts: 3
|
||||
registered lesson: LSN-0094
|
||||
|
||||
discussion validate (after housekeeping)
|
||||
validation passed
|
||||
|
||||
discussion inspect DSC-0093
|
||||
DSC-0093 done pbs-sdk-map-keyval; sole artifact: LSN-0094 done, present.
|
||||
|
||||
Runtime: clean dcf6561ea73446e0a3e1cf1c73eda20923b38df0, no writes or commits.
|
||||
Next lesson ID was obtained through DiscussionIndex.next_id (read only);
|
||||
housekeep owned registration, counter advancement and index mutations.
|
||||
@@ -269,3 +269,5 @@ iteration protocols and List logical bounds/slot transfer are separate decisions
|
||||
- [Typed arrays and optional execution](typed-arrays-and-optional-execution.md).
|
||||
- [First-class functions and captures](first-class-functions-and-captures.md).
|
||||
- [Concrete Registry and PBX handoff](../../general/specs/typed-registry-and-pbx-v0.md).
|
||||
- [SDK Map and Keyval](sdk-map-and-keyval.md), a two-parameter source consumer
|
||||
preserving separate key/value policies and complete optional/grouped fields.
|
||||
|
||||
@@ -177,11 +177,12 @@ faults. List itself rejects directly optional elements.
|
||||
|
||||
The shared implementation is independent of List representation.
|
||||
[Linked](sdk-linked-and-cursor.md) uses Cursor<T> for forward and reverse captures.
|
||||
[Set](sdk-set-and-identity.md) produces Cursor<T>; future Map<K,V> uses
|
||||
Cursor<keyval<K,V>>. Set/Map gain no ordering guarantee between captures.
|
||||
[Set](sdk-set-and-identity.md) produces Cursor<T>; Map<K,V> uses
|
||||
Cursor<keyval<K,V>> as specified by [Map/Keyval](sdk-map-and-keyval.md).
|
||||
Set/Map gain no ordering guarantee between captures.
|
||||
A captured keyval association is read-only
|
||||
and does not follow later association replacement; referenced objects stay shared.
|
||||
Map and keyval remain separate deliveries.
|
||||
Map owns entry production and Keyval representation while reusing this protocol.
|
||||
|
||||
For n logical List positions and k present occurrences, capture takes O(n) work
|
||||
and O(k) additional nodes; next follows one link in O(1). Each node costs allocation,
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
# SDK Map and read-only Keyval associations
|
||||
|
||||
Owner: `compiler/pbs`. Map algorithms execute as PBS SDK source. This contract
|
||||
builds on [generic structs](generic-structs-and-free-functions.md),
|
||||
[Array/optional](typed-arrays-and-optional-execution.md),
|
||||
[Set/Identity/hash](sdk-set-and-identity.md) and the
|
||||
[shared snapshot Cursor](sdk-list-and-cursor.md#cursor-protocol).
|
||||
Registry/PBX, storage, ownership, faults and resource limits remain provider contracts.
|
||||
|
||||
## Types, construction and public API
|
||||
|
||||
`@sdk:collections` exports invariant ordinary generic structs `map<K,V>` and
|
||||
`keyval<K,V>`, alongside the nominal `Identity<T>` and shared `Cursor<T>` contracts.
|
||||
Applications retain nominal origin through imports, aliases and reexports. User
|
||||
homonyms and untrusted SDK attributes acquire no reserved behavior.
|
||||
|
||||
```pbs
|
||||
import {map, keyval, Identity, Cursor} from @sdk:collections;
|
||||
let scores = new map<str, int>();
|
||||
let contextual: map<str, int> = new map();
|
||||
let entry = new keyval<str, int>("player", 42);
|
||||
let previous: optional int = scores.put(entry);
|
||||
```
|
||||
|
||||
Map offers `new map<K,V>()` and `new map<K,V>(identity: Identity<K>)`. Keyval offers
|
||||
`new keyval<K,V>(key: K, value: V)`. Diamond/omitted type arguments require a
|
||||
sufficient expected application; constructor values do not infer type arguments.
|
||||
Every constructor initializes its fields before returning.
|
||||
|
||||
Directly optional K, including grouping, is invalid for Map with either constructor.
|
||||
V may be optional. Independent keyval admits all valid generic field compositions,
|
||||
including optional K/V. Optional of the Map itself remains valid. Array's direct
|
||||
optional-element restriction does not apply to V fields in private Map nodes.
|
||||
|
||||
| Operation | Result | Behavior |
|
||||
| --- | --- | --- |
|
||||
| m[key] | optional V | none for absent key, some(stored value) for a present key |
|
||||
| m[key] = value | No previous value | Insert or replace V |
|
||||
| containsKey(key: K) | bool | Membership under selected key identity |
|
||||
| put(entry: keyval<K,V>) | optional V | Insert/replace; return previous V if present |
|
||||
| remove(key: K) | optional V | Remove; return previous V if present |
|
||||
| clear() | unit | Remove associations, release table, restore lazy empty state |
|
||||
| size() | long | Number of associations |
|
||||
| isEmpty() | bool | size equals zero |
|
||||
| cursor() | Cursor<keyval<K,V>> | Complete independent entry snapshot |
|
||||
| entry.key() | K | Captured key reference/value |
|
||||
| entry.value() | V | Captured value reference/value |
|
||||
|
||||
Receivers and arguments evaluate once in source order, including named application.
|
||||
Map indexing expects K and does not apply the additional int-to-long index promotion
|
||||
of Array/List/Linked. Complete key/value groups cross source calls unchanged.
|
||||
Map has stable reference identity: aliases observe the same mutations.
|
||||
|
||||
Only one association exists for each key equivalence class; values may repeat.
|
||||
Replacement changes only V and preserves the original stored K, cached hash and
|
||||
size. It never triggers growth. Replacing the representative key requires removing
|
||||
the entry and reinserting the new key. put reads association components without
|
||||
retaining its keyval instance as an editable internal node. remove of an absent
|
||||
key returns none without changing associations/topology. Prepare previous-value
|
||||
carriers before replacement or unlinking.
|
||||
|
||||
Insertion/iteration order is unspecified. There are no keys/values projections,
|
||||
capacity constructors, capacity/reserve/trim, bulk APIs, redundant tryGet, public
|
||||
nodes, universal Element or positional indexing contract.
|
||||
|
||||
## Presence and optional payloads
|
||||
|
||||
The outer optional of read/put/remove describes association existence, independently
|
||||
of V. For `map<str, optional int>`, absence is none, present V=none is some(none),
|
||||
and present V=some(7) is some(some(7)). containsKey is true for a stored none;
|
||||
assigning none as V does not remove an association. Zero/false and complete
|
||||
multi-slot groups remain present. Preserve deeper valid optional nesting.
|
||||
Type/callback/resource faults never become none/false.
|
||||
|
||||
## Key Identity and read-only Keyval
|
||||
|
||||
Use the exact defaults and eligibility rules of Set: int/long/bool by static-domain
|
||||
value; str by exact UTF-8 content; finite float equality with equal signed zeros;
|
||||
source structs, arrays, Fn, Random and eligible services by instance; contracts by
|
||||
fully validated receiver identity. Tuples and other types without a default require
|
||||
an explicit Identity<K>. An unavailable default constructor must not invalidate an
|
||||
otherwise valid explicit-strategy application. V requires no equality/hash capability.
|
||||
|
||||
Hash filters candidates and equals resolves collisions. Keep all signed-long hash
|
||||
bits. Identity must define a stable equivalence relation while stored and satisfy
|
||||
`equals(a,b) => hash(a) == hash(b)`. Relevant key content and strategy configuration
|
||||
must remain coherent. Remove from affected collections before changing content
|
||||
used by hashing/equality, then reinsert. Cached hashes do not stabilize mutable
|
||||
equality. No structural fallback, freezing, purity proof or effect system is added.
|
||||
|
||||
Keyval has private fields and only key()/value() accessors, with no mutators.
|
||||
It retains ordinary struct instance identity: separately constructed keyvals are
|
||||
distinct under default Identity even when components match. Component comparison
|
||||
requires explicit policy; unconstrained K/V gain no equality operator. Assignment
|
||||
shares the keyval instance and payload aliases. Its association cannot be edited
|
||||
through Map or follow later replacements; referenced objects remain mutable/shared.
|
||||
|
||||
## Private storage, rehash and costs
|
||||
|
||||
Map owns a private bucket array with private chained nodes containing full cached
|
||||
long hash, K, V and next link. It is not implemented over Set/Linked and requires
|
||||
no public keyval wrapper per internally stored association. Reuse Identity/hash,
|
||||
common private arithmetic helpers and shared Cursor implementation.
|
||||
|
||||
Empty construction has no nonempty bucket table. First inclusion uses 8 buckets.
|
||||
For capacity c and next size r, grow if r exceeds floor(3*c/4), to
|
||||
min(2*c, 4294967295). Use checked long arithmetic. At maximum bucket capacity,
|
||||
chaining can continue within checked signed-long size and ordinary quotas;
|
||||
Array's u32 bound limits buckets rather than entry count. For positive capacity,
|
||||
use signed hash remainder and add capacity when negative, without abs, narrowing
|
||||
or assuming powers of two. Removal does not shrink. Clear returns to lazy state.
|
||||
|
||||
Rehash prepares independent nodes/topology from cached hashes, with no callbacks
|
||||
or edits to published links before installation. Complete payload groups and
|
||||
reference identities survive. Ordinary mutation does not reconstruct the whole
|
||||
table. Old/candidate structures coexist under normal quotas and GC; preparation
|
||||
does not make subsequent stores atomic. Search has worst case O(N), growing rehash
|
||||
costs O(new buckets + N), and String hashing costs content-dependent work. No fixed
|
||||
instruction cost, adversarial resistance or allocation-free optional is promised.
|
||||
|
||||
## Guard, preparation and failure boundaries
|
||||
|
||||
Read/write indexing, containsKey, put and remove install a private guard before
|
||||
Identity callbacks. Reject callback reentry into these operations or clear on the
|
||||
same Map, including aliases, through the private terminal TRAP_EXPLICIT path
|
||||
before changing associations. During callback preparation, size/isEmpty/cursor
|
||||
may inspect the consistent prior structure without invoking strategies.
|
||||
|
||||
Prepare checks, callbacks/search, next sizes, values, return carriers and candidate
|
||||
structures before the first structural write. Structural stores are sequential,
|
||||
without user callbacks or explicit suspension. Normal returns release the guard,
|
||||
including absent reads/removals and insertion/replacement.
|
||||
|
||||
| Outcome | Guarantee |
|
||||
| --- | --- |
|
||||
| Refusal before structural writes | Prior associations/topology survive; guard, external effects and provisional allocations are not undone |
|
||||
| Successful return | Size, table, groups, representative identity, cleanup, snapshot and guard invariants hold |
|
||||
| Internal/resource fault after structural writes start | Earlier writes and incomplete invariants may remain; no rollback, retry, recovery or safe reuse guarantee |
|
||||
|
||||
Installing the guard is already a write. Callback faults can leave it active.
|
||||
No catch/finally, poison flag or recovery API is introduced. Allowed callback reads
|
||||
do not establish post-fault reuse. Per-instruction refusal preserves that
|
||||
instruction's applicable entry state, not prior instructions. Budget/debugger
|
||||
pauses are resumable instruction boundaries; a source method is not an atomic
|
||||
observation region for host/debugger inspection.
|
||||
|
||||
## Entry snapshot and lifetime
|
||||
|
||||
cursor creates one new independent keyval and one immutable private snapshot node
|
||||
per association, without editable Map-node/position links or hash/equals calls.
|
||||
Capture completes before returning; failure returns no partial Cursor and leaves
|
||||
source structure unchanged. Preserve the shared Cursor state table: nonempty-born
|
||||
starts on first, hasNext tests successor, next without successor keeps last, and
|
||||
only empty-born has absent current. No reset, mutation or new for-in is added.
|
||||
|
||||
Later insertions/replacements/removals/clear/rehash cannot rewrite captured
|
||||
associations. Mutations of referenced objects remain visible; order between captures
|
||||
is unspecified. Capture costs O(B+N) work and O(N) additional storage, including
|
||||
N keyvals, N nodes and applicable carriers. next is O(1). Consumed prefixes may
|
||||
become unreachable, while final current stays retained until its Cursor releases it.
|
||||
|
||||
Preserve complete groups and roots/owners across calls, allocation, hashing,
|
||||
rehash, returns and snapshots. Replacement/removal/clear release obsolete Map
|
||||
references; snapshots/other owners remain independent. Tracing and native owners
|
||||
retain normal costs; immediate GC/quota recovery is not guaranteed.
|
||||
|
||||
## Qualification and distribution
|
||||
|
||||
Compile real source through typed IR/PBX into the production loader/verifier/VM,
|
||||
using ordinary/optimized producers and independent debug/release harness profiles.
|
||||
Cover the full API, optional presence, evaluation order, representative retention,
|
||||
identity/collisions/negative hashes, all Cursor states, groups/aliases, resource
|
||||
prefix refusals, memory coexistence and real GC. Counters establish callback-free
|
||||
rehash/capture. Distinguish natural production quotas from named test-only
|
||||
post-write injection, never shipped in production SDK. Missing mandatory fixtures
|
||||
fail qualification. Regress existing collections, hashing and language boundaries.
|
||||
|
||||
Package this English specification, SDK source and executable examples in installed
|
||||
knowledge. Compile actual installed examples outside the checkout using installed
|
||||
JARs and execute their PBX. No collection syscall/opcode, changed ABI/catalog policy,
|
||||
quota relaxation or provider source mutation is required.
|
||||
@@ -235,8 +235,8 @@ PBX. Normal compilation uses versioned Studio catalogs/resources without a sibli
|
||||
checkout. Runtime ownership, limits and semantics remain the provider contract;
|
||||
Set adds no VM collection instruction/syscall or provider source change.
|
||||
|
||||
Identity/hash are reusable by future Map. Map/keyval API, representation and
|
||||
implementation are separate consumers; sharing policy does not impose a shared
|
||||
Identity/hash are reused by [Map/Keyval](sdk-map-and-keyval.md). Its API, representation
|
||||
and implementation are separate consumers; sharing policy does not impose a shared
|
||||
physical table or universal entry type. See the
|
||||
[common typed Registry contract](../../general/specs/typed-registry-and-pbx-v0.md)
|
||||
and [catalog consumer rules](../../general/specs/runtime-catalog-support.md).
|
||||
|
||||
@@ -88,6 +88,11 @@ policies remain separate concerns.
|
||||
|
||||
See [Runtime Random integration](runtime-random-integration.md) for opaque generator aliases in typed storage and captures.
|
||||
|
||||
[Map/Keyval](sdk-map-and-keyval.md) stores V in generic node fields and therefore
|
||||
admits optional values. Its outer lookup/previous-value optional describes entry
|
||||
existence independently of stored V; some(none) is distinct from absent none.
|
||||
This does not change Array's direct optional-element restriction.
|
||||
|
||||
|
||||
## Parameterized contract integration
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ class CompilerProjectKnowledgeTest {
|
||||
assertTrue(result.references().stream().anyMatch(value -> value.id().equals("pbs:example:game:1:src/collections.pbs")));
|
||||
assertTrue(result.references().stream().anyMatch(value -> value.id().equals("pbs:spec:sdk-linked-and-cursor.md")));
|
||||
assertTrue(result.references().stream().anyMatch(value -> value.id().equals("pbs:example:game:1:src/linked.pbs")));
|
||||
assertTrue(result.references().stream().anyMatch(value -> value.id().equals("pbs:spec:sdk-map-and-keyval.md")));
|
||||
assertTrue(result.references().stream().anyMatch(value -> value.id().equals("pbs:example:game:1:src/maps.pbs")));
|
||||
assertTrue(language.referenceIds().contains("pbs:quickstart"));
|
||||
assertFalse(result.limitations().stream().anyMatch(value -> value.contains("DOCUMENTATION_UNAVAILABLE")));
|
||||
assertFalse(Files.exists(root.resolve(".workspace")));
|
||||
|
||||
@@ -33,6 +33,8 @@ public final class InstalledKnowledgeProbe {
|
||||
check(docs.stream().anyMatch(r -> r.id().equals("pbs:example:game:1:src/linked.pbs")), "Missing installed Linked example");
|
||||
check(docs.stream().anyMatch(r -> r.id().equals("pbs:spec:sdk-set-and-identity.md")), "Missing installed Set/Identity specification");
|
||||
check(docs.stream().anyMatch(r -> r.id().equals("pbs:example:game:1:src/sets.pbs")), "Missing installed Set example");
|
||||
check(docs.stream().anyMatch(r -> r.id().equals("pbs:spec:sdk-map-and-keyval.md")), "Missing installed Map/Keyval specification");
|
||||
check(docs.stream().anyMatch(r -> r.id().equals("pbs:example:game:1:src/maps.pbs")), "Missing installed Map/Keyval example");
|
||||
check(docs.stream().anyMatch(r -> r.id().equals("pbs:example:game:1:src/hashing.pbs")), "Missing installed hashing example");
|
||||
check(docs.stream().anyMatch(r -> r.id().equals("pbs:sdk:game:1:sdk/hash/main.pbs")), "Missing installed hash SDK");
|
||||
for (var reference : docs) {
|
||||
@@ -95,12 +97,12 @@ public final class InstalledKnowledgeProbe {
|
||||
check(linkedResult.diagnostics().stream().noneMatch(issue->issue.isError()),"Installed Linked example must compile");
|
||||
Files.write(fixtures.resolve("pbs-linked-installed.pbx"),linkedResult.bytecodeBytes());
|
||||
System.out.println("Installed Linked execution fixture generated");
|
||||
for(var example:java.util.Map.of("set","sets.pbs","hash","hashing.pbs").entrySet()) {
|
||||
for(var example:java.util.Map.of("set","sets.pbs","hash","hashing.pbs","map","maps.pbs").entrySet()) {
|
||||
Path exampleRoot=Files.createDirectory(Path.of(example.getKey()+"-example")).toRealPath();
|
||||
Files.createDirectories(exampleRoot.resolve("src"));
|
||||
Files.copy(root.resolve("prometeu.json"),exampleRoot.resolve("prometeu.json"));
|
||||
Files.writeString(exampleRoot.resolve("src/mod.barrel"),"pub fn frame() -> void;");
|
||||
String function=example.getKey().equals("set")?"setExample":"hashingExample";
|
||||
String function=switch(example.getKey()){case "set"->"setExample";case "map"->"mapsExample";default->"hashingExample";};
|
||||
Files.writeString(exampleRoot.resolve("src/main.pbs"),Files.readString(root.resolve("src/"+example.getValue()))
|
||||
+"\n[Frame] fn frame()->void {if "+function+"()!=42 {let failure=1/0;}}");
|
||||
var exampleResult=BuilderPipelineService.INSTANCE.compile(
|
||||
|
||||
@@ -17,6 +17,7 @@ class InstalledKnowledgeTest {
|
||||
assertTrue(log.contains("Packaged external sources verified"), log);
|
||||
assertTrue(log.contains("Installed List/Cursor execution fixture generated"), log);
|
||||
assertTrue(log.contains("Installed Linked execution fixture generated"), log);
|
||||
assertTrue(log.contains("Installed map execution fixture generated"), log);
|
||||
}
|
||||
|
||||
@Test void installedCompilerAndSdkCarryTheSameVerifiedCatalog() throws Exception {
|
||||
|
||||
+2
-1
@@ -44,9 +44,10 @@ class PbsListCursorTest {
|
||||
if(name.startsWith("gc"))module=PbsStructuredValuesTest.withTestSafepoint(module);
|
||||
new BytecodePreloadVerifierService().verify(module);
|
||||
Files.createDirectories(directory());Files.write(directory().resolve("pbs-"+collection+"-"+name+".pbx"),module.serialize());
|
||||
if(!name.startsWith("gc")) {
|
||||
if(!name.startsWith("gc") || collection.equals("map")) {
|
||||
var optimized=new OptimizeIRVMService().optimize(new LowerToIRVMService().lower(backend));
|
||||
var optimizedModule=new BytecodeEmitter().emit(optimized.coherentEmissionPlan());
|
||||
if(name.startsWith("gc"))optimizedModule=PbsStructuredValuesTest.withTestSafepoint(optimizedModule);
|
||||
new BytecodePreloadVerifierService().verify(optimizedModule);
|
||||
Files.write(directory().resolve("pbs-"+collection+"-"+name+"-optimized.pbx"),optimizedModule.serialize());
|
||||
}
|
||||
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
package p.studio.compiler.backend.irvm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class PbsMapKeyvalTest {
|
||||
static void compile(String name,String source)throws Exception { PbsListCursorTest.compileCollection("map",name,source); }
|
||||
static void probe(String name,String body)throws Exception { compile(name,"declare service Probe {fn main()->int {"+body+"}}"); }
|
||||
|
||||
@Test void fullApiAndConstructionPreservePreviousValues()throws Exception {
|
||||
probe("basic","""
|
||||
let values:map<str,int>=new map();let alias=values;
|
||||
if values.isEmpty()==false or values.size()!=(0 as long){return 0;}
|
||||
if values["missing"].hasSome() or values.remove("missing").hasSome() or values.containsKey("missing"){return 0;}
|
||||
values["a"]=0;if values["a"].hasNone() or values.containsKey("a")==false{return 0;}
|
||||
if (values.put(new keyval<str,int>("a",20)) else -1) != 0 {return 0;}
|
||||
if (alias["a"] else 0) != 20 {return 0;}
|
||||
if values.put(new keyval<str,int>("b",22)).hasSome(){return 0;}
|
||||
if values.size()!=(2 as long){return 0;}
|
||||
let total:int=(values.remove("a") else 0)+(values.remove("b") else 0);
|
||||
if values.remove("a").hasSome() or values.isEmpty()==false{return 0;}
|
||||
for i:int from 0 until 40 {let indexed=new map<int,int>();indexed[i]=42;if (indexed[i] else 0) != 42{return 0;}}
|
||||
values["again"]=42;values.clear();values.clear();
|
||||
let diamond:map<long,bool>=new map<>();diamond[9223372036854775807]=false;
|
||||
if diamond[9223372036854775807].hasNone(){return 0;}
|
||||
let maybe:optional (map<int,int>)=some(new map());
|
||||
if let present=maybe {present[0]=total;return present[0] else 0;}return 0;
|
||||
""");
|
||||
}
|
||||
@Test void optionalPayloadPresenceIsNeverEntryAbsence()throws Exception {
|
||||
probe("optional","""
|
||||
let values=new map<str,optional int>();
|
||||
if values["a"].hasSome(){return 0;}
|
||||
values["a"]=none;
|
||||
if values.containsKey("a")==false{return 0;}
|
||||
if let payload=values["a"] {if payload.hasSome(){return 0;}}else{return 0;}
|
||||
if let old=values.put(new keyval<str,optional int>("a",some(42))) {if old.hasSome(){return 0;}}else{return 0;}
|
||||
let capture=values.cursor();values["a"]=none;
|
||||
if let entry=capture.current(){if (entry.value() else 0) != 42{return 0;}}else{return 0;}
|
||||
if let removed=values.remove("a"){if removed.hasSome(){return 0;}}else{return 0;}
|
||||
if values.remove("a").hasSome(){return 0;}
|
||||
let nested=new map<int,optional (optional int)>();nested[0]=some(none);
|
||||
if let outer=nested[0]{if let inner=outer{if inner.hasSome(){return 0;}}else{return 0;}}else{return 0;}
|
||||
let independent=new keyval<optional int,optional int>(none,some(42));
|
||||
if independent.key().hasSome(){return 0;}return independent.value() else 0;
|
||||
""");
|
||||
}
|
||||
@Test void defaultIdentitiesPreserveStaticDomainsAndObjectAliases()throws Exception {
|
||||
probe("scalars","""
|
||||
let ints=new map<int,int>();ints[-2147483648]=20;ints[0]=22;
|
||||
let longs=new map<long,int>();longs[-9223372036854775808]=20;longs[9223372036854775807]=22;
|
||||
let floats=new map<float,int>();floats[0.0]=20;floats[-0.0]=42;
|
||||
if floats.size()!=(1 as long) or (floats[0.0] else 0)!=42{return 0;}
|
||||
let flags=new map<bool,bool>();flags[false]=false;flags[true]=true;
|
||||
if flags[false].hasNone() or (flags[false] else true){return 0;}
|
||||
let text=new map<str,int>();text["hel"+"lo"]=42;text[""]=0;text["ação 😀"]=20;
|
||||
if (text["hello"] else 0)!=42 or text.size()!=(3 as long){return 0;}
|
||||
return (ints[-2147483648] else 0)+(longs[9223372036854775807] else 0);
|
||||
""");
|
||||
compile("objects","""
|
||||
declare struct Item(pub mut value:int);
|
||||
declare contract Read{fn read()->int;}
|
||||
implements Read for Item using x{fn read()->int{return x.value;}}
|
||||
declare service Probe{fn main()->int{
|
||||
let a=new Item(20);let b=new Item(20);let values=new map<Item,Item>();
|
||||
values[a]=a;values[b]=b;a.value=42;
|
||||
if values.size()!=(2 as long){return 0;}
|
||||
if let stored=values[a]{if stored!=a or stored.value!=42{return 0;}}else{return 0;}
|
||||
let views=new map<Read,int>();views[a as Read]=20;views[b as Read]=22;
|
||||
if views.size()!=(2 as long){return 0;}
|
||||
let receivers=new map<Read,Read>();receivers[a as Read]=b as Read;
|
||||
let capture=receivers.cursor();receivers.clear();
|
||||
if let e=capture.current(){if e.key().read()!=42 or e.value().read()!=20{return 0;}}else{return 0;}
|
||||
return (views[a as Read] else 0)+(views[b as Read] else 0);
|
||||
}}
|
||||
""");
|
||||
String random;
|
||||
try(var stream=getClass().getResourceAsStream("/game/stdlib/1/sdk/random/main.pbs")) {
|
||||
assertNotNull(stream);random=new String(stream.readAllBytes(),java.nio.charset.StandardCharsets.UTF_8);
|
||||
}
|
||||
compile("random",random+"""
|
||||
fn randomMapProbe()->int{
|
||||
let values=new map<Random,Random>();let a=random.new(42);let b=random.new(42);
|
||||
values[a]=b;values[b]=a;random.next(a);
|
||||
if values.size()!=(2 as long) or values.containsKey(a)==false{return 0;}
|
||||
if let found=values[a]{if found!=b{return 0;}}else{return 0;}return 42;
|
||||
}
|
||||
declare service Probe{fn main()->int{return randomMapProbe();}}
|
||||
""");
|
||||
probe("references","""
|
||||
let a=new array<int>(1);a[0]=20;let b=new array<int>(1);b[0]=20;
|
||||
let arrays=new map<array<int>,int>();arrays[a]=20;arrays[b]=22;a[0]=42;
|
||||
if arrays.size()!=(2 as long){return 0;}
|
||||
let f:Fn(int)->int=fn[](x:int)->int{return x;};let g:Fn(int)->int=fn[](x:int)->int{return x;};
|
||||
let functions=new map<Fn(int)->int,int>();functions[f]=20;functions[g]=22;
|
||||
if functions.size()!=(2 as long) or (arrays[a] else 0)!=20{return 0;}
|
||||
return (functions[f] else 0)+(functions[g] else 0);
|
||||
""");
|
||||
}
|
||||
@Test void contentReplacementPreservesTheOriginalRepresentativeAndSnapshot()throws Exception {
|
||||
compile("content","""
|
||||
declare struct Item(pub id:int,pub mut score:int);
|
||||
declare service Policy{}
|
||||
implements Identity<Item> for Policy using p{
|
||||
fn hash(v:Item)->long{return v.id as long;}
|
||||
fn equals(a:Item,b:Item)->bool{return a.id==b.id;}
|
||||
}
|
||||
declare service Probe{fn main()->int{
|
||||
let a=new Item(7,20);let equal=new Item(7,22);let values=new map<Item,Item>(Policy);
|
||||
values[a]=a;let before=values.cursor();
|
||||
let old=values.put(new keyval<Item,Item>(equal,equal));
|
||||
if let item=old{if item!=a{return 0;}}else{return 0;}
|
||||
if values.size()!=(1 as long){return 0;}
|
||||
if let entry=values.cursor().current(){if entry.key()!=a or entry.value()!=equal{return 0;}}else{return 0;}
|
||||
if let entry=before.current(){if entry.key()!=a or entry.value()!=a{return 0;}}else{return 0;}
|
||||
a.score=42;if let entry=before.current(){if entry.value().score!=42{return 0;}}else{return 0;}
|
||||
values.remove(equal);values[equal]=equal;
|
||||
if let entry=values.cursor().current(){if entry.key()!=equal{return 0;}}else{return 0;}
|
||||
let one=new keyval<Item,Item>(a,equal);let two=new keyval<Item,Item>(a,equal);
|
||||
let associations=new set<keyval<Item,Item>>();associations.add(one);associations.add(two);
|
||||
if associations.size()!=(2 as long){return 0;}return 42;
|
||||
}}
|
||||
""");
|
||||
}
|
||||
@Test void collisionCountersCoverRehashAndChainRemoval()throws Exception {
|
||||
compile("collisions","""
|
||||
declare struct Policy(pub mut hashes:int,pub mut comparisons:int);
|
||||
implements Identity<int> for Policy using p{
|
||||
fn hash(v:int)->long{p.hashes=p.hashes+1;return -9223372036854775808;}
|
||||
fn equals(a:int,b:int)->bool{p.comparisons=p.comparisons+1;return a==b;}
|
||||
}
|
||||
declare service Probe{fn main()->int{
|
||||
let policy=new Policy(0,0);let values=new map<int,int>(policy);
|
||||
for i:int from 0 until 6{values[i]=i;}
|
||||
if policy.hashes!=6 or policy.comparisons!=15{return 0;}
|
||||
values[6]=6;if policy.hashes!=7 or policy.comparisons!=21{return 0;}
|
||||
let capture=values.cursor();if policy.hashes!=7 or policy.comparisons!=21{return 0;}
|
||||
let total:int=0;
|
||||
while true{if let entry=capture.current(){total=total+entry.value();}else{break;}if capture.hasNext(){capture.next();}else{break;}}
|
||||
if total!=21{return 0;}
|
||||
values[6]=42;if values.size()!=(7 as long) or (values[6] else 0)!=42{return 0;}
|
||||
for i:int from 7 until 40{values[i]=i;}
|
||||
for i:int from 0 until 40{if values.containsKey(i)==false{return 0;}}
|
||||
values.remove(20);values.remove(39);values.remove(0);
|
||||
if values.containsKey(20) or values.containsKey(39) or values.containsKey(0){return 0;}
|
||||
for i:int from 0 until 40{values.remove(i);}
|
||||
if values.isEmpty()==false{return 0;}return 42;
|
||||
}}
|
||||
""");
|
||||
probe("arithmetic","""
|
||||
let maximum:long=4294967295;let sizeMaximum:long=9223372036854775807;
|
||||
if _hashCapacity(0,1)!=(8 as long) or _hashCapacity(8,6)!=(8 as long){return 0;}
|
||||
if _hashCapacity(8,7)!=(16 as long) or _hashCapacity(maximum-1,maximum)!=maximum{return 0;}
|
||||
if _hashCapacity(maximum,maximum+1)!=maximum or _hashNextSize(sizeMaximum-1)!=sizeMaximum{return 0;}
|
||||
if _hashBucket(-9223372036854775808,maximum)<(0 as long) or _hashBucket(-1,8)!=(7 as long){return 0;}return 42;
|
||||
""");
|
||||
probe("fault-overflow","_hashNextSize(9223372036854775807);return 0;");
|
||||
}
|
||||
@Test void groupedKeysValuesAndOptionalCarriersPreserveFullPayloads()throws Exception {
|
||||
compile("tuple","""
|
||||
declare service Policy{}
|
||||
implements Identity<(a:int,b:int)> for Policy using p{
|
||||
fn hash(v:(a:int,b:int))->long{return -1;}
|
||||
fn equals(a:(a:int,b:int),b:(a:int,b:int))->bool{return a.a==b.a&&a.b==b.b;}
|
||||
}
|
||||
declare service Probe{fn main()->int{
|
||||
let m=new map<(a:int,b:int),optional (left:int,right:int)>(Policy);
|
||||
let key=(a:20,b:22);m[key]=some((left:20,right:22));
|
||||
for i:int from 0 until 20{m[(a:i,b:0)]=none;}
|
||||
let walk=m.cursor();m.clear();let total:int=0;
|
||||
while true{if let entry=walk.current(){if let payload=entry.value(){total=total+payload.left+payload.right;}}else{break;}if walk.hasNext(){walk.next();}else{break;}}
|
||||
return total;
|
||||
}}
|
||||
""");
|
||||
compile("native","""
|
||||
[BuiltinType(name="vec2",version=1)]declare builtin type Vector(pub x:float,pub y:float){}
|
||||
declare service Policy{}
|
||||
implements Identity<Vector> for Policy using p{
|
||||
fn hash(v:Vector)->long{return -1;}
|
||||
fn equals(a:Vector,b:Vector)->bool{return a.x==b.x&&a.y==b.y;}
|
||||
}
|
||||
fn nativeProbe()->int{
|
||||
let values=new map<Vector,Vector>(Policy);let k=new Vector(1.0,2.0);values[k]=new Vector(20.0,22.0);
|
||||
if let previous=values.put(new keyval<Vector,Vector>(new Vector(1.0,2.0),new Vector(21.0,21.0))){if previous.x!=20.0 or previous.y!=22.0{return 0;}}else{return 0;}
|
||||
let capture=values.cursor();values.clear();if let e=capture.current(){if e.key().x!=1.0 or e.key().y!=2.0{return 0;}return (e.value().x+e.value().y) as int;}return 0;
|
||||
}
|
||||
declare service Probe{fn main()->int{return nativeProbe();}}
|
||||
""");
|
||||
compile("pixel","""
|
||||
[BuiltinType(name="color",version=1)]declare builtin type Color(pub raw:long){}
|
||||
[BuiltinConst(target="color",name="red",version=1)]declare const RED:Color;
|
||||
[BuiltinType(name="pixel",version=1)]declare builtin type Pixel(pub x:long,pub y:long,pub color:Color){}
|
||||
declare service Policy{}
|
||||
implements Identity<Pixel> for Policy using p{
|
||||
fn hash(v:Pixel)->long{return -1;}
|
||||
fn equals(a:Pixel,b:Pixel)->bool{return a.x==b.x&&a.y==b.y&&a.color==b.color;}
|
||||
}
|
||||
fn pixelProbe()->int{
|
||||
let values=new map<Pixel,Pixel>(Policy);let k=new Pixel(1,2,RED);values[k]=new Pixel(20,22,RED);
|
||||
let capture=values.cursor();values.clear();if let e=capture.current(){if e.key().x!=(1 as long) or e.key().y!=(2 as long) or e.value().color!=RED{return 0;}return (e.value().x+e.value().y) as int;}return 0;
|
||||
}
|
||||
declare service Probe{fn main()->int{return pixelProbe();}}
|
||||
""");
|
||||
}
|
||||
@Test void cursorKeepsTheSharedFullStateTableAndIndependentAssociations()throws Exception {
|
||||
probe("cursor-empty","""
|
||||
let values=new map<int,int>();let capture=values.cursor();
|
||||
for i:int from 0 until 3{if capture.hasNext() or capture.current().hasSome(){return 0;}capture.next();}return 42;
|
||||
""");
|
||||
probe("cursor-single","""
|
||||
let values=new map<int,int>();values[0]=42;let capture=values.cursor();values[0]=0;values.clear();
|
||||
for i:int from 0 until 3{if capture.hasNext(){return 0;}if let e=capture.current(){if e.key()!=0 or e.value()!=42{return 0;}}else{return 0;}capture.next();}return 42;
|
||||
""");
|
||||
probe("snapshot","""
|
||||
let values=new map<int,int>();values[0]=20;values[1]=22;let capture=values.cursor();
|
||||
values[0]=0;values.remove(1);for i:int from 2 until 40{values[i]=i;}values.clear();
|
||||
let sum:int=0;let count:int=0;
|
||||
while true{if let e=capture.current(){sum=sum+e.value();count=count+1;}else{break;}if capture.hasNext(){capture.next();}else{break;}}
|
||||
if count!=2{return 0;}return sum;
|
||||
""");
|
||||
}
|
||||
@Test void receiverAndArgumentsAreEvaluatedOnceInSourceOrder()throws Exception {
|
||||
compile("evaluation","""
|
||||
declare struct Effects(pub mut trace:int,pub m:map<str,int>){
|
||||
fn receiver()->map<str,int>{this.trace=this.trace*10+1;return this.m;}
|
||||
fn key()->str{this.trace=this.trace*10+2;return "a";}
|
||||
fn value()->int{this.trace=this.trace*10+3;return 42;}
|
||||
}
|
||||
fn insert(values:map<str,int>,key:str,value:int){values[key]=value;}
|
||||
declare service Probe{fn main()->int{
|
||||
let m=new map<str,int>();let e=new Effects(0,m);e.receiver()[e.key()]=e.value();
|
||||
if e.trace!=123{return 0;}e.trace=0;let found=e.receiver()[e.key()];if e.trace!=12{return 0;}
|
||||
e.trace=0;insert apply (value:e.value(),key:e.key(),values:e.receiver());if e.trace!=321{return 0;}
|
||||
e.trace=0;let removed=e.receiver().remove(e.key());if e.trace!=12{return 0;}return removed else 0;
|
||||
}}
|
||||
""");
|
||||
}
|
||||
@Test void callbacksRespectGuardAndReadOnlyPreparation()throws Exception {
|
||||
for(int action=1;action<=7;action++){
|
||||
String operation=switch(action){case 1->"let found=m[0];";case 2->"m[0]=42;";case 3->"m.containsKey(0);";case 4->"m.put(new keyval<int,int>(0,42));";case 5->"m.remove(0);";case 6->"m.clear();";default->"let failure=1/0;";};
|
||||
compile("fault-callback-"+action,"""
|
||||
declare struct Policy(pub mut owner:optional (map<int,int>));
|
||||
implements Identity<int> for Policy using p{
|
||||
fn hash(v:int)->long{if let m=p.owner{OPERATION}return 0;}
|
||||
fn equals(a:int,b:int)->bool{return a==b;}
|
||||
}
|
||||
declare service Probe{fn main()->int{let p=new Policy(none);let m=new map<int,int>(p);p.owner=some(m);m[0]=42;return 0;}}
|
||||
""".replace("OPERATION",operation));
|
||||
compile("fault-equals-"+action,"""
|
||||
declare struct Policy(pub mut owner:optional (map<int,int>),pub mut armed:bool);
|
||||
implements Identity<int> for Policy using p{
|
||||
fn hash(v:int)->long{return 0;}
|
||||
fn equals(a:int,b:int)->bool{if p.armed{if let m=p.owner{OPERATION}}return a==b;}
|
||||
}
|
||||
declare service Probe{fn main()->int{let p=new Policy(none,false);let m=new map<int,int>(p);p.owner=some(m);m[0]=20;p.armed=true;m[1]=22;return 0;}}
|
||||
""".replace("OPERATION",operation));
|
||||
}
|
||||
compile("callback-reads","""
|
||||
declare struct Policy(pub mut owner:optional (map<int,int>),pub mut calls:int);
|
||||
implements Identity<int> for Policy using p{
|
||||
fn hash(v:int)->long{
|
||||
if let m=p.owner{if m.size()!=(p.calls as long){let failure=1/0;}let c=m.cursor();if p.calls==0&&c.current().hasSome(){let failure=1/0;}if p.calls>0&&c.current().hasNone(){let failure=1/0;}}
|
||||
p.calls=p.calls+1;return 0;
|
||||
}
|
||||
fn equals(a:int,b:int)->bool{return a==b;}
|
||||
}
|
||||
declare service Probe{fn main()->int{let p=new Policy(none,0);let m=new map<int,int>(p);p.owner=some(m);m[0]=20;m[1]=22;if p.calls!=2{return 0;}return 42;}}
|
||||
""");
|
||||
}
|
||||
@Test void resourceFixturesExposeEachStructuralPhase()throws Exception {
|
||||
for(var operation:java.util.Map.of(
|
||||
"growth","values[42]=42;","add","values[42]=42;","replace","values[1]=42;",
|
||||
"put","let old=values.put(new keyval<int,int>(1,42));","remove","let old=values.remove(1);",
|
||||
"clear","values.clear();","cursor","let capture=values.cursor();","read","let found=values[1];").entrySet()){
|
||||
compile("refusal-"+operation.getKey(),"""
|
||||
fn mutationMarker(){let marker:int=314160;}
|
||||
fn completedMarker(){let marker:int=314161;}
|
||||
fn performSecond(values:map<int,int>){OPERATION}
|
||||
fn perform(values:map<int,int>){performSecond(values);}
|
||||
declare service Probe{fn main()->int{let values=new map<int,int>();for i:int from 0 until COUNT{values[i]=i;}mutationMarker();perform(values);completedMarker();return 42;}}
|
||||
""".replace("OPERATION",operation.getValue()).replace("COUNT",operation.getKey().equals("growth")?"6":"5"));
|
||||
}
|
||||
String sdk=PbsSetTest.sdk();int offset=sdk.indexOf("[SdkMap]");
|
||||
String injected=sdk.substring(0,offset)+sdk.substring(offset).replace("this.buckets = published;","""
|
||||
this.buckets = published;
|
||||
if this.length == (6 as long) {let injectedQuotaProbe=new array<int>(1000000);}
|
||||
""");
|
||||
PbsListCursorTest.compileCollection("map","injected-refusal-growth","""
|
||||
declare service Probe{fn main()->int{let values=new map<int,int>();for i:int from 0 until 6{values[i]=i;}values[42]=42;return 42;}}
|
||||
""",injected);
|
||||
}
|
||||
@Test void realSafepointsObserveKeysValuesAssociationsAndSnapshots()throws Exception {
|
||||
compile("gc","""
|
||||
declare struct Item(pub value:int);declare struct Garbage();
|
||||
fn collect(){let marker:int=314159;}
|
||||
fn makeCursor()->Cursor<keyval<Item,Item>>{
|
||||
let values=new map<Item,Item>();for i:int from 0 until 1200{let key=new Item(i);let value=new Item(i);values[key]=value;}return values.cursor();
|
||||
}
|
||||
fn useCursor(){let cursor=makeCursor();collect();for i:int from 0 until 1199{cursor.next();}collect();for i:int from 0 until 1200{cursor.next();}collect();}
|
||||
declare service Probe{fn main()->int{useCursor();for i:int from 0 until 1200{let x=new Garbage();}collect();return 42;}}
|
||||
""");
|
||||
compile("gc-collection","""
|
||||
declare struct Item(pub value:int);declare struct Garbage();
|
||||
fn collect(){let marker:int=314159;}
|
||||
fn pressure(){for i:int from 0 until 1200{let x=new Garbage();}}
|
||||
fn create()->map<Item,Item>{let m=new map<Item,Item>();for i:int from 0 until 64{m[new Item(i)]=new Item(i);}return m;}
|
||||
fn replace(values:map<Item,Item>){let c=values.cursor();for i:int from 0 until 3{if let e=c.current(){values[e.key()]=new Item(42);}c.next();}}
|
||||
fn discard(values:map<Item,Item>){let c=values.cursor();for i:int from 0 until 3{if let e=c.current(){values.remove(e.key());}c.next();}}
|
||||
fn use(){let m=create();pressure();collect();replace(m);pressure();collect();discard(m);pressure();collect();m.clear();pressure();collect();}
|
||||
declare service Probe{fn main()->int{use();pressure();collect();return 42;}}
|
||||
""");
|
||||
}
|
||||
@Test void importsAndGenericReexportsUseRealSdkModules(@TempDir Path root)throws Exception {
|
||||
Files.createDirectories(root.resolve("src/facade"));
|
||||
Files.writeString(root.resolve("prometeu.json"),"""
|
||||
{"name":"app","version":"1.0.0","language":"pbs","stdlib":"1","target":"Game","dependencies":[]}
|
||||
""");
|
||||
Files.writeString(root.resolve("src/mod.barrel"),"pub fn frame()->void;");
|
||||
Files.writeString(root.resolve("src/facade/mod.barrel"),"pub struct Values<K,V>;pub struct Entry<K,V>;pub contract Walk<T>;");
|
||||
Files.writeString(root.resolve("src/facade/main.pbs"),"import {map as Values,keyval as Entry,Cursor as Walk} from @sdk:collections;");
|
||||
Files.writeString(root.resolve("src/main.pbs"),"""
|
||||
import {Values,Entry,Walk} from @app:facade;
|
||||
[Frame]fn frame()->void{
|
||||
let values:Values<str,optional int>=new Values();values["left"]=some(20);
|
||||
let old=values.put(new Entry<str,optional int>("right",some(22)));
|
||||
if old.hasSome(){let failure=1/0;}
|
||||
values["empty"]=none;let c:Walk<Entry<str,optional int>>=values.cursor();values.clear();
|
||||
let sum:int=0;while true{if let e=c.current(){if let v=e.value(){sum=sum+v;}}else{break;}if c.hasNext(){c.next();}else{break;}}
|
||||
if sum!=42{let failure=1/0;}
|
||||
}
|
||||
""");
|
||||
var compiled=p.studio.compiler.workspaces.BuilderPipelineService.INSTANCE.compile(
|
||||
p.studio.compiler.models.BuilderPipelineContext.fromConfig(new p.studio.compiler.messages.BuilderPipelineConfig(false,root.toString())),
|
||||
p.studio.utilities.logs.LogAggregator.stdout());
|
||||
assertFalse(compiled.diagnostics().stream().anyMatch(d->d.isError()),compiled.diagnostics().toString());
|
||||
Files.write(Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("pbs-map-imports.pbx"),compiled.bytecodeBytes());
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -44,13 +44,13 @@ class PbsSetTest {
|
||||
""");
|
||||
probe("arithmetic","""
|
||||
let maximum:long=4294967295;let sizeMaximum:long=9223372036854775807;
|
||||
if _setCapacity(0,1)!=(8 as long) or _setCapacity(8,6)!=(8 as long) {return 0;}
|
||||
if _setCapacity(8,7)!=(16 as long) or _setCapacity(16,13)!=(32 as long) {return 0;}
|
||||
if _setCapacity(maximum-1,maximum)!=maximum {return 0;}
|
||||
if _setCapacity(maximum,maximum+1)!=maximum {return 0;}
|
||||
if _setNextSize(sizeMaximum-1)!=sizeMaximum {return 0;}
|
||||
if _hashCapacity(0,1)!=(8 as long) or _hashCapacity(8,6)!=(8 as long) {return 0;}
|
||||
if _hashCapacity(8,7)!=(16 as long) or _hashCapacity(16,13)!=(32 as long) {return 0;}
|
||||
if _hashCapacity(maximum-1,maximum)!=maximum {return 0;}
|
||||
if _hashCapacity(maximum,maximum+1)!=maximum {return 0;}
|
||||
if _hashNextSize(sizeMaximum-1)!=sizeMaximum {return 0;}
|
||||
let minimum:long=-9223372036854775808;
|
||||
if _setBucket(minimum,maximum)<(0 as long) or _setBucket(-1,8)!=(7 as long) {return 0;}
|
||||
if _hashBucket(minimum,maximum)<(0 as long) or _hashBucket(-1,8)!=(7 as long) {return 0;}
|
||||
return 42;
|
||||
""");
|
||||
}
|
||||
@@ -254,7 +254,7 @@ class PbsSetTest {
|
||||
}}
|
||||
""");
|
||||
for(int mode=1;mode<=5;mode++)compile("fault-callback-"+mode,policy+"declare service Probe {fn main()->int {let policy=new Policy(none,"+mode+",0);let values=new set<int>(policy);let alias=values;policy.target=some(alias);values.add(42);return 0;}}");
|
||||
probe("fault-overflow","_setNextSize(9223372036854775807);return 0;");
|
||||
probe("fault-overflow","_hashNextSize(9223372036854775807);return 0;");
|
||||
}
|
||||
@Test void arraysFunctionsAndRandomKeepReferenceDefaults()throws Exception {
|
||||
compile("references","""
|
||||
|
||||
+18
-4
@@ -245,8 +245,8 @@ public final class PbsGenericInstantiation {
|
||||
return null;
|
||||
}
|
||||
if (PbsSdkCollections.isCollection(template) && PbsSdkCollections.directOptional(arguments.getFirst())) {
|
||||
error(PbsSdkCollections.isSet(template)?"SET_OPTIONAL_ELEMENT":PbsSdkCollections.isLinked(template) ? "LINKED_OPTIONAL_ELEMENT" : "LIST_OPTIONAL_ELEMENT",
|
||||
"SDK " + name(template) + "<T> does not permit a directly optional element", site);
|
||||
error(PbsSdkCollections.isMap(template)?"MAP_OPTIONAL_KEY":PbsSdkCollections.isSet(template)?"SET_OPTIONAL_ELEMENT":PbsSdkCollections.isLinked(template) ? "LINKED_OPTIONAL_ELEMENT" : "LIST_OPTIONAL_ELEMENT",
|
||||
"SDK " + name(template) + " does not permit a directly optional " + (PbsSdkCollections.isMap(template)?"key":"element"), site);
|
||||
return null;
|
||||
}
|
||||
var application = PbsAst.TypeRef.applied(name(template), arguments, template.span());
|
||||
@@ -548,6 +548,8 @@ public final class PbsGenericInstantiation {
|
||||
for(var member:a.target().pathSegments())target=new PbsAst.MemberExpr(target,member,a.target().span());
|
||||
}
|
||||
var expected = target == null ? locals.get(a.target().rootName()) : infer(target);
|
||||
if(target instanceof PbsAst.IndexExpr && expected!=null && expected.kind()==PbsAst.TypeRefKind.OPTIONAL)
|
||||
expected=expected.inner();
|
||||
return new PbsAst.AssignStatement(a.target(), a.operator(), expression(a.value(), expected), a.span());
|
||||
}
|
||||
return super.statement(s);
|
||||
@@ -555,6 +557,13 @@ public final class PbsGenericInstantiation {
|
||||
|
||||
@Override public PbsAst.Expression expression(PbsAst.Expression e, PbsAst.TypeRef expected) {
|
||||
if (e != null) { budget.visit(e.span(), chain.size()); budget.store(e.span(), 64); }
|
||||
if(e instanceof PbsAst.IndexExpr index) {
|
||||
var receiver=expression(index.receiver(),null);
|
||||
var owner=types.declaration(infer(receiver));
|
||||
var origin=PbsContractTypes.applicationOrigin(owner);
|
||||
var key=origin!=null&&PbsSdkCollections.isMap(origin.declaration())?origin.arguments().getFirst():null;
|
||||
return new PbsAst.IndexExpr(receiver,expression(index.index(),key),index.span());
|
||||
}
|
||||
if(symbolicProbe&&e instanceof PbsAst.MemberExpr member) {
|
||||
var receiver=infer(member.receiver());
|
||||
if(receiver!=null)requiredShapes.add(receiver.name());
|
||||
@@ -647,11 +656,12 @@ public final class PbsGenericInstantiation {
|
||||
else { error("CONTEXT", "Construction of "+n.typeName()+" requires explicit arguments or an expected application", n.span()); return n; }
|
||||
}
|
||||
var concreteType = type(applied);
|
||||
if(PbsSdkCollections.isSet(s)&&n.arguments().isEmpty()&&!symbolicProbe) {
|
||||
if((PbsSdkCollections.isSet(s)||PbsSdkCollections.isMap(s))&&n.arguments().isEmpty()&&!symbolicProbe) {
|
||||
var owner=types.declaration(concreteType);
|
||||
var origin=PbsContractTypes.applicationOrigin(owner);
|
||||
if(origin!=null&&!PbsSdkCollections.hasDefaultIdentity(origin.arguments().getFirst(),types))
|
||||
error("SET_IDENTITY_REQUIRED","This Set element type requires an explicit Identity<T> strategy",n.span());
|
||||
error(PbsSdkCollections.isMap(s)?"MAP_IDENTITY_REQUIRED":"SET_IDENTITY_REQUIRED",
|
||||
"This collection key/element type requires an explicit Identity strategy",n.span());
|
||||
}
|
||||
if (symbolicProbe) requiredShapes.add(concreteType.name());
|
||||
var constructor = PbsSdkCollections.isCollection(s) && n.ctorName() == null ? "make" : n.ctorName();
|
||||
@@ -677,6 +687,10 @@ public final class PbsGenericInstantiation {
|
||||
case PbsAst.NewExpr n -> n.explicitType() != null ? n.explicitType() : PbsAst.TypeRef.simple(n.typeName(), n.span());
|
||||
case PbsAst.IndexExpr i -> {
|
||||
var receiver=infer(i.receiver());
|
||||
var declaration=types.declaration(receiver);
|
||||
var origin=PbsContractTypes.applicationOrigin(declaration);
|
||||
if(origin!=null&&PbsSdkCollections.hasIndexer(origin.declaration()))
|
||||
yield PbsAst.TypeRef.optional(origin.arguments().get(PbsSdkCollections.isMap(origin.declaration())?1:0),i.span());
|
||||
yield receiver!=null && receiver.kind()==PbsAst.TypeRefKind.ARRAY ? PbsAst.TypeRef.optional(receiver.inner(),i.span()) : null;
|
||||
}
|
||||
case PbsAst.GroupExpr g -> infer(g.expression());
|
||||
|
||||
+7
-1
@@ -170,7 +170,7 @@ final class PbsGenericTemplateValidator {
|
||||
context.error("CONTEXT", "Generic construction requires an expected application or explicit type arguments", n.span());
|
||||
if (d instanceof PbsAst.StructDecl s) {
|
||||
var env = bindings(s, result);
|
||||
var constructor = PbsSdkCollections.isIndexedCollection(s) && n.ctorName()==null ? "make" : n.ctorName();
|
||||
var constructor = PbsSdkCollections.isCollection(s) && n.ctorName()==null ? "make" : n.ctorName();
|
||||
var expectedParameters = constructor == null ? map(s.fields(), f -> new PbsAst.Parameter(f.name(), PbsTypeSubstitution.substitute(f.typeRef(), env), f.span()))
|
||||
: s.ctors().stream().filter(c -> c.name().equals(constructor) && c.parameters().size()==n.arguments().size()).findFirst().map(c ->
|
||||
map(c.parameters(), p -> new PbsAst.Parameter(p.name(), PbsTypeSubstitution.substitute(p.typeRef(), env), p.span()))).orElse(ReadOnlyList.empty());
|
||||
@@ -209,6 +209,12 @@ final class PbsGenericTemplateValidator {
|
||||
case PbsAst.UnaryExpr u -> { var value = infer(u.expression(), null); if (containsParameter(value)) capability(u.span()); yield value; }
|
||||
case PbsAst.IndexExpr i -> {
|
||||
var receiver = infer(i.receiver(), null);
|
||||
var declaration=context.declaration(receiver);
|
||||
if(declaration instanceof PbsAst.StructDecl s&&PbsSdkCollections.hasIndexer(s)) {
|
||||
var method=s.methods().stream().filter(m->m.name().equals("_at")).findFirst().orElse(null);
|
||||
if(method!=null&&PbsSdkCollections.isMap(s))infer(i.index(),PbsTypeSubstitution.substitute(method.parameters().getFirst().typeRef(),bindings(s,receiver)));
|
||||
if(method!=null)yield PbsTypeSubstitution.substitute(method.returnType(),bindings(s,receiver));
|
||||
}
|
||||
yield receiver != null && receiver.kind() == PbsAst.TypeRefKind.ARRAY ? PbsAst.TypeRef.optional(receiver.inner(), i.span()) : null;
|
||||
}
|
||||
case PbsAst.GroupExpr g -> infer(g.expression(), expected);
|
||||
|
||||
+7
-1
@@ -18,8 +18,14 @@ public final class PbsSdkCollections {
|
||||
public static boolean isSet(PbsAst.TopDecl declaration) {
|
||||
return declaration instanceof PbsAst.StructDecl s && attribute(s.attributes(), "SdkSet") != null;
|
||||
}
|
||||
public static boolean isMap(PbsAst.TopDecl declaration) {
|
||||
return declaration instanceof PbsAst.StructDecl s && attribute(s.attributes(), "SdkMap") != null;
|
||||
}
|
||||
public static boolean hasIndexer(PbsAst.TopDecl declaration) {
|
||||
return isIndexedCollection(declaration) || isMap(declaration);
|
||||
}
|
||||
public static boolean isCollection(PbsAst.TopDecl declaration) {
|
||||
return isIndexedCollection(declaration)||isSet(declaration);
|
||||
return hasIndexer(declaration)||isSet(declaration);
|
||||
}
|
||||
public static boolean hasDefaultIdentity(PbsAst.TypeRef type,PbsContractTypes types) {
|
||||
while(type!=null&&type.kind()==PbsAst.TypeRefKind.GROUP)type=type.inner();
|
||||
|
||||
+12
-5
@@ -572,7 +572,7 @@ final class PbsExecutableBodyLowerer {
|
||||
var receiverType = PbsRuntimeTypes.unwrap(expressionType(member.receiver(), context));
|
||||
if (receiverType != null && receiverType.kind() == PbsAst.TypeRefKind.OPTIONAL
|
||||
&& (member.memberName().equals("hasSome") || member.memberName().equals("hasNone"))) {
|
||||
lowerExpression(member.receiver(), context);
|
||||
lowerExpected(member.receiver(), receiverType, context);
|
||||
int slot = save(1, callExpr.span(), context);
|
||||
optionalPresence(slot, receiverType, callExpr.span(), context);
|
||||
if (member.memberName().equals("hasNone")) {
|
||||
@@ -1170,7 +1170,7 @@ final class PbsExecutableBodyLowerer {
|
||||
var array = PbsRuntimeTypes.unwrap(expressionType(index.receiver(), c));
|
||||
if(array==null)return null;
|
||||
var declaration=c.types().structs.get(array.name());
|
||||
return p.studio.compiler.pbs.PbsSdkCollections.isIndexedCollection(declaration)
|
||||
return p.studio.compiler.pbs.PbsSdkCollections.hasIndexer(declaration)
|
||||
? declaration.methods().stream().filter(m->m.name().equals("_at")).findFirst().orElseThrow().returnType()
|
||||
: PbsAst.TypeRef.optional(array.inner(),index.span());
|
||||
}
|
||||
@@ -1238,6 +1238,11 @@ final class PbsExecutableBodyLowerer {
|
||||
var struct = c.types().structs.get(owner.name());
|
||||
var service = c.types().services.get(owner.name());
|
||||
var methods = struct != null ? struct.methods() : service != null ? service.methods() : ReadOnlyList.<PbsAst.FunctionDecl>empty();
|
||||
var applicable=methods.stream().filter(candidate -> candidate.name().equals(member.memberName())
|
||||
&& parametersMatch(candidate.parameters(),call.arguments(),c)).toList();
|
||||
// A chained receiver has its own result type; the outer call's expected
|
||||
// bool (for example hasSome) cannot erase a uniquely resolved optional.
|
||||
if(applicable.size()==1)return PbsTypeSubstitution.replaceSelf(applicable.getFirst().returnType(),owner.name());
|
||||
for (var candidate : methods) if (candidate.name().equals(member.memberName()) && parametersMatch(candidate.parameters(),call.arguments(),c)
|
||||
&& returnMatches(candidate.returnType(),owner.name(),c)) return PbsTypeSubstitution.replaceSelf(candidate.returnType(),owner.name());
|
||||
var method=c.types().signatures.get(owner.name()+"."+member.memberName()+"#"+call.arguments().size());
|
||||
@@ -1692,12 +1697,14 @@ final class PbsExecutableBodyLowerer {
|
||||
|
||||
private boolean lowerCollectionIndex(PbsAst.IndexExpr index, PbsAst.Expression value, PbsAst.TypeRef type, PbsExecutableLoweringContext c) {
|
||||
var declaration=type==null?null:c.types().structs.get(type.name());
|
||||
if(!p.studio.compiler.pbs.PbsSdkCollections.isIndexedCollection(declaration))return false;
|
||||
if(!p.studio.compiler.pbs.PbsSdkCollections.hasIndexer(declaration))return false;
|
||||
var name=value==null?"_at":"_put";
|
||||
var method=declaration.methods().stream().filter(m->m.name().equals(name)).findFirst().orElseThrow();
|
||||
lowerExpected(index.receiver(),type,c);
|
||||
lowerArrayIndex(index.index(),c);
|
||||
int pops=2;
|
||||
var key=method.parameters().getFirst().typeRef();
|
||||
if(p.studio.compiler.pbs.PbsSdkCollections.isMap(declaration))lowerExpected(index.index(),key,c);
|
||||
else lowerArrayIndex(index.index(),c);
|
||||
int pops=1+c.types().slots(key);
|
||||
if(value!=null) {
|
||||
var element=method.parameters().get(1).typeRef();
|
||||
lowerExpected(value,element,c);pops+=c.types().slots(element);
|
||||
|
||||
+1
-1
@@ -685,7 +685,7 @@ final class PbsDeclarationParser {
|
||||
final String targetSurface) {
|
||||
for (final var attribute : attributes) {
|
||||
if ("Doc".equals(attribute.name()) || attribute.trustedSdkOrigin() &&
|
||||
java.util.Set.of("SdkList", "SdkLinked", "SdkSet").contains(attribute.name()) && "struct declarations".equals(targetSurface)) {
|
||||
java.util.Set.of("SdkList", "SdkLinked", "SdkSet", "SdkMap").contains(attribute.name()) && "struct declarations".equals(targetSurface)) {
|
||||
continue;
|
||||
}
|
||||
p.studio.compiler.source.diagnostics.Diagnostics.error(context.diagnostics(),
|
||||
|
||||
+29
-3
@@ -41,7 +41,7 @@ public final class PbsEditorialSupportService {
|
||||
final Integer previousTokenIndex = context.previousSignificantTokenIndexAt(offset);
|
||||
if (previousTokenIndex != null && context.token(previousTokenIndex).kind() == PbsTokenKind.DOT) {
|
||||
final TypeView receiverType = context.resolveReceiverTypeBeforeDot(previousTokenIndex, scopeState);
|
||||
return context.memberCompletions(receiverType);
|
||||
return context.memberCompletions(receiverType, context.receiverExpressionBefore(previousTokenIndex) instanceof PbsAst.ThisExpr);
|
||||
}
|
||||
return context.generalCompletions(scopeState);
|
||||
}
|
||||
@@ -72,6 +72,7 @@ public final class PbsEditorialSupportService {
|
||||
final Integer previousTokenIndex = context.previousSignificantTokenIndex(tokenIndex);
|
||||
if (previousTokenIndex != null && context.token(previousTokenIndex).kind() == PbsTokenKind.DOT) {
|
||||
final TypeView receiverType = context.resolveReceiverTypeBeforeDot(previousTokenIndex, scopeState);
|
||||
if(!context.visibleMember(receiverType,token.lexeme(),context.receiverExpressionBefore(previousTokenIndex) instanceof PbsAst.ThisExpr))return Optional.empty();
|
||||
return context.resolveMemberHover(receiverType, token.lexeme());
|
||||
}
|
||||
return context.resolveSymbolHover(token.lexeme(), tokenIndex, scopeState);
|
||||
@@ -753,13 +754,29 @@ public final class PbsEditorialSupportService {
|
||||
}
|
||||
|
||||
private List<PbsEditorialCompletionCandidate> memberCompletions(final TypeView receiverType) {
|
||||
return memberCompletions(receiverType, false);
|
||||
}
|
||||
private boolean visibleMember(TypeView receiverType,String name,boolean ownFields) {
|
||||
if(receiverType==null||receiverType.kind()==Kind.UNKNOWN)return false;
|
||||
if(receiverType.kind()!=Kind.STRUCT)return true;
|
||||
if(model.isSdkPrivateMember(receiverType,name))return false;
|
||||
var symbolic=symbolicStruct(receiverType);
|
||||
if(symbolic!=null) {
|
||||
var field=symbolic.fields().stream().filter(f->f.name().equals(name)).findFirst();
|
||||
if(field.isPresent())return ownFields||field.get().isPublic();
|
||||
}
|
||||
var owner=model.structs.get(receiverType.name());
|
||||
var field=owner==null?null:owner.fields().get(name);
|
||||
return field==null||ownFields||field.isPublic();
|
||||
}
|
||||
private List<PbsEditorialCompletionCandidate> memberCompletions(final TypeView receiverType, boolean ownFields) {
|
||||
if (receiverType == null) {
|
||||
return List.of();
|
||||
}
|
||||
final Map<String, PbsEditorialCompletionCandidate> completions = new LinkedHashMap<>();
|
||||
var symbolic = symbolicStruct(receiverType);
|
||||
if (symbolic != null) {
|
||||
for (var field : symbolic.fields()) if(!p.studio.compiler.pbs.PbsSdkCollections.isCollection(symbolic)||field.isPublic()) completions.put(field.name(), new PbsEditorialCompletionCandidate(
|
||||
for (var field : symbolic.fields()) if(ownFields||field.isPublic()) completions.put(field.name(), new PbsEditorialCompletionCandidate(
|
||||
field.name(), PbsEditorialSymbolKind.FIELD, field.typeRef().surface(), symbolic.name()));
|
||||
for (var method : symbolic.methods()) if(p.studio.compiler.pbs.PbsSdkCollections.attribute(method.attributes(),"SdkPrivate")==null) completions.put(method.name(), new PbsEditorialCompletionCandidate(
|
||||
method.name(), PbsEditorialSymbolKind.METHOD, signatureFromFunction(method.name(), method.parameters(),
|
||||
@@ -778,7 +795,7 @@ public final class PbsEditorialSupportService {
|
||||
final StructInfo structInfo = model.structs.get(receiverType.name());
|
||||
if (structInfo != null) {
|
||||
for (final var field : structInfo.fields().entrySet()) {
|
||||
if(model.isSdkCollection(receiverType)&&!field.getValue().isPublic())continue;
|
||||
if(!ownFields&&!field.getValue().isPublic())continue;
|
||||
completions.put(field.getKey(), new PbsEditorialCompletionCandidate(
|
||||
field.getKey(),
|
||||
PbsEditorialSymbolKind.FIELD,
|
||||
@@ -959,6 +976,7 @@ public final class PbsEditorialSupportService {
|
||||
final Integer previousTokenIndex = previousSignificantTokenIndex(tokenIndex);
|
||||
if (previousTokenIndex != null && token(previousTokenIndex).kind() == PbsTokenKind.DOT) {
|
||||
final TypeView receiverType = resolveReceiverTypeBeforeDot(previousTokenIndex, scopeState);
|
||||
if(!visibleMember(receiverType,token.lexeme(),receiverExpressionBefore(previousTokenIndex) instanceof PbsAst.ThisExpr))return List.of();
|
||||
return resolveMemberDefinition(receiverType, token.lexeme());
|
||||
}
|
||||
return resolveSymbolDefinition(token.lexeme(), tokenIndex, scopeState, offset);
|
||||
@@ -1305,6 +1323,7 @@ public final class PbsEditorialSupportService {
|
||||
private List<PbsEditorialSignature> resolveMemberSignatures(
|
||||
final TypeView receiverType,
|
||||
final String memberName) {
|
||||
if(!visibleMember(receiverType,memberName,false))return List.of();
|
||||
return resolveMemberHover(receiverType, memberName)
|
||||
.map(PbsEditorialResolvedSymbol::signatures)
|
||||
.orElse(List.of());
|
||||
@@ -1749,6 +1768,13 @@ public final class PbsEditorialSupportService {
|
||||
return new CallSite(CallSiteKind.MEMBER, calleeToken.lexeme(), activeParameter, maybeDotIndex);
|
||||
}
|
||||
if (maybeDotIndex != null && token(maybeDotIndex).kind() == PbsTokenKind.NEW) {
|
||||
// Contextual construction records the application on the whole
|
||||
// NewExpr span rather than on an explicit angular type suffix.
|
||||
for(var resolution:genericResolutions.entrySet())
|
||||
if(resolution.getKey().getStart()==token(maybeDotIndex).start()
|
||||
&& resolution.getKey().getEnd()>=calleeToken.end()
|
||||
&& concreteSymbols.get(resolution.getValue()) instanceof PbsAst.StructDecl)
|
||||
return new CallSite(CallSiteKind.CONSTRUCTOR,resolution.getValue(),activeParameter,-1);
|
||||
return new CallSite(CallSiteKind.CONSTRUCTOR, calleeToken.lexeme(), activeParameter, -1);
|
||||
}
|
||||
return new CallSite(CallSiteKind.FUNCTION, calleeToken.lexeme(), activeParameter, -1);
|
||||
|
||||
+4
@@ -202,6 +202,10 @@ final class PbsFlowSemanticSupport {
|
||||
return type != null && p.studio.compiler.pbs.PbsSdkCollections.isIndexedCollection(contractTypes.declaration(
|
||||
type.sourceType() == null ? PbsAst.TypeRef.simple(type.name(), Span.none()) : type.sourceType()));
|
||||
}
|
||||
boolean isSdkMap(TypeView type) {
|
||||
return type != null && p.studio.compiler.pbs.PbsSdkCollections.isMap(contractTypes.declaration(
|
||||
type.sourceType() == null ? PbsAst.TypeRef.simple(type.name(), Span.none()) : type.sourceType()));
|
||||
}
|
||||
boolean isSdkCollection(TypeView type) {
|
||||
return type != null && p.studio.compiler.pbs.PbsSdkCollections.isCollection(contractTypes.declaration(
|
||||
type.sourceType() == null ? PbsAst.TypeRef.simple(type.name(), Span.none()) : type.sourceType()));
|
||||
|
||||
+7
@@ -52,6 +52,13 @@ final class PbsFlowStructuralExpressionAnalyzer {
|
||||
}
|
||||
if (expression instanceof PbsAst.IndexExpr index) {
|
||||
final var receiver = analyzeValueExpression(index.receiver(), context, null).type();
|
||||
if (model.isSdkMap(receiver)) {
|
||||
var read=model.structs.get(receiver.name()).methods().get("_at").getFirst();
|
||||
var key=analyzeValueExpression(index.index(),context,read.inputTypes().getFirst()).type();
|
||||
if(!typeOps.compatible(key,read.inputTypes().getFirst())) Diagnostics.error(diagnostics,
|
||||
"E_SEM_MAP_KEY_TYPE", "Map key does not match its declared key type", index.index().span());
|
||||
return ExprResult.type(read.outputType());
|
||||
}
|
||||
checkArrayIndex(index.index(), context);
|
||||
if (model.isSdkIndexedCollection(receiver)) {
|
||||
return ExprResult.type(model.structs.get(receiver.name()).methods().get("_at").getFirst().outputType());
|
||||
|
||||
+200
-10
@@ -320,19 +320,19 @@ fn _collectionHash<T>(value: T) -> long { return 0; }
|
||||
[IdentityPrimitive(name = "defaultEquals")]
|
||||
fn _collectionEquals<T>(left: T, right: T) -> bool { return false; }
|
||||
|
||||
fn _setBucket(hash: long, capacity: long) -> long {
|
||||
fn _hashBucket(hash: long, capacity: long) -> long {
|
||||
let bucket: long = hash % capacity;
|
||||
if bucket < (0 as long) { bucket = bucket + capacity; }
|
||||
return bucket;
|
||||
}
|
||||
|
||||
fn _setNextSize(length: long) -> long {
|
||||
fn _hashNextSize(length: long) -> long {
|
||||
let maximum: long = 9223372036854775807;
|
||||
_bounds(length, maximum);
|
||||
return length + 1;
|
||||
}
|
||||
|
||||
fn _setCapacity(capacity: long, required: long) -> long {
|
||||
fn _hashCapacity(capacity: long, required: long) -> long {
|
||||
let maximum: long = 4294967295;
|
||||
if capacity == (0 as long) { return 8; }
|
||||
if capacity < maximum && required > capacity * (3 as long) / (4 as long) {
|
||||
@@ -385,7 +385,7 @@ declare struct set<T>(buckets: optional array<_SetNode<T>>, length: long, strate
|
||||
[SdkPrivate]
|
||||
fn _find(hash: long, value: T) -> bool {
|
||||
if let buckets = this.buckets {
|
||||
let current: optional _SetNode<T> = buckets[_setBucket(hash, buckets.length)];
|
||||
let current: optional _SetNode<T> = buckets[_hashBucket(hash, buckets.length)];
|
||||
while current.hasSome() {
|
||||
if let node = current {
|
||||
if node.hash == hash && this._equals(node.value, value) { return true; }
|
||||
@@ -404,7 +404,7 @@ declare struct set<T>(buckets: optional array<_SetNode<T>>, length: long, strate
|
||||
let current: optional _SetNode<T> = buckets[index];
|
||||
while current.hasSome() {
|
||||
if let node = current {
|
||||
let bucket: long = _setBucket(node.hash, capacity);
|
||||
let bucket: long = _hashBucket(node.hash, capacity);
|
||||
let copied = new _SetNode<T>(node.hash, node.value, target[bucket]);
|
||||
target[bucket] = copied;
|
||||
current = node.next;
|
||||
@@ -426,20 +426,20 @@ declare struct set<T>(buckets: optional array<_SetNode<T>>, length: long, strate
|
||||
this._begin();
|
||||
let hash: long = this._hash(value);
|
||||
if this._find(hash, value) { this.busy = false; return false; }
|
||||
let required: long = _setNextSize(this.length);
|
||||
let required: long = _hashNextSize(this.length);
|
||||
let capacity: long = 0;
|
||||
if let buckets = this.buckets { capacity = buckets.length; }
|
||||
let nextCapacity: long = _setCapacity(capacity, required);
|
||||
let nextCapacity: long = _hashCapacity(capacity, required);
|
||||
if nextCapacity != capacity {
|
||||
let target = this._rehash(nextCapacity);
|
||||
let bucket: long = _setBucket(hash, nextCapacity);
|
||||
let bucket: long = _hashBucket(hash, nextCapacity);
|
||||
let inserted = new _SetNode<T>(hash, value, target[bucket]);
|
||||
target[bucket] = inserted;
|
||||
let published: optional array<_SetNode<T>> = some(target);
|
||||
this.buckets = published;
|
||||
} else {
|
||||
if let buckets = this.buckets {
|
||||
let bucket: long = _setBucket(hash, capacity);
|
||||
let bucket: long = _hashBucket(hash, capacity);
|
||||
let inserted = new _SetNode<T>(hash, value, buckets[bucket]);
|
||||
buckets[bucket] = inserted;
|
||||
}
|
||||
@@ -452,7 +452,7 @@ declare struct set<T>(buckets: optional array<_SetNode<T>>, length: long, strate
|
||||
this._begin();
|
||||
let hash: long = this._hash(value);
|
||||
if let buckets = this.buckets {
|
||||
let bucket: long = _setBucket(hash, buckets.length);
|
||||
let bucket: long = _hashBucket(hash, buckets.length);
|
||||
let previous: optional _SetNode<T> = none;
|
||||
let current: optional _SetNode<T> = buckets[bucket];
|
||||
while current.hasSome() {
|
||||
@@ -500,3 +500,193 @@ declare struct set<T>(buckets: optional array<_SetNode<T>>, length: long, strate
|
||||
return new _SnapshotCursor<T>(head) as Cursor<T>;
|
||||
}
|
||||
}
|
||||
|
||||
// An association is independent of mutable Map nodes. Only payload aliases are shared.
|
||||
declare struct keyval<K, V>(storedKey: K, storedValue: V) {
|
||||
ctor make(key: K, value: V) { this.storedKey = key; this.storedValue = value; }
|
||||
fn key() -> K { return this.storedKey; }
|
||||
fn value() -> V { return this.storedValue; }
|
||||
}
|
||||
|
||||
declare struct _MapNode<K, V>(pub hash: long, pub key: K, pub mut value: V, pub mut next: optional _MapNode<K, V>) {
|
||||
ctor make(hash: long, key: K, value: V, next: optional _MapNode<K, V>) {
|
||||
this.hash = hash;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.next = next;
|
||||
}
|
||||
}
|
||||
|
||||
[SdkMap]
|
||||
declare struct map<K, V>(buckets: optional array<_MapNode<K, V>>, length: long, strategy: optional Identity<K>, busy: bool) {
|
||||
ctor make() {
|
||||
this.buckets = none;
|
||||
this.length = 0;
|
||||
this.strategy = none;
|
||||
this.busy = false;
|
||||
}
|
||||
ctor make(identity: Identity<K>) {
|
||||
this.buckets = none;
|
||||
this.length = 0;
|
||||
this.strategy = some(identity);
|
||||
this.busy = false;
|
||||
}
|
||||
fn size() -> long { return this.length; }
|
||||
fn isEmpty() -> bool { return this.length == (0 as long); }
|
||||
[SdkPrivate]
|
||||
fn _check() { if this.busy { _fail(); } }
|
||||
[SdkPrivate]
|
||||
fn _begin() { this._check(); this.busy = true; }
|
||||
[SdkPrivate]
|
||||
fn _hash(key: K) -> long {
|
||||
if let identity = this.strategy { return identity.hash(key); }
|
||||
return _collectionHash<K>(key);
|
||||
}
|
||||
[SdkPrivate]
|
||||
fn _equals(left: K, right: K) -> bool {
|
||||
if let identity = this.strategy { return identity.equals(left, right); }
|
||||
return _collectionEquals<K>(left, right);
|
||||
}
|
||||
[SdkPrivate]
|
||||
fn _find(hash: long, key: K) -> optional _MapNode<K, V> {
|
||||
if let buckets = this.buckets {
|
||||
let current: optional _MapNode<K, V> = buckets[_hashBucket(hash, buckets.length)];
|
||||
while current.hasSome() {
|
||||
if let node = current {
|
||||
if node.hash == hash && this._equals(node.key, key) { return some(node); }
|
||||
current = node.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
return none;
|
||||
}
|
||||
[SdkPrivate]
|
||||
fn _at(key: K) -> optional V {
|
||||
this._begin();
|
||||
let hash: long = this._hash(key);
|
||||
let retrieved: optional V = none;
|
||||
if let node = this._find(hash, key) { retrieved = some(node.value); }
|
||||
this.busy = false;
|
||||
return retrieved;
|
||||
}
|
||||
[SdkPrivate]
|
||||
fn _put(key: K, value: V) { let discarded: optional V = this._associate(key, value, false); }
|
||||
fn containsKey(key: K) -> bool {
|
||||
this._begin();
|
||||
let hash: long = this._hash(key);
|
||||
let found: bool = this._find(hash, key).hasSome();
|
||||
this.busy = false;
|
||||
return found;
|
||||
}
|
||||
[SdkPrivate]
|
||||
fn _rehash(capacity: long) -> array<_MapNode<K, V>> {
|
||||
let target: array<_MapNode<K, V>> = new array<>(capacity);
|
||||
if let buckets = this.buckets {
|
||||
let index: long = 0;
|
||||
while index < buckets.length {
|
||||
let current: optional _MapNode<K, V> = buckets[index];
|
||||
while current.hasSome() {
|
||||
if let node = current {
|
||||
let bucket: long = _hashBucket(node.hash, capacity);
|
||||
let copied = new _MapNode<K, V>(node.hash, node.key, node.value, target[bucket]);
|
||||
target[bucket] = copied;
|
||||
current = node.next;
|
||||
}
|
||||
}
|
||||
index = index + 1;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
[SdkPrivate]
|
||||
fn _associate(key: K, value: V, returnPrevious: bool) -> optional V {
|
||||
this._begin();
|
||||
let hash: long = this._hash(key);
|
||||
if let node = this._find(hash, key) {
|
||||
let previous: optional V = none;
|
||||
if returnPrevious { previous = some(node.value); }
|
||||
node.value = value;
|
||||
this.busy = false;
|
||||
return previous;
|
||||
}
|
||||
// Typed absence can materialize a carrier; prepare it before publishing nodes.
|
||||
let absent: optional V = none;
|
||||
let required: long = _hashNextSize(this.length);
|
||||
let capacity: long = 0;
|
||||
if let buckets = this.buckets { capacity = buckets.length; }
|
||||
let nextCapacity: long = _hashCapacity(capacity, required);
|
||||
if nextCapacity != capacity {
|
||||
let target = this._rehash(nextCapacity);
|
||||
let bucket: long = _hashBucket(hash, nextCapacity);
|
||||
let inserted = new _MapNode<K, V>(hash, key, value, target[bucket]);
|
||||
target[bucket] = inserted;
|
||||
let published: optional array<_MapNode<K, V>> = some(target);
|
||||
this.buckets = published;
|
||||
} else {
|
||||
if let buckets = this.buckets {
|
||||
let bucket: long = _hashBucket(hash, capacity);
|
||||
let inserted = new _MapNode<K, V>(hash, key, value, buckets[bucket]);
|
||||
buckets[bucket] = inserted;
|
||||
}
|
||||
}
|
||||
this.length = required;
|
||||
this.busy = false;
|
||||
return absent;
|
||||
}
|
||||
fn put(entry: keyval<K, V>) -> optional V {
|
||||
return this._associate(entry.key(), entry.value(), true);
|
||||
}
|
||||
fn remove(key: K) -> optional V {
|
||||
this._begin();
|
||||
let hash: long = this._hash(key);
|
||||
if let buckets = this.buckets {
|
||||
let bucket: long = _hashBucket(hash, buckets.length);
|
||||
let previous: optional _MapNode<K, V> = none;
|
||||
let current: optional _MapNode<K, V> = buckets[bucket];
|
||||
while current.hasSome() {
|
||||
if let node = current {
|
||||
if node.hash == hash && this._equals(node.key, key) {
|
||||
let retrieved: optional V = some(node.value);
|
||||
let next: optional _MapNode<K, V> = node.next;
|
||||
let length: long = this.length - 1;
|
||||
if let predecessor = previous { predecessor.next = next; }
|
||||
else {
|
||||
if let successor = next { buckets[bucket] = successor; }
|
||||
else { buckets.clear(bucket); }
|
||||
}
|
||||
this.length = length;
|
||||
this.busy = false;
|
||||
return retrieved;
|
||||
}
|
||||
previous = current;
|
||||
current = node.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.busy = false;
|
||||
return none;
|
||||
}
|
||||
fn clear() {
|
||||
this._check();
|
||||
this.buckets = none;
|
||||
this.length = 0;
|
||||
}
|
||||
fn cursor() -> Cursor<keyval<K, V>> {
|
||||
let head: optional _SnapshotNode<keyval<K, V>> = none;
|
||||
if let buckets = this.buckets {
|
||||
let index: long = 0;
|
||||
while index < buckets.length {
|
||||
let current: optional _MapNode<K, V> = buckets[index];
|
||||
while current.hasSome() {
|
||||
if let node = current {
|
||||
let captured = new keyval<K, V>(node.key, node.value);
|
||||
head = some(new _SnapshotNode<keyval<K, V>>(captured, head));
|
||||
current = node.next;
|
||||
}
|
||||
}
|
||||
index = index + 1;
|
||||
}
|
||||
}
|
||||
return new _SnapshotCursor<keyval<K, V>>(head) as Cursor<keyval<K, V>>;
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -3,3 +3,5 @@ pub contract Cursor<T>;
|
||||
pub struct linked<T>;
|
||||
pub struct set<T>;
|
||||
pub contract Identity<T>;
|
||||
pub struct map<K, V>;
|
||||
pub struct keyval<K, V>;
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import {map, keyval} from @sdk:collections;
|
||||
|
||||
fn mapsExample() -> int {
|
||||
let scores = new map<str, optional int>();
|
||||
scores["left"] = some(20);
|
||||
let previous = scores.put(new keyval<str, optional int>("right", some(22)));
|
||||
if previous.hasSome() { return 0; }
|
||||
scores["empty"] = none;
|
||||
if scores.containsKey("empty") == false { return 0; }
|
||||
if let empty = scores["empty"] {
|
||||
if empty.hasSome() { return 0; }
|
||||
} else { return 0; }
|
||||
if scores["missing"].hasSome() { return 0; }
|
||||
|
||||
let captured = scores.cursor();
|
||||
scores["left"] = some(0);
|
||||
scores.clear();
|
||||
let total: int = 0;
|
||||
while true {
|
||||
if let entry = captured.current() {
|
||||
if let value = entry.value() { total = total + value; }
|
||||
} else { break; }
|
||||
if captured.hasNext() { captured.next(); }
|
||||
else { break; }
|
||||
}
|
||||
return total;
|
||||
}
|
||||
+1
@@ -6,3 +6,4 @@ pub fn collectionsExample() -> int;
|
||||
pub fn linkedExample() -> int;
|
||||
pub fn setExample() -> int;
|
||||
pub fn hashingExample() -> int;
|
||||
pub fn mapsExample() -> int;
|
||||
|
||||
+23
@@ -124,6 +124,29 @@ class PbsGateUSdkInterfaceConformanceTest {
|
||||
assertTrue(copied.hasErrors());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapExportsUseOriginCheckedKeyTypingAndPrivateAssociations() throws IOException {
|
||||
var positive=compileWorkspaceModule(tempDir.resolve("map-positive"),"""
|
||||
import {map as Maps,keyval as Entry} from @sdk:collections;
|
||||
[Frame] fn frame()->void{
|
||||
let m:Maps<str,optional int>=new Maps();m["a"]=none;
|
||||
let previous=m.put(new Entry<str,optional int>("a",some(42)));
|
||||
if let value=m["a"]{if (value else 0)!=42{let failure=1/0;}}else{let failure=1/0;}
|
||||
}
|
||||
""","pub fn frame()->void;",1,null);
|
||||
assertFalse(positive.diagnostics().hasErrors(),positive.diagnostics().toString());
|
||||
for(var entry:java.util.Map.of(
|
||||
"optional","let m=new map<optional int,int>();",
|
||||
"key","let m=new map<str,int>();m[0]=42;",
|
||||
"private","let m=new map<int,int>();let exposed=m.buckets;",
|
||||
"association","let e=new keyval<int,int>(20,22);e.storedKey=0;",
|
||||
"capacity","let m=new map<int,int>(8);").entrySet()){
|
||||
var negative=compileWorkspaceModule(tempDir.resolve("map-negative-"+entry.getKey()),
|
||||
"import {map,keyval} from @sdk:collections;[Frame]fn frame()->void{"+entry.getValue()+"}","pub fn frame()->void;",1,null);
|
||||
assertTrue(negative.diagnostics().hasErrors(),entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void removedInputObjectsExplainTheirMigration() throws IOException {
|
||||
final var result = compileWorkspaceModule(tempDir.resolve("removed-input"), """
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package p.studio.compiler.pbs;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.models.SourceKind;
|
||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class PbsMapKeyvalTest {
|
||||
private DiagnosticSink compile(String source)throws Exception {
|
||||
String sdk;
|
||||
try(var stream=getClass().getResourceAsStream("/game/stdlib/1/sdk/collections/main.pbs")){
|
||||
assertNotNull(stream);sdk=new String(stream.readAllBytes(),StandardCharsets.UTF_8);
|
||||
}
|
||||
var diagnostics=DiagnosticSink.empty();
|
||||
new PbsFrontendCompiler().compileFile(new FileId(0),sdk+"\n"+source,diagnostics,SourceKind.SDK_INTERFACE);
|
||||
return diagnostics;
|
||||
}
|
||||
private void accepts(String source)throws Exception {
|
||||
var diagnostics=compile(source);assertFalse(diagnostics.hasErrors(),()->diagnostics.stream().map(d->d.getCode()+":"+d.getMessage()).toList().toString());
|
||||
}
|
||||
private void rejects(String source,String code)throws Exception {
|
||||
var diagnostics=compile(source);assertTrue(diagnostics.stream().anyMatch(d->d.getCode().contains(code)),()->diagnostics.stream().map(d->d.getCode()+":"+d.getMessage()).toList().toString());
|
||||
}
|
||||
@Test void keyAndValueApplicationsHaveIndependentRules()throws Exception {
|
||||
accepts("""
|
||||
fn main()->optional int {
|
||||
let a:map<str,optional int>=new map<>();a["a"]=none;
|
||||
let b:map<str,optional int>=new map();b["a"]=some(42);
|
||||
let entry:keyval<str,optional int>=new keyval("a",none);
|
||||
let prior:optional (optional int)=b.put(entry);
|
||||
let detached=new keyval<optional int,optional int>(none,some(42));
|
||||
return detached.value();
|
||||
}
|
||||
""");
|
||||
rejects("fn main(){let m=new map<optional int,int>();}","MAP_OPTIONAL_KEY");
|
||||
rejects("fn main(){let m=new map<(optional int),int>();}","MAP_OPTIONAL_KEY");
|
||||
rejects("""
|
||||
declare service Policy {}
|
||||
implements Identity<optional int> for Policy using p {
|
||||
fn hash(v:optional int)->long{return 0;}fn equals(a:optional int,b:optional int)->bool{return true;}
|
||||
}
|
||||
fn main(){let m=new map<optional int,int>(Policy);}
|
||||
""","MAP_OPTIONAL_KEY");
|
||||
rejects("fn main(){let m=new map();}","GENERIC_CONTEXT");
|
||||
rejects("fn main(){let k=new keyval(1,2);}","GENERIC_CONTEXT");
|
||||
rejects("fn main(){let m:map<int,long>=new map<int,int>();}","GENERIC_TYPE_MISMATCH");
|
||||
rejects("fn main(){let m=new map<str,int>();m[0]=42;}","MAP_KEY_TYPE");
|
||||
rejects("fn main(){let m=new map<str,int>();m[\"a\"]=false;}","ASSIGN_TYPE_MISMATCH");
|
||||
}
|
||||
@Test void strategiesAreNominalAndNeverRequiredForValues()throws Exception {
|
||||
accepts("""
|
||||
declare struct Box<T>(value:T){fn get()->T{return this.value;}}
|
||||
fn main(){let m=new map<Box<int>,Box<int>>();m[new Box(20)]=new Box(22);}
|
||||
""");
|
||||
accepts("""
|
||||
declare service Policy {}
|
||||
implements Identity<(a:int,b:int)> for Policy using p {
|
||||
fn hash(v:(a:int,b:int))->long{return 0;}
|
||||
fn equals(a:(a:int,b:int),b:(a:int,b:int))->bool{return a.a==b.a&&a.b==b.b;}
|
||||
}
|
||||
fn main(){let m=new map<(a:int,b:int),optional int>(Policy);m[(a:20,b:22)]=none;}
|
||||
""");
|
||||
accepts("fn main(){let m=new map<int,(a:int,b:int)>();m[1]=(a:20,b:22);}");
|
||||
rejects("fn main(){let m=new map<(a:int,b:int),int>();}","MAP_IDENTITY_REQUIRED");
|
||||
rejects("fn main(){let k=new keyval<int,int>(20,22);k.storedKey=42;}","ACCESS_DENIED");
|
||||
rejects("fn main(){let k=new keyval<int,int>(20,22);let hidden=k.storedValue;}","ACCESS_DENIED");
|
||||
rejects("fn main(){let m=new map<int,int>();m._at(0);}","PRIVATE");
|
||||
var source="declare struct map<K,V>(pub key:K,pub value:V);fn main(){let m=new map<optional int,optional int>(none,none);}";
|
||||
var diagnostics=DiagnosticSink.empty();new PbsFrontendCompiler().compileFile(new FileId(0),source,diagnostics);
|
||||
assertFalse(diagnostics.hasErrors(),diagnostics.toString());
|
||||
}
|
||||
@Test void reservedMapBindingCannotBeForgedByProjectCode() {
|
||||
var diagnostics=DiagnosticSink.empty();new PbsFrontendCompiler().compileFile(new FileId(0),
|
||||
"[SdkMap] declare struct map<K,V>(key:K,value:V);",diagnostics);
|
||||
assertTrue(diagnostics.hasErrors());
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package p.studio.compiler.pbs.semantics;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.compiler.pbs.ast.PbsAst;
|
||||
import p.studio.compiler.pbs.lexer.PbsLexer;
|
||||
import p.studio.compiler.pbs.parser.PbsParser;
|
||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class PbsMapKeyvalEditorialTest {
|
||||
@Test void concretePublicApiAndIndexResultsRetainSdkOrigins()throws Exception {
|
||||
var diagnostics=DiagnosticSink.empty();var sdkId=new FileId(1);String sdk;
|
||||
try(var stream=getClass().getResourceAsStream("/game/stdlib/1/sdk/collections/main.pbs")){
|
||||
assertNotNull(stream);sdk=new String(stream.readAllBytes(),StandardCharsets.UTF_8);
|
||||
}
|
||||
var library=PbsParser.parse(PbsLexer.lex(sdk,sdkId,diagnostics),sdkId,diagnostics,PbsParser.ParseMode.INTERFACE_MODULE);
|
||||
var source="""
|
||||
import {map as Maps,keyval as Entry,Cursor} from @sdk:collections;
|
||||
fn sample(values:Maps<str,optional int>,entry:Entry<str,optional int>)->optional (optional int){
|
||||
let created:Maps<str,optional int>=new Maps();
|
||||
let association:Entry<str,optional int>=new Entry("a",none);
|
||||
values.put(entry);entry.key();entry.value();return values["a"];
|
||||
}
|
||||
""";
|
||||
var id=new FileId(2);var ast=PbsParser.parse(PbsLexer.lex(source,id,diagnostics),id,diagnostics);
|
||||
var declarations=new java.util.ArrayList<PbsAst.TopDecl>(library.topDecls().stream().toList());
|
||||
for(var binding:java.util.Map.of("map","Maps","keyval","Entry").entrySet()){
|
||||
var origin=library.topDecls().stream().filter(d->d instanceof PbsAst.StructDecl s&&s.name().equals(binding.getKey())).findFirst().orElseThrow();
|
||||
declarations.add(new PbsAst.TypeBindingDecl(binding.getValue(),origin,ast.span()));
|
||||
}
|
||||
var supplemental=ReadOnlyList.wrap(declarations);var service=new PbsEditorialSupportService();
|
||||
assertFalse(diagnostics.hasErrors(),diagnostics.toString());
|
||||
int put=source.indexOf("values.put")+7;
|
||||
var methods=service.completion(source,ast,supplemental,put);
|
||||
assertEquals(Set.of("containsKey","put","remove","clear","size","isEmpty","cursor"),methods.stream().map(c->c.label()).collect(Collectors.toSet()));
|
||||
var hover=service.hover(source,ast,supplemental,put).orElseThrow();
|
||||
assertTrue(hover.signatures().getFirst().label().contains("optional int"),hover.toString());
|
||||
assertEquals(sdkId,service.definition(source,ast,supplemental,put).getFirst().span().getFileId());
|
||||
int key=source.indexOf("entry.key")+6;
|
||||
assertEquals(Set.of("key","value"),service.completion(source,ast,supplemental,key).stream().map(c->c.label()).collect(Collectors.toSet()));
|
||||
assertTrue(service.hover(source,ast,supplemental,key).orElseThrow().signatures().getFirst().label().contains("str"));
|
||||
int construction=source.indexOf("new Maps(")+9;
|
||||
var ctors=service.signatureHelp(source,ast,supplemental,construction).orElseThrow().signatures();
|
||||
assertEquals(2,ctors.size());assertTrue(ctors.stream().noneMatch(s->s.label().contains("buckets")||s.label().contains("$generic$")));
|
||||
var entryCtor=service.signatureHelp(source,ast,supplemental,source.indexOf("new Entry(")+10).orElseThrow();
|
||||
assertTrue(entryCtor.signatures().getFirst().label().contains("key: str"),entryCtor.toString());
|
||||
assertTrue(service.rename(source,ast,supplemental,source.indexOf("values:Maps"),"scores").allowed());
|
||||
assertTrue(service.references(source,ast,supplemental,source.indexOf("values:Maps")).size()>=3);
|
||||
String invalid=source.replace("entry.key();","entry.storedKey;entry.key();");
|
||||
var invalidAst=PbsParser.parse(PbsLexer.lex(invalid,id,diagnostics),id,diagnostics);
|
||||
int hidden=invalid.indexOf("entry.storedKey")+6;
|
||||
assertTrue(service.hover(invalid,invalidAst,supplemental,hidden).isEmpty());
|
||||
assertTrue(service.definition(invalid,invalidAst,supplemental,hidden).isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,42 @@
|
||||
Owner: compiler/general. This harness uses the production runtime loader and VM;
|
||||
it does not implement a Java approximation of runtime admission.
|
||||
|
||||
## PBS Map and Keyval qualification
|
||||
|
||||
Generate the mandatory Map corpus and actual installed-JAR example, then execute
|
||||
the dedicated verifier in both runtime profiles:
|
||||
|
||||
```sh
|
||||
./gradlew :prometeu-architecture-tests:test --tests '*PbsMapKeyvalTest' :prometeu-app:installedKnowledgeTest --console=plain
|
||||
CARGO_TARGET_DIR=/tmp/studio-pbx-map-target python3 tools/pbx-conformance/run.py --runtime ../runtime --map-only
|
||||
CARGO_TARGET_DIR=/tmp/studio-pbx-map-target python3 tools/pbx-conformance/run.py --runtime ../runtime --map-only --release
|
||||
```
|
||||
|
||||
Each non-GC source case has ordinary/optimized PBS producer variants, independent
|
||||
of the Rust dev/release profile. The manifest names every required success/fault,
|
||||
resource, injection, GC, import and installed fixture; missing files fail. The
|
||||
full harness includes Map separately from its historical catch-all PBS verifier.
|
||||
|
||||
The corpus covers typed non-positional keys; default/explicit Identity; optional
|
||||
V and previous-value presence; original-key retention under content policies;
|
||||
read-only Keyval instance identity; collisions/negative full hashes; rehash and
|
||||
capture callback counters; complete tuple/native/contract groups; evaluation order;
|
||||
alias reentrancy and permitted callback reads; and the shared snapshot state table.
|
||||
|
||||
Resource fixtures compare attempted instruction prefixes with successful
|
||||
instruction prefixes under lowered production quotas. They separate installed
|
||||
guard writes from structural mutation and measure old/candidate table/node and
|
||||
snapshot/keyval peaks. A named test-only allocation after the real candidate-table
|
||||
store qualifies permitted post-write incomplete invariants; production SDK has no
|
||||
injected probe. Natural quota refusal counts are reported separately.
|
||||
|
||||
Real safepoints check independent key/value roots, obsolete-value release after
|
||||
replacement, removed-key/value reclamation, Map-node reclamation, captured Keyvals,
|
||||
consumed Cursor prefixes, retained final current and release after all owners exit.
|
||||
Imported/reexported and installed examples execute through the production loader
|
||||
and VM and actually construct the shared entry Cursor. This is local semantic and
|
||||
resource qualification, not a performance benchmark or a new provider contract.
|
||||
|
||||
From the Studio root:
|
||||
|
||||
```sh
|
||||
|
||||
@@ -41,6 +41,7 @@ fn main() {
|
||||
for resource in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes,Q::StringBytes,Q::StringAllocations,Q::IndividualStringBytes,Q::CallDepth] {
|
||||
println!("DEFAULT VM LIMIT {resource:?}={}",limits.get(resource));
|
||||
}
|
||||
if std::env::args().any(|arg| arg == "--map-only") { verify_pbs_map_fixtures(&root); return; }
|
||||
if std::env::args().any(|arg| arg == "--set-only") { verify_pbs_set_fixtures(&root); return; }
|
||||
if std::env::args().any(|arg| arg == "--identity-hashing-only") { verify_identity_hashing_fixtures(&root); return; }
|
||||
if std::env::args().any(|arg| arg == "--linked-only") { verify_common_storage_fixtures(&root); verify_pbs_linked_fixtures(&root); return; }
|
||||
@@ -61,6 +62,7 @@ fn main() {
|
||||
verify_pbs_list_cursor_fixtures(&root);
|
||||
verify_pbs_linked_fixtures(&root);
|
||||
verify_pbs_set_fixtures(&root);
|
||||
verify_pbs_map_fixtures(&root);
|
||||
verify_pbs_resource_refusals(&root);
|
||||
verify_pbs_closure_frames(&root);
|
||||
for name in [
|
||||
@@ -501,7 +503,7 @@ fn verify_pbs_fixtures(root: &std::path::Path) {
|
||||
for entry in std::fs::read_dir(root).unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
let name = path.file_stem().unwrap().to_str().unwrap();
|
||||
if name.starts_with("pbs-random-") || name.starts_with("pbs-math-") || name.starts_with("pbs-structured-") || name.starts_with("pbs-generic-contract-") || name.starts_with("pbs-generic-struct-") || name.starts_with("pbs-list-") || name.starts_with("pbs-linked-") || name.starts_with("pbs-hash-") || name.starts_with("pbs-set-") || !name.starts_with("pbs-") || path.extension().and_then(|v| v.to_str()) != Some("pbx") { continue; }
|
||||
if name.starts_with("pbs-random-") || name.starts_with("pbs-math-") || name.starts_with("pbs-structured-") || name.starts_with("pbs-generic-contract-") || name.starts_with("pbs-generic-struct-") || name.starts_with("pbs-list-") || name.starts_with("pbs-linked-") || name.starts_with("pbs-hash-") || name.starts_with("pbs-set-") || name.starts_with("pbs-map-") || !name.starts_with("pbs-") || path.extension().and_then(|v| v.to_str()) != Some("pbx") { continue; }
|
||||
count += 1;
|
||||
let bytes = std::fs::read(&path).unwrap();
|
||||
let image = ValidatedProgramImage::load(&bytes, &mut LoadBudget::new(LoadLimits::default()), caps::NONE)
|
||||
@@ -1829,3 +1831,241 @@ fn verify_installed_hash(root:&std::path::Path) {
|
||||
assert!(matches!(report.reason,End::FrameSync|End::Halted|End::EndOfRom),"installed hashing: {report:?}");
|
||||
println!("HASH INSTALLED JAR/SDK/EXAMPLE LOAD/EXEC PASS");
|
||||
}
|
||||
|
||||
|
||||
fn map_state(vm:&VirtualMachine,image:&ValidatedProgramImage)->ObservedStorage {
|
||||
use prometeu_vm::resource_diagnostics::StorageValue as V;
|
||||
let objects=vm.heap().diagnostic_typed_storage();
|
||||
let owner=objects.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("map<int, int>")).expect("source Map");
|
||||
let mut pending=vec![owner.reference];let mut state:ObservedStorage=Vec::new();
|
||||
while let Some(reference)=pending.pop() {
|
||||
if state.iter().any(|o|o.reference==reference){continue;}
|
||||
let object=objects.iter().find(|o|o.reference==reference).expect("live complete Map group");
|
||||
for value in object.groups.iter().flatten(){if let V::Reference(reference)=value{pending.push(*reference);}}
|
||||
state.push(object.clone());
|
||||
}
|
||||
state.sort_by_key(|o|(o.reference.index,o.reference.generation));state
|
||||
}
|
||||
fn map_without_guard(mut state:ObservedStorage,image:&ValidatedProgramImage)->ObservedStorage {
|
||||
for object in &mut state {
|
||||
if image.registry().declarations().types[object.type_id.0 as usize].name.as_deref()==Some("map<int, int>") {
|
||||
object.groups[3]=vec![prometeu_vm::resource_diagnostics::StorageValue::Boolean(false)];
|
||||
}
|
||||
}
|
||||
state
|
||||
}
|
||||
fn validate_map(vm:&VirtualMachine,image:&ValidatedProgramImage,expected:i64)->usize {
|
||||
use prometeu_vm::resource_diagnostics::StorageValue as V;
|
||||
let state=map_state(vm,image);
|
||||
let owner=state.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("map<int, int>")).unwrap();
|
||||
assert_eq!(owner.groups[1],vec![V::Int64(expected)]);assert_eq!(owner.groups[3],vec![V::Boolean(false)]);
|
||||
let get=|reference|state.iter().find(|o|o.reference==reference).expect("reachable object");
|
||||
let V::Reference(carrier)=owner.groups[0][0] else{assert_eq!(expected,0);return 0;};
|
||||
let V::Reference(table)=get(carrier).groups[0][0] else{panic!("bucket carrier")};
|
||||
let buckets=get(table);let capacity=buckets.groups.len();let mut nodes=std::collections::HashSet::new();
|
||||
for (bucket,group) in buckets.groups.iter().enumerate() {
|
||||
if *group==vec![V::Null,V::Null]{continue;}
|
||||
let [V::Int64(tag),V::Reference(first)]=group.as_slice() else{panic!("complete bucket group")};
|
||||
assert_eq!(image.registry().declarations().types[*tag as usize].name.as_deref(),Some("_MapNode<int, int>"));
|
||||
let mut next=Some(*first);
|
||||
while let Some(reference)=next {
|
||||
assert!(nodes.insert(reference),"each node appears once, no cycles");let node=get(reference);
|
||||
let V::Int64(hash)=node.groups[0][0] else{panic!("cached complete hash")};
|
||||
assert_eq!(hash.rem_euclid(capacity as i64) as usize,bucket);
|
||||
next=match node.groups[3][0]{V::Null=>None,V::Reference(carrier)=>{let V::Reference(value)=get(carrier).groups[0][0] else{panic!("next node carrier")};Some(value)},_=>panic!("next group")};
|
||||
}
|
||||
}
|
||||
assert_eq!(nodes.len(),expected as usize);capacity
|
||||
}
|
||||
fn verify_map_refusals(root:&std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End,resource_budget::{RuntimeLimits,RuntimeResource as Q}};
|
||||
use prometeu_bytecode::{decode_next,isa::core::CoreOpCode as Op,TRAP_RESOURCE_LIMIT};
|
||||
let mut node_refusal=false;let mut snapshot_refusal=false;let mut table_refusal=false;let mut guard_effect=false;
|
||||
for name in ["growth","add","replace","put","remove","clear","cursor","read"] {
|
||||
for suffix in ["","-optimized"] {
|
||||
let bytes=std::fs::read(root.join(format!("pbs-map-refusal-{name}{suffix}.pbx"))).expect("mandatory Map resource fixture");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let marker=|value:i32|{let mut pc=0;let mut found=Vec::new();while pc<image.code().len(){let i=decode_next(pc,image.code()).unwrap();if i.opcode==Op::PushI32&&i.imm_i32().unwrap()==value{found.push(pc);}pc=i.next_pc;}assert_eq!(found.len(),1);found[0]};
|
||||
let before_pc=marker(314160);let after_pc=marker(314161);
|
||||
let prepare=|limits|{let mut vm=VirtualMachine::from_image(image.clone(),limits);vm.prepare_boot_call().unwrap();vm.insert_breakpoint(before_pc);vm.insert_breakpoint(after_pc);vm};
|
||||
let mut baseline=prepare(RuntimeLimits::default());assert!(matches!(baseline.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap().reason,End::Breakpoint));
|
||||
let before=baseline.resource_snapshot();let old=map_state(&baseline,&image);let size=if name=="growth"{6}else{5};
|
||||
assert_eq!(validate_map(&baseline,&image,size),8);baseline.remove_breakpoint(before_pc);
|
||||
let mut successful=Vec::new();let mut max_nodes=0;let mut max_tables=0;
|
||||
loop {
|
||||
let objects=baseline.heap().diagnostic_typed_storage();
|
||||
max_nodes=max_nodes.max(objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_MapNode<int, int>")).count());
|
||||
max_tables=max_tables.max(objects.iter().filter(|o|matches!(image.registry().declarations().types[o.type_id.0 as usize].kind,prometeu_bytecode::registry::TypeKind::Array(_))).count());
|
||||
successful.push((baseline.pc(),observe_originals(&baseline,&old)));
|
||||
let report=baseline.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
if baseline.pc()==after_pc{break;}
|
||||
assert!(matches!(report.reason,End::BudgetExhausted),"Map {name}: {report:?}");assert!(successful.len()<200_000);
|
||||
}
|
||||
let after=baseline.resource_snapshot();let expected=match name{"growth"|"add"=>size+1,"remove"=>size-1,"clear"=>0,_=>size};
|
||||
let capacity=validate_map(&baseline,&image,expected);
|
||||
assert_eq!(capacity,if name=="growth"{16}else if name=="clear"{0}else{8});
|
||||
if name=="replace"||name=="put"{let state=map_state(&baseline,&image);assert!(state.iter().any(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_MapNode<int, int>")&&o.groups[1]==vec![prometeu_vm::resource_diagnostics::StorageValue::Int32(1)]&&o.groups[2]==vec![prometeu_vm::resource_diagnostics::StorageValue::Int32(42)]));}
|
||||
if name=="growth"{assert!(max_nodes>=13,"six old + six copied + inserted");assert!(max_tables>=2);}
|
||||
if name=="read"||name=="cursor"{assert_eq!(map_state(&baseline,&image),old);}
|
||||
println!("MAP PEAK {name}{suffix} nodes={max_nodes} tables={max_tables} before={:?} after={:?}",before.budget.peaks,after.budget.peaks);
|
||||
let mut refusals=0;let mut structural_refusals=0;
|
||||
for resource in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes,Q::CallDepth] {
|
||||
let lower=before.budget.peaks[resource as usize];let upper=after.budget.peaks[resource as usize];if lower>=upper{continue;}
|
||||
let mut limits=vec![lower,lower+(upper-lower)/4,lower+(upper-lower)/2,upper-1];
|
||||
if resource==Q::HandleSlots{limits.extend(lower..upper.min(lower+24));}limits.sort_unstable();limits.dedup();
|
||||
for limit in limits {
|
||||
let mut vm=prepare(RuntimeLimits::default().lowered(resource,limit).unwrap());let observer=vm.resource_observer();
|
||||
assert!(matches!(vm.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap().reason,End::Breakpoint),"Map setup {name} {resource:?}={limit}");
|
||||
let original=map_state(&vm,&image);vm.remove_breakpoint(before_pc);
|
||||
let (report,prefix,_)=trace_collection_attempt(&mut vm,&original,after_pc);assert_mutation_prefix(&prefix,&successful);
|
||||
if let End::Trap(info)=report.reason {
|
||||
assert_eq!(info.code,TRAP_RESOURCE_LIMIT,"Map {name} {resource:?}={limit}: {info:?}");
|
||||
let touched=prefix.iter().any(|(_,state)|map_without_guard(state.clone(),&image)!=map_without_guard(original.clone(),&image));
|
||||
if !touched {assert_eq!(map_without_guard(observe_originals(&vm,&original),&image),map_without_guard(original.clone(),&image));}
|
||||
if name=="cursor"{assert_eq!(map_state(&vm,&image),original);}
|
||||
let now=observe_originals(&vm,&original);guard_effect|=!touched&&now!=original;
|
||||
structural_refusals+=usize::from(touched);
|
||||
let instruction=decode_next(info.pc as usize,image.code()).unwrap();table_refusal|=name=="growth"&&instruction.opcode==Op::ArrayNew;
|
||||
if instruction.opcode==Op::StructNew {
|
||||
let named=image.registry().declarations().types[instruction.imm_u32().unwrap() as usize].name.as_deref();
|
||||
node_refusal|=named==Some("_MapNode<int, int>");snapshot_refusal|=named==Some("_SnapshotNode<keyval<int, int>>");
|
||||
}
|
||||
refusals+=1;println!("MAP PHASE REFUSAL {name}{suffix} structural={touched} resource={resource:?} limit={limit} opcode={:?}",instruction.opcode);
|
||||
}else{assert!(matches!(report.reason,End::BudgetExhausted|End::Breakpoint)&&vm.pc()==after_pc);}
|
||||
drop(vm);for q in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes]{assert_eq!(observer.used(q),0);}
|
||||
}
|
||||
}
|
||||
assert!(refusals>0,"Map {name}: resource refusal evidence");
|
||||
println!("MAP PHASE SUMMARY {name}{suffix} refusals={refusals} after_structural_write={structural_refusals}");
|
||||
}
|
||||
}
|
||||
assert!(node_refusal&&snapshot_refusal&&table_refusal&&guard_effect,"nodes/snapshot/table/guard refusal evidence required");
|
||||
}
|
||||
fn verify_map_collection_gc(root:&std::path::Path) {
|
||||
for suffix in ["","-optimized"] {verify_map_collection_gc_variant(root,suffix);}
|
||||
}
|
||||
fn verify_map_collection_gc_variant(root:&std::path::Path,suffix:&str) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let bytes=std::fs::read(root.join(format!("pbs-map-gc-collection{suffix}.pbx"))).expect("mandatory Map collection GC fixture");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let mut vm=VirtualMachine::from_image(image.clone(),Default::default());vm.prepare_boot_call().unwrap();let mut previous=0;
|
||||
for (round,count) in [64,64,61,0,0].into_iter().enumerate() {
|
||||
let report=vm.run_budget(30_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::FrameSync),"Map GC {round}: {report:?}");
|
||||
let collections=vm.resource_snapshot().gc.collections;assert!(collections>previous);previous=collections;
|
||||
let objects=vm.heap().diagnostic_typed_storage();
|
||||
for name in ["_MapNode<Item, Item>","Item"] {
|
||||
let actual=objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some(name)).count();assert_eq!(actual,if name=="Item"{count*2}else{count},"Map GC {round}: {name}");
|
||||
}
|
||||
println!("MAP COLLECTION/OLD-CANDIDATE GC PASS {suffix} round={round} live_nodes={count}");
|
||||
}
|
||||
let report=vm.run_budget(100_000,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::Halted|End::EndOfRom));assert_eq!(vm.operand_stack_top(1),vec![Value::Int32(42)]);
|
||||
}
|
||||
|
||||
|
||||
// Controlled test-only source instrumentation, never a production SDK algorithm.
|
||||
// A quota probe is inserted after the real candidate-table store and before size.
|
||||
// Natural production-quota coverage and its refusal frequencies remain separate.
|
||||
fn verify_map_postpublication_injection(root:&std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End,resource_budget::{RuntimeLimits,RuntimeResource as Q},resource_diagnostics::StorageValue as V};
|
||||
use prometeu_bytecode::{decode_next,isa::core::CoreOpCode as Op,TRAP_RESOURCE_LIMIT};
|
||||
for suffix in ["","-optimized"] {
|
||||
let bytes=std::fs::read(root.join(format!("pbs-map-injected-refusal-growth{suffix}.pbx"))).expect("explicit test-only post-publication injection");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let limits=RuntimeLimits::default().lowered(Q::GuestBytes,500_000).unwrap();
|
||||
let mut vm=VirtualMachine::from_image(image.clone(),limits);let observer=vm.resource_observer();vm.prepare_boot_call().unwrap();
|
||||
let mut found=false;
|
||||
for _ in 0..200_000 {
|
||||
let instruction=decode_next(vm.pc(),image.code()).unwrap();
|
||||
if instruction.opcode==Op::ArrayNew&&vm.operand_stack_top(1)==vec![Value::Int64(1_000_000)] {
|
||||
let original=vm.heap().diagnostic_typed_storage();let state=map_state(&vm,&image);
|
||||
let owner=state.iter().find(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("map<int, int>")).unwrap();
|
||||
assert_eq!(owner.groups[1],vec![V::Int64(6)]);assert_eq!(owner.groups[3],vec![V::Boolean(true)]);
|
||||
assert_eq!(state.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_MapNode<int, int>")).count(),7);
|
||||
assert!(state.iter().any(|o|matches!(image.registry().declarations().types[o.type_id.0 as usize].kind,prometeu_bytecode::registry::TypeKind::Array(_))&&o.groups.len()==16));
|
||||
let input=vm.operand_stack_top(1).to_vec();let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
let End::Trap(info)=report.reason else{panic!("post-publication injection: {report:?}")};assert_eq!(info.code,TRAP_RESOURCE_LIMIT);
|
||||
assert_eq!(vm.heap().diagnostic_typed_storage(),original,"refused probe preserves its entry state, retaining earlier table publication");
|
||||
assert_eq!(vm.operand_stack_top(1),input);
|
||||
println!("MAP TEST-ONLY POST-PUBLICATION QUOTA INJECTION PASS {suffix}: new table=16 nodes=7 old size=6 guard=true");found=true;break;
|
||||
}
|
||||
let report=vm.run_budget(1,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::BudgetExhausted),"before injection: {report:?}");
|
||||
}
|
||||
assert!(found);drop(vm);for q in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes]{assert_eq!(observer.used(q),0);}
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_pbs_map_fixtures(root:&std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End,resource_budget::RuntimeResource as Q};
|
||||
let successes=["basic","optional","scalars","objects","references","content","collisions","arithmetic",
|
||||
"tuple","native","pixel","random","cursor-empty","cursor-single","snapshot","evaluation","callback-reads"];
|
||||
let faults=(1..=7).map(|n|(format!("fault-callback-{n}"),if n==7{prometeu_bytecode::TRAP_DIV_ZERO}else{prometeu_bytecode::TRAP_EXPLICIT}))
|
||||
.chain((1..=7).map(|n|(format!("fault-equals-{n}"),if n==7{prometeu_bytecode::TRAP_DIV_ZERO}else{prometeu_bytecode::TRAP_EXPLICIT})))
|
||||
.chain(std::iter::once(("fault-overflow".to_string(),prometeu_bytecode::TRAP_EXPLICIT)));
|
||||
let mut count=0;
|
||||
for (base,fault) in successes.into_iter().map(|n|(n.to_string(),None)).chain(faults.map(|(n,f)|(n,Some(f)))) {
|
||||
for suffix in ["","-optimized"] {
|
||||
let name=format!("{base}{suffix}");let bytes=std::fs::read(root.join(format!("pbs-map-{name}.pbx"))).unwrap_or_else(|e|panic!("mandatory Map {name}: {e}"));
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap_or_else(|e|panic!("Map {name}: {e:?}"));
|
||||
let registry=image.registry().clone();let mut vm=VirtualMachine::from_image(image,Default::default());let observer=vm.resource_observer();
|
||||
vm.prepare_boot_call().unwrap();let report=vm.run_budget(20_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();
|
||||
if let Some(code)=fault {
|
||||
let End::Trap(info)=report.reason else{panic!("{name}: {report:?}")};assert_eq!(info.code,code,"{name}: {info:?}");
|
||||
if base.starts_with("fault-callback")||base.starts_with("fault-equals") {
|
||||
use prometeu_vm::resource_diagnostics::StorageValue as V;
|
||||
let objects=vm.heap().diagnostic_typed_storage();
|
||||
let owner=objects.iter().find(|o|registry.declarations().types[o.type_id.0 as usize].name.as_deref()==Some("map<int, int>")).expect("faulted Map retained");
|
||||
let populated=base.starts_with("fault-equals");
|
||||
assert_eq!(owner.groups[1],vec![V::Int64(if populated{1}else{0})]);assert_eq!(owner.groups[3],vec![V::Boolean(true)]);
|
||||
if populated{assert!(objects.iter().any(|o|registry.declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_MapNode<int, int>")&&o.groups[1]==vec![V::Int32(0)]&&o.groups[2]==vec![V::Int32(20)]));}
|
||||
else{assert_eq!(owner.groups[0],vec![V::Null]);}
|
||||
}
|
||||
} else {assert!(matches!(report.reason,End::Halted|End::EndOfRom),"{name}: {report:?}");assert_eq!(vm.operand_stack_top(1),vec![Value::Int32(42)],"{name}");}
|
||||
drop(vm);for q in [Q::GuestBytes,Q::HandleSlots,Q::AuxiliaryBytes,Q::TemporaryBytes,Q::StringBytes,Q::StringAllocations]{assert_eq!(observer.used(q),0,"{name}: owner release {q:?}");}
|
||||
count+=1;println!("MAP SOURCE/LOAD/EXEC/GUARD PASS {name}");
|
||||
}
|
||||
}
|
||||
println!("MAP MANDATORY SOURCE CASES {count}");
|
||||
verify_map_refusals(root);verify_map_postpublication_injection(root);verify_map_cursor_gc(root);verify_map_collection_gc(root);verify_map_distribution(root);
|
||||
}
|
||||
|
||||
fn verify_map_cursor_gc(root:&std::path::Path) {
|
||||
for suffix in ["","-optimized"] {verify_map_cursor_gc_variant(root,suffix);}
|
||||
}
|
||||
fn verify_map_cursor_gc_variant(root:&std::path::Path,suffix:&str) {
|
||||
use prometeu_vm::LogicalFrameEndingReason as End;
|
||||
let bytes=std::fs::read(root.join(format!("pbs-map-gc{suffix}.pbx"))).expect("mandatory Map snapshot GC fixture");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let mut vm=VirtualMachine::from_image(image.clone(),Default::default());vm.prepare_boot_call().unwrap();let mut previous=0;
|
||||
for (round,count) in [1200,1,1,0].into_iter().enumerate() {
|
||||
let report=vm.run_budget(100_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::FrameSync),"Map cursor GC {round}: {report:?}");
|
||||
let snapshot=vm.resource_snapshot();assert!(snapshot.gc.collections>previous);previous=snapshot.gc.collections;
|
||||
let objects=vm.heap().diagnostic_typed_storage();
|
||||
assert!(!objects.iter().any(|o|matches!(image.registry().declarations().types[o.type_id.0 as usize].kind,prometeu_bytecode::registry::TypeKind::Array(_))),"snapshot retains no Map table");
|
||||
for (name,expected) in [("_SnapshotNode<keyval<Item, Item>>",count),("keyval<Item, Item>",count),("Item",count*2),("_MapNode<Item, Item>",0)] {
|
||||
assert_eq!(objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some(name)).count(),expected,"Map cursor GC {round}: {name}");
|
||||
}
|
||||
println!("MAP CURSOR/KEYVAL/KEY/VALUE GC PASS {suffix} round={round} nodes={count} items={}",count*2);
|
||||
}
|
||||
let report=vm.run_budget(100_000,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::Halted|End::EndOfRom));assert_eq!(vm.operand_stack_top(1),vec![Value::Int32(42)]);
|
||||
}
|
||||
|
||||
fn verify_map_distribution(root:&std::path::Path) {
|
||||
use prometeu_vm::{LogicalFrameEndingReason as End,resource_diagnostics::StorageValue as V};
|
||||
for name in ["imports","installed"] {
|
||||
let bytes=std::fs::read(root.join(format!("pbs-map-{name}.pbx"))).expect("mandatory Map workspace/installed example");
|
||||
let image=ValidatedProgramImage::load(&bytes,&mut LoadBudget::new(LoadLimits::default()),caps::NONE).unwrap();
|
||||
let mut vm=VirtualMachine::from_image(image.clone(),Default::default());vm.prepare_boot_call().unwrap();
|
||||
let report=vm.run_budget(2_000_000,&mut NoNative,&mut HostContext::new(None)).unwrap();assert!(matches!(report.reason,End::FrameSync|End::Halted|End::EndOfRom),"Map distribution {name}: {report:?}");
|
||||
let objects=vm.heap().diagnostic_typed_storage();
|
||||
let cursors=objects.iter().filter(|o|image.registry().declarations().types[o.type_id.0 as usize].name.as_deref()==Some("_SnapshotCursor<keyval<str, optional int>>")).collect::<Vec<_>>();
|
||||
assert!(!cursors.is_empty(),"installed/imported Map actually constructs the common entry Cursor");
|
||||
let get=|r|objects.iter().find(|o|o.reference==r).unwrap();
|
||||
for cursor in cursors {
|
||||
let V::Reference(carrier)=cursor.groups[0][0] else{panic!("current carrier")};let V::Reference(node)=get(carrier).groups[0][0] else{panic!("node")};
|
||||
assert_eq!(get(node).groups[1],vec![V::Null],"complete traversal retains sticky final node");
|
||||
let V::Reference(entry)=get(node).groups[0][0] else{panic!("captured keyval")};
|
||||
assert_eq!(image.registry().declarations().types[get(entry).type_id.0 as usize].name.as_deref(),Some("keyval<str, optional int>"));
|
||||
}
|
||||
println!("MAP DISTRIBUTION SOURCE/LOAD/EXEC PASS {name}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ parser.add_argument("--fixtures", type=pathlib.Path, default=pathlib.Path("prome
|
||||
parser.add_argument("--online", action="store_true", help="Allow Cargo to fetch uncached dependencies")
|
||||
parser.add_argument("--release", action="store_true", help="Execute an optimized runtime harness")
|
||||
parser.add_argument("--set-only", action="store_true", help="Run mandatory PBS Set corpus")
|
||||
parser.add_argument("--map-only", action="store_true", help="Run mandatory PBS Map/Keyval corpus")
|
||||
parser.add_argument("--identity-hashing-only", action="store_true", help="Run mandatory neutral and PBS identity/hash corpus")
|
||||
parser.add_argument("--math-only", action="store_true", help="Run the complete PBS math corpus only")
|
||||
parser.add_argument("--random-only", action="store_true", help="Run the complete PBS Random corpus only")
|
||||
@@ -58,4 +59,4 @@ with tempfile.TemporaryDirectory(prefix="pbx-conformance-") as directory:
|
||||
(root / "Cargo.lock").write_text((runtime / "Cargo.lock").read_text())
|
||||
(root / "src").mkdir()
|
||||
(root / "src/main.rs").write_text(pathlib.Path(__file__).with_name("main.rs").read_text())
|
||||
subprocess.run(["cargo", "run", *(["--release"] if args.release else []), *([] if args.online else ["--offline"]), "--manifest-path", str(root / "Cargo.toml"), "--", str(args.fixtures.resolve()), str(runtime / "devtools/headless-protocol/response.schema.json"), *(["--set-only"] if args.set_only else []), *(["--identity-hashing-only"] if args.identity_hashing_only else []), *(["--math-only"] if args.math_only else []), *(["--random-only"] if args.random_only else []), *(["--generic-contracts-only"] if args.generic_contracts_only else []), *(["--generic-structs-only"] if args.generic_structs_only else []), *(["--list-cursor-only"] if args.list_cursor_only else []), *(["--linked-only"] if args.linked_only else [])], check=True)
|
||||
subprocess.run(["cargo", "run", *(["--release"] if args.release else []), *([] if args.online else ["--offline"]), "--manifest-path", str(root / "Cargo.toml"), "--", str(args.fixtures.resolve()), str(runtime / "devtools/headless-protocol/response.schema.json"), *(["--map-only"] if args.map_only else []), *(["--set-only"] if args.set_only else []), *(["--identity-hashing-only"] if args.identity_hashing_only else []), *(["--math-only"] if args.math_only else []), *(["--random-only"] if args.random_only else []), *(["--generic-contracts-only"] if args.generic_contracts_only else []), *(["--generic-structs-only"] if args.generic_structs_only else []), *(["--list-cursor-only"] if args.list_cursor_only else []), *(["--linked-only"] if args.linked_only else [])], check=True)
|
||||
|
||||
Reference in New Issue
Block a user