Commit graph

37272 commits

Author SHA1 Message Date
Nathan Michaels
aa2f318935 std.mem.ReverseIterator: make public 2026-03-05 21:07:36 +01:00
Koko Bhadra
4fa465fc8f compiler_rt: optimize udivmod large-divisor case with trial quotient
Replace the O(n) shift-subtract loop with a constant-time trial
quotient approach (Knuth Algorithm D, TAOCP Vol 2 Section 4.3.1).

The old code iterates clz(b_hi)-clz(a_hi)+1 times (up to 64
iterations of 128-bit arithmetic). The new code uses a single
divwide call to get a trial quotient, then verifies with two
native-width widening multiplies.

Benchmark (Apple M1, ReleaseFast):
- Large divisor, large shift: 87ns -> 7.5ns (11.5x faster)
- Small divisor / uniform: unchanged
2026-03-05 20:22:19 +01:00
xeondev
15f0af09d0 Io.Threaded.batchAwaitConcurrent: fix poll args 2026-03-05 20:17:21 +01:00
Alex Rønne Petersen
b778826df5
std.crypto.argon2: disable kdf test
https://codeberg.org/ziglang/zig/issues/31402
2026-03-05 18:49:31 +01:00
Alex Rønne Petersen
571543237f
ci: update to wasmtime 42.0.1 2026-03-04 21:29:48 +01:00
Alex Rønne Petersen
0ae1c6b54a
std.Io.RwLock: disable smoke test on aarch64-netbsd
https://codeberg.org/ziglang/zig/issues/31393
2026-03-04 12:14:11 +01:00
Alex Rønne Petersen
ce32003625
std.Io.net.test: disable listen on a port, send bytes, receive bytes
https://codeberg.org/ziglang/zig/issues/31388
2026-03-04 01:21:08 +01:00
Alex Rønne Petersen
af1ab5fa08
ci: bump aarch64-freebsd-debug timeout by 1 hour 2026-03-04 00:16:47 +01:00
Alex Rønne Petersen
96a19d3a6b ci: stop downloading tarballs on x86_64-windows
It's annoying to have jobs fail on new machines or when switching tarball. Also
quirky is easily accessible over SSH now, so we can just upload tarballs as we
do for other machines.
2026-03-03 23:28:01 +01:00
Alex Rønne Petersen
852c5d2824
build: bump some max_rss values 2026-03-03 22:50:48 +01:00
Robby Zambito
d2db1d45f1 fix: inline to propagate comptime-ness to call site
See conversation at: https://ziggit.dev/t/why-is-the-comptime-keyword-needed-in-this-inline-for-loop-condition/14090
2026-03-03 21:10:30 +01:00
Andrew Kelley
2d88a5a103 Merge pull request 'Another dll dependency bites the dust (advapi32.dll)' (#31384) from squeek502/zig:delete-advapi32 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31384
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-03 18:26:12 +01:00
Ryan Liptak
fdde8e6394 Delete advapi32 bindings 2026-03-03 01:12:48 -08:00
Ryan Liptak
70058471e3 WindowsSdk: Use ntdll instead of advapi32 APIs for registry querying
The dependency on advapi32.dll actually silently brings along 3 other dlls at runtime (msvcrt.dll, sechost.dll, bcrypt.dll), even if no advapi32 APIs are called. So, this commit actually reduces the number of dlls loaded at runtime by 4 (but only when LLVM is not linked, since LLVM has its own dependency on advapi32.dll).

The data is not super conclusive, but the ntdll version of WindowsSdk appears to run slightly faster than the previous advapi32 version:

Benchmark 1: libc-ntdll.exe ..
  Time (mean ± σ):       6.0 ms ±   0.6 ms    [User: 3.9 ms, System: 7.1 ms]
  Range (min … max):     4.8 ms …   7.9 ms    112 runs

Benchmark 2: libc-advapi32.exe ..
  Time (mean ± σ):       7.2 ms ±   0.5 ms    [User: 5.4 ms, System: 9.2 ms]
  Range (min … max):     6.1 ms …   8.9 ms    103 runs

Summary
  'libc-ntdll.exe ..' ran
    1.21 ± 0.15 times faster than 'libc-advapi32.exe ..'

and this mostly seems to be due to changes in the implementation (the advapi32 APIs do a lot of NtQueryKey calls that the new implementation doesn't do) rather than due to the decrease in dll loading. LLVM-less zig binaries don't show the same reduction (the only difference here is the DLLs being loaded):

Benchmark 1: stage4-ntdll\bin\zig.exe version
  Time (mean ± σ):       3.0 ms ±   0.6 ms    [User: 5.3 ms, System: 4.8 ms]
  Range (min … max):     1.3 ms …   4.2 ms    112 runs

Benchmark 2: stage4-advapi32\bin\zig.exe version
  Time (mean ± σ):       3.5 ms ±   0.6 ms    [User: 6.9 ms, System: 5.5 ms]
  Range (min … max):     2.5 ms …   5.9 ms    111 runs

Summary
  'stage4-ntdll\bin\zig.exe version' ran
    1.16 ± 0.28 times faster than 'stage4-advapi32\bin\zig.exe version'

---

With the removal of the advapi32 dependency, the non-ntdll dependencies that remain in an LLVM-less Zig binary are ws2_32.dll (which brings along rpcrt4.dll at runtime), kernel32.dll (which brings along kernelbase.dll at runtime), and crypt32.dll (which brings along ucrtbase.dll at runtime).
2026-03-03 01:12:47 -08:00
Andrew Kelley
0a412853aa std.Io: fix Select cancel deadlock with no tasks 2026-03-03 02:26:23 +01:00
Alex Rønne Petersen
ac24e6caf5 Merge pull request 'enable aarch64-netbsd CI' (#31377) from alexrp/zig:aarch64-netbsd-ci into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31377
2026-03-03 01:25:45 +01:00
Alex Rønne Petersen
421c3c3cc5 ci: update qemu to 10.2.1.1
https://patchwork.kernel.org/project/qemu-devel/list/?series=1059138
2026-03-02 19:25:09 +01:00
invlpg
0a2f6a048b fix msghdr and cmsghdr on non-Linux targets, document musl behaviour
The following assertions fail on non-Linux platforms after c0c2010535
which inserted padding based on musl definitions. This padding only
exists on musl to workaround a discrepancy betweeen the POSIX API and
Linux ABI, and is incorrect on other POSIX operating systems.

This change makes the padding musl-only, and documents the reason it
exists. With this change, the assertions pass on Linux and FreeBSD
targets. The corresponding definitions on other targets line up with the
POSIX and FreeBSD ones, so they should work there too.

```zig
const std = @import("std");
const assert = std.debug.assert;
const msghdr = std.c.msghdr;
const cmsghdr = std.c.cmsghdr;

const c = @cImport({
    @cInclude("sys/socket.h");
});

comptime {
    assert(@offsetOf(msghdr, "iovlen") == @offsetOf(c.msghdr, "msg_iovlen"));
    assert(@offsetOf(msghdr, "controllen") == @offsetOf(c.msghdr, "msg_controllen"));
    assert(@offsetOf(msghdr, "control") == @offsetOf(c.msghdr, "msg_control"));
    assert(@offsetOf(msghdr, "flags") == @offsetOf(c.msghdr, "msg_flags"));

    assert(@sizeOf(msghdr) == @sizeOf(c.msghdr));

    assert(@offsetOf(cmsghdr, "len") == @offsetOf(c.cmsghdr, "cmsg_len"));
    assert(@offsetOf(cmsghdr, "level") == @offsetOf(c.cmsghdr, "cmsg_level"));

    assert(@sizeOf(cmsghdr) == @sizeOf(c.cmsghdr));
}
```
2026-03-02 17:46:26 +01:00
Alex Rønne Petersen
d6e9b9eb64
ci: enable aarch64-netbsd 2026-03-02 15:08:37 +01:00
Alex Rønne Petersen
d182feacf7
ci: add aarch64-netbsd scripts 2026-03-02 15:08:37 +01:00
Alex Rønne Petersen
f75e4027bd
test: disable an error trace test on optimized aarch64-netbsd 2026-03-02 15:08:37 +01:00
rpkak
442b292a37
zig fetch: wait until all jobs are finished 2026-03-02 10:17:55 +01:00
Ryan Liptak
e58fea8227 tar: Fix symlink test when symlinks can't be created on Windows 2026-03-01 15:01:51 -08:00
hemisputnik
74f361a5ce std.math.big.int: address log2/log10 reviews
There were good reviews made after #31365 was merged, so this commit
addresses them separately.

1. Assert that the number is greater than zero
2. Use `constants` instead of calculating constants manually
3. Use `Const.bitCountAbs` for log2
2026-03-01 20:34:17 +01:00
Alex Rønne Petersen
da6d4e28ef
Revert "ci: disable aarch64-freebsd"
This reverts commit 104e73ecb2.

The OOM issues should be resolved now.
2026-03-01 17:54:47 +01:00
Alex Rønne Petersen
104e73ecb2
ci: disable aarch64-freebsd
Working through some OOM issues.
2026-03-01 12:04:55 +01:00
Alex Rønne Petersen
bf13b6b41d
test: partially disable cmakedefine standalone test
https://codeberg.org/ziglang/zig/issues/31368
2026-03-01 11:53:05 +01:00
Andrew Kelley
9ef1050bb3 Merge pull request 'std.math.big.int: add log2 and log10 operations' (#31365) from hemisputnik/zig:work/13642-bigint-log2-log10 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31365
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-01 03:35:16 +01:00
hemisputnik
bd6f512f0c
std.math.big.int: add log10 2026-02-28 20:16:32 +02:00
Alex Rønne Petersen
41594c1903 Merge pull request 'enable aarch64-freebsd CI' (#31354) from alexrp/zig:aarch64-freebsd-ci into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31354
2026-02-28 08:19:51 +01:00
Alex Rønne Petersen
b3c8c0df0d ci: switch to VS 2026 in x86_64-windows scripts 2026-02-28 07:08:06 +01:00
Andrew Kelley
02142a54d2 std.Io: remove cancelation propagation assertions
While the general guidance remains useful, it is not the case that
error.Canceled will always pass across the Group task function boundary.

Remove the too-aggressive assertions and add unit test coverage.

Closes #30096
Closes #31340
Closes #31358
2026-02-28 05:07:54 +01:00
hemisputnik
925f82da09
std.math.big.int: add log2 2026-02-28 04:15:19 +02:00
hemisputnik
99229ceb55 std.Io.{Writer|Duration}: move duration formatting to a format method
Remove the `{D}` format specifier. It is moved into `std.Io.Duration` as
a format method.

Migration plan:

```diff
-writer.print("{D}", .{ns});
+writer.print("{f}", .{std.Io.Duration{ .nanoseconds = ns }});
```

All instances where `{D}` was used have been changed to use
`std.Io.Duration` and `{f}`.

Fixes #31281
2026-02-28 02:46:04 +01:00
Andrew Kelley
8c70fd0a57 std.Io.Select: introduce cancelDiscard
and make the return value of `cancel` return queue items.

I don't think it's possible to make `cancel` not deadlock with an empty
queue buffer without introducing a new Group primitive.

This is the best I could come up with based on existing primitives.
Let's see if applications find these APIs palatable.
2026-02-28 01:46:43 +01:00
Alex Rønne Petersen
424061381b
ci: enable aarch64-freebsd 2026-02-27 20:30:31 +01:00
mintonmu
e779ca7223 fix(docs/wasm):zig std html render error function 'a' 2026-02-27 19:17:47 +01:00
Nils Juto
2da1370a7e sync CallModifier in langref with what's actually there 2026-02-27 13:50:12 +01:00
Alex Rønne Petersen
d130f76bab
ci: add aarch64-freebsd scripts 2026-02-27 08:49:27 +01:00
Alex Rønne Petersen
b781615e09
test: disable an error trace test on optimized aarch64-freebsd 2026-02-27 08:49:27 +01:00
Justus Klausecker
bbc77df3eb std.heap: delete ThreadSafeAllocator
We can keep ourselves safe from those threads perfectly well without you, thanks!
2026-02-26 21:20:34 +01:00
Saurabh Mishra
4e2cec265d Make std.PriorityQueue an unmanaged container (#31299)
## Summary of changes

+ Make adjustments to the `allocator` field and ensure the below tests pass:

  ```sh
  zig test lib/std/std.zig --zig-lib-dir lib
  zig build test-std -Dno-matrix --summary all
  ```

+ Rename `add` to `push` and `remove` to `pop` in methods and tests

+ Incorporate the functionality of `pop` in `popOrNull`, then rename the `popOrNull` to `pop` and update tests

+ Use `.empty` to set default field values and rename the `init` method to `initContext`

+ Improve variable types in tests: min heap uses the less than context function and max heap uses greater than context function

+ Remove the `dump` method as its not being used anywhere

+ Document methods `clearRetainingCapacity`, `clearAndFree`, `update`, and `ensureTotalCapacityPrecise`

Closes https://codeberg.org/ziglang/zig/issues/31298

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31299
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Saurabh Mishra <saurabh.m@proton.me>
Co-committed-by: Saurabh Mishra <saurabh.m@proton.me>
2026-02-26 21:09:52 +01:00
estevesnp
0b6b65b387 fix: Allow async and concurrent from Io.Select to accept non-void error unions 2026-02-26 20:49:05 +01:00
Alex Rønne Petersen
2d867223be build: use -ffunction-sections -fdata-sections for the Zig compiler on ARM
See 7daf0b6f46; builds for ARM can run into the
same problems due to limited branch range.
2026-02-26 20:48:29 +01:00
Andrew Kelley
7bc6546fdf Merge pull request 'std.heap.ArenaAllocator: Get rid of cmpxchg loop in hot path' (#31343) from justusk/zig:lock-free-arena-overshoot into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31343
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-26 20:42:30 +01:00
Justus Klausecker
de41123957 std.heap.ArenaAllocator: fix reset creating undersized nodes
Previously resetting with `retain_capacity < @sizeOf(Node)` would create
an invalid node. This is now fixed, plus `Node.size` now has its own `Size`
type that provides additional safety via assertions to prevent bugs like
this in the future.
2026-02-26 15:40:48 +01:00
Justus Klausecker
2fa2300ba4 std.heap.ArenaAllocator: Get rid of cmpxchg loop in hot path
This is achieved by bumping `end_index` by a large enough amount so that
a suitably aligned region of memory can always be provided. The potential
wasted space this creates is then recovered by a single cmpxchg. This is
always successful for single-threaded arenas which means that this version
still behaves exactly the same as the old single-threaded implementation
when only being accessed by one thread at a time. It can however fail when
another thread bumps `end_index` in the meantime. The observerd failure
rates under extreme load are:

2 Threads: 4-5%
3 Threads: 13-15%
4 Threads: 15-17%
5 Threads: 17-18%
6 Threads: 19-20%
7 Threads: 18-21%

This version offers ~25% faster performance under extreme load from 7 threads,
with diminishing speedups for less threads. The performance for 1 and 2
threads is nearly identical.
2026-02-26 15:30:55 +01:00
Motiejus Jakštys
56253d9e31 x86_64 codegen: fix RoundMode vroundss immediate value
Quoting Vol. 2B 4-590 of [Intel SSA manual][1]:

> Bit 3 of the immediate byte controls processor behavior for a
precision exception <...>

The Direction struct is incorrectly sized to 4 bits, which pushes the
precision exception bit to the reserved bits, which helpfully crashes
under valgrind (but works on real hardware, since CPU ignores it):

``
const std = @import("std");

noinline fn ceil(x: f32) f32 {
    return @ceil(x);
}

test "ceil" {
    try std.testing.expectEqual(@as(f32, 2.0), ceil(1.5));
}
```

With Zig 0.15.1:

```
$ zig test -fno-llvm -mcpu x86_64_v3  -fvalgrind  ceil_test.zig  --test-cmd valgrind --test-cmd --quiet --test-cmd-bin
Illegal instruction at address 0x102d14d
/home/motiejus/code/ceil_test.zig:4:5: 0x102d14d in ceil (ceil_test.zig)
    return @ceil(x);
    ^
/home/motiejus/code/ceil_test.zig:8:52: 0x102d097 in test.ceil (ceil_test.zig)
    try std.testing.expectEqual(@as(f32, 2.0), ceil(1.5));
                                                   ^
/nix/store/n81qdpd96d86ngfv5bqymy26b8kqm654-zig-0.15.1/lib/compiler/test_runner.zig:218:25: 0x1167e80 in mainTerminal (test_runner.zig)
        if (test_fn.func()) |_| {
                        ^
/nix/store/n81qdpd96d86ngfv5bqymy26b8kqm654-zig-0.15.1/lib/compiler/test_runner.zig:66:28: 0x11610a1 in main (test_runner.zig)
        return mainTerminal();
                           ^
/nix/store/n81qdpd96d86ngfv5bqymy26b8kqm654-zig-0.15.1/lib/std/start.zig:618:22: 0x115ae3d in posixCallMainAndExit (std.zig)
            root.main();
                     ^
/nix/store/n81qdpd96d86ngfv5bqymy26b8kqm654-zig-0.15.1/lib/std/start.zig:232:5: 0x115a6d1 in _start (std.zig)
    asm volatile (switch (native_arch) {
    ^
???:?:?: 0x0 in ??? (???)
error: the following test command crashed:
valgrind --quiet /home/motiejus/.cache/zig/o/7cc564b5410fc3facdb6e8768643074e/test
```

Zig 0.15.1 with this patch:

```
zig/zig3 test -fno-llvm -mcpu x86_64_v3  -fvalgrind  ceil_test.zig  --test-cmd valgrind --test-cmd --quiet --test-cmd-bin
All 1 tests passed.
```

Looking through `CodeGen.zig` it _seems_ like the same RoundMode struct
is used for vroundss/vroundps/vcvtps2ph, so update the comment while
we're at it. But I am only 90% sure it's true.

[1]: https://cdrdv2.intel.com/v1/dl/getContent/671200
2026-02-25 20:34:08 +01:00
Andrew Kelley
e0173c2ce0 Merge pull request 'rework fuzz testing to be smith based' (#31205) from gooncreeper/zig:integrated-smith into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31205
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-02-25 20:23:36 +01:00
Kendall Condon
bb304796f4 optimize flate decompression
Matches now use memcpy and memset when possible.

Block loops have been rewritten to be more optimizer friendly.

Reworks Symbol and HuffmanDecoder
* Symbol now only includes the value and number of code bits.
  decodeSymbol returns only the value.
* HuffmanDecoder now takes the regular bits instead of the reversed.
* Code table construction now uses buckets instead of sorting.
* For linked codes, the value field of Symbol is now used as the next
  index. The actual value is the element index.
* InvalidCode is now detected only once with a special linked index.

Performance is 39.7% faster than before and 1.1% faster than gzip using
a sample created from compressing a tar of the src directory.
2026-02-25 20:05:48 +01:00