Commit Graph

14895 Commits

Author SHA1 Message Date
mihael 4ccac1de41 compiler_rt: Make long double trig impls non-generic 2026-04-02 23:54:20 +02:00
mihael ad10c76007 compiler_rt: Stop using dunders for trig functions names
Additionally, use `std.math.pi / 4.0` for `pi/4` in `trig.zig`
instead of hardcoding the value.
2026-04-02 23:54:20 +02:00
mihael 61161132b6 compiler_rt: Dissolve math_utils.zig into long_double.zig & trig.zig
The closest namespace the pi/4 constant could belong to is `trig.zig` since
it's used across trig function implementations. On the other hand, chucking
`long double` bit slicing functions into `trig.zig` seems a little more
awkward, so they're put into their own namespace.
2026-04-02 23:54:20 +02:00
mihael f6ac1a6e05 compiler_rt: Symbolically link cosl & sinl impl to __cosl & __sinl
Some of the functions (e.g., `lgammal`) depended on the `__sinl` and
`__cosl`
functions being present.
2026-04-02 23:54:20 +02:00
mihael 9a53be5fb4 libzigc/math: Implement more precise sincosl in compiler_rt
The changes were tested by running:
```bash
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=sincosl -fqemu -fwasmtime --summary line
Build Summary: 369/369 steps succeeded
```

Additionally, I've added unit tests for `sincos`.
2026-04-02 23:54:20 +02:00
mihael a6d6af947d libzigc/math: Implement more precise cosl in compiler_rt
The implementation was ported from `musl`. Unit tests for `f80` and `f128` were also added.
`__cosl` was already implemented in `trig.zig` while working on `sinl`.

The changes were tested by running:
```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter='math.cosl' -fqemu -fwasmtime --summary line
Build Summary: 553/553 steps succeeded
```
2026-04-02 23:54:20 +02:00
mihael b5ec3e597e libzigc/math: Implement more precise sinl in compiler_rt
The implementation was ported from `musl`. Unit tests for `f80` and `f128` were also added.

The changes were tested by running:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=sinl -fqemu -fwasmtime --summary line
Build Summary: 553/553 steps succeeded
```
2026-04-02 23:54:20 +02:00
mihael ffd6f6cc6e libzigc/math: Implement more precise tanl in compiler_rt
The logic was more or less ported from `musl`, with small adjustments
where it was convenient. The 'internal' `__tanl` function was implemented
in the `trig.zig` module along with other 'internal' trigonometric functions.

Now, the `tanl` implementation is precise enough to pass all the relevant `libc-test` suite tests:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=tanl -fqemu -fwasmtime --summary line
Build Summary: 553/553 steps succeeded
```

The unit tests were also extended to include cases for `f80` and `f128`, and they're passing.
2026-04-02 23:54:20 +02:00
mihael c76644caf3 libzigc/math: Port rem_pio2l from musl to compiler_rt
Additionally, add helper functions for fetching the sign+exponent
and top 16 bits of a f80/f128's mantissa.

We'll need these functions to implement `cosl`, `sinl`, `tanl`, and,
transitively, `sincosl`.
2026-04-02 23:54:20 +02:00
mihael 19334f95c1 libzigc/math: Implement lrintf
This was checked by running:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=lrintf -fqemu -fwasmtime --summary line
Build Summary: 369/369 steps succeeded
```
2026-04-02 23:54:20 +02:00
mihael bd1dc8948f libzigc/math: Remove straggler rint file in vendored MinGW
Seems like it was missed when implementing `rint`.

This was checked by running:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=rint -fqemu -fwasmtime --summary line
Build Summary: 2209/2209 steps succeeded
```
2026-04-02 23:54:19 +02:00
mihael 245c160a7b libzigc/math: Implement rintf
The implementation was ported from `musl` to Zig code, and the `rint`
unit tests were generalized so they could be used for `rintf` as well.

This was checked both through unit tests and running `libc-test` suite:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=rintf -fqemu -fwasmtime --summary line
Build Summary: 1657/1657 steps succeeded
```
2026-04-02 23:54:19 +02:00
mihael 811bada06d libzigc/math: Implement lrint
The changes were tested by running:
```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=lrint -fqemu -fwasmtime --summary line
Build Summary: 737/737 steps succeeded
```
2026-04-02 23:54:19 +02:00
mihael 2cbd6980e5 libzigc/math: Implement finite, finitef
The behaviour of `libc` `finite` functions is the same as Zig std's, so
the function basically delegates to `math.isFinite` and no new tests were
added. These functions are obsolete, but still part of `musl`.

No results are attached in this case as `libc-test` doesn't have tests for them.
2026-04-02 23:54:19 +02:00
mihael db1e649575 libzigc/math: Implement frexpl
The changes were tested by running:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=frexpl -fqemu -fwasmtime --summary line
Build Summary: 369/369 steps succeeded
```
2026-04-02 23:54:19 +02:00
mihael 521a093334 libzigc/math: Implement frexpf
The `frexp` implementation was generalized so it can be used for `f32`
and `c_longdouble` types as well.

The changes were tested by running:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=frexp -fqemu -fwasmtime --summary line
Build Summary: 737/737 steps succeeded

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=frexpf -fqemu -fwasmtime --summary line
Build Summary: 369/369 steps succeeded
```
2026-04-02 23:54:19 +02:00
mihael dcffee0672 libzigc/math: Implement frexp
The changes were tested by running:

```
$ ./build/stage3/bin/zig build -p stage4 -Denable-llvm -Dno-lib

$ stage4/bin/zig build test-libc -Dlibc-test-path=<LIBC-TEST-PATH> -Dtest-filter=frexp -fqemu -fwasmtime --summary line
Build Summary: 737/737 steps succeeded
```

The tests were passing even when it was a straightforward calling of Zig
std library, but I wanted the `x is NaN` special case to match the
behaviour described in `libc` manpages, and for it to be consistent
with how infinities as arguments are handled in Zig.
2026-04-02 23:54:19 +02:00
mihael ba4af7aa8a libzigc/math: Switch to compiler_rt impl of tanl 2026-04-02 23:54:19 +02:00
mihael a8b710697e libzigc/math: Switch to compiler_rt impl of sincosl 2026-04-02 23:54:19 +02:00
Justus Klausecker ce3f254526 std.heap.ArenaAllocator: do not cmpxchg in hot path when it would be a noop
The cmpxchg is there to recover alignment padding that isn't needed (which
can only be determined after the fetch-and-add that reserves it as allocated
memory). As cmpxchg tends to be a very expensive operation, it is actually
faster to introduce an additional branch here that checks if the cmpxchg
would be a noop (because all of the reserved alignment padding was in fact
necessary) and skips it if that's the case.

This does not measurably regress performance if the arena is only accessed
by a single thread and yields slight performance benefits for multi-threaded
usage. If the arena is commonly used for unaligned allocations, the perf
benefits are quite significant.

Co-authored-by: Jacob Young <amazingjacob@gmail.com>
2026-04-02 23:00:26 +02:00
Andrew Kelley e9df86aed0 Merge pull request 'std.heap.ArenaAllocator: decrease fuzz test workload per run' (#31596) from justusk/zig:fuzz-arena-2 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31596
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-02 15:57:41 +02:00
Andrew Kelley 43d84420f3 Merge pull request 'std: add mem.absorbSentinel(), fix sentinel handling in Allocator interface' (#31611) from ifreund/zig:absorb-sent into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31611
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-02 15:55:21 +02:00
Pavel Verigo 557caecaaa stage2-wasm: start big int support 2026-04-02 15:48:43 +02:00
Andrew Kelley 3e0f55fcc7 Merge pull request 'add an ast smith' (#31635) from gooncreeper/zig:ast-smith into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31635
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-04-02 15:41:05 +02:00
johan0A 022c76fc89 std.Build.Module: fix dangling slice in dynamic linker arg 2026-04-02 15:19:14 +02:00
Josh Megnauth 56507ecf98 libzigc: stropts/isastream
`isastream` is an old, deprecated function for the STREAMS framework.
Linux doesn't even support this natively, and so the musl implementation
just returns 0 (not a STREAMS file) for valid file descriptors or -1
(for bad file descriptors).
2026-04-02 15:13:39 +02:00
Hila Friedman 746dd51faf Simplify std.ArrayList.replaceRange and std.ArrayList.replaceRangeAssumeCapacity (#31710)
The implementations of `std.ArrayList.replaceRange` and `std.ArrayList.replaceRangeAssumeCapacity` were needlessly complicated, called `@memcpy` too many times, and left the structure in a semi-modified state in OOM conditions. This commit fixes that.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31710
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Hila Friedman <red.black.liquorice@gmail.com>
Co-committed-by: Hila Friedman <red.black.liquorice@gmail.com>
2026-04-02 15:11:24 +02:00
Jonathan Marler f4eecf8d7d handle EROFS in create/open file
I hit an unexpected errno 30 on macos attempting to call createFile on a
directory in PATH.  errno 30 is EROFS, this change propagates that error
as error.ReadOnlyFileSystem.
2026-04-02 15:05:31 +02:00
badayvedat 6cdd576d41 libzigc: fdim 2026-04-02 14:50:19 +02:00
Andrew Kelley 617979ef26 std.Build.WebServer: use Io.concurrent rather than threads
allows the code to also work in evented mode
2026-04-01 02:54:25 -07:00
Andrew Kelley bd05d13d5f std: make file locking tests use io not threads
This will allow the tests to also run in single-threaded evented mode.
2026-04-01 02:54:25 -07:00
Brandon Black 1226bb9268 LinuxThreadImpl: be precise in tls.prepareArea arg
This isn't causing any functional problem today, but technically
`mapped[tls_offset..]` runs past the tls part of `mapped` and into
the `Instance` storage, and currently `prepareArea()` memsets its
entire argument to zero.  It is only the current layout and
initialization order of `mapped` that prevents this from being a
problem.  Being more precise here avoids future footguns if any of
that changes.
2026-03-31 14:48:03 -05:00
Brandon Black 614cd66e7e LinuxThreadImpl: clear tidptr during detached exit
Fixes: #31714
2026-03-31 14:47:44 -05:00
Brandon Black bb9f97e085 std.os.linux: add set_tid_address 2026-03-31 14:47:22 -05:00
Andrew Kelley 9b1eaad13f std.Build.Step.ConfigHeader: add addIdent function
for when you need to emit a bare identifier but from a string
2026-03-30 00:37:39 -07:00
Jacob Young 0db75c0116 std.Io.Threaded: fix dns queries on windows
by working around various bugs in `DnsQueryEx`.

Closes #31659
2026-03-30 09:33:04 +02:00
Frank Denis 42e33db9d0 Merge pull request 'crypto.base64: use "-" instead of "+" character in URL-safe mode' (#31709) from jedisct1/zig:urlsafe into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31709
2026-03-29 18:20:14 +02:00
Frank Denis dcb33abc2c crypto.base64: use "-" instead of "+" character in URL-safe mode
/ was turned into _, but + also needs to be turned into -
2026-03-29 09:33:22 +02:00
Matthew Lugg b36cfc6352 compiler-rt: work around LLVM not respecting -fno-builtin 2026-03-28 19:25:01 +00:00
Matthew Lugg d28c5069b8 llvm: rework handling of globals
The main goal here is to make incremental compilation work a bit better.
I also slightly expanded some `std.zig.llvm.Builder` APIs so that we
don't need to pointlessly create new `Global`s whenever e.g. a function
turns into a variable or vice versa.

Also, lean into aliases for exports! If we just use aliases for every
export, everything becomes simpler. Besides, we can't just go around
renaming the globals of `Nav`s: the export could disappear on a future
update, in which case we'd have to somehow revert that change, which is
easier said than done.
2026-03-28 16:50:42 +00:00
Andrew Kelley b490412cd2 build runner: fail, not warn when insufficient memory
Users can proceed by telling the build system how much memory to assume
the system has. I have improved the failure message to communicate this.

Partially reverts 87f8f47ba5

Even if we wanted to unrevert this reverted commit, it's not sufficient
to merely downgrade the failure to a warning, because the main
scheduling logic will fail to schedule steps that have a max_rss
exceeding the detected system value, causing some steps to never get
executed, eventually tripping an assert. Such a change would need to
also override the max_rss value to be equal to the greatest value across
all steps.

closes #31510
2026-03-27 18:06:08 +01:00
Andrew Kelley b4e21ccb49 Merge pull request 'std.tar.extract: sanitize path traversal' (#31685) from tar into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31685
2026-03-27 15:00:29 +01:00
Andrew Kelley 2d3694ab42 Merge pull request 'std.Io.Dir: add resolve_beneath flag and implement for freebsd,macos' (#31684) from resolve_beneath into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31684
2026-03-27 12:24:09 +01:00
GasInfinity 1f79a9e4e3 feat(Io.net): add allow_broadcast to BindOptions
* and implement it in `Threaded`, `Uring` and `Kqueue`
2026-03-27 09:43:57 +01:00
Andrew Kelley 9ad6843b20 std.tar.extract: sanitize path traversal
closes #31362
2026-03-27 01:27:38 -07:00
Andrew Kelley 79b5433da7 std.tar: rename pipeToFileSystem to extract 2026-03-27 01:27:26 -07:00
Andrew Kelley 2e4482cd14 std.Io.Dir: add resolve_beneath flag and implement for freebsd,macos 2026-03-27 01:23:04 -07:00
Andrew Kelley 6f467e436d std.Io: move File.CreateFlags to Dir.CreateFileOptions
for naming consistency.

same thing with File.OpenFlags -> Dir.OpenFileFlags
2026-03-27 01:23:04 -07:00
Andrew Kelley 0d25302d43 Package.Fetch: bump redirect buffer size
RFC 9110 says

> It is RECOMMENDED that all senders and recipients support, at a minimum,
> URIs with lengths of 8000 octets in protocol elements.

closes #30207
2026-03-27 08:42:02 +01:00
Jacob Young 49a258c0e0 std.Build.Step.Run: improve syscalls while running zig test executables
Previously, each message requires an unseekable error to be returned
from a syscall before proceeding.  Ideally, the code would just pass
around `*std.Io.Writer` instead of `std.Io.File` in the first place, but
even then, you could argue for saving a syscall with `writerStreaming`.
2026-03-27 03:28:50 +01:00