Commit graph

42 commits

Author SHA1 Message Date
Andrew Kelley
922ab8b8bc std: finish moving time to Io interface
Importantly, adds ability to get Clock resolution, which may be zero.
This allows error.Unexpected and error.ClockUnsupported to be removed
from timeout and clock reading error sets.
2026-02-02 23:02:31 -08:00
Andrew Kelley
cc442d24ab std.Io: move fileWriteStreaming to Operation
This serves as an example to contributors of how to move VTable
functions to becoming an Operation, thereby enabling Batch API and
timeouts.
2026-01-31 22:53:28 -08:00
Jacob Young
2674acdb77 Io.Batch: implement alternate API 2026-01-30 22:03:14 -08:00
Andrew Kelley
6a1fd3c69d std.Io.File.MultiReader: make checkAnyError exclude EndOfStream 2026-01-30 22:03:14 -08:00
Andrew Kelley
8a80b54640 std: remove error.BrokenPipe from file reads, add error.EndOfStream
and make reading file streaming allowed to return 0 byte reads.
According to Microsoft documentation, on Windows it is possible to get
0-byte reads from pipes when 0-byte writes are made.
2026-01-30 22:03:14 -08:00
Andrew Kelley
372e8e54d3 compiler: update for std.Io.File.MultiReader API 2026-01-30 22:03:14 -08:00
Andrew Kelley
e56563ce3f std.Io.File.MultiReader: implementation fixes 2026-01-30 22:03:14 -08:00
Andrew Kelley
12cfc96e1b std: update rest of build runner to new File.MultiReader API 2026-01-30 22:03:14 -08:00
Andrew Kelley
20cadd60aa std.Io.File: introduce MultiReader
Concurrently read from multiple file streams, eliminating risk of
deadlocking.
2026-01-30 22:03:14 -08:00
Jacob Young
8146ccfecc Io: add ring to Batch API 2026-01-30 22:03:14 -08:00
Andrew Kelley
0a0ecc4fb1 std.Io: proof-of-concept "operations" API
This commit shows a proof-of-concept direction for std.Io.VTable to go,
which is to have general support for batching, timeouts, and
non-blocking.

I'm not sure if this is a good idea or not so I'm putting it up for
scrutiny.

This commit introduces `std.Io.operate`, `std.Io.Operation`, and
implements it experimentally for `FileReadStreaming`.

In `std.Io.Threaded`, the implementation is based on poll().

This commit shows how it can be used in `std.process.run` to collect
both stdout and stderr in a single-threaded program using
`std.Threaded.Io`.

It also demonstrates how to upgrade code that was previously using
`std.Io.poll` (*not* integrated with the interface!) using concurrency.
This may not be ideal since it makes the build runner no longer support
single-threaded mode. There is still a needed abstraction for
conveniently reading multiple File streams concurrently without
io.concurrent, but this commit demonstrates that such an API can be
built on top of the new `std.Io.operate` functionality.
2026-01-30 22:03:13 -08:00
Andrew Kelley
9b415761dd std.os.windows: delete unused APIs
Intention is to go through std.Io for these things.
2026-01-30 03:39:46 +01:00
Andrew Kelley
499ba5d55c compiler: use Io.MemoryMap
Also make setLength return error.OperationUnsupported when it cannot be
done atomically.
2026-01-22 21:25:53 -08:00
Andrew Kelley
1badb2a840 std.Io.Threaded: dirCreateFileWindows uses NtCreateFile directly 2026-01-22 18:08:13 -08:00
Andrew Kelley
7b21fd7244 std.Io.Threaded: fix memory mapping on windows
- set protection flags properly
- handle when mapping fails after unmapping
2026-01-15 14:18:21 -08:00
Andrew Kelley
2b01764d86 std: fix handling of EBADF error code
In the context of read/write it's ambiguous, means file was opened
without read/write respectively.
2026-01-15 14:18:20 -08:00
Andrew Kelley
c917f619f0 std: fix compilation failures on various targets 2026-01-15 14:18:20 -08:00
Andrew Kelley
eb163361d9 std.Io.File.MemoryMap: add some alignment type safety 2026-01-15 14:18:20 -08:00
Andrew Kelley
4821898432 std.Io.File.MemoryMap API tuning
- remove file_size parameter from MemoryMap.write
- remove requirement for mapping length to be aligned
- align allocated fallback memory
- add unit test for std.Io.Threaded.disable_memory_mapping = true
- add unit test for MemoryMap.setLength
2026-01-15 14:18:20 -08:00
Andrew Kelley
bed7bc37c4 std.File.MemoryMap updates
- change offset to u64
- make len non-optional
- make write take a file_size parameter
- std.Io.Threaded: introduce disable_memory_mapping flag to force it to
  take the fallback path.

Additionally:

- introduce BlockSize to File.Stat. On Windows, based on cached call to
  NtQuerySystemInformation. On unsupported OS's, set to 1.
- support File.NLink on Windows. this was available the whole time, we
  just didn't see the field at first.
- remove EBADF / INVALID_HANDLE from reading/writing file error sets
2026-01-15 14:18:20 -08:00
Andrew Kelley
a70e006157 std: add unit test for memory mapping 2026-01-15 14:18:20 -08:00
Andrew Kelley
5a7dc4b0fa std.Io: introduce File.MemoryMap
by defining the pointer contents to only be synchronized after explicit
sync points, makes it legal to have a fallback implementation based on
file operations while still supporting a handful of use cases for memory
mapping.

furthermore, it makes it legal for evented I/O implementations to use
evented file I/O for the sync points rather than memory mapping.

not yet done:
- implement checking the length when options.len is null
- some windows impl work
- some wasi impl work
- unit tests
- integration with compiler
2026-01-15 14:18:20 -08:00
Andrew Kelley
1ddae8585a std.Io.Threaded: add procfs fallback for fileHardLink
oof what a clunky set of functionality we have here
2026-01-07 11:03:37 -08:00
Andrew Kelley
ee574f665c std.Io.Dir: introduce renamePreserve and use it in File.Atomic.link
breaking change: the error for renaming over a non-empty directory now
returns error.DirNotEmpty rather than error.PathAlreadyExists.
2026-01-07 11:03:37 -08:00
Andrew Kelley
81bfd28974 std.Io.Dir: rework atomic file 2026-01-05 20:28:58 -08:00
Andrew Kelley
ace08ba642 std.Io.Threaded: prevent 0-byte file writes
these cause EINVAL on darwin and are generally a wasted syscall.

and remove a bogus error from File.Writer.Error.
2025-12-23 23:46:43 -08:00
Andrew Kelley
3e624e17a4 std: fix compilation errors on FreeBSD 2025-12-23 22:15:11 -08:00
Andrew Kelley
7ce5ee2e92 std: update remaining unit tests for std.Io API changes 2025-12-23 22:15:10 -08:00
Andrew Kelley
21d0264c61 std.dynamic_library: use a global static single threaded Io
See #30150
2025-12-23 22:15:10 -08:00
Andrew Kelley
608145c2f0 fix more fallout from locking stderr 2025-12-23 22:15:10 -08:00
Andrew Kelley
aa57793b68 std: rework locking stderr 2025-12-23 22:15:09 -08:00
Andrew Kelley
b042e93522 std: update tty config references in the build system 2025-12-23 22:15:09 -08:00
Andrew Kelley
7837d975dc std: save terminal escape stripping for later 2025-12-23 22:15:09 -08:00
Andrew Kelley
3a6e15449b std.Io: add ResetEvent based on futexes
and add futex to the vtable. A future commit may make the other sync
primitives based on futexes.
2025-12-23 22:15:09 -08:00
Andrew Kelley
ffcbd48a12 std: rework TTY detection and printing
This commit sketches an idea for how to deal with detection of file
streams as being terminals.

When a File stream is a terminal, writes through the stream should have
their escapes stripped unless the programmer explicitly enables terminal
escapes. Furthermore, the programmer needs a convenient API for
intentionally outputting escapes into the stream. In particular it
should be possible to set colors that are silently discarded when the
stream is not a terminal.

This commit makes `Io.File.Writer` track the terminal mode in the
already-existing `mode` field, making it the appropriate place to
implement escape stripping.

`Io.lockStderrWriter` returns a `*Io.File.Writer` with terminal
detection already done by default. This is a higher-level application
layer stream for writing to stderr.

Meanwhile, `std.debug.lockStderrWriter` also returns a `*Io.File.Writer`
but a lower-level one that is hard-coded to use a static single-threaded
`std.Io.Threaded` instance. This is the same instance that is used for
collecting debug information and iterating the unwind info.
2025-12-23 22:15:09 -08:00
Andrew Kelley
5b436d2c51 build_runner compiling again 2025-12-23 22:15:08 -08:00
Andrew Kelley
bee8005fe6 std.heap.DebugAllocator: never detect TTY config
instead, allow the user to set it as a field.

this fixes a bug where leak printing and error printing would run tty
config detection for stderr, and then emit a log, which is not necessary
going to print to stderr.

however, the nice defaults are gone; the user must explicitly assign the
tty_config field during initialization or else the logging will not have
color.

related: https://github.com/ziglang/zig/issues/24510
2025-12-23 22:15:08 -08:00
Andrew Kelley
4a53e5b0b4 fix a handful of compilation errors related to std.fs migration 2025-12-23 22:15:08 -08:00
Andrew Kelley
9e3bda5eff tests: close() -> close(io) 2025-12-23 22:15:08 -08:00
Andrew Kelley
72b76077ab std: fix some surface level compilation errors
And boldly remove preadv, pwritev, readv, writev, pread, pwrite from
std.posix.
2025-12-23 22:15:07 -08:00
Andrew Kelley
ba999d608c std: extract sendfile/copy_file_range from Io.File.Writer
and move it into std.Io.Threaded (below the VTable)
2025-12-23 22:15:07 -08:00
Andrew Kelley
814480db7c std: all File functions moved to std.Io 2025-12-23 22:15:07 -08:00