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:
1 parent
8d8bef8f3e
commit
8edec5b831
35 files changed
+1189
-8
No files matched your search
@@ -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.
|
||||
Reference in new issue
Block a user