cli: add explicit owning buffered file adapters
Add pinned std.io.reader and std.io.writer using safe source, explicit fixed allocation and file transfer. Finish/discard return complete resources; writer failures preserve pending data and prohibit unsound partial retries. Specify cursor, acceptance, failure and cleanup contracts in spec 16, RFC 0034, the API reference and source bundle. Add standalone conformance, independent byte oracles, task/GC stress, CLI/package/profile checks and hosted partial-write tests with a raised child quota to detect retries. Validation: 1061 conformance cases; 34 buffered cases with per-step GC and 12 schedule seeds; unit/Quick Reference, formatting, hosted smoke, 89 CLI checks, 115 source coverage constructs and reference generation.
This commit is contained in:
1 parent
3e1c0f34e8
commit
8d8bef8f3e
51 files changed
+1916
-8
No files matched your search
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: std.io.writer.Writer) -> void effects [] { std.io.writer.discard(move q); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,34 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1];
|
||||
{ mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => {}, std.io.reader.ReadResult::err(error) => { trap; } }
|
||||
exact(std.io.reader.read_exact(q,mut byte[0usize..0usize])); match std.io.reader.read(q,mut byte[0usize..0usize]) { std.io.reader.ReadResult::ok(n) => { assert(n == 0usize); }, std.io.reader.ReadResult::err(error) => { trap; } } }
|
||||
let (file,unread) = struct.unpack(std.io.reader.discard(move value)); assert(unread == 2usize); fs.close(move file) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1];
|
||||
{ mut q = value; exact(std.io.reader.read_exact(q,mut byte[0usize..0usize])); match std.io.reader.read(q,mut byte[0usize..0usize]) { std.io.reader.ReadResult::ok(n) => { assert(n == 0usize); }, std.io.reader.ReadResult::err(error) => { trap; } } }
|
||||
let file = finished_reader(move value); exact(std.io.read_exact_file(mut file,mut byte)); assert(byte[0] == 97u8); fs.close(move file) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: std.io.reader.Reader) -> void effects [fs.read] { mut file = q.file; std.io.reader.finish(move q); var bytes: [u8;1] = [0u8;1]; fs.read(file,mut bytes) or trap; trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: std.io.writer.Writer) -> void effects [fs.write] { match std.io.writer.finish(move q) { std.io.writer.FinishResult::ok(file) => { trap; }, std.io.writer.FinishResult::err(error) => { return; } } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var prefix: [u8;3] = [0u8;3];
|
||||
{ mut q = value; exact(std.io.reader.read_exact(q,mut prefix)); }
|
||||
let file = finished_reader(move value); exact(std.io.read_exact_file(mut file,mut prefix)); assert(prefix[0] == 100u8); assert(prefix[2] == 102u8); fs.close(move file) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:3
|
||||
// grant: src=fs.read:/out
|
||||
// file: /out/data=abcd
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn observed(src: cap<fs.read>,expected: usize) -> void effects [fs.read] {
|
||||
let file = fs.open_read(src,b"/out/data") or trap; var bytes: [u8;6] = [0u8;6]; match std.io.read_to_end_file(mut file,mut bytes) { std.io.ReadToEndResult::eof(n) => { assert(n == expected); }, std.io.ReadToEndResult::full(n) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } } fs.close(move file) or trap;
|
||||
}
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap); let blank: [u8;1] = [0u8;1];
|
||||
{ mut q = value; written(std.io.writer.write(q,b"abc")); written(std.io.writer.write(q,ref blank[0usize..0usize])); } observed(src,0usize);
|
||||
{ mut q = value; written(std.io.writer.write(q,b"d")); } observed(src,3usize);
|
||||
{ mut q = value; match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } } observed(src,4usize);
|
||||
fs.close(finished_writer(move value)) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E4101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn worker(q: mut<std.io.reader.Reader>) -> void effects [fs.read] {}
|
||||
fn bad(q: mut<std.io.reader.Reader>) -> void effects [fs.read,task.spawn,task.wait] { scope s { let t = task.spawn(s,worker,q); var bytes: [u8;1] = [0u8;1]; std.io.reader.read(q,mut bytes); task.join(move t); } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,35 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
// schedules: 12
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn worker(q: mut<std.io.reader.Reader>) -> void effects [fs.read] { var bytes: [u8;3] = [0u8;3]; exact(std.io.reader.read_exact(q,mut bytes)); assert(bytes[0] == 97u8); }
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc,task.spawn,task.wait] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var bytes: [u8;3] = [0u8;3];
|
||||
{ mut q = value; scope s { let t = task.spawn(s,worker,q); task.join(move t); exact(std.io.reader.read_exact(q,mut bytes)); } }
|
||||
assert(bytes[0] == 100u8); fs.close(finished_reader(move value)) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
// grant: dst=fs.write:/out
|
||||
// file: /out/data=
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc] {
|
||||
let input = fs.open_read(src,b"/in/data") or trap; let output = fs.create(dst,b"/out/data") or trap;
|
||||
match std.io.reader.new(move input,18446744073709551615usize,heap) { std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.close(move file) or trap; } }
|
||||
match std.io.writer.new(move output,18446744073709551615usize,heap) { std.io.writer.NewResult::ok(value) => { trap; }, std.io.writer.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.close(move file) or trap; } }
|
||||
return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<read>,heap: cap<mem.alloc>) -> std.io.reader.NewResult effects [] { return std.io.reader.new(move file,3usize,heap); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E7003
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: std.io.reader.Reader) -> void effects [] { std.io.reader.finish(q); trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: mut<std.io.reader.Reader>,dest: slice_mut<u8>) -> void effects [] { std.io.reader.read(q,dest); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: mut<std.io.writer.Writer>) -> void effects [] { std.io.writer.flush(q); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,284 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/case
|
||||
// grant: dst=fs.write:/case
|
||||
// grant: heap=mem.alloc:5
|
||||
// file: /case/input=abcdefgh
|
||||
// file: /case/output=abcdefgh
|
||||
// fuel: 2000000
|
||||
module test.buffered_model
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.bytes;
|
||||
fn prepare(contents: slice<u8>,dst: cap<fs.write>) -> void effects [fs.write] {
|
||||
let file = fs.create(dst,b"/case/input") or trap; fs.write_all(file,contents) or trap; fs.close(move file) or trap;
|
||||
}
|
||||
fn reads(contents: slice<u8>,capacity: usize,chunk: usize,src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> void effects [fs.read,fs.write,mem.alloc] {
|
||||
prepare(contents,dst); let file = fs.open_read(src,b"/case/input") or trap;
|
||||
match std.io.reader.new(move file,capacity,heap) {
|
||||
std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => {
|
||||
var bytes: [u8;9] = [255u8;9]; var offset: usize = 0;
|
||||
{ mut q = value; loop {
|
||||
match std.io.reader.read(q,mut bytes[1usize..chunk+1usize]) {
|
||||
std.io.reader.ReadResult::err(error) => { trap; }, std.io.reader.ReadResult::ok(count) => {
|
||||
assert(count <= chunk); assert(offset + count <= contents.len);
|
||||
assert(std.bytes.equal(ref bytes[1usize..count+1usize],ref contents[offset..offset+count]));
|
||||
assert(bytes[0] == 255u8); for i in chunk+1usize..9usize { assert(bytes[i] == 255u8); }
|
||||
offset = offset + count; if count == 0usize { break; }
|
||||
}
|
||||
}
|
||||
} }
|
||||
assert(offset == contents.len);
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { fs.close(move file) or trap; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
fn exact(contents: slice<u8>,capacity: usize,requested: usize,prefix: usize,full: bool,src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> void effects [fs.read,fs.write,mem.alloc] {
|
||||
prepare(contents,dst); let file = fs.open_read(src,b"/case/input") or trap;
|
||||
match std.io.reader.new(move file,capacity,heap) {
|
||||
std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => {
|
||||
var bytes: [u8;12] = [255u8;12];
|
||||
{ mut q = value; match std.io.reader.read_exact(q,mut bytes[1usize..requested+1usize]) {
|
||||
std.io.ReadExactResult::ok => { assert(full); }, std.io.ReadExactResult::eof(n) => { assert(not full); assert(n == prefix); }, std.io.ReadExactResult::err(error) => { trap; }
|
||||
} }
|
||||
assert(std.bytes.equal(ref bytes[1usize..prefix+1usize],ref contents[0usize..prefix]));
|
||||
assert(bytes[0] == 255u8); for i in prefix+1usize..12usize { assert(bytes[i] == 255u8); }
|
||||
let (file,unread) = struct.unpack(std.io.reader.discard(move value)); fs.close(move file) or trap;
|
||||
}
|
||||
}
|
||||
}
|
||||
fn writes(contents: slice<u8>,capacity: usize,chunk: usize,flush: bool,src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> void effects [fs.read,fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/case/output") or trap;
|
||||
match std.io.writer.new(move file,capacity,heap) {
|
||||
std.io.writer.NewResult::err(error) => { trap; }, std.io.writer.NewResult::ok(value) => {
|
||||
var offset: usize = 0;
|
||||
{ mut q = value; match std.io.writer.write(q,ref contents[0usize..0usize]) { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } }
|
||||
while offset < contents.len {
|
||||
let left = contents.len - offset; let count = if left < chunk { left } else { chunk };
|
||||
match std.io.writer.write(q,ref contents[offset..offset+count]) { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } }
|
||||
offset = offset + count;
|
||||
if flush { match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } }
|
||||
}
|
||||
}
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { fs.close(move file) or trap; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
}
|
||||
let file = fs.open_read(src,b"/case/output") or trap; var bytes: [u8;12] = [255u8;12];
|
||||
match std.io.read_to_end_file(mut file,mut bytes[1usize..11usize]) { std.io.ReadToEndResult::eof(n) => { assert(n == contents.len); assert(std.bytes.equal(ref bytes[1usize..n+1usize],contents)); }, std.io.ReadToEndResult::full(n) => { trap; }, std.io.ReadToEndResult::err(error) => { trap; } }
|
||||
assert(bytes[0] == 255u8); assert(bytes[11] == 255u8); fs.close(move file) or trap;
|
||||
}
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc] {
|
||||
let blank: [u8;1] = [0u8;1];
|
||||
reads(ref blank[0usize..0usize],0usize,1usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,1usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,1usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],0usize,3usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,3usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,3usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],0usize,7usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,7usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],0usize,7usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],0usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],0usize,1usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],0usize,4usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],0usize,9usize,0usize,false,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],1usize,1usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,1usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,1usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],1usize,3usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,3usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,3usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],1usize,7usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,7usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],1usize,7usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],1usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],1usize,1usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],1usize,4usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],1usize,9usize,0usize,false,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],2usize,1usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,1usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,1usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],2usize,3usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,3usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,3usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],2usize,7usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,7usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],2usize,7usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],2usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],2usize,1usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],2usize,4usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],2usize,9usize,0usize,false,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],5usize,1usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,1usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,1usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],5usize,3usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,3usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,3usize,true,src,dst,heap);
|
||||
reads(ref blank[0usize..0usize],5usize,7usize,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,7usize,false,src,dst,heap);
|
||||
writes(ref blank[0usize..0usize],5usize,7usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],5usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],5usize,1usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],5usize,4usize,0usize,false,src,dst,heap);
|
||||
exact(ref blank[0usize..0usize],5usize,9usize,0usize,false,src,dst,heap);
|
||||
reads(b"a",0usize,1usize,src,dst,heap);
|
||||
writes(b"a",0usize,1usize,false,src,dst,heap);
|
||||
writes(b"a",0usize,1usize,true,src,dst,heap);
|
||||
reads(b"a",0usize,3usize,src,dst,heap);
|
||||
writes(b"a",0usize,3usize,false,src,dst,heap);
|
||||
writes(b"a",0usize,3usize,true,src,dst,heap);
|
||||
reads(b"a",0usize,7usize,src,dst,heap);
|
||||
writes(b"a",0usize,7usize,false,src,dst,heap);
|
||||
writes(b"a",0usize,7usize,true,src,dst,heap);
|
||||
exact(b"a",0usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"a",0usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"a",0usize,4usize,1usize,false,src,dst,heap);
|
||||
exact(b"a",0usize,9usize,1usize,false,src,dst,heap);
|
||||
reads(b"a",1usize,1usize,src,dst,heap);
|
||||
writes(b"a",1usize,1usize,false,src,dst,heap);
|
||||
writes(b"a",1usize,1usize,true,src,dst,heap);
|
||||
reads(b"a",1usize,3usize,src,dst,heap);
|
||||
writes(b"a",1usize,3usize,false,src,dst,heap);
|
||||
writes(b"a",1usize,3usize,true,src,dst,heap);
|
||||
reads(b"a",1usize,7usize,src,dst,heap);
|
||||
writes(b"a",1usize,7usize,false,src,dst,heap);
|
||||
writes(b"a",1usize,7usize,true,src,dst,heap);
|
||||
exact(b"a",1usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"a",1usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"a",1usize,4usize,1usize,false,src,dst,heap);
|
||||
exact(b"a",1usize,9usize,1usize,false,src,dst,heap);
|
||||
reads(b"a",2usize,1usize,src,dst,heap);
|
||||
writes(b"a",2usize,1usize,false,src,dst,heap);
|
||||
writes(b"a",2usize,1usize,true,src,dst,heap);
|
||||
reads(b"a",2usize,3usize,src,dst,heap);
|
||||
writes(b"a",2usize,3usize,false,src,dst,heap);
|
||||
writes(b"a",2usize,3usize,true,src,dst,heap);
|
||||
reads(b"a",2usize,7usize,src,dst,heap);
|
||||
writes(b"a",2usize,7usize,false,src,dst,heap);
|
||||
writes(b"a",2usize,7usize,true,src,dst,heap);
|
||||
exact(b"a",2usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"a",2usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"a",2usize,4usize,1usize,false,src,dst,heap);
|
||||
exact(b"a",2usize,9usize,1usize,false,src,dst,heap);
|
||||
reads(b"a",5usize,1usize,src,dst,heap);
|
||||
writes(b"a",5usize,1usize,false,src,dst,heap);
|
||||
writes(b"a",5usize,1usize,true,src,dst,heap);
|
||||
reads(b"a",5usize,3usize,src,dst,heap);
|
||||
writes(b"a",5usize,3usize,false,src,dst,heap);
|
||||
writes(b"a",5usize,3usize,true,src,dst,heap);
|
||||
reads(b"a",5usize,7usize,src,dst,heap);
|
||||
writes(b"a",5usize,7usize,false,src,dst,heap);
|
||||
writes(b"a",5usize,7usize,true,src,dst,heap);
|
||||
exact(b"a",5usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"a",5usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"a",5usize,4usize,1usize,false,src,dst,heap);
|
||||
exact(b"a",5usize,9usize,1usize,false,src,dst,heap);
|
||||
reads(b"abc",0usize,1usize,src,dst,heap);
|
||||
writes(b"abc",0usize,1usize,false,src,dst,heap);
|
||||
writes(b"abc",0usize,1usize,true,src,dst,heap);
|
||||
reads(b"abc",0usize,3usize,src,dst,heap);
|
||||
writes(b"abc",0usize,3usize,false,src,dst,heap);
|
||||
writes(b"abc",0usize,3usize,true,src,dst,heap);
|
||||
reads(b"abc",0usize,7usize,src,dst,heap);
|
||||
writes(b"abc",0usize,7usize,false,src,dst,heap);
|
||||
writes(b"abc",0usize,7usize,true,src,dst,heap);
|
||||
exact(b"abc",0usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abc",0usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abc",0usize,4usize,3usize,false,src,dst,heap);
|
||||
exact(b"abc",0usize,9usize,3usize,false,src,dst,heap);
|
||||
reads(b"abc",1usize,1usize,src,dst,heap);
|
||||
writes(b"abc",1usize,1usize,false,src,dst,heap);
|
||||
writes(b"abc",1usize,1usize,true,src,dst,heap);
|
||||
reads(b"abc",1usize,3usize,src,dst,heap);
|
||||
writes(b"abc",1usize,3usize,false,src,dst,heap);
|
||||
writes(b"abc",1usize,3usize,true,src,dst,heap);
|
||||
reads(b"abc",1usize,7usize,src,dst,heap);
|
||||
writes(b"abc",1usize,7usize,false,src,dst,heap);
|
||||
writes(b"abc",1usize,7usize,true,src,dst,heap);
|
||||
exact(b"abc",1usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abc",1usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abc",1usize,4usize,3usize,false,src,dst,heap);
|
||||
exact(b"abc",1usize,9usize,3usize,false,src,dst,heap);
|
||||
reads(b"abc",2usize,1usize,src,dst,heap);
|
||||
writes(b"abc",2usize,1usize,false,src,dst,heap);
|
||||
writes(b"abc",2usize,1usize,true,src,dst,heap);
|
||||
reads(b"abc",2usize,3usize,src,dst,heap);
|
||||
writes(b"abc",2usize,3usize,false,src,dst,heap);
|
||||
writes(b"abc",2usize,3usize,true,src,dst,heap);
|
||||
reads(b"abc",2usize,7usize,src,dst,heap);
|
||||
writes(b"abc",2usize,7usize,false,src,dst,heap);
|
||||
writes(b"abc",2usize,7usize,true,src,dst,heap);
|
||||
exact(b"abc",2usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abc",2usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abc",2usize,4usize,3usize,false,src,dst,heap);
|
||||
exact(b"abc",2usize,9usize,3usize,false,src,dst,heap);
|
||||
reads(b"abc",5usize,1usize,src,dst,heap);
|
||||
writes(b"abc",5usize,1usize,false,src,dst,heap);
|
||||
writes(b"abc",5usize,1usize,true,src,dst,heap);
|
||||
reads(b"abc",5usize,3usize,src,dst,heap);
|
||||
writes(b"abc",5usize,3usize,false,src,dst,heap);
|
||||
writes(b"abc",5usize,3usize,true,src,dst,heap);
|
||||
reads(b"abc",5usize,7usize,src,dst,heap);
|
||||
writes(b"abc",5usize,7usize,false,src,dst,heap);
|
||||
writes(b"abc",5usize,7usize,true,src,dst,heap);
|
||||
exact(b"abc",5usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abc",5usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abc",5usize,4usize,3usize,false,src,dst,heap);
|
||||
exact(b"abc",5usize,9usize,3usize,false,src,dst,heap);
|
||||
reads(b"abcdefgh",0usize,1usize,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,1usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,1usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",0usize,3usize,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,3usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,3usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",0usize,7usize,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,7usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",0usize,7usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",0usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",0usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",0usize,4usize,4usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",0usize,9usize,8usize,false,src,dst,heap);
|
||||
reads(b"abcdefgh",1usize,1usize,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,1usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,1usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",1usize,3usize,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,3usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,3usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",1usize,7usize,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,7usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",1usize,7usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",1usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",1usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",1usize,4usize,4usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",1usize,9usize,8usize,false,src,dst,heap);
|
||||
reads(b"abcdefgh",2usize,1usize,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,1usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,1usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",2usize,3usize,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,3usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,3usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",2usize,7usize,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,7usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",2usize,7usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",2usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",2usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",2usize,4usize,4usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",2usize,9usize,8usize,false,src,dst,heap);
|
||||
reads(b"abcdefgh",5usize,1usize,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,1usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,1usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",5usize,3usize,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,3usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,3usize,true,src,dst,heap);
|
||||
reads(b"abcdefgh",5usize,7usize,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,7usize,false,src,dst,heap);
|
||||
writes(b"abcdefgh",5usize,7usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",5usize,0usize,0usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",5usize,1usize,1usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",5usize,4usize,4usize,true,src,dst,heap);
|
||||
exact(b"abcdefgh",5usize,9usize,8usize,false,src,dst,heap);
|
||||
return 42;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<read>,heap: cap<mem.alloc>) -> void effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,1usize,heap) { std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => { return; } }
|
||||
} fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E4002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn worker(q: ref<std.io.writer.Writer>) -> void effects [] {}
|
||||
fn bad(q: ref<std.io.writer.Writer>) -> void effects [task.spawn,task.wait] { scope s { let t = task.spawn(s,worker,q); task.join(move t); } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,37 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:6
|
||||
// vfs: /in/data=abcdef
|
||||
// grant: dst=fs.write:/out
|
||||
// file: /out/data=abcdef
|
||||
// schedules: 12
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn work_read(value: std.io.reader.Reader) -> file<read> effects [fs.read] { var bytes: [u8;6] = [0u8;6]; { mut q = value; exact(std.io.reader.read_exact(q,mut bytes)); } assert(bytes[0] == 97u8); assert(bytes[5] == 102u8); return finished_reader(move value); }
|
||||
fn work_write(value: std.io.writer.Writer) -> file<write> effects [fs.write] { { mut q = value; written(std.io.writer.write(q,b"abcdef")); } return finished_writer(move value); }
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc,task.spawn,task.wait] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let a = reader(move file,3usize,heap); let file = fs.create(dst,b"/out/data") or trap; let b = writer(move file,3usize,heap);
|
||||
scope s { let a = task.spawn(s,work_read,move a); let b = task.spawn(s,work_write,move b); fs.close(task.join(move a)) or trap; fs.close(task.join(move b)) or trap; } return 42;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var bytes: [u8;8] = [255u8;8];
|
||||
{ mut q = value; exact(std.io.reader.read_exact(q,mut bytes[1usize..5usize]));
|
||||
match std.io.reader.read_exact(q,mut bytes[5usize..8usize]) { std.io.ReadExactResult::eof(count) => { assert(count == 2usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
assert(bytes[0] == 255u8); assert(bytes[1] == 97u8); assert(bytes[2] == 98u8); assert(bytes[3] == 99u8); assert(bytes[4] == 100u8); assert(bytes[5] == 101u8); assert(bytes[6] == 102u8); assert(bytes[7] == 255u8);
|
||||
fs.close(finished_reader(move value)) or trap; let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: mut<std.io.reader.Reader>) -> void effects [fs.read] { mut storage = q.storage; mut bytes = buffer.view(storage); std.io.reader.read(q,bytes); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,34 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1];
|
||||
{ mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => { assert(n == 1usize); }, std.io.reader.ReadResult::err(error) => { trap; } } }
|
||||
let (file,unread) = struct.unpack(std.io.reader.discard(move value)); assert(unread == 2usize); exact(std.io.read_exact_file(mut file,mut byte)); assert(byte[0] == 100u8); fs.close(move file) or trap;
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap;
|
||||
match std.io.reader.new(move file,4usize,heap) {
|
||||
std.io.reader.NewResult::ok(value) => { trap; }, std.io.reader.NewResult::err(error) => {
|
||||
let (file,error) = struct.unpack(move error); var bytes: [u8;3] = [0u8;3]; exact(std.io.read_exact_file(mut file,mut bytes)); assert(bytes[0] == 97u8); fs.close(move file) or trap;
|
||||
}
|
||||
}
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:0
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,0usize,heap); var bytes: [u8;7] = [0u8;7];
|
||||
{ mut q = value; match std.io.reader.read_exact(q,mut bytes) { std.io.ReadExactResult::eof(n) => { assert(n == 6usize); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::err(error) => { trap; } } }
|
||||
assert(bytes[0] == 97u8); assert(bytes[5] == 102u8); fs.close(finished_reader(move value)) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
// grant: dst=fs.write:/out
|
||||
// file: /out/data=
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.read,fs.write,mem.alloc] {
|
||||
let narrow = cap.narrow.budget(heap,3usize) or trap; let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,narrow); fs.close(finished_reader(move value)) or trap;
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,narrow); fs.close(finished_writer(move value)) or trap;
|
||||
let allocation = own.new([0u8;3],narrow) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: src=fs.read:/in
|
||||
// grant: heap=mem.alloc:3
|
||||
// vfs: /in/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/in/data") or trap; let value = reader(move file,3usize,heap); var byte: [u8;1] = [0u8;1];
|
||||
{ mut q = value; match std.io.reader.read(q,mut byte) { std.io.reader.ReadResult::ok(n) => { assert(n == 1usize); }, std.io.reader.ReadResult::err(error) => { trap; } } }
|
||||
assert(byte[0] == 97u8);
|
||||
match std.io.reader.finish(move value) {
|
||||
std.io.reader.FinishResult::ok(file) => { trap; },
|
||||
std.io.reader.FinishResult::unread(value) => {
|
||||
var tail: [u8;5] = [0u8;5]; { mut q = value; exact(std.io.reader.read_exact(q,mut tail)); }
|
||||
assert(tail[0] == 98u8); assert(tail[4] == 102u8); fs.close(finished_reader(move value)) or trap;
|
||||
}
|
||||
}
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(value: std.io.reader.Reader) -> void effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { trap; }, std.io.reader.FinishResult::unread(value) => { return; } }
|
||||
} fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:3
|
||||
// file: /out/data=abcdef
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap);
|
||||
{ mut q = value; written(std.io.writer.write(q,b"ab")); written(std.io.writer.write(q,b"cd")); written(std.io.writer.write(q,b"ef")); }
|
||||
fs.close(finished_writer(move value)) or trap; let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E2101
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(q: mut<std.io.writer.Writer>) -> void effects [fs.write] { ref storage = q.storage; ref bytes = buffer.view(storage); std.io.writer.write(q,bytes); }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,33 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:3
|
||||
// file: /out/data=z
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,3usize,heap); { mut q = value; written(std.io.writer.write(q,b"abc")); }
|
||||
let (file,pending,failed) = struct.unpack(std.io.writer.discard(move value)); assert(pending == 3usize); assert(not std.option.is_some::<io_error>(failed)); fs.write_all(file,b"z") or trap; fs.close(move file) or trap;
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:3
|
||||
// file: /out/data=abc
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap;
|
||||
match std.io.writer.new(move file,4usize,heap) {
|
||||
std.io.writer.NewResult::ok(value) => { trap; }, std.io.writer.NewResult::err(error) => { let (file,error) = struct.unpack(move error); fs.write_all(file,b"abc") or trap; fs.close(move file) or trap; }
|
||||
}
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E3002
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<write>,heap: cap<mem.alloc>) -> void effects [mem.alloc] { match std.io.writer.new(move file,3usize,heap) { std.io.writer.NewResult::ok(q) => { trap; }, std.io.writer.NewResult::err(error) => { return; } } }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,32 @@
|
||||
// expect: run
|
||||
// result: 42
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
// grant: dst=fs.write:/out
|
||||
// grant: heap=mem.alloc:0
|
||||
// file: /out/data=abc
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn main(dst: cap<fs.write>,heap: cap<mem.alloc>) -> u64 effects [fs.write,mem.alloc] {
|
||||
let file = fs.create(dst,b"/out/data") or trap; let value = writer(move file,0usize,heap); { mut q = value; written(std.io.writer.write(q,b"abc")); match std.io.writer.flush(q) { std.io.writer.FlushResult::ok => {}, std.io.writer.FlushResult::err(error) => { trap; } } }
|
||||
fs.close(finished_writer(move value)) or trap; return 42;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<read>,heap: cap<fs.read>) -> void effects [mem.alloc] { std.io.reader.new(move file,3usize,heap); trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,26 @@
|
||||
// expect: reject E7005
|
||||
// phase: 6
|
||||
// spec: docs/spec/16-standard-library.md §2.18
|
||||
module test.buffered
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
fn reader(file: file<read>,capacity: usize,heap: cap<mem.alloc>) -> std.io.reader.Reader effects [mem.alloc] {
|
||||
match std.io.reader.new(move file,capacity,heap) { std.io.reader.NewResult::ok(value) => { return move value; }, std.io.reader.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn writer(file: file<write>,capacity: usize,heap: cap<mem.alloc>) -> std.io.writer.Writer effects [mem.alloc] {
|
||||
match std.io.writer.new(move file,capacity,heap) { std.io.writer.NewResult::ok(value) => { return move value; }, std.io.writer.NewResult::err(error) => { trap; } }
|
||||
}
|
||||
fn exact(result: std.io.ReadExactResult) -> void effects [] {
|
||||
match result { std.io.ReadExactResult::ok => {}, std.io.ReadExactResult::eof(count) => { trap; }, std.io.ReadExactResult::err(error) => { trap; } }
|
||||
}
|
||||
fn written(result: std.io.writer.WriteResult) -> void effects [] { match result { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } }
|
||||
fn finished_reader(value: std.io.reader.Reader) -> file<read> effects [] {
|
||||
match std.io.reader.finish(move value) { std.io.reader.FinishResult::ok(file) => { return move file; }, std.io.reader.FinishResult::unread(value) => { trap; } }
|
||||
}
|
||||
fn finished_writer(value: std.io.writer.Writer) -> file<write> effects [fs.write] {
|
||||
match std.io.writer.finish(move value) { std.io.writer.FinishResult::ok(file) => { return move file; }, std.io.writer.FinishResult::err(error) => { trap; } }
|
||||
}
|
||||
fn bad(file: file<append>,heap: cap<mem.alloc>) -> void effects [mem.alloc] { std.io.writer.new(move file,3usize,heap); trap; }
|
||||
fn main() -> u64 effects [] { return 42; }
|
||||
@@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Owning buffered adapters: CLI/AIR/packages, hosted failure and no retry."""
|
||||
import base64
|
||||
import json
|
||||
from pathlib import Path
|
||||
import resource
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
REPO = Path(__file__).resolve().parents[2]
|
||||
AJI = REPO / "zig-out/bin/aji"
|
||||
CASES = REPO / "tests/conformance/source/buffered_io"
|
||||
checks = 0
|
||||
|
||||
|
||||
def cli(*args, code=0, **kwargs):
|
||||
global checks
|
||||
run = subprocess.run([str(AJI), *map(str, args)], capture_output=True, text=True, **kwargs)
|
||||
detail = None
|
||||
if run.returncode != code and "--result-file" in args:
|
||||
result = Path(args[args.index("--result-file") + 1])
|
||||
if result.exists():
|
||||
detail = result.read_text()
|
||||
assert run.returncode == code, (args, run.returncode, run.stdout, run.stderr, detail)
|
||||
checks += 1
|
||||
return run.stdout
|
||||
|
||||
|
||||
def returned(path, *grants, extra=()):
|
||||
args = [item for grant in grants for item in ("--grant", grant)]
|
||||
record = json.loads(cli("run", "--fuel", "2000000", *args, *extra, path))
|
||||
assert record["status"] == "returned", record
|
||||
return record
|
||||
|
||||
|
||||
example = REPO / "examples/std/buffered_io.aji"
|
||||
grants = ("src=fs.read:/in", "dst=fs.write:/out", "heap=mem.alloc:6")
|
||||
record = returned(example, *grants, extra=("--vfs", "/in/data=abcdefgh"))
|
||||
assert record["value"] == 8 and base64.b64decode(record["files"]["/out/data"]["data"]) == b"abcdefgh", record
|
||||
cli("check", example)
|
||||
report = json.loads(cli("report", example))
|
||||
assert report["unsafe"]["operations"] == 0 and report["unsafe"]["trusted_functions"] == [], report
|
||||
canonical = cli("lower", example)
|
||||
assert canonical == cli("lower", example)
|
||||
for path in sorted(CASES.glob("*.aji")):
|
||||
if "// expect: run\n" not in path.read_text():
|
||||
continue
|
||||
args = []
|
||||
for line in path.read_text().splitlines():
|
||||
if line.startswith("// grant: "):
|
||||
args.extend(("--grant", line.removeprefix("// grant: ")))
|
||||
if line.startswith("// vfs: "):
|
||||
args.extend(("--vfs", line.removeprefix("// vfs: ")))
|
||||
assert returned(path, extra=args)["value"] == 42
|
||||
for name, expected in (("missing_read_effect", "E3101"), ("missing_write_effect", "E3101"),
|
||||
("missing_alloc_effect", "E3101"), ("wrong_kind", "E7005"), ("wrong_mode", "E7005"),
|
||||
("missing_move", "E7003"), ("discard_leak", "E3002"), ("finish_error_leak", "E3002"),
|
||||
("reader_alias", "E2101"), ("writer_alias", "E2101"), ("loan", "E4101"), ("not_share", "E4002")):
|
||||
commands = ("check", "lower", "report", "run", "explore") if expected in ("E7003", "E7005") else ("check", "report", "run", "explore")
|
||||
for command in commands:
|
||||
path = CASES / (name + ".aji")
|
||||
errors = [json.loads(line) for line in cli(command, path, code=1).splitlines()]
|
||||
assert errors and {error["code"] for error in errors} == {expected}, errors
|
||||
assert all(Path(error["file"]).resolve() == path.resolve() for error in errors), errors
|
||||
|
||||
CHECK_ERROR = '''fn error_is_other(error: io_error) -> void effects [] {
|
||||
match error { io_error::other => {}, _ => { trap; } }
|
||||
}
|
||||
fn flush_failed(result: std.io.writer.FlushResult) -> void effects [] {
|
||||
match result { std.io.writer.FlushResult::err(error) => { error_is_other(error); }, std.io.writer.FlushResult::ok => { trap; } }
|
||||
}
|
||||
fn write_failed(result: std.io.writer.WriteResult,accepted: usize) -> void effects [] {
|
||||
match result { std.io.writer.WriteResult::err(error) => { assert(error.accepted == accepted); error_is_other(error.error); }, std.io.writer.WriteResult::ok => { trap; } }
|
||||
}
|
||||
fn pending(value: ref<std.io.writer.Writer>,expected: usize) -> void effects [] {
|
||||
assert(value.used == expected);
|
||||
if expected != 0usize { ref storage = value.storage; ref bytes = buffer.view(storage); assert(bytes[0] == 99u8); assert(bytes[1] == 100u8); }
|
||||
}
|
||||
'''
|
||||
# Enum matches are exhaustive (no enum wildcard); construct the remaining arms.
|
||||
TAGS = ("not_found", "permission_denied", "already_exists", "invalid_input", "no_space", "broken_pipe",
|
||||
"connection_refused", "connection_reset", "address_in_use", "address_unavailable", "timed_out")
|
||||
CHECK_ERROR = CHECK_ERROR.replace('_ => { trap; }', ', '.join(f'io_error::{tag} => {{ trap; }}' for tag in TAGS))
|
||||
with tempfile.TemporaryDirectory(prefix="aji-buffered-io-") as directory:
|
||||
root = Path(directory)
|
||||
air = root / "lowered.air"
|
||||
air.write_text(canonical)
|
||||
cli("check", air)
|
||||
assert returned(air, *grants, extra=("--vfs", "/in/data=abcdefgh")) == record
|
||||
entry, manifest = root / "main.aji", root / "aji.toml"
|
||||
entry.write_text(example.read_text())
|
||||
manifest.write_text('[package]\nname = "buffered"\nversion = "1"\nentry = "main.aji"\n[capabilities]\nsrc = "fs.read:/in"\ndst = "fs.write:/out"\nheap = "mem.alloc:6"\n')
|
||||
package = json.loads(cli("run", "--fuel", "2000000", "--vfs", "/in/data=abcdefgh", "--manifest", manifest))
|
||||
assert package == record, package
|
||||
assert cli("lower", "--manifest", manifest) == canonical
|
||||
entry.write_text(example.read_text().replace('import std.io.reader;\nimport std.io.writer;', 'import std.io.writer;\nimport std.io.reader;'))
|
||||
assert cli("lower", "--manifest", manifest) == canonical
|
||||
source, target, result = root / "input", root / "output", root / "result.json"
|
||||
source.write_text("abcdefgh")
|
||||
entry.write_text(example.read_text().replace('b"/in/data"', f'b"{source}"').replace('b"/out/data"', f'b"{target}"'))
|
||||
stdout = cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", f"src=fs.read:{root}", "--grant", f"dst=fs.write:{root}", "--grant", "heap=mem.alloc:6", "--result-file", result, entry)
|
||||
assert stdout == "" and json.loads(result.read_text())["value"] == 8 and target.read_bytes() == b"abcdefgh"
|
||||
# Linux /proc/self/mem opens normally but offset zero cannot be read.
|
||||
# No memory contents are read; the hosted primitive returns EIO / other.
|
||||
if sys.platform.startswith("linux"):
|
||||
entry.write_text('''module app.read_error
|
||||
import std.io;
|
||||
import std.io.reader;
|
||||
''' + CHECK_ERROR.split("fn flush_failed")[0] + '''fn main(src: cap<fs.read>,heap: cap<mem.alloc>) -> u64 effects [fs.read,mem.alloc] {
|
||||
let file = fs.open_read(src,b"/proc/self/mem") or trap;
|
||||
match std.io.reader.new(move file,3usize,heap) {
|
||||
std.io.reader.NewResult::err(error) => { trap; }, std.io.reader.NewResult::ok(value) => {
|
||||
var bytes: [u8;6] = [99u8;6];
|
||||
{ mut q = value; match std.io.reader.read_exact(q,mut bytes[1usize..5usize]) {
|
||||
std.io.ReadExactResult::err(error) => { assert(error.completed == 0usize); error_is_other(error.error); }, std.io.ReadExactResult::ok => { trap; }, std.io.ReadExactResult::eof(n) => { trap; }
|
||||
}
|
||||
assert(q.begin == 0usize); assert(q.end == 0usize);
|
||||
match std.io.reader.read(q,mut bytes[0usize..0usize]) { std.io.reader.ReadResult::ok(n) => { assert(n == 0usize); }, std.io.reader.ReadResult::err(error) => { trap; } }
|
||||
match std.io.reader.read(q,mut bytes[1usize..5usize]) { std.io.reader.ReadResult::err(error) => { error_is_other(error); }, std.io.reader.ReadResult::ok(n) => { trap; } }
|
||||
}
|
||||
assert(bytes[0] == 99u8); assert(bytes[5] == 99u8);
|
||||
let (file,unread) = struct.unpack(std.io.reader.discard(move value)); assert(unread == 0usize); fs.close(move file) or trap;
|
||||
}
|
||||
}
|
||||
let allocation = own.new([0u8;3],heap) or trap; own.free(move allocation); return 42;
|
||||
}
|
||||
''')
|
||||
cli("run", "--profile", "hosted", "--fuel", "2000000", "--grant", "src=fs.read:/proc/self", "--grant", "heap=mem.alloc:3", "--result-file", result, entry)
|
||||
assert json.loads(result.read_text())["value"] == 42
|
||||
|
||||
def partial_write_limit():
|
||||
signal.signal(signal.SIGXFSZ, signal.SIG_IGN)
|
||||
resource.setrlimit(resource.RLIMIT_FSIZE, (3, 1048576))
|
||||
|
||||
for mode in ("room", "prior", "flush", "direct"):
|
||||
capacity = 0 if mode == "direct" else 2
|
||||
initial = {
|
||||
"direct": 'write_failed(std.io.writer.write(q,b"abcdef"),0usize);',
|
||||
"room": 'write_failed(std.io.writer.write(q,b"abcdef"),4usize);',
|
||||
"prior": 'match std.io.writer.write(q,b"ab") { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } write_failed(std.io.writer.write(q,b"cdefgh"),2usize);',
|
||||
"flush": 'match std.io.writer.write(q,b"abcd") { std.io.writer.WriteResult::ok => {}, std.io.writer.WriteResult::err(error) => { trap; } } flush_failed(std.io.writer.flush(q));',
|
||||
}[mode]
|
||||
entry.write_text('''module app.partial_write
|
||||
import std.io;
|
||||
import std.io.writer;
|
||||
import std.option;
|
||||
''' + CHECK_ERROR + f'''fn main(dst: cap<fs.write>,heap: cap<mem.alloc>,input: cap<io.read>,print: cap<io.write>) -> u64 effects [fs.write,mem.alloc,io.read,io.write] {{
|
||||
let file = fs.create(dst,b"{target}") or trap;
|
||||
match std.io.writer.new(move file,{capacity}usize,heap) {{
|
||||
std.io.writer.NewResult::err(error) => {{ trap; }}, std.io.writer.NewResult::ok(value) => {{
|
||||
{{ mut q = value; {initial} pending(ref q,{capacity}usize);
|
||||
match q.failed {{ std.option.Option::<io_error>::some(error) => {{ error_is_other(error); }}, std.option.Option::<io_error>::none => {{ trap; }} }}
|
||||
}}
|
||||
io.stdout_write(print,b"E") or trap;
|
||||
var ack: [u8;1] = [0u8;1]; match std.io.read_exact_stdin(input,mut ack) {{ std.io.ReadExactResult::ok => {{}}, std.io.ReadExactResult::eof(n) => {{ trap; }}, std.io.ReadExactResult::err(error) => {{ trap; }} }} assert(ack[0] == 89u8);
|
||||
{{ mut q = value; flush_failed(std.io.writer.flush(q)); write_failed(std.io.writer.write(q,b"z"),0usize); write_failed(std.io.writer.write(q,ref ack[0usize..0usize]),0usize); pending(ref q,{capacity}usize); }}
|
||||
match std.io.writer.finish(move value) {{
|
||||
std.io.writer.FinishResult::ok(file) => {{ trap; }}, std.io.writer.FinishResult::err(error) => {{
|
||||
let (writer,error) = struct.unpack(move error); error_is_other(error);
|
||||
let (file,pending,failed) = struct.unpack(std.io.writer.discard(move writer)); assert(pending == {capacity}usize);
|
||||
match failed {{ std.option.Option::<io_error>::some(error) => {{ error_is_other(error); }}, std.option.Option::<io_error>::none => {{ trap; }} }} fs.close(move file) or trap;
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
let allocation = own.new([0u8;2],heap) or trap; own.free(move allocation); io.stdout_write(print,b"42") or trap; return 42;
|
||||
}}
|
||||
''')
|
||||
cli("check", entry)
|
||||
command = [str(AJI), "run", "--profile", "hosted", "--fuel", "2000000", "--grant", f"dst=fs.write:{root}", "--grant", "heap=mem.alloc:2", "--grant", "input=io.read", "--grant", "print=io.write", str(entry)]
|
||||
with subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=partial_write_limit) as process:
|
||||
marker = process.stdout.read(1)
|
||||
if marker != b"E":
|
||||
output, error = process.communicate()
|
||||
raise AssertionError((mode, marker, process.returncode, output, error))
|
||||
assert target.read_bytes() == b"abc", (mode, target.read_bytes())
|
||||
# On Linux raise the child's quota before subsequent calls. A retry
|
||||
# would now succeed and append duplicated buffered bytes to the file.
|
||||
if hasattr(resource, "prlimit"):
|
||||
resource.prlimit(process.pid, resource.RLIMIT_FSIZE, (1048576, 1048576))
|
||||
output, error = process.communicate(b"Y")
|
||||
assert process.returncode == 0 and output == b"42", (mode, process.returncode, output, error)
|
||||
assert target.read_bytes() == b"abc", (mode, target.read_bytes())
|
||||
checks += 1
|
||||
|
||||
print(f"buffered I/O integration passed ({checks} checks, partial room/flush/direct writes; Linux read error and raised-quota no retry)")
|
||||
Reference in new issue
Block a user