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.
7.2 KiB
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 joins into caller storage and borrows its component ranges. A one-byte canceled result and disjoint slices are valid. Overlapping slices reject E2101; a live task loan rejects E4101. Authority remains independently enforced, and reusing a range on a shorter input 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.