-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Writergate #24329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Writergate #24329
+15,235
−13,432
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alexrp
reviewed
Jul 4, 2025
Techatrix
reviewed
Jul 6, 2025
5837754 to
1ef243b
Compare
Macos uses the BSD definition of msghdr All linux architectures share a single msghdr definition. Many architectures had manually inserted padding fields that were endian specific and some had fields with different integers. This unifies all architectures to use a single correct msghdr definition.
preparing to rearrange std.io namespace into an interface how to upgrade: std.io.getStdIn() -> std.fs.File.stdin() std.io.getStdOut() -> std.fs.File.stdout() std.io.getStdErr() -> std.fs.File.stderr()
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API
make std.testing.expectFmt work at compile-time
std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.
Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
- anytype -> *std.io.Writer
- inferred error set -> error{WriteFailed}
- options -> (deleted)
* std.fmt.Formatted
- now takes context type explicitly
- no fmt string
behavior tests must not depend on std.io
for structs, enums, and unions.
auto untagged unions are no longer printed as pointers; instead they are
printed as "{ ... }".
extern and packed untagged unions have each field printed, similar to
what gdb does.
also fix bugs in delimiter based reading
it didn't account for data.len can no longer be zero
now it avoids writing to buffer in the case of fixed
So that when returning from drain there is always capacity for at least one more byte.
IntegratedQuantum
added a commit
to PixelGuys/Cubyz
that referenced
this pull request
Jul 15, 2025
For reference: ziglang/zig#24329 some commits have been extracted from #1583, but the x86_64 backend has been disabled due to its horrible performance. Remaining work: - [x] Wait for official builds on ziglang.org and upload them to our repository - [x] Add workaround for ziglang/zig#24466 - [x] Fix TODO comment about ANSI support in stdout - [x] Check for compile-time performance changes → it went from 13.1 to 11.9 seconds 🎉
2 tasks
silbinarywolf
added a commit
to silbinarywolf/zig-android-sdk
that referenced
this pull request
Jul 27, 2025
…ort) (#47) **Why?** Writer interface was changed and broken, need to update the Android SDK to support 0.14.1 vs 0.15.x-dev **Related to breaking change here:** ziglang/zig#24329
This was referenced Jul 29, 2025
dasimmet
pushed a commit
to dasimmet/zig
that referenced
this pull request
Aug 4, 2025
don't forget to save the list. this allows a `testing.checkAllAllocationFailures()` test to pass in one of my projects which newly failed since ziglang#24329 was merged.
This was referenced Aug 5, 2025
This was referenced Aug 27, 2025
Merged
eliminmax
added a commit
to eliminmax/colortest
that referenced
this pull request
Dec 24, 2025
Buffered printing to stdout in Zig now requires more explicit buffer usage, so the Zig implementation now uses that, and the version of Zig installed by `RUNNERS/install-deps.sh` can be updated to the latest release. see ziglang/zig#24329
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
breaking
Implementing this issue could cause existing code to no longer compile or have different behavior.
release notes
This PR should be mentioned in the release notes.
standard library
This issue involves writing Zig code for the standard library.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previous Scandal
Summary
Deprecates all existing std.io readers and writers in favor of the newly provided
std.Io.Readerandstd.Io.Writerwhich are non-generic and have the buffer above the vtable - in other words the buffer is in the interface, not the implementation. This means that although Reader and Writer are no longer generic, they are still transparent to optimization; all of the interface functions have a concrete hot path operating on the buffer, and only make vtable calls when the buffer is full.I have a lot more changes to upstream but it was taking too long to finish them so I decided to do it more piecemeal. Therefore, I opened this tiny baby PR to get things started.
These changes are extremely breaking. I am sorry for that, but I have carefully examined the situation and acquired confidence that this is the direction that Zig needs to go. I hope you will strap in your seatbelt and come along for the ride; it will be worth it.
The breakage in this first PR mainly has to do with formatted printing.
More Detailed Motivation
I wrote this up for ziggit but I think it would be good to include in release notes:
anytype. The new interface is concrete.http.Serverafter the change no longer depends onstd.net- it operates only on streams now.anyerror. The new interface carefully defines precise error sets for each function with actionable meaning.Performance Data
Building Self-Hosted Compiler with Itself
Building My Music Player Project
source
Compiler Binary Size (ReleaseSmall)
C Backend Building the Zig Compiler
C Backend Building Hello World
ReleaseFast zig
Debug zig
Upgrade Guide
Turn on
-freference-traceto help you find all the format string breakage."{f}"Required to CallformatMethodsExample:
This will now cause a compile error:
Fixed by:
Motivation: eliminate these two footguns:
Introducing a
formatmethod to a struct caused a bug if there was formatting code somewhere that prints with {} and then starts rendering differently.Removing a
formatmethod to a struct caused a bug if there was formatting code somewhere that prints with {} and is now changed without notice.Now, introducing a
formatmethod will cause compile errors at all{}sites. In the future, it will have no effect.Similarly, eliminating a
formatmethod will not change any sites that use{}.Using
{f}always tries to call aformatmethod, causing a compile error if none exists.Format Methods No Longer Have Format Strings or Options
⬇️
The deleted FormatOptions are now for numbers only.
Any state that you got from the format string, there are three suggested alternatives:
This can be called with
"{f}", .{std.fmt.alt(Foo, .formatB)}.std.fmt.AltThis can be called with
"{f}", .{foo.bar(1234)}.{f}.This can be called with
"{f}", .{foo.bar(1234)}.Formatted Printing No Longer Deals with Unicode
If you were relying on alignment combined with Unicode codepoints, it is now ASCII/bytes only. The previous implementation was not fully Unicode-aware. If you want to align Unicode strings you need full Unicode support which the standard library does not provide.
std.io.getStdOut().writer().print()
Please use buffering! And don't forget to flush!
Miscellaneous
These are deprecated but not deleted yet:
If you have an old stream and you need a new one, you can use
adaptToNewApi()like this:New API
Formatted Printing
@tagName()and@errorName()formatNumbermethod.std.io.Writerandstd.io.ReaderThese have a bunch of handy new APIs that are more convenient, perform better, and are not generic. For instance look at how reading until a delimiter works now.
These streams also feature some unique concepts compared with other languages' stream implementations:
std.fs.File.ReaderMemoizes key information about a file handle such as:
sendfile)versus plain variants (e.g.
read).Fulfills the
std.io.Readerinterface.This API turned out to be super handy in practice. Having a concrete type to pass around that memoizes file size is really nice.
std.fs.File.WriterSame idea but for writing.
What's NOT Included in this Branch
This is part of a series of changes leading up to "I/O as an Interface" and Async/Await Resurrection. However, this branch does not do any of that. It also does not do any of these things:
I have done all the above in a separate branch and plan to upstream them one at a time in follow-up PRs, eliminating dependencies on the old streaming APIs like a game of pick-up-sticks.
Merge Checklist: