cli: add explicit bounded standard I/O composition
Add std.io exact stdin/file/TCP reads, bounded file read-to-end and limited file write/append copies. Use caller slices and resource loans, exact effects, explicit EOF/capacity/limit and confirmed partial progress. No implicit heap, open/close, timeout or new AIR/runtime semantics. Document failure limits and check hosted read errors and a partial external file write under a child-only file-size quota. Integrate normative contracts, RFC, source reference budgets, CLI/profile/package checks and independent byte/count/cursor vectors. Validation: 1027 conformance cases, 20 I/O GC cases, scheduled stress, unit/Quick Reference, formatting, hosted smoke, 55 CLI checks, 111 source coverage constructs and unchanged AIR reference bundle.
This commit is contained in:
1 parent
cfece6080c
commit
3e1c0f34e8
37 files changed
+1181
-6
No files matched your search
+24
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
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/std.heap new/reserve.
|
||||
|
||||
Except std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap 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.io (§2.17) and std.vec/std.deque/std.map/std.hashmap/std.hashset/std.heap 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 |
|
||||
|---|---|---|
|
||||
@@ -373,3 +373,26 @@ The visible representation is entries: buffer<Entry<T>> / indices: buffer<usize>
|
||||
New allocates empty entries then indices, refunding entries on second-allocation failure. Reserve allocates/copies new indices before growing entries; returned failure preserves both old buffers, values/positions/indices and extraction order, and refunds temporaries. Success preserves the layout and frees old indices explicitly. Peak quota includes both entry/index buffers and all external user allocations; refunds go to recorded authorities. Zero capacity is valid; size overflow returns budget_exceeded. On air64 each capacity slot costs sizeof(T)+16 bytes. The [owning example](../../examples/std/heap.aji) needs 32 bytes for one Item slot plus 8 for its payload: heap=mem.alloc:40.
|
||||
|
||||
Existing ownership/alias/task-loan/Send/Share rules apply with no unsafe boundary or new runtime semantics. Callback/fuel traps are abnormal. Abstract push/pop need O(log L) comparisons/swaps, peek O(1), reserve O(L) copies; interpreter prefix-copy/GC costs may add host work. There is no native-throughput guarantee.
|
||||
|
||||
## Bounded I/O composition
|
||||
|
||||
Import `std.io`. Six concrete functions compose existing primitives with caller-provided slices. They never allocate, open/close resources or retain borrows. Effects and authority remain explicit even for empty/no-op paths. File/stream resources are mutably lent and remain owned by the caller on every normal return.
|
||||
|
||||
| Function | Result | Effects |
|
||||
|---|---|---|
|
||||
| read_exact_stdin(input: cap<io.read>, destination: slice_mut<u8>) | ReadExactResult | io.read |
|
||||
| read_exact_file(input: mut<file<read>>, destination: slice_mut<u8>) | ReadExactResult | fs.read |
|
||||
| read_exact_stream(input: mut<stream>, destination: slice_mut<u8>) | ReadExactResult | net.read |
|
||||
| read_to_end_file(input: mut<file<read>>, destination: slice_mut<u8>) | ReadToEndResult | fs.read |
|
||||
| copy_file(input: mut<file<read>>, output: mut<file<write>>, scratch: slice_mut<u8>, limit: usize) | CopyResult | fs.read, fs.write |
|
||||
| copy_file_append(input: mut<file<read>>, output: mut<file<append>>, scratch: slice_mut<u8>, limit: usize) | CopyResult | fs.read, fs.write |
|
||||
|
||||
ReadExactResult is ok / eof(completed:usize) / err(ReadError{completed:usize,error:io_error}). Exact reads fill the destination, looping over short reads. Empty destination is ok without I/O. EOF leaves the remaining suffix unchanged. A read error guarantees only the successful prefix; the attempted suffix follows the primitive's failure contract. Bytes outside the supplied destination remain unchanged.
|
||||
|
||||
ReadToEndResult is eof(completed:usize) / full(completed:usize) / err(ReadError). Full means the supplied buffer was filled; it does not establish whether EOF was reached or unread data remains. Empty destination is full(0), and no extra byte is read/discarded to probe EOF. Growing/owning read-to-end and buffered adapters are separate work.
|
||||
|
||||
CopyResult is eof(completed:usize) / limit(completed:usize) / err(CopyError{read:usize,confirmed_written:usize,error:io_error}). Copies bound every scratch chunk by remaining limit and stop without probing past it. Exact EOF at the limit reports limit. A read error has both counts equal to earlier completed chunks. A write error includes its consumed input chunk in read; confirmed_written includes only prior successful writes. The failed write may have externally written a prefix: there is no rollback promise or exact failed-output count. Resources remain borrowed for explicit caller cleanup.
|
||||
|
||||
Zero limit returns limit(0) without I/O, even with empty scratch. Empty scratch with positive limit returns invalid_input with both error counts zero without I/O. No counter exceeds the limit or overflows. Scratch contents after a call are unspecified; bytes outside its slice remain unchanged. The [copy example](../../examples/std/io.aji) uses only fs.read/fs.write entry grants and a fixed frame scratch array, handling results and closing both resources explicitly. Existing fs.write_all/net.send_all/console writes already write all bytes on success, so this increment adds no duplicate write alias.
|
||||
|
||||
Ordinary alias/task-loan, type/mode, capability and effect checks apply; imports grant nothing. Blocking/fuel/profile errors remain spec 11 behavior, with no hidden timeout, task or unsafe boundary. std.io's concrete contracts are spec 16 §2.17; owning buffered adapters and lexical paths remain forthcoming.
|
||||
Reference in new issue
Block a user