cli: add safe owning general-key hash sets
Add std.hashset with explicit pure hash/equality policies and complete owning keys. Duplicate/full insert returns the original input, while remove/pop and nonempty free preserve explicit resource ownership. Reuse safe HashMap storage and failure/peak/refund accounting. Integrate normative contracts, RFC, references, complexity measurements, CLI/profile checks and independent Copy/owner set traces. Validation: 973 conformance cases; runtime set GC and schedule stress; unit/Quick Reference, formatting, hosted smoke, 53 CLI checks, 106 source coverage constructs and bundle generation.
This commit is contained in:
1 parent
7743f515c5
commit
4716cda0f1
43 files changed
+2696
-7
No files matched your search
@@ -121,3 +121,5 @@ RFC 0028 numeric-key owning map (cl100k, relative to error_values; includes the
|
||||
RFC 0029 static function parameters (cl100k, relative to numeric maps): Quick Reference 7,863 → 8,051 (+2.4%); other source docs 50,079 → 51,002 (+1.8%); full source excluding AIR 57,942 → 59,053 (+1.9%). language/generics.md is 2,194 tokens; AIR remains 179,282 bytes / 51 sections. One explicit operation-selection concept adds two source forms and bounded frontend state, with no runtime/verifier state or new AIR construct/diagnostic. Cumulative growth is +73.8%; the RFC justifies the general hash/equality/order prerequisite, keeps general collections open and makes no empirical MCC claim.
|
||||
|
||||
RFC 0030 general owning HashMap (cl100k, relative to static operations): Quick Reference 8,051 → 8,124 (+0.9%), other source docs 51,002 → 53,363 (+4.6%), full source excluding AIR 59,053 → 61,487 (+4.1%). library/std.md is 16,504 tokens; AIR remains 179,282 bytes / 51 sections. Ten safe source functions use explicit static policies and complete key/value transfer, with no new language form, verifier/runtime state or diagnostic. Cumulative source growth is +80.9%, justified in the RFC without an empirical MCC claim; full policies/failure/dense-index invariants stay on demand.
|
||||
|
||||
RFC 0031 general owning HashSet (cl100k, relative to HashMap): Quick Reference 8,124 → 8,201 (+0.9%), other source docs 53,363 → 54,798 (+2.7%), full source excluding AIR 61,487 → 62,999 (+2.5%). library/std.md is 17,939 tokens; AIR remains 179,282 bytes / 51 sections. Nine safe wrappers return duplicate/full incoming keys and transfer stored keys through ordinary ownership rules. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +85.4%, justified by explicit ownership/accounting contracts without an empirical MCC claim.
|
||||
@@ -365,6 +365,8 @@ The usual enum rules apply: missing arm `E7004`, wrong enum/payload `E7005`, unk
|
||||
|
||||
`std.hashmap.HashMap<K,V,fn hash,fn equal>` supports general owning keys/values through explicit pure ref-key operations (§12). Insert returns replaced/full key/value pairs; remove/pop move both out, get requires only V: Copy, growth is explicit and free returns nonempty maps. Full contracts are in `/docs/library/std.md`.
|
||||
|
||||
`std.hashset.HashSet<K,fn hash,fn equal>` uses the same policies for complete owning keys. Insert returns `present(input)` for duplicates, preserving the stored key, or `full(input)`; remove/pop move stored keys out. Only new/reserve allocate with explicit authority; free returns nonempty sets. Full contracts are in `/docs/library/std.md`.
|
||||
|
||||
`std.hash.fnv1a64` and `crc32c` hash byte slices without allocation; their `_extend` forms continue from a previous result. Hashes do not establish key equality or authentication. Exact algorithms and chunk/byte-order conventions are in `/docs/library/std.md`.
|
||||
|
||||
## 11. Package modules
|
||||
|
||||
@@ -8,7 +8,7 @@ The other files in `/docs` hold the full rules. Open one only when this page is
|
||||
|
||||
| Need | Read |
|
||||
|---|---|
|
||||
| built-in bytes/math/text/formatting/hash, option/result, owning Vec/Deque and numeric/general maps, signatures and failure contracts | `/docs/library/std.md` |
|
||||
| built-in bytes/math/text/formatting/hash, option/result, owning Vec/Deque, numeric/general maps and general sets, signatures and failure contracts | `/docs/library/std.md` |
|
||||
| initialized buffer storage, explicit growth/drain and child views | `/docs/language/buffers.md` |
|
||||
| whole-value linear aggregates, unpack, exchange and allocation failure | `/docs/language/linear-aggregates.md` |
|
||||
| generic declarations/applications, property constraints, static function contracts and specialization limits | `/docs/language/generics.md` |
|
||||
|
||||
@@ -141,4 +141,4 @@ Lowering layers (P6A-3/4), each with accepted (golden AIR), rejected (`E7xxx`) a
|
||||
| P6-9 | todo | Port reference programs and examples to `.aji` | P6-5 | `tests/programs/`, `examples/` | exit criterion passes |
|
||||
| P6-10 | todo | Phase exit review | all | plan status | exit criterion passes |
|
||||
|
||||
The [standard-library track](standard-library.md) implements thirteen compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 on the branch with explicit manifest source mapping, acyclic linking, direct qualified names, imported struct literals and task workers. Dependency fetching/resolution is separate package work; STD-4/RFC 0022 completes explicit generics and structural constraints on the branch. STD-5/RFC 0023 adds whole-value linear structs/enums/fixed arrays, complete unpack/match, explicit exchange and ownership-preserving allocation failure through all layers (spec 15 §16). STD-6a/b/RFC 0024 resolves Q-036 with initialized buffer<T> and safe std.vec, explicit growth, returned failure ownership and draining (spec 15 §17). STD-6c/RFC 0025 adds safe owning Deque with existing source primitives. STD-6d.1/RFC 0026 adds pure std.hash; STD-6d.2/RFC 0028 adds safe owning U64Map<V> after the explicit error_values prerequisite (RFC 0027). STD-6d.3/RFC 0029 adds explicit static function parameters for general hash/equality/order operations with existing AIR calls/workers. STD-6d.4/RFC 0030 implements the general owning-key std.hashmap contract; its final GC/stress validation remains in progress (Q-037). Remaining sets/heaps are STD-6d. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6.
|
||||
The [standard-library track](standard-library.md) implements fourteen compiler-pinned modules and qualified standard enum names. STD-3/RFC 0021 completes P6-3 on the branch with explicit manifest source mapping, acyclic linking, direct qualified names, imported struct literals and task workers. Dependency fetching/resolution is separate package work; STD-4/RFC 0022 completes explicit generics and structural constraints on the branch. STD-5/RFC 0023 adds whole-value linear structs/enums/fixed arrays, complete unpack/match, explicit exchange and ownership-preserving allocation failure through all layers (spec 15 §16). STD-6a/b/RFC 0024 resolves Q-036 with initialized buffer<T> and safe std.vec, explicit growth, returned failure ownership and draining (spec 15 §17). STD-6c/RFC 0025 adds safe owning Deque with existing source primitives. STD-6d.1/RFC 0026 adds pure std.hash; STD-6d.2/RFC 0028 adds safe owning U64Map<V> after the explicit error_values prerequisite (RFC 0027). STD-6d.3/RFC 0029 adds explicit static function parameters for general hash/equality/order operations with existing AIR calls/workers. STD-6d.4/RFC 0030 implements the general owning-key std.hashmap contract; its final GC/stress validation remains in progress (Q-037). STD-6d.5/RFC 0031 implements general owning std.hashset with duplicate input return; its conformance, GC/schedule, CLI and documentation checks pass. BinaryHeap remains STD-6d. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6.
|
||||
@@ -20,7 +20,7 @@ Without external source dependencies, Aji should support ordinary CLI tools, sto
|
||||
|---|---|---|
|
||||
| Scalars, structs/enums, slices/arrays, explicit borrows | implemented | pure fixed-storage algorithms can start now |
|
||||
| Heap/regions, I/O, files, TCP, clock/random, structured tasks/channels/mutex | implemented primitives | wrappers can reuse them, but their presence does not imply the complete APIs below |
|
||||
| Built-in standard imports and enum types | STD-0/1a/2a/2b branch implementation | compiler-pinned, closed registry; eleven modules; qualified enum types/constructors/patterns; no package lookup |
|
||||
| Built-in standard imports and enum types | STD-0/1a/2a/2b branch implementation | compiler-pinned, closed registry; fourteen modules; qualified enum types/constructors/patterns; no package lookup |
|
||||
| General modules/imported struct literals | STD-3 branch implementation (P6-3; RFC Proposed) | explicit manifest mapping, direct qualified names, ordinary verifier |
|
||||
| User generics/structural constraints | STD-4 branch implementation (P6-4; RFC Proposed) | needed for reusable `Vec<T>`, `HashMap<K,V>`, option/result |
|
||||
| `linear_aggregates` | STD-5 branch implementation (RFC Proposed) | whole-value owning structs/enums/fixed arrays; initialized buffer<T>/std.vec implemented by STD-6a/b |
|
||||
@@ -57,12 +57,13 @@ SQL/database clients, Redis/Kafka, ORMs, application authentication, gRPC/protob
|
||||
| STD-6a | done (branch implementation; RFC 0024 Proposed) | dynamic initialized buffer<T> storage/drain contract (Q-036) | STD-4/5 | vertical allocate/grow/push/pop/view/free; allocation failures preserve state, returned owners consumed; no hidden destruction |
|
||||
| STD-6b | done (branch implementation; RFC 0024 Proposed) | safe std.vec for Copy/owners/files/channel endpoints | STD-6a | explicit reserve, bounded push, moving pop/replace, empty-only free; deterministic and failure/cleanup tests |
|
||||
| STD-6c | done (branch implementation; RFC 0025 Proposed) | safe std.deque for Copy/owners/files/endpoints | STD-6a/b | bounded ring, both ends, failure-preserving explicit growth, complete resource transfer and empty-only free |
|
||||
| STD-6d | todo (hash and numeric-key map done; general keys, sets and heaps remain) | HashMap, HashSet, BinaryHeap | STD-6a/b/c | safe collection contracts, including HashMap<Key, Own<Value>>, recoverable failures and explicit draining |
|
||||
| STD-6d | in progress (maps/set implemented; heap and final general-map GC remain) | HashMap, HashSet, BinaryHeap | STD-6a/b/c | safe collection contracts, including HashMap<Key, Own<Value>>, recoverable failures and explicit draining |
|
||||
| STD-6d.1 | done (branch implementation; RFC 0026 Proposed) | pure std.hash: FNV-1a 64 / CRC32C, fresh/extend | STD-1b | four safe functions, exact byte/chunk conventions, independent public vectors and CLI/profile checks |
|
||||
| STD-6d.2a | done (branch implementation; RFC 0027 Proposed) | pure built-in error construction prerequisite | STD-6d.1 | vertical error_values feature, no authority/effect/resource changes; preflight allocation validation |
|
||||
| STD-6d.2 | done (numeric-key branch implementation; RFC 0028 Proposed) | U64Map<V> first; general HashMap<K,V> key policy Q-037 | STD-6d.1 | safe map with ownership/failure/collision tests and error_values prerequisite (RFC 0027); general-key gate remains open |
|
||||
| STD-6d.3 | done (branch implementation; RFC 0029 Proposed) | explicit static hash/equality/order functions | STD-4 | exact callable contracts, ordinary AIR calls/workers and nominal operation identity; general collections remain required |
|
||||
| STD-6d.4 | implementation validated; final GC/stress in progress (RFC 0030 Proposed) | general owning HashMap<K,V,H,E> | STD-6d.3 | dense complete entries, Copy probe indices, exact equality and returned key/value ownership |
|
||||
| STD-6d.5 | done (branch implementation; RFC 0031 Proposed) | general owning HashSet<K,H,E> | STD-6d.4 | exact membership, duplicate/full input ownership, moving extraction and empty-only free |
|
||||
| STD-7 | todo | concrete I/O adapters, buffered I/O and lexical paths | STD-1b/2a/2b; STD-3 for public types | short reads, EOF, capacity and write failures covered; paths never grant filesystem authority |
|
||||
| STD-8 | todo | filesystem gaps, args/env capability RFC, time/random distinctions and structured log | STD-3/7; vertical runtime feature where needed | CLI/storage milestone examples work in deterministic and hosted profiles; all authority is granted at entry |
|
||||
| STD-9 | todo | independent integration application and API review | STD-6/7/8 | integration gate; public application is not private benchmark material |
|
||||
@@ -144,3 +145,10 @@ STD-6d.1/RFC 0026 adds safe std.hash with four byte-only fresh/continuation oper
|
||||
## General operation-selection prerequisite
|
||||
|
||||
STD-6d.3/RFC 0029 implements explicitly bound static functions with exact typed/effect contracts, forwarding, generic function arguments, nominal operation identity and named workers. It reuses ordinary AIR and preserves direct-import visibility, capability inputs, ownership and task loans. Source/AIR positives/rejections, recursive/cyclic contracts, GC/scheduler stress, CLI/profile/provenance checks and documentation budgets are recorded in the RFC. General HashMap/HashSet storage/API remains Q-037; BinaryHeap and STD-7 are still required.
|
||||
|
||||
|
||||
## General owning set verification
|
||||
|
||||
STD-6d.5/RFC 0031 implements safe HashSet<K,H,E> over the general map, with nine explicit operations. Duplicate insertion preserves every stored entry/bucket and returns the exact incoming key, including its resources; full does likewise for new keys. Remove/pop transfer complete stored keys, and nonempty free returns the whole set. Allocation, failure rollback, peak/refund accounting and dense pop order follow the map. No new language syntax, verifier/runtime state, diagnostic, AIR feature or trusted boundary is added.
|
||||
|
||||
All 973 conformance cases pass, including 26 set cases. Runtime fixtures pass collection before every instruction; the shared lookup fixture passes 12 seeds under quanta 1, 2, 7 and its own quantum. Independent Python set/representative oracles cover 80 operations across Copy/owning traces and check membership after each operation. Byte-buffer/file keys, exact duplicate-table preservation, returned owners, allocation failure/refunds/peaks and rejected leaks/moves/aliases/loans/policies/non-Share contents are covered. Unit/Quick Reference, formatting, hosted smoke, 53 CLI/profile/package/source/AIR checks, 106/106 source coverage constructs and bundle generation pass. RFC 0031 records documentation growth. The separate general-map full GC/stress process remains pending; BinaryHeap is the next collection increment, followed by STD-7 I/O/path.
|
||||
+24
-2
@@ -1,8 +1,8 @@
|
||||
# Standard library API
|
||||
|
||||
Normative contracts: spec 16. Import rules: spec 15 §13. These modules are bundled with the compiler, with no external source dependencies. Allocation authority is explicit for std.vec/std.deque/std.map/std.hashmap new/reserve.
|
||||
Normative contracts: spec 16. Import rules: spec 15 §13. These modules are bundled with the compiler, with no external source dependencies. Allocation authority is explicit for std.vec/std.deque/std.map/std.hashmap/std.hashset new/reserve.
|
||||
|
||||
Except std.vec/std.deque/std.map/std.hashmap new/reserve, functions below declare `effects []`, allocate no heap memory and retain no borrows. Pass arrays/slices using explicit `ref` or `mut`. Names are fully qualified; no alias or short-name import exists.
|
||||
Except std.vec/std.deque/std.map/std.hashmap/std.hashset new/reserve, functions below declare `effects []`, allocate no heap memory and retain no borrows. Pass arrays/slices using explicit `ref` or `mut`. Names are fully qualified; no alias or short-name import exists.
|
||||
|
||||
| Module | Function signature | Result/failure |
|
||||
|---|---|---|
|
||||
@@ -326,3 +326,25 @@ Here HashMap abbreviates the fully applied type, and Entry<K,V> has key: K/value
|
||||
Only new/reserve allocate and declare mem.alloc with explicit authority. Growth has no implicit trigger and returned failure preserves every old entry/bucket and pop order. A capacity N reserves N StoredEntry slots (hash + full K/V sizes) and 2N Copy Bucket slots (hash + usize + state tag). Live entries form an initialized dense prefix, with a separate probe-index table and cached hashes. Removing a middle entry exchanges the last into its position, repairing the index. Pop drains reverse current dense order; reserve preserves it and clears tombstones. Zero capacity is valid. Peak growth includes both entry buffers, both index buffers and external user owners; refunds follow the recorded allocation capabilities. Capacity-one Key{id:u64}/own<u64> reserves 58 bytes, plus 8 for the owned payload in the [checked example](../../examples/std/hashmap.aji), which runs with heap=mem.alloc:66.
|
||||
|
||||
Representation fields are ordinary visible source; manual construction/mutation must preserve the full invariant in spec 16 §2.14. Hash/equality traps and fuel exhaustion are abnormal outcomes. Existing moves, alias/task-loan and Copy/Send/Share rules apply without unsafe or map-specific runtime semantics. Worst-case lookup/insert/remove/pop is O(N) plus callback work, rehash O(N²); no adversarial collision/native-throughput guarantee is made. `std.map.U64Map<V>` retains its existing API for numeric keys.
|
||||
|
||||
## Owning general-key sets
|
||||
|
||||
Import `std.hashset` and `std.option` for extraction results. `HashSet<K,fn hash,fn equal>` uses the map's exact pure `fn(ref<K>) -> u64 effects []` / `fn(ref<K>,ref<K>) -> bool effects []` contracts and stable equality/hash laws. Complete owning keys, including byte buffers and resource-bearing structs, need no Copy constraint. Every operation supplies `::<K,fn hash,fn equal>`:
|
||||
|
||||
| Function arguments | Result |
|
||||
|---|---|
|
||||
| new(capacity: usize, heap: cap<mem.alloc>) | NewResult<K,fn hash,fn equal>: ok(HashSet), err(alloc_error) |
|
||||
| len(set: ref<HashSet>) | usize live count |
|
||||
| capacity(set: ref<HashSet>) | usize maximum live keys |
|
||||
| reserve(set: mut<HashSet>, capacity: usize, heap: cap<mem.alloc>) | ReserveResult: ok, err(alloc_error) |
|
||||
| insert(set: mut<HashSet>, key: K) | InsertResult<K>: inserted, present(K), full(K) |
|
||||
| contains(set: ref<HashSet>, key: ref<K>) | bool |
|
||||
| remove(set: mut<HashSet>, key: ref<K>) | std.option.Option<K> moving extraction |
|
||||
| pop(set: mut<HashSet>) | std.option.Option<K> moving extraction |
|
||||
| free(set: HashSet) | FreeResult<K,fn hash,fn equal>: ok, not_empty(HashSet) |
|
||||
|
||||
Here HashSet abbreviates the applied type. Duplicate insertion preserves the stored representative and every entry/bucket, returning the original incoming K as present, even at capacity. Full returns the original new key. Remove/pop return stored keys; free returns a nonempty set. Explicitly consume all owning results. Use `move` for named linear inputs and `ref q` for queries through mut q; contains retains no borrow. Replacement requires explicit remove followed by insert.
|
||||
|
||||
Only new/reserve allocate with mem.alloc and explicit authority. There is no automatic growth or cleanup. The visible representation is `map: std.hashmap.HashMap<K,bool,fn hash,fn equal>` with every live value true; callers must preserve spec 16 §2.15's complete invariant. Dense extraction/pop order, failure preservation, peak accounting and refunds follow the map. Each capacity slot charges hash + K + bool and two buckets: 51 bytes for u64, or 59 for Key{id:u64,owner:own<u64>}, plus the separately allocated payload. The [owning example](../../examples/std/hashset.aji) returns 42 with heap=mem.alloc:67.
|
||||
|
||||
Policies may run for membership and again for insertion, with no runtime dispatch or gained authority. Existing moves/aliases/task loans and Copy/Send/Share checks apply. Callback traps/fuel exhaustion are abnormal outcomes. Worst-case membership/insert/remove/pop is O(N) plus callbacks; growth is O(N²) under collisions. No sorted iteration or native-throughput guarantee is made.
|
||||
@@ -0,0 +1,47 @@
|
||||
# RFC 0031: Safe owning general-key hash set
|
||||
|
||||
Status: Proposed
|
||||
Scope: STD-6d.5, safe library source after RFCs 0029/0030
|
||||
|
||||
## Motivation and normative changes
|
||||
|
||||
General maps provide exact explicit hash/equality and complete owning keys. Spec 16 §2.15 adds std.hashset without set-specific language machinery. Duplicate insertion returns the original input and retains the existing representative, exposing resource ownership without hidden destructors.
|
||||
|
||||
## Preserved invariant
|
||||
|
||||
The underlying general map's dense/probe invariant holds with bool values true. Every live K has one owned occurrence; equal keys are unique. Keys/hash/equality remain stable. Duplicate/full/failing-growth paths preserve stored entries/buckets and return input ownership as specified.
|
||||
|
||||
## Verifier rule
|
||||
|
||||
No new transfer function: complete struct/enum/buffer moves, exact static callable contracts, borrow/task-loan exclusion, bounds, effects, Copy/Send/Share and explicit consumption apply. All code is ordinary safe Aji.
|
||||
|
||||
## Runtime and deterministic behavior
|
||||
|
||||
Nine wrappers use existing map AIR calls, without runtime dispatch, allocation beyond explicit new/reserve or cleanup. Normal failure preserves all old state; peak charges/refunds and deterministic pop order follow the map. User callback traps/fuel are abnormal outcomes.
|
||||
|
||||
## Valid and rejected examples
|
||||
|
||||
An owning byte/struct key is moved into insert. Duplicate/full returns the original key for explicit consumption. A successful remove/pop returns the stored key; nonempty free returns the set. Missing moves, ignored owning results, bad aliases/task loans, invalid effect/policy bindings and sharing non-Share keys reject through existing diagnostics.
|
||||
|
||||
The [owning example](../../examples/std/hashset.aji) allocates one slot and one payload with a 67-byte grant, inserts the complete key, pops/unpacks/takes it and frees the empty set. [Owning duplicates](../../tests/conformance/source/hashset/owner.aji) return the incoming payload and retain the original. [A leaked duplicate](../../tests/conformance/source/hashset/present_leak.aji) rejects with E3002; [missing move](../../tests/conformance/source/hashset/missing_move.aji) rejects with E7003; [a file key shared with a worker](../../tests/conformance/source/hashset/not_share.aji) rejects with E4002.
|
||||
|
||||
## Diagnostics / compatibility / AIR
|
||||
|
||||
No new code, opcode, AIR feature, source syntax or verifier/runtime state. Existing source/type/availability/alias/effect/Send/Share diagnostics apply. Registry addition is additive and imports grant no authority; old APIs retain meaning.
|
||||
|
||||
## Agent complexity impact
|
||||
|
||||
No additional language concept beyond explicit static policy arguments. Nine operations omit value lookup and replacement alternatives; duplicate handling clearly distinguishes stored and returned owner. An extra membership check reuses the map and its stable callback laws, avoiding a new primitive or overwrite/destructor rule. Full API/representation/accounting stays on demand; measured bundle growth and executable validation are recorded below. No empirical MCC result is claimed.
|
||||
|
||||
No new syntax form, diagnostic or verifier state. Relative to RFC 0030, cl100k Quick Reference grows 8,124 → 8,201 (+0.9%); other source documentation 53,363 → 54,798 (+2.7%); full source excluding AIR 61,487 → 62,999 (+2.5%). The on-demand std reference is 17,939 tokens. Corresponding o200k counts are 8,234 / 54,977 / 63,211; qwen2.5 counts are 8,451 / 56,295 / 64,746. AIR remains 179,282 bytes, 19 files and 51 sections; its source-bundle copy remains 46,300 / 46,451 / 47,800 tokens. Cumulative cl100k source growth from the 33,981-token pre-std baseline is +85.4%. The increase buys explicit duplicate ownership, nine signatures and representation/failure/quota laws; mandatory Quick Reference stays at one short paragraph. No language expansion or measured compression benefit is claimed.
|
||||
|
||||
## Validation gate
|
||||
|
||||
Copy/owning/byte keys, duplicate/full preservation, collisions, pop/remove order, zero capacity, growth failure/refunds/peak, rejected leaks/moves/loans/policy/effects, independent Python set traces, source/AIR/package/profile checks, GC/scheduler stress and documentation budgets are required. BinaryHeap and I/O/path remain following increments.
|
||||
|
||||
|
||||
## Validation result
|
||||
|
||||
Full conformance passes 973/973, including 26 set fixtures. All runtime set fixtures pass collection before every instruction, including both independent model traces; shared lookup runs 12 schedule seeds under quanta 1, 2, 7 and its own quantum. Existing compilation checks reject owner leaks, missing moves, bad borrows/task loans, wrong nominal policies, missing effects and non-Share file keys. Copy and owning key traces use independent Python set/representative/dense-order oracles for 80 operations, checking every domain key after every operation. Duplicate input/stored representative and complete probe metadata, owning byte keys, files, full/remove/pop/nonempty-free ownership, zero/overflow, both failure phases, rollback, exact peaks and cross-authority refunds are covered.
|
||||
|
||||
Unit/Quick Reference checks, formatting, hosted smoke, agent-reference generation, source coverage (106/106 constructs) and 53 CLI checks pass. CLI checks compare source/AIR results, hosted execution, explicit package policies, reordered imports, report/audit and callback provenance. AIR and source syntax remain unchanged. The separate general-map full GC/stress process remains running, with no result claimed here and no wall-clock termination. BinaryHeap and I/O/path remain subsequent work.
|
||||
@@ -10,7 +10,7 @@ APIs SHOULD offer one canonical operation for a common need, small documentation
|
||||
|
||||
## 2. Bootstrap module registry
|
||||
|
||||
The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.fmt`, `std.hash`, `std.hashmap`, `std.map`, `std.math`, `std.option`, `std.result`, `std.utf8`, `std.vec` and `std.deque`. They are implemented in safe `.aji`; their stable source paths are `std/bytes.aji`, `std/encoding/base64.aji`, `std/encoding/hex.aji`, `std/fmt.aji`, `std/hash.aji`, `std/hashmap.aji`, `std/map.aji`, `std/math.aji`, `std/option.aji`, `std/result.aji`, `std/utf8.aji`, `std/vec.aji` and `std/deque.aji`, respectively. Spec 15 §13 defines imports; the reference API tables are in `reference/std.md`. All operations are deterministic in every profile and have no concurrency effects. Modules other than std.vec/std.deque/std.map/std.hashmap declare effects [] and allocate no heap memory. std.vec/std.deque/std.map/std.hashmap new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11, §2.13–§2.14); their other functions allocate no heap. Ordinary interpreter fuel limits apply.
|
||||
The built-in registry contains `std.bytes`, `std.encoding.base64`, `std.encoding.hex`, `std.fmt`, `std.hash`, `std.hashmap`, `std.hashset`, `std.map`, `std.math`, `std.option`, `std.result`, `std.utf8`, `std.vec` and `std.deque`. They are implemented in safe `.aji`; their stable source paths are `std/bytes.aji`, `std/encoding/base64.aji`, `std/encoding/hex.aji`, `std/fmt.aji`, `std/hash.aji`, `std/hashmap.aji`, `std/hashset.aji`, `std/map.aji`, `std/math.aji`, `std/option.aji`, `std/result.aji`, `std/utf8.aji`, `std/vec.aji` and `std/deque.aji`, respectively. Spec 15 §13 defines imports; the reference API tables are in `reference/std.md`. All operations are deterministic in every profile and have no concurrency effects. Modules other than std.vec/std.deque/std.map/std.hashmap/std.hashset declare effects [] and allocate no heap memory. std.vec/std.deque/std.map/std.hashmap/std.hashset new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11, §2.13–§2.15); their other functions allocate no heap. Ordinary interpreter fuel limits apply.
|
||||
|
||||
### 2.1 `std.math`
|
||||
|
||||
@@ -261,3 +261,27 @@ Removal exchanges the last dense entry into the removed entry's position when ne
|
||||
New checks 2N overflow, allocates the empty entry buffer, then the fully initialized bucket buffer. A returned second-allocation failure MUST free the temporary empty entry buffer and refund its recorded authority. Reserve≤N is an unchanged no-op with its declared mut/effect/capability requirements. Growth MUST allocate/initialize a new bucket buffer before calling ownership-preserving buffer.reserve on the dense entries. Any returned failure MUST free temporary metadata, preserve both original buffers, every key/value/hash/index/state and pop order, and refund all temporary charges. After entries reserve succeeds, only cached hashes are used to rebuild the new buckets; no further recoverable allocation or callback occurs. Swap in the new buckets and explicitly free the old Copy metadata buffer. Peak quota includes old/new entry buffers, old/new bucket buffers and separately charged user owners. All old storage refunds go to their recorded authorities, even when growth uses another capability. Arithmetic/allocation-size overflow returns alloc_error.budget_exceeded; no shrink occurs.
|
||||
|
||||
Each StoredEntry slot charges hash plus full K/V slot sizes, including uninitialized capacity; each Bucket charges hash, usize and state tag. Unused capacity reserves bytes but contains no live K/V. There is no tag/default key allocation and no implicit destruction. Existing initialized buffers, aggregate transfer/exchange, borrows/task loans, bounds, effects, Copy/Send/Share and quota verification suffice; no new AIR instruction/feature, source form, verifier/runtime state or diagnostic is added. Generic callback contracts are RFC 0029. Valid bookkeeping does not trap with a valid representation and successful callbacks. Existing API/AIR meanings remain unchanged, including std.map.U64Map. Deterministic/hosted behavior agrees. Probe operations are O(N) worst-case plus callback work, pop/removal repair O(N), reserve O(N²) worst-case collision work; buffer-prefix interpreter copying may add host cost. No adversarial collision or native throughput promise is made.
|
||||
|
||||
### 2.15 `std.hashset`: bounded owning general-key set
|
||||
|
||||
The registry MUST include std.hashset at std/hashset.aji, ordinary safe source. HashSet<K,H,E> binds the same exact pure ref-key hash/equality contracts and stable algebraic laws as std.hashmap (§2.14), with explicit type/application arguments `K,fn hash,fn equal`. It owns complete arbitrary K, including owning byte buffers, structs, resources and endpoints subject to existing member/Send/Share rules. Its representation is one field map: std.hashmap.HashMap<K,bool,H,E>, with every live value true; all underlying dense/probe invariants apply. No default key, implicit destruction or library access privilege is added.
|
||||
|
||||
Nine operations use the three ordered arguments above:
|
||||
|
||||
| Operation | Result / transfer |
|
||||
|---|---|
|
||||
| new(capacity: usize, heap: cap<mem.alloc>) | NewResult<K,H,E>: ok(HashSet<K,H,E>), err(alloc_error) |
|
||||
| len(set: ref<HashSet<K,H,E>>) -> usize | live count |
|
||||
| capacity(set: ref<HashSet<K,H,E>>) -> usize | maximum live keys |
|
||||
| reserve(set: mut<HashSet<K,H,E>>, capacity: usize, heap: cap<mem.alloc>) | ReserveResult: ok, err(alloc_error) |
|
||||
| insert(set: mut<HashSet<K,H,E>>, key: K) | InsertResult<K>: inserted, present(original_input_K), full(original_input_K) |
|
||||
| contains(set: ref<HashSet<K,H,E>>, key: ref<K>) -> bool | exact membership |
|
||||
| remove(set: mut<HashSet<K,H,E>>, key: ref<K>) -> std.option.Option<K> | moving extraction of the stored key |
|
||||
| pop(set: mut<HashSet<K,H,E>>) -> std.option.Option<K> | moving extraction of last dense key |
|
||||
| free(set: HashSet<K,H,E>) | FreeResult<K,H,E>: ok, not_empty(HashSet<K,H,E>) |
|
||||
|
||||
Only new/reserve declare mem.alloc and take explicit heap authority. Insert checks membership before transferring to the underlying map: duplicate insertion MUST preserve the existing stored key and every entry/bucket, returning the exact input key as present, even when full. New-key full also preserves the set and returns its exact input. This gives one canonical insert contract; replacement requires explicit remove/insert by the caller. No automatic growth occurs. Owning present/full/remove/pop/not_empty results MUST be consumed. contains returns no borrow. Missing remove and nonempty free preserve all state. Pop order is the underlying reverse current dense order; removal may move the last key to a hole, and reserve preserves the order.
|
||||
|
||||
New/reserve failure, peak quota/refund, zero capacity, probing, collision equality, callback/fuel traps and visible representation invariants are exactly §2.14's rules. Each capacity slot charges hash plus complete K plus bool, and two buckets: for K=u64, N charges 51N bytes; separately owned K allocations remain separately charged. insert MAY evaluate H/E for membership and again for bounded map insertion; these pure stable operations grant no authority and cannot be inferred away. Once membership says absent, map replacement is unreachable under the valid representation/hash/equality laws; invalid laws may trap under ordinary abnormal-path semantics.
|
||||
|
||||
Existing buffers/aggregates/borrows, static callable identity, effects, Copy/Send/Share and ownership verification suffice. No new syntax, diagnostic, feature/opcode, verifier/runtime state, implicit allocation/destructor or trusted boundary is added. Deterministic/hosted behavior agrees and existing APIs/AIR meanings remain unchanged. Worst-case insertion/membership/removal/pop is O(N) plus callback work; growth is O(N²) worst-case collision work with existing interpreter prefix-copy costs. No sorted output, adversarial collision bound or native throughput promise is added.
|
||||
Reference in new issue
Block a user