Skip to content

fs: add io_uring-style prep functions to File - #684

Merged
lalinsky merged 2 commits into
mainfrom
file-prep-ops
Aug 18, 2026
Merged

lalinsky merged 2 commits into
mainfrom
file-prep-ops

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

First slice of the "make the ev layer comfortable" direction: io_uring-style prep functions on File that fill an ev op in place without submitting it, so users hold and submit ops without ever constructing ev structs by hand:

var bufs: [4][4096]u8 = undefined;
var storage: [4][1]os.iovec = undefined;
var ops: [4]ev.FileRead = undefined;
for (&ops, &bufs, &storage, 0..) |*op, *buf, *iov, i| {
    file.prepRead(op, .fromSlice(buf, iov), i * 4096);
    try cq.submit(&op.c);
}
while (!cq.isEmpty()) {
    const c = try cq.wait();
    const n = try c.cast(ev.FileRead).getResult();
    // ...
}

Added: prepRead, prepWrite, prepReadStreaming, prepWriteStreaming, prepStat, prepSync.

Design points:

  • Prep never submits. The op is inert until handed to the loop (waitForIo, CompletionQueue.submit, ev.Group.add), so it is safe to move until then; no result-location hazards.
  • The object contributes its hidden state. Streaming preps carry pollable routing (event loop vs thread pool), which a hand-rolled ev.FileReadStreaming.init would silently miss.
  • Prep surface is the Buf-taking tier only. The slice conveniences (read, readVec, ...) keep their iovec storage on the blocking call's frame, which cannot outlive a prep, so they stay blocking-only and now route through readBuf/writeBuf.
  • Single construction point. The blocking methods are refactored on top of the prep functions, so the two tiers cannot drift.

Tests: a 4-way concurrent positional read batch driven through a CompletionQueue with per-op result and buffer verification, and a streaming prep + waitForIo round-trip that checks the pollable routing is carried over.

Scope: File only for now; Dir and socket preps can follow the same pattern.

Fill an ev op with the file's handle and routing state without submitting
it: prepRead, prepWrite, prepReadStreaming, prepWriteStreaming, prepStat,
prepSync. The op is inert until handed to the loop, so callers can build
batches of typed ops and drive them through a CompletionQueue or an
ev.Group without constructing ev structs by hand; the streaming preps
carry the file's pollable routing, which a hand-rolled init would
silently miss.

The blocking methods are refactored to sit on top of the prep functions
(and the slice conveniences on top of the Buf variants), so each
operation has a single construction point.
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 97e89fc1-389c-43d3-98bd-05f3efe08e72

📥 Commits

Reviewing files that changed from the base of the PR and between 9a7af43 and 571b6fb.

📒 Files selected for processing (1)
  • src/fs.zig
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/fs.zig

Included review availability: Your plan includes up to 4 reviews per rolling hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

File now exposes helpers that prepare positional, streaming, stat, and sync operations without submission. Existing convenience methods use these helpers. Tests cover concurrent prepared reads and streaming pollable routing.

Changes

File operation preparation

Layer / File(s) Summary
Preparation helpers and pollable routing
src/fs.zig
Adds prepRead, prepWrite, prepReadStreaming, prepWriteStreaming, prepStat, and prepSync. Streaming helpers copy the file’s pollable routing state.
Convenience method integration
src/fs.zig
Routes positional, streaming, stat, and sync methods through the new preparation helpers while preserving result, cancellation, and timeout handling.
Prepared operation tests
src/fs.zig
Tests concurrent prepared reads through CompletionQueue and verifies pollability for prepared streaming writes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 571b6

The PR adds non-submitting file-operation preparation helpers and routes existing blocking methods through them; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

  • lalinsky/zio#2: Extends the File I/O API with streaming and operation-oriented read/write functionality.
  • lalinsky/zio#162: Adds File.prepStat and related FileStat operations.
  • lalinsky/zio#363: Adds streaming file read/write preparation and operations.

Poem

Prepared reads wait in line,
Streaming writes keep their route.
Stat and sync share the setup,
CompletionQueue checks them out.
Zig operations, ready to run.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding io_uring-style preparation functions to File.
Description check ✅ Passed The description explains the new File preparation functions, behavior, design points, tests, and scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch file-prep-ops

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Streaming I/O on regular files is not supported on Windows (the fallback
writev fails with INVALID_PARAMETER); the io.zig streaming-file tests are
skipped there for the same reason. The prep itself is platform-independent
and stays checked everywhere.
@lalinsky
lalinsky merged commit 307e3f7 into main Aug 18, 2026
30 checks passed
@lalinsky
lalinsky deleted the file-prep-ops branch August 18, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant