cli: add caller-buffer lexical path APIs

Add pure std.path queries and failure-preserving normalization/join using
safe reverse measurement/emission and caller-provided output storage.
Component queries return explicit Copy ranges; filesystem authority is
checked independently. Complete the STD-7 implementation gate.

Validation: 1079 conformance cases, 18 path cases with per-step collection
and 12-seed schedule stress, independent 132-path/49-join capacity oracle,
68 CLI checks, fourteen previous source/std CLI suites, unit/Quick Reference,
formatting, hosted smoke, 117/117 source coverage and reference budgets.
This commit is contained in:
dev committed 2026-10-07 13:41:45 +03:00
1 parent 8d8bef8f3e
commit 8edec5b831
35 files changed
+1189 -8

No files matched your search

+2
View File
@@ -129,3 +129,5 @@ RFC 0032 owning BinaryHeap (cl100k, relative to HashSet): Quick Reference 8,201
RFC 0033 bounded I/O (cl100k, relative to BinaryHeap): Quick Reference 8,284 → 8,350 (+0.8%), other source docs 56,770 → 58,473 (+3.0%), full source excluding AIR 65,054 → 66,823 (+2.7%). library/std.md is 21,614 tokens; AIR remains 179,282 bytes / 51 sections. Six safe concrete compositions retain exact effects and caller resource loans, distinguishing EOF/limits from partial failure. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +96.6%, justified by progress/authority/cleanup contracts without an empirical MCC claim.
RFC 0034 owning buffered files (cl100k, relative to bounded I/O): Quick Reference 8,350 → 8,445 (+1.1%), other source docs 58,473 → 61,223 (+4.7%), full source excluding AIR 66,823 → 69,668 (+4.3%). library/std.md is 24,364 tokens; AIR remains 179,282 bytes / 51 sections. Ten safe concrete operations keep fixed allocation, file transfer, prefetch and first-error/partial-write cleanup visible. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +105.0%, justified by these contracts without an empirical MCC claim. Full representation/API details stay on demand; front-door consolidation remains separate work.
RFC 0035 caller-buffer paths (cl100k, relative to buffered files): Quick Reference 8,445 → 8,518 (+0.9%), other source docs 61,223 → 63,296 (+3.4%), full source excluding AIR 69,668 → 71,814 (+3.1%). library/std.md is 26,437 tokens; AIR remains 179,282 bytes / 51 sections. Six pure operations return raw Copy ranges or write a measured canonical prefix, keeping lifetime, byte syntax, capacity failure and authority visible. No new syntax, diagnostic or verifier/runtime state; cumulative source growth is +111.3%, justified by these contracts without an empirical MCC claim. API details stay on demand; front-door consolidation remains separate work.
+2
View File
@@ -373,6 +373,8 @@ The usual enum rules apply: missing arm `E7004`, wrong enum/payload `E7005`, unk
`std.io.reader`/`std.io.writer` own a file and an explicitly allocated fixed byte buffer. Use new, read/read_exact or write/flush, then finish to return the file for explicit close. Unread/failed finish returns the whole adapter; discard explicitly abandons buffered bytes and frees storage. A failed writer preserves its first error and never retries. Capacity zero uses direct I/O. Effects and ownership remain explicit; see `/docs/library/std.md`.
`std.path` provides pure slash-based is_absolute/basename/parent/extension and supplied-buffer normalize/join. Queries return Copy Range{start,end}; explicitly borrow that range from the original path. Writers preserve output on error and return the successful prefix size, with no heap or filesystem authority. Dot/parent and root rules 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
+1 -1
View File
@@ -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 eighteen 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 full GC/stress validation passes and Q-037 is resolved. STD-6d.5/RFC 0031 implements general owning std.hashset with duplicate input return; its conformance, GC/schedule, CLI and documentation checks pass. STD-6d.6/RFC 0032 implements safe owning std.heap with explicit order; conformance, GC/schedule, CLI and documentation checks pass. STD-7a/RFC 0033 implements bounded std.io composition with explicit progress, resource loans and exact effects; conformance, GC/schedule, CLI and documentation checks pass. STD-7b/RFC 0034 implements safe owning buffered file adapters with explicit finish/discard and first-error/no-retry behavior; conformance, GC/schedule, CLI and documentation checks pass. Lexical paths remain STD-7c. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6.
The [standard-library track](standard-library.md) implements nineteen 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 full GC/stress validation passes and Q-037 is resolved. STD-6d.5/RFC 0031 implements general owning std.hashset with duplicate input return; its conformance, GC/schedule, CLI and documentation checks pass. STD-6d.6/RFC 0032 implements safe owning std.heap with explicit order; conformance, GC/schedule, CLI and documentation checks pass. STD-7a/RFC 0033 implements bounded std.io composition with explicit progress, resource loans and exact effects; conformance, GC/schedule, CLI and documentation checks pass. STD-7b/RFC 0034 implements safe owning buffered file adapters with explicit finish/discard and first-error/no-retry behavior; conformance, GC/schedule, CLI and documentation checks pass. STD-7c/RFC 0035 adds pure caller-buffer lexical paths and Copy component ranges; conformance, GC/schedule, CLI and documentation checks pass. Existing `from`-returns remain unimplemented (Q-034). These increments do not complete Phase 6.
+10 -3
View File
@@ -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; eighteen 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; nineteen 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 |
@@ -65,10 +65,10 @@ SQL/database clients, Redis/Kafka, ORMs, application authentication, gRPC/protob
| STD-6d.4 | done (branch implementation; 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-6d.6 | done (branch implementation; RFC 0032 Proposed) | owning BinaryHeap<T,B> | STD-6a/6d.3 | explicit pure order, complete resource extraction, bounded push, failure-preserving growth |
| STD-7 | in progress | 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-7 | done (branch implementation; RFCs Proposed) | 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-7a | done (branch implementation; RFC 0033 Proposed) | exact/bounded reads and limited file copies | STD-1b/3 | explicit progress/EOF/error, borrowed resources, caller slices and exact effects |
| STD-7b | done (branch implementation; RFC 0034 Proposed) | owning buffered concrete file reader/writer | STD-6a/7a | failure ownership, refill/flush, explicit finish/discard and no hidden cleanup |
| STD-7c | todo | caller-buffer lexical paths | STD-1b/2a | pure normalization/join/components with no filesystem authority |
| STD-7c | done (branch implementation; RFC 0035 Proposed) | caller-buffer lexical paths | STD-1b/2a | pure normalization/join/components with no 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 |
| STD-10 | todo | IPv4/IPv6/TCP/DNS contracts and runtime gaps; task/channel helpers | STD-9 | bounded service fixtures, deterministic scheduling and schedule stress pass |
@@ -179,3 +179,10 @@ All 1027 conformance cases pass, including 20 I/O cases. All runtime I/O fixture
STD-7b/RFC 0034 implements safe std.io.reader/std.io.writer, each owning a file and a fixed-capacity initialized byte buffer. Only new allocates with explicit authority and failure returns the original file. Reads distinguish cached data/refill/EOF and finish returns unread readers. Writer errors preserve pending bytes and the first error, forbid further writes/retries, and return the whole failed writer from finish. Explicit discard reports abandoned cached/pending bytes, frees storage and returns the file. No file open/close/sync, hidden growth/cleanup or new syntax/AIR/runtime/verifier state is added.
All 1061 conformance cases pass, including 34 buffered adapter fixtures. Every buffered fixture passes collection before every instruction; worker transfer and restored loans run 12 seeds under quanta 1, 2, 7 and their own quantum. Independent byte oracles cover 48 read streams, 64 exact prefixes and 96 segmented writes. On Linux, 89 CLI/source/AIR/package/profile/provenance checks include a real read fault and four external partial-write cases; raising the child's file quota after failure proves the writer still performs no retry and preserves pending bytes/error. Unit/Quick Reference, formatting, hosted smoke, 115/115 source coverage constructs and reference generation pass. RFC 0034 records documentation growth. Lexical paths STD-7c, system gaps STD-8 and the Std 0.1 exit examples remain required; the full std roadmap is unfinished.
## Caller-buffer lexical path verification
STD-7c/RFC 0035 implements six pure std.path operations: raw component queries return bounded Copy ranges; normalize/join write into caller-provided storage with no heap or authority. NUL/size/capacity errors preserve the entire output. Reverse measurement/emission retains relative unmatched parents, drops parents above root, and needs only the final normalized capacity. Filesystem operations still enforce their independent path/grant rules.
All 1079 conformance cases pass, including 18 path fixtures. All path runtime fixtures pass collection before every instruction; shared reads and restored output loans pass 12 seeds under quanta 1, 2, 7 and their own quantum. An independent Python forward-stack oracle covers 132 paths with raw queries/idempotence and every short/exact/extra capacity, 49 joins and four malformed pairs; separate fixtures cover all 255 non-NUL bytes, disjoint slices, one-byte canceled results, late malformed input, guards/suffixes and T0008 for reused ranges. The model uses bounded batches with separate literal frames, preserving all vectors and capacities. Linux CLI/source/AIR/package/profile/provenance/audit/authority checks pass (68); all fourteen preceding std/source CLI suites pass again. Unit/Quick Reference, formatting, hosted smoke, 117/117 source construct coverage and reference generation pass. RFC 0035 records documentation growth. STD-7 and the intermediate foundation are complete; STD-8, the full Std 0.1 exit and later service milestones remain unfinished.
+23
View File
@@ -425,3 +425,26 @@ Any failed external write preserves pending bytes/used and records its first io_
The visible representations are Reader{file,storage,begin,end}, 0≤begin≤end≤N, and Writer{file,storage,used,failed}, 0≤used≤N. Both buffers have initialized length=capacity=N. Caller field access/construction must preserve spec 16 §2.18's complete data/cursor/first-error invariant and must not independently consume/use the internal file/storage. Existing ownership, alias/task-loan, effects and Send/Share checks apply. Adapters can transfer to workers but cannot be shared immutably across tasks because files are non-Share. No unsafe/trusted boundary or new runtime/verifier state is needed.
The [copy example](../../examples/std/buffered_io.aji) uses two three-byte buffers (heap=mem.alloc:6), explicitly handles constructor/finish failure and returns the copied byte count, or zero after normal error cleanup. Conformance fixtures include capacities zero/full, unread finish/discard, exact EOF, allocation failure/refunds, worker transfer and rejected ownership/effect/alias cases. Hosted tests exercise read errors and real partial external writes; Linux raises the child file quota after failure to detect forbidden retry.
## Lexical paths
Import `std.path`. Six pure operations use byte `/` separators in every profile. They never allocate heap, retain/return a borrow, inspect the filesystem/current directory or grant authority. Backslash, colon and non-UTF-8 bytes are ordinary component bytes; there is no drive/UNC or symlink resolution. Range{start:usize,end:usize} is Copy; callers explicitly borrow ref path[range.start..range.end]. A range is data, and bounds are still checked if it is reused for a different path.
| Function arguments | Result |
|---|---|
| is_absolute(path: slice<u8>) | bool: first byte is `/` |
| basename(path: slice<u8>) | Range of final nonempty raw component, ignoring trailing separators; 0..0 for empty/root-only |
| parent(path: slice<u8>) | Range of raw prefix before basename, trimming the separator run before it; rooted input retains first `/`; 0..0 for empty/relative leaf |
| extension(path: slice<u8>) | Range after basename's last dot, excluding dot; empty at basename.end for absent/leading-only/trailing dot or `.`/`..` |
| normalize(destination: slice_mut<u8>, path: slice<u8>) | WriteResult: ok(usize), invalid_input, size_overflow, short_output |
| join(destination: slice_mut<u8>, base: slice<u8>, child: slice<u8>) | WriteResult |
Queries accept arbitrary bytes, including NUL, and return offsets into the original input, without normalizing it. For a//b///, basename selects b and parent selects a; parent(a/../b) selects `a/..`. Root-only parent selects the first slash; root-only basename is empty. Extension(.profile) is empty, extension(.profile.json) selects json, extension(a..b) selects b, extension(a.) is empty. Empty extension deliberately makes no distinction between no dot and empty suffix.
Normalize collapses separator runs and leading slashes, removes `.` and trailing slashes, and cancels each ordinary component followed by `..`. Relative unmatched parents remain leading `..`; parents above root are dropped. Empty/reduced-empty relative input becomes `.`; empty rooted output becomes `/`. Examples: a//b/../c/ → a/c; a/../../b → ../b; /../../a → /a; a/.. → . . Normalization is idempotent. Exactly two leading slashes have no special meaning.
Join normalizes absolute child alone, replacing base. Otherwise it normalizes base followed by child as components separated by a slash; an empty base does not introduce a root. Empty child normalizes base, both empty become `.`, and child parents can cancel base components. Examples: /data/a + ../b → /data/b; a + /b → /b; empty + a → a. These transformations give no capability-containment proof. Filesystem primitives still reject normalized relative paths and enforce their granted scopes on absolute ones.
Both writers first validate all input bytes: NUL yields invalid_input, including in base when an absolute child replaces it. Invalid input precedes size_overflow, which precedes short_output. Every returned error leaves the entire destination unchanged. Success writes exactly the reported prefix, preserves the suffix and writes no NUL terminator. Only final normalized size must fit: a long component followed by `..` can normalize into one byte of output. Reverse measurement/emission needs fixed frame state and no intermediate buffer or allocation. Work is linear in supplied input/output bytes.
Input borrows can overlap each other; destination must be disjoint. Explicit split_at permits source/output in one allocation. Existing type/borrow/task-loan/Send/Share checks apply, including no-op/short-output paths. No unsafe boundary, new language/AIR semantics or hidden effects are needed. Borrow-return source support (Q-034) remains separate. The [pure example](../../examples/std/path.aji) joins into a caller buffer and borrows basename/parent/extension from the returned prefix. The independent Python forward-stack oracle covers normalization/join/query/capacity/idempotence; hosted fixtures confirm filesystem authority remains independent.
@@ -0,0 +1,45 @@
# RFC 0035: Caller-buffer lexical paths
Status: Proposed
Scope: STD-7c, std.path after owning buffered files
## Motivation and spec integration
Spec 16 §2.19 adds six pure path operations on bytes with one portable slash syntax. Paths are frequent CLI/storage data; normalization/join/component loops should be reusable without hidden allocations, host state or a larger authority surface. Spec 16 and reference/std.md contain the normative contracts; this record explains them.
## Preserved invariant and verifier rule
Output writes remain within the supplied exclusive slice, successful output preserves its suffix, and every returned input/size/capacity error preserves the entire destination. Input borrows only read; no borrow escapes, file/resource is consumed or capability is gained. Component queries return bounded Copy index ranges, keeping lifetime/bounds decisions visible in the caller. Ordinary borrow, bounds, Copy/Send/Share, task loans and effect checks apply without new verifier state.
## Runtime / deterministic behavior
Only safe source algorithms: validation and final-size measurement precede emission. Reverse scanning cancels components with pending parents; a second reverse pass writes retained components into the exact final prefix. Capacity is measured after cancellation, so a short destination can hold a result whose raw input was long. No heap/scratch allocation, platform branch, filesystem access, symlink interpretation or current directory. `/` is the separator in every profile. NUL rejects in writers; non-UTF-8/backslash bytes remain ordinary data. Primitive filesystem capability/path checks are unchanged and still mandatory.
## Valid and rejected examples
Join /data/a with ../b into a caller array, handle WriteResult, then use the resulting slice with an explicit fs capability. Normalization alone cannot authorize the path. Disjoint slices within one allocation are valid; overlapping source/output, task-loaned output and wrong scalar/slice types reject through existing diagnostics. The [pure example](../../examples/std/path.aji) joins into caller storage and borrows its component ranges. [A one-byte canceled result](../../tests/conformance/source/path/canceled_capacity.aji) and [disjoint slices](../../tests/conformance/source/path/disjoint.aji) are valid. [Overlapping slices](../../tests/conformance/source/path/overlap.aji) reject E2101; [a live task loan](../../tests/conformance/source/path/loan.aji) rejects E4101. [Authority](../../tests/conformance/source/path/authority.aji) remains independently enforced, and [reusing a range on a shorter input](../../tests/conformance/source/path/range_bounds.aji) traps T0008 through ordinary bounds checking.
## Diagnostics / AIR / compatibility
No new diagnostic, source syntax, AIR instruction/feature/meaning, verifier/runtime state or trusted boundary. Existing E7002/E7005/E2101/E4101 apply. WriteResult variants are ordinary Copy data; insufficient output and malformed input do not trap or mutate output. All existing paths/fs grants/source/AIR contracts retain their meaning. Q-034 is neither expanded nor silently inferred: callers explicitly borrow a returned Range from their own path.
## Agent complexity impact
Six supported operations: is_absolute/basename/parent/extension/normalize/join. One separator syntax and one destination-first writing result. Queries report raw bounded offsets without borrowed returns; writing reports final prefix size and has an unchanged-output error contract. No agent needs platform-specific normalization, hidden allocation or lifetime inference. Existing primitives suffice; no language concepts, verifier state, syntax forms or diagnostics are added. Full edge rules stay on demand. Measured Quick Reference/source bundle budgets follow; no empirical MCC benefit is claimed.
## Alternatives considered
Host-dependent paths would make deterministic fixtures/platform reasoning harder and disagree with the existing runtime slash syntax. Borrowed query returns would require a separate vertical lifetime feature before safe source can use them. Requiring raw-input-sized output would fail ordinary cancellation cases unnecessarily. In-place mutation would need explicit overlap semantics and would violate the current exclusive-output/shared-input contract. Adding an opaque path opcode is unnecessary.
## Validation gate
Independent forward-stack byte oracle; empty/root/relative/absolute, repeated separators, dot/parent cancellation, root saturation, hidden/multiple/trailing extensions, non-UTF-8/backslash/NUL, exact/short capacities, late malformed input, suffix preservation, disjoint same-allocation slices and small canceled-result output. Rejected aliases/types/imports/task loans; valid task transfer/restored loans; source/AIR/package/profile/provenance/audit and authority checks; GC/scheduler stress, full conformance, unit/Quick Reference, formatting, source coverage and documentation budget. STD-7 completes only after this gate; STD-8 and the broader roadmap remain required.
Measured cl100k growth from RFC 0034: Quick Reference 8,445 → 8,518 (+0.9%); other source documentation 61,223 → 63,296 (+3.4%); full source excluding AIR 69,668 → 71,814 (+3.1%). library/std.md is 26,437 tokens. Corresponding o200k groups are 8,552 / 63,497 / 72,049; qwen2.5 groups are 8,768 / 64,821 / 73,589. AIR remains 179,282 bytes / 19 files / 51 sections; its source-bundle copy remains 46,300 / 46,451 / 47,800 tokens. Cumulative cl100k growth over pre-std 33,981 is +111.3%, justified for owner review by visible byte syntax, cancellation/root, range/capacity and authority contracts. Quick Reference is beyond its 4–6k target; front-door consolidation/selective reading remains separate work. No new syntax, diagnostic or verifier/runtime state is added, and no empirical MCC improvement is claimed.
## Validation result
All 1079 repository conformance cases pass, including 18 path fixtures. The independent Python forward-stack oracle covers 132 paths with queries/idempotence and every short/exact/extra output capacity, 49 joins and four malformed pairs. All 255 non-NUL bytes are additionally tested. Fixtures cover one-byte canceled outputs, late malformed input winning over short capacity (including ignored base), suffix/guard preservation, raw ranges, no borrowed-return inference, disjoint same-allocation slices, aliases, task loans, wrong types/imports and independent filesystem authority. Reused ranges retain normal runtime bounds checks, with T0008 on a shorter unrelated path.
68 CLI/source/AIR/package/profile/provenance/audit checks pass. Pure APIs use no entry grants, heap allocation or unsafe sites. Lowered AIR and source agree; reordered imports/package loading/name collisions are deterministic. Hosted cases cover arbitrary byte components and actual denied-file authority independently of normalization. Unit/Quick Reference, formatting, 117/117 source coverage constructs and reference generation pass. All 18 path fixtures pass the collection-before-every-step gate; scheduled fixtures pass 12 seeds under quanta 1, 2, 7 and their own quantum. The oracle batches preserve every vector/capacity while ending literal frames between batches, bounding collector roots. STD-7c and the intermediate STD-0..7 foundation are complete. STD-8 and Std 0.1 remain unfinished.
+27 -2
View File
@@ -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.hashset`, `std.heap`, `std.io`, `std.io.reader`, `std.io.writer`, `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/heap.aji`, `std/io.aji`, `std/io/reader.aji`, `std/io/writer.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`. Modules other than std.io/std.io.reader/std.io.writer implement deterministic algorithms in every profile and have no concurrency effects; std.io/std.io.reader/std.io.writer follow the profile I/O/blocking rules in §2.17–§2.18 and spec 11. Modules other than std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap and std.io/std.io.reader/std.io.writer declare effects [] and allocate no heap memory. std.io declares only the concrete I/O effects in §2.17 and allocates no heap storage. std.io.reader/std.io.writer declare mem.alloc only on new and the concrete file effects in §2.18 on read/write/flush/finish; their other operations allocate no heap. std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11, §2.13–§2.16); 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.heap`, `std.io`, `std.io.reader`, `std.io.writer`, `std.map`, `std.math`, `std.option`, `std.path`, `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/heap.aji`, `std/io.aji`, `std/io/reader.aji`, `std/io/writer.aji`, `std/map.aji`, `std/math.aji`, `std/option.aji`, `std/path.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`. Modules other than std.io/std.io.reader/std.io.writer implement deterministic algorithms in every profile and have no concurrency effects; std.io/std.io.reader/std.io.writer follow the profile I/O/blocking rules in §2.17–§2.18 and spec 11. Modules other than std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap and std.io/std.io.reader/std.io.writer declare effects [] and allocate no heap memory. std.io declares only the concrete I/O effects in §2.17 and allocates no heap storage. std.io.reader/std.io.writer declare mem.alloc only on new and the concrete file effects in §2.18 on read/write/flush/finish; their other operations allocate no heap. std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap new/reserve declare mem.alloc and require explicit allocation authority (§2.10–§2.11, §2.13–§2.16); their other functions allocate no heap. Ordinary interpreter fuel limits apply.
### 2.1 `std.math`
@@ -371,4 +371,29 @@ Writer.write accepts the complete input into buffered storage or successful writ
Writer.flush on a healthy empty buffer returns ok without I/O. On a successful external write, used becomes zero. On any external write failure, used/data remain unchanged and failed becomes some(the first error); no automatic retry/reset is allowed. Once failed is some(error), every write (including empty) MUST return err with accepted=0 and that error, and every flush MUST return err(error), without I/O or buffer mutation. Unknown partial external writes make retrying pending data unsound. Writer.finish first flushes: success drains/frees storage and returns the file; error returns FinishError with the complete unchanged failed Writer and original error. Finish does not sync or close. Writer.discard explicitly abandons buffered pending bytes, drains/frees storage and returns the file, used count and failure state; pending on failure MAY overlap an already externally written prefix and is not an exact loss count.
Effects, moves and mut/task-loan requirements apply on no-op/cached/failure paths. Existing aggregate/buffer moves, resource borrowing, alias exclusion, bounds/arithmetic, effect/capability and Copy/Send/Share rules verify all safe code; files make adapters non-Share and ordinary Send checks govern task transfer. Deterministic/hosted behavior follows existing profile primitives. No new AIR meaning, instruction/feature, syntax, diagnostic, verifier/runtime state, unsafe boundary, implicit destructor or cancellation policy is introduced. Invalid representation may trap through existing checked operations, preserving memory safety. Valid bookkeeping does not trap for a valid invariant/conforming primitives. Work is linear in initialized/copy/drained bytes plus I/O calls, with existing interpreter prefix-copy/GC costs. Lexical paths and Std 0.1 remain unfinished.
Effects, moves and mut/task-loan requirements apply on no-op/cached/failure paths. Existing aggregate/buffer moves, resource borrowing, alias exclusion, bounds/arithmetic, effect/capability and Copy/Send/Share rules verify all safe code; files make adapters non-Share and ordinary Send checks govern task transfer. Deterministic/hosted behavior follows existing profile primitives. No new AIR meaning, instruction/feature, syntax, diagnostic, verifier/runtime state, unsafe boundary, implicit destructor or cancellation policy is introduced. Invalid representation may trap through existing checked operations, preserving memory safety. Valid bookkeeping does not trap for a valid invariant/conforming primitives. Work is linear in initialized/copy/drained bytes plus I/O calls, with existing interpreter prefix-copy/GC costs. Std 0.1 remains unfinished.
### 2.19 `std.path`: caller-buffer lexical paths
The registry MUST include std.path at std/path.aji as ordinary safe source. All six supported operations declare effects [], allocate no heap, retain/return no borrow and grant no filesystem authority. Paths use the same byte separator `/` in every profile, independent of host platform. Backslash, colon and non-UTF-8 bytes are ordinary component bytes; there is no drive/UNC, symlink, filesystem lookup or current-directory interpretation. Lexical normalization MUST NOT be used as a capability-containment or symlink-resolution check; every filesystem operation still validates its path and granted scope independently.
Range is Copy `{ start: usize, end: usize }`. For a query on path, 0≤start≤end≤path.len; the caller takes ref path[start..end] under ordinary bounds/borrow rules. Empty ranges are valid. Query functions accept every byte slice, including NUL, and perform no normalization or validity claim. WriteResult is Copy `{ ok(usize), invalid_input, size_overflow, short_output }`. Both writing functions MUST reject NUL anywhere in either input with invalid_input, including an ignored base when child is absolute. Invalid input takes precedence over output-size overflow, which takes precedence over short output. Every returned error MUST leave the complete destination unchanged. Success writes exactly the reported canonical prefix and preserves the destination suffix. No NUL terminator is written. Aliased inputs/output MUST reject under existing borrowing rules; explicitly disjoint slices of the same allocation are permitted.
| Function arguments | Result |
|---|---|
| is_absolute(path: slice<u8>) | bool: nonempty and first byte `/` |
| basename(path: slice<u8>) | Range of the last nonempty component, ignoring trailing separators; empty/root-only input returns 0..0 |
| parent(path: slice<u8>) | Range of the raw prefix before basename, trimming the separator run before it; rooted input retains at least its first `/`; empty/relative single component returns 0..0 |
| extension(path: slice<u8>) | Range after the final dot in basename, excluding the dot; absent/leading-only/trailing dot and `.`/`..` return the empty range at basename.end |
| normalize(destination: slice_mut<u8>, path: slice<u8>) | WriteResult |
| join(destination: slice_mut<u8>, base: slice<u8>, child: slice<u8>) | WriteResult |
Component queries preserve original byte offsets and do not collapse interior separator runs or dot components. For example basename(b"a//b///") is 3..4 and parent is 0..1; basename(b"///") is 0..0 and parent is 0..1; parent(b"a/../b") is 0..4. Extension(b".profile") is 8..8, extension(b".profile.json") selects json, and extension(b"a..b") selects b. Empty extension makes no distinction between no dot and an empty suffix after a trailing dot. A returned Range is ordinary data, not a proof that it applies to some different/mutated path.
Normalize MUST collapse separator runs, remove `.` components and trailing separators, and cancel each ordinary component followed by `..`. Relative unmatched `..` components MUST be preserved at the beginning. Rooted `..` above `/` MUST be ignored. Empty or reduced-empty relative input becomes `.`; root-only/reduced-empty rooted input becomes `/`. All leading separators collapse to one root; there is no special meaning for exactly two. Dot bytes embedded in other names are ordinary bytes. Examples: a//b/../c/ → a/c; a/../../b → ../b; /../../a → /a; ../a/.. → ..; a/.. → . . Normalization is idempotent.
Join MUST normalize child alone when child is absolute; otherwise normalize the component sequence of base followed by child, as if separated by one `/`, without making an empty base into an artificial root. An empty child normalizes base; both empty become `.`. Relative child `..` may cancel base components; an absolute child replaces base. Examples: /data/a joined with ../b → /data/b; a joined with /b → /b; empty base joined with a → a. These are byte algorithms only: a successfully normalized relative path is still invalid for current filesystem primitives, and a normalized absolute result may still lie outside the caller's authority.
Writing operations MUST validate input and determine final normalized length before mutation. Capacity need only accommodate the final prefix, not canceled components or raw concatenation; joining/normalization MUST NOT demand hidden scratch/heap storage. The safe reference algorithm scans components backward, tracking pending parent components, measures retained bytes/separators with checked arithmetic, then emits the retained components backward into the already-validated prefix. Pending relative parents become the leading `..` components; rooted excess parents are dropped. No combined raw input length is required. Input-size/length/cursor arithmetic MUST avoid overflow; size_overflow is ordinary data, not a trap. For conforming slices, returned errors/success do not trap except ordinary fuel exhaustion.
Existing slices, Copy structs/enums, checked bounds/arithmetic, exclusive-output/shared-input loans, effects and task Send/Share rules suffice. No owner/resource is consumed and no loan escapes. Valid/rejected calls use existing E7002/E7005/E2101/E4101; malformed bytes and insufficient capacity are ordinary WriteResult variants, not verifier diagnostics. No new syntax, AIR meaning/instruction/feature, verifier/runtime state or unsafe/trusted boundary is introduced. Query work is O(path.len); writing work is O(base.len+child.len+output.len) with fixed frame state and existing interpreter costs. Current source borrow-return limitations (Q-034) remain unchanged. Filesystem/system gaps and the Std 0.1 exit examples remain subsequent work.