Commit Graph

37477 Commits

Author SHA1 Message Date
mlugg abd099e97f Merge pull request 'compiler: fix missing "local variable is never mutated" error' (#31534) from variable-not-mutated into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31534
2026-03-16 00:05:30 +01:00
pentuppup 2383709431 coerce assembly clobbers in sema 2026-03-15 22:37:38 +01:00
Jan200101 43d5bea7af test: use expectEqualStrings to check cmakedefine behavior
this has the added benefit of outputting the difference making it
easier to figure out why the test is flakey.

https://codeberg.org/ziglang/zig/issues/31368
2026-03-15 21:41:37 +01:00
Yanfeng Liu 584b8f281e zig fmt: remove dead functions
This drops a few dead functions in AutoIndentingStream.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2026-03-15 21:38:45 +01:00
Matthew Lugg 827a96b1ef compiler: fix missing "local variable is never mutated" error
This regressed back in https://github.com/ziglang/zig/pull/25154. I
didn't get around to fixing it until now, so a few instances of the
warning snuck into the repo over the past few months, which were fixed
in the previous commit. The regression has not appeared in a tagged
release though, so this is not a breaking change in 0.16.0.

Resolves: https://codeberg.org/ziglang/zig/issues/31049
2026-03-15 18:24:32 +00:00
Matthew Lugg 64f1c27332 compiler,std: fix never-mutated local variables 2026-03-15 18:22:13 +00:00
Matthew Lugg 5d215838a7 InternPool.Nav: fix race, refactor
I've realised that the cause of at least some of our weird CI flakiness
was a bug in how `Nav` values were resolved. Consider this scenario: the
frontend resolves the type of a `Nav`, and then sends a function to the
backend, which requires the backend to lower a pointer to that `Nav`.
The backend calls `InternPool.getNav` to determine the `Nav`'s type.
However, this races with the frontend resolving the *value* of that
`Nav`. This involves writing separately to two fields, `bits` and
`type_or_value`. If only one of these changes is observed, then the
backend will incorrectly interpret the type as the value or vice versa,
leading to a crash or even a miscompilation. (Of course, there's also
the straightforward issue that the racing loads were non-atomic, making
them illegal).

The only good solution to this was to make `Nav` 4 bytes bigger, giving
it separate `type` and `value` fields. In theory that's a quite small
change, but it ended up having a bunch of nice consequences which led to
this diff being a bit bulkier than expected:

* `Nav.Repr.Bits` was simplified, because it no longer has to track
  "resolution status": we can use `.none` for that. This frees up some
  bits to make things more consistent between the "type resolved" and
  "fully resolved" states.

* This consistency allowed the `Nav.status` union to be replaced with a
  simpler field `Nav.resolved`, which is a bit nicer to work with.

* Most of the "getter" functions were able to be removed from `Nav`
  because the state they were fetching had been moved to simple fields
  on `Nav.resolved`.

* There were still a handful of free bits in `Nav.Repr.Bits`, which
  could be used to represent the "const" and "threadlocal" flags rather
  than these being stored on `Key.Extern` and `Key.Variable`. This is a
  bit more convenient for linkers.

* With those bits gone, `Key.Variable` is a trivial wrapper around a
  type and an initial value, and the fact that a declaration is mutable
  can be represented solely through the "const" flag. Therefore,
  `Key.Variable` no longer served a purpose, and could be eliminated
  entirely in favour of storing the variable's initial value directly in
  the "value" field of the `Nav`.

So, I'm quite pleased with this refactor! But anyway, regarding the bug
fix which actually motivated this: if I've done my job correctly, this
should solve some crashes, such as these (which were what tipped me off
to this bug in the first place):

https://codeberg.org/ziglang/zig/actions/runs/2306/jobs/7/attempt/1
https://codeberg.org/ziglang/zig/actions/runs/2173/jobs/6/attempt/1

...and, who knows, perhaps even the random SIGSEGVs we've seen on some
targets! Probably not, but one can hope.
2026-03-15 11:47:14 +00:00
Guillaume 065c6e7946 std.Io.net.HostName: simplify validate logic (#30764)
Follow-up of efe649b13e

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30764
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Guillaume <guillaume.alabre@gmail.com>
Co-committed-by: Guillaume <guillaume.alabre@gmail.com>
2026-03-15 09:11:11 +01:00
Josh Megnauth aaba36ff76 libzigc: posix_{fadvise, fallocate}, fallocate
This commit removes `posix_fadvise`, `posix_fallocate`, and `fallocate`
from the bundled musl by forwarding to Zig's wrappers. `musl`'s
implemenation does not use `__syscall_cp`, so I assume trivially
replacing these functions is okay.

For `posix_fadvise`, `musl` notes that the arguments are reordered
for ARM and other architectures. Zig's wrapper already handles this
case.

Contributes toward: #30978
2026-03-14 22:04:43 +01:00
David Rubin 50cc3b91a5 Sema: coerce tail call result to immediate function 2026-03-14 05:23:13 -07:00
Brandon Freeman 22c4fbdf16 fix: chdir on uring 2026-03-14 07:11:08 +01:00
Alex Rønne Petersen c6cb5f691d Merge pull request 'link.Lld: pass --be8 to ld.lld for armeb/thumbeb for v6+' (#31489) from alexrp/zig:arm-be8 into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31489
2026-03-14 06:19:00 +01:00
Andrew Kelley a7b686ac5e std: disable flaky test on Windows
tracked by #31499
2026-03-14 06:06:03 +01:00
Andrew Kelley d6402955d9 kernel32: another one bytes the dust 2026-03-14 06:06:03 +01:00
Alex Rønne Petersen e0d38561f0 std.crypto.argon2: disable flaky test kdf derived key length
https://codeberg.org/ziglang/zig/issues/31504
2026-03-14 05:55:24 +01:00
Matthew Lugg 5d71e30518 std: remove another kernel32 dependency
We can directly access this path string from the PEB (albeit with some
weirdness around addressing) and that ends up making the downstream code
simpler and more efficient. (Almost like the kernel32 API isn't very
good!)
2026-03-13 20:56:00 +01:00
Alex Rønne Petersen 05c059e563 link.Lld: pass --be8 to ld.lld for armeb/thumbeb v6+
BE32 is deprecated and only supported by older cores and some v6 cores. All
cores v6 or newer support BE8, so default to that for v6+.

closes https://codeberg.org/ziglang/zig/issues/31404
2026-03-13 14:58:12 +01:00
Alex Rønne Petersen bc67a49c5c std.zig.target: fix glibc triple for armeb-linux-gnueabi* to use be8 2026-03-13 14:58:12 +01:00
rpkak 090ae3042e Set link_libunwind to true for zig build-exe -lunwind 2026-03-13 13:24:33 +01:00
Andrew Kelley b15aa0540d Merge pull request 'add a fuzz test for zig fmt' (#30082) from gooncreeper/zig:fmt-fuzzing into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30082
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-13 08:43:19 +01:00
Andrew Kelley 2c61deaae2 Merge pull request 'std.Io.net: enable more tests + coverage for canceling accept' (#31468) from net-test-coverage into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31468
2026-03-13 08:27:14 +01:00
Alex Rønne Petersen ab1a4b26ec zig cc: link compiler-rt when given -lcompiler_rt even with -nostdlib
closes https://codeberg.org/ziglang/zig/issues/31460
2026-03-13 04:16:07 +01:00
Alex Rønne Petersen 26f2749c1e Merge pull request 'FreeBSD libc: guard ssp headers and definitions introduced in FreeBSD 15' (#31457) from kid/zig:fbsd-libc-guard into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31457
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-03-13 04:07:26 +01:00
Andrew Kelley 314264ee7d std: windows isn't passing cancel accept yet
tracked by #30865
2026-03-12 15:42:13 -07:00
Andrew Kelley 9634e98357 std.Io.Threaded: fix missing calls to syscall.finish() 2026-03-12 15:41:00 -07:00
Andrew Kelley a50458777b std.Io.Threaded: NtTerminateProcess can return PROCESS_IS_TERMINATING 2026-03-12 15:40:59 -07:00
Andrew Kelley 8973c8a826 std.Io.Threaded.netWriteWindows: IO_PENDING is not unreachable 2026-03-12 15:40:59 -07:00
Andrew Kelley 1c9bd1d74c std.Io.net: enable all the tests
closes #18315
closes #25983
closes #31388
2026-03-12 15:40:59 -07:00
Kendall Condon 02e8339ca7 zig build fmt 2026-03-12 17:44:03 -04:00
Pablo Alessandro Santos Hugen 627f03af9d std.os.linux: add explicit backing type to packed structs in extern types 2026-03-12 22:33:03 +01:00
Kendall Condon 9632ee3eb0 zig fmt: remove dead function 2026-03-12 17:25:06 -04:00
Kendall Condon 2b6589bd3b zig fmt: fix error sets with empty line before comma 2026-03-12 17:25:01 -04:00
Kendall Condon 99fea4431b zig fmt: rewrite renderArrayInit
There were just too many bugs. This new implementation supports zig fmt:
on/off. It also puts expressions with unicode characters on their own
line, which avoids issues with aligning them.
2026-03-12 17:25:00 -04:00
Kendall Condon c477df98bb zig fmt: fix tracking of applied indentation 2026-03-12 17:23:24 -04:00
Kendall Condon 9014daedbb zig fmt: properly check escape sequences 2026-03-12 17:23:24 -04:00
Kendall Condon 409541bc77 zig fmt: canonicalize stray backslashes in identifiers 2026-03-12 17:23:23 -04:00
Kendall Condon bbc2e7a74d Ast: fix comptime wrapper for destructure 2026-03-12 17:23:23 -04:00
Kendall Condon 84ac2e8714 Ast: fix pointer types with subexprs containing qualifiers 2026-03-12 17:23:22 -04:00
Kendall Condon e03851e522 zig fmt: fix array size indenting when expr becomes multiline
Adds a new function becomesMultilineExpr to determine this and extracts
the logic from several functions.
2026-03-12 17:23:21 -04:00
Kendall Condon b0db0ef4e1 zig fmt: fix doc comments on fn paramaters without comma 2026-03-12 17:23:19 -04:00
Kendall Condon 472992ae45 zig fmt: implement expanding error sets when comments are present 2026-03-12 17:23:17 -04:00
Kendall Condon d5d3e40b6c zig fmt: preserve space for field accesses of number literals 2026-03-12 17:23:07 -04:00
Kendall Condon fcc54ca981 zig fmt: fix many bugs with multiline string literals
Adds two new space modes maybe_space and comma_maybe_space which only
render the space when the next token is not a multiline string literal.
This is used in a lot of places to avoid a trailing space on lines
caused by multiline string literals forcing newlines.

Fixes places where the node tag is compared to be a multiline string
literal to instead check if the first token is a multiline string
literal line. This fixes cases like `\\ ++ text`.

This commit also rewrites quite a bit of code to be clearer /
deduplicated.
2026-03-12 17:22:46 -04:00
Kendall Condon 476c3a1f37 zig fmt: add a fuzz test
This fuzz test checks several properties of zig fmt are upheld, namely
idempotency, textual equivilence, and no trailing whitespace.

All functions in the fuzz test have @disableInstrumentation for
performance and since their branches are not interesting to the fuzzer.
2026-03-12 17:14:29 -04:00
Matthew Lugg 0978566db8 incremental: handle loss of main struct instruction
My changes to how incremental compilation handles container types mean
that, at least for now, it is possible for the ZIR `.main_struct_inst`
of a source file to be lost (this happens if the number of top-level
fields in a file changes for instance). I missed a few things which
needed changing to account for this, which could lead to crashes with
certain (trivial) changes---oops!

Adds two new incremental test cases. They are currently disabled for
wasm32-wasi-selfhosted because they both trigger a crash in the WASM
backend.
2026-03-12 21:27:16 +01:00
Jay Petacat 01cc1a5867 std.math.sign: Return smallest integer type that fits possible values
This may be a breaking change for callers that depend on the return type
size being identical to the input. For example, `sign(i32) * i8 + i8`
could now overflow. Callers can add an explicit type annotation to avoid
that problem.
2026-03-12 21:05:22 +01:00
Justus Klausecker 499aba9ca6 Sema: require else prong for comptime_int
This fixes a bug introduced a couple of commits ago.
2026-03-12 21:03:16 +01:00
Justus Klausecker 4d6bef538e std.heap.ArenaAllocator: relax memory ordering for stealing free list
We only need acquire instead of acq_rel here, since we're always swapping
in `null` there's no node whose content we'd need to release.
2026-03-12 21:02:43 +01:00
andrew.kraevskiii 47597a6d7c std.ArrayList: add toOwnedSliceAssert, shrinkToLen. (#30769)
Adds a set of new APIs to ArrayList with goal of making it easier to avoid toOwnedSlice foot gun:

```zig
fn wrongUsageOfCurrentApi(gpa: std.mem.Allocator) ![2][]const u8 {
    var a: std.ArrayList(u8) = .empty;
    defer a.deinit(gpa);
    var b: std.ArrayList(u8) = .empty;
    defer b.deinit(gpa);

    // ...

    return .{
        try a.toOwnedSlice(gpa),
        try b.toOwnedSlice(gpa), // oom here causes leak :(
    };
}

fn correctUsageOfCurrentApi(gpa: std.mem.Allocator) ![2][]const u8 {
    var a: std.ArrayList(u8) = .empty;
    defer a.deinit(gpa);
    var b: std.ArrayList(u8) = .empty;
    defer b.deinit(gpa);

    // ...

    const a_slice = try a.toOwnedSlice(gpa);
    errdefer gpa.free(a_slice);
    const b_slice = try b.toOwnedSlice(gpa);
    // may be omited but good if error appear bellow later in development.
    errdefer gpa.free(b_slice);

    return .{
        a_slice,
        b_slice,
    };
}

fn proposedApi(gpa: std.mem.Allocator) ![2][]const u8 {
    var a: std.ArrayList(u8) = .empty;
    defer a.deinit(gpa);
    var b: std.ArrayList(u8) = .empty;
    defer b.deinit(gpa);

    // ...

    try a.shrinkToLen(gpa);
    try b.shrinkToLen(gpa);
    return .{
        a.toOwnedSliceAssert(),
        b.toOwnedSliceAssert(),
    };
}
```

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30769
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: andrew.kraevskiii <andrew.kraevskii@gmail.com>
Co-committed-by: andrew.kraevskiii <andrew.kraevskii@gmail.com>
2026-03-12 20:50:27 +01:00
Andrew Kelley d5bfa657c4 Merge pull request 'fix several fuzzing bugs' (#31470) from gooncreeper/zig:fuzzing-fixes into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31470
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-12 20:25:02 +01:00