Commit Graph

37575 Commits

Author SHA1 Message Date
Kendall Condon ab237855b8 zig fmt: render asm colons with trailing comments
Previously, the comments would be lost with the colons.

This required a substantial rewrite of renderAsm to determine how many
colons should be rendered.
2026-03-25 17:30:51 -04:00
Kendall Condon c818a1e61f zig fmt: handle skip space for multiline strings 2026-03-25 17:30:51 -04:00
Kendall Condon ed3ca0f570 zig fmt: call ais.resetLine after "zig fmt: on" 2026-03-25 17:30:51 -04:00
Kendall Condon d70a9ea5d7 zig fmt: properly revert nested asm indentation 2026-03-25 17:30:51 -04:00
Kendall Condon 23db309043 zig fmt: use AstSmith in fuzz test 2026-03-25 17:30:51 -04:00
Kendall Condon 785fb1be11 fix several inconsistencies between parser and PEG
- PEG / Parser Changes

All the changes made here are to places where the PEG was more
permissive than the parser. Changes to the parser make it more
permissive and changes to the PEG make it more strict. When choosing
between these two options for discrepancies, I opted for the choice
that was more natural and increased code readability.

Changes to the Parser
* Tuple types can now be `inline` and `extern` (e.g. `extern struct`).
* Break labels are now only consumed if both the colon and identifier
  are present instead of failing if there is only a colon.
* Labeled blocks are no longer parsed in PrimaryExpr (so they are now
  allowed to have CurlySuffixExpr) as in the PEG.
* While expressions can now be grouped on the same line.
* Added distinction in error messages for "a multiline string literal"
  so places where only single string literals are allowed do not give
  "expected 'a string literal', found 'a string literal'".

Changes to the PEG
* Made it so extern functions cannot have a body
* Made it so ... can be only the last function argument
* Made it so many item pointers can't have bit alignment
* Made it so asm inputs / outputs can not be multiline string literals
* Added distinction between block-level statements and regular
  statements

-- Pointer Qualifier Order

The PEG allowed for duplicated qualifiers, which the parser did not.
The simplest fix for this was to make each be allowed zero or one times
which required giving them a order similar to how FnProto already
works. The chosen order is the same as used by zig fmt. The parser
still accepts them in any order similar to functions.

-- Backtracking

Made it so several places could not backtrack in the PEG. A common
pattern for this was (A / !A).

--- !ExprSuffix

Expressions ending with expressions now have !ExprSuffix after.
This change prevents expressions such as `if (a) T else U{}` being be
parsable as `(if (a) T else U){}`. It also stops some backtracking,
take for example:

`if (a) for (b) |c| d else |e| f`

It may seem at first that the else clause belongs to the `for`, however
it actually belongs to the `if` because for else-clauses cannot have a
payload. This is fixed by a new `KEYWORD_else / !KEYWORD_else`, however
this alone does not fix more complex cases such as:

`if (a) for (b) |c| d() else |e| f`

The PEG would first attempt to parse it as expected but fail due to the
new guard. It will then backtrack to

`if (a) (for (b) |c| d)() else |e| f`

which is surprising but avoids the new gaurd. So, !ExprSuffix is
required to disallow this type of backtracking.

--- !LabelableExpr

For identifiers, excluding labels is necessary despite ordered choice
due to pointer bit alignment. For example `*align(a : b: for (c) e) T`
could backtrack to `*align(a : b : (for (c) e)) T`.

--- !SinglePtrTypeStart

Prevents expressions like `break * break` which is parsed as
`break (*break)` backtracking to `(break) * (break)`

--- !BlockExpr

Prevents expressions like `test { {} = a; }` being backtracked to and
parsed as `test { ({} = a); }` (the parenthesis are just for
demonstration, that expression is not legal either)

--- !ExprStatement

In addition to splitting up block level statements, statements that are
also parsable as expressions are now part of ExprStatement to disallow
backtracking.
2026-03-25 17:29:56 -04:00
Kendall Condon 2aee0cd6b9 add an ast smith
This generates zig ASTs from `testing.Smith` and is based off the
langref's PEG.

The choice to not build the Ast while generating and instead parsing it
afterwards makes the smith more versatile by not being tied to a single
implementation at a cost of efficiency.

Additionally, a new function `boolWeighted` was added to `Smith` due to
its frequent use in `AstSmith`.
2026-03-25 17:27:18 -04:00
Kendall Condon ebca8c2dbb x86_64: fix runtime array concat with comptime slice 2026-03-25 17:27:18 -04:00
Alex Rønne Petersen 54b3484256 Revert "disable flaky test: aarch64-macos stage3/4 nondeterminism check"
This reverts commit 8669898819.
2026-03-25 20:40:29 +01:00
Alex Rønne Petersen 5e0e1841c0 Compilation: close the linker output file before writing whole cache manifest
Otherwise a different process may get a cache hit on the file while we still
have a writable fd open for it. This isn't actually a real problem in the sense
that running the file should just work as expected if the OS allows it. But
until very recently[0], the Linux kernel would give ETXTBSY in this case. So
make sure we close the file before letting other processes know that it's
usable.

closes https://codeberg.org/ziglang/zig/issues/31563

[0] https://github.com/torvalds/linux/commit/2a010c41285345da60cece35575b4e0af7e7bf44
2026-03-25 19:33:43 +01:00
Alex Rønne Petersen 8a517285ce Merge pull request 'std.heap.ArenaAllocator/std.heap.FixedBufferAllocator: fix end_index memory ordering' (#31647) from justusk/zig:arena-mem-ord into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31647
Reviewed-by: jacobly <jacobly@noreply.codeberg.org>
2026-03-25 18:27:03 +01:00
Justus Klausecker 5363a81a57 std.heap.FixedBufferAllocator: fix end_index memory ordering
This prevents a race between `alloc` and `free` where T1 receives memory
from `alloc` that is semantically about to be freed by T2 and still being
accessed, but the `free` is already visible to T1. Using acquire-release
here guarantees that any `free` is only published after all accesses to
the memory being freed have already happened.

Co-authored-by: Jacob Young <amazingjacob@gmail.com>
2026-03-25 11:48:45 +01:00
Justus Klausecker 3af5f81e11 std.heap.ArenaAllocator: fix end_index memory ordering
This prevents a race between `alloc` and `free` where T1 receives memory
from `alloc` that is semantically about to be freed by T2 and still being
accessed, but the `free` is already visible to T1. Using acquire-release
here guarantees that any `free` is only published after all accesses to
the memory being freed have already happened.

Co-authored-by: Jacob Young <amazingjacob@gmail.com>
2026-03-25 11:48:43 +01:00
Justus Klausecker 9bfe827ade Revert "std.heap.ArenaAllocator: Make resize and free check whether allocation is within current node more rigorously"
This reverts commit 589bcb2544.

The scenario presented in the reverted commit cannot actually happen.
Even if there are two contiguous arena nodes N1 and N2 and the `end_index`
of N1 points to somewhere in N2, a `resize` can never lead to an increase
of the `end_index` of N1 since it checks whether it's `<= size` first.
A `resize`/`free` *can* decrease `end_index`, but even if it is wrongly
assumed that some allocation that belongs to N2 actually belongs to N1
based on the `end_index` of N1, it can only ever be decreased to the start
of the buffer of N2. That's because a valid allocation of N2 logically
cannot be at any lower address than N2 itself. And any point still in N2
can never also be in N1, so there's no danger of overwriting any other
allocations of N1.
2026-03-25 11:20:21 +01:00
Andrew Kelley 94355f1920 README: add information about installation via bootstrap.c
closes #31650
2026-03-25 01:43:12 -07:00
rpkak 8f6bad065e std.Thread.setName/getName: remove wrong error handling
std.posix.prctl already does error handling.
According to the man page PR_SET_NAME(2const), 0 is returned on success.
2026-03-25 08:10:25 +01:00
Jake Greenfield 4431ca28b8 fix Windows clock handling
Address two separate but related issues:
- Return value of `RtlQueryPerformanceFrequency` was used inconsistently; it
  returns a nonzero value to indicate success.
- `timeoutToWindowsInterval` wasn't converting absolute deadlines back to the
  Windows epoch before passing them to the system, which meant that values (in
  the Unix epoch) were always in the distant past, so sleeps would return
  immediately.

Fixes #31653
2026-03-24 21:33:27 -04:00
akhildevelops eec244c5a2 std.crypto.tls.Client: expose InitError (#31610)
Fixes: https://codeberg.org/ziglang/zig/issues/31581
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31610
Co-authored-by: akhildevelops <akhildevelops@noreply.codeberg.org>
Co-committed-by: akhildevelops <akhildevelops@noreply.codeberg.org>
2026-03-25 00:56:22 +01:00
Justus Klausecker 589bcb2544 std.heap.ArenaAllocator: Make resize and free check whether allocation is within current node more rigorously
This prevents the following scenario where an allocation is wrongly assumed
to be part of the current head node (`node0`):

```
| node0 - - - - | node1 - - - - - - - - - - - - |
          |   |         |   |           |
          |   |         |   end_index0  end_index1
          |   |         |   |
          alloc0        alloc1

free(alloc1):
    load node0
    buf0.ptr + end_index0 == alloc1.ptr + alloc1.len ? yes!
    end_index0 -= alloc1.len

| node0 - - - - | node1 - - - - - - - - - - - |
          | | |                         |
          | end_index0                  end_index1
          |   |
          alloc0
```

which could move `end_index0` *into* `alloc0` and make it possible for any
subsequent calls to `alloc` to overwrite its contents!
2026-03-25 00:54:44 +01:00
Karol Kosek 5861afb189 langref: make float mode fields lowercase
Reflects the change made in aab84a3dec.
2026-03-25 00:53:36 +01:00
Alex Rønne Petersen 3de16858f7 ci: update to qemu 10.2.2 2026-03-25 00:51:40 +01:00
Alex Rønne Petersen b0ab55b8ea Merge pull request 'Add psp os' (#31609) from IridescentRose/zig:psp-os-target into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31609
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-03-25 00:51:01 +01:00
Alex Rønne Petersen 558a5c7913 std.c: audit some time types for non-Linux OSs
Some initial work towards https://codeberg.org/ziglang/zig/issues/31414.

Conclusion from this: Only x86-freebsd, x86-haiku, and x86-illumos remain time32
and are currently unfixable. I don't think the upstreams for any of these
targets actually care about them anymore (probably why they weren't migrated to
time64), so this is not a particularly big concern.

I split UTIME constants out from timespec because they were causing unreasonable
code duplication by being there.
2026-03-24 09:42:32 +01:00
Evgenii Orlov 0ee6a79da5 std.Io.net.HostName.netLookup: make canonical_name_buffer optional 2026-03-23 11:02:47 +01:00
Alex Rønne Petersen c7d69f0160 std.mem: delete illegal code in findSentinel()
I understand the temptation to exploit page size knowledge to make this function
faster, but I don't think this code can ever be compatible with any reasonable
set of pointer provenance/aliasing rules. At the very least, I don't believe it
is compatible with LLVM's.

closes https://github.com/ziglang/zig/issues/23184
2026-03-23 05:35:04 +01:00
Techatrix 029719cf47 std.Uri: reject invalid URI schemes according to RFC3986 2026-03-23 05:22:46 +01:00
Kendall Condon 1708da2c71 libfuzzer: fix SkipZigTest with new inputs
It is now ignored for inputs from the corpus to ensure the filesystem
and process corpus stay in sync. For other (nondeterministic) inputs the
input builder is now reset.
2026-03-23 05:19:04 +01:00
Frank Denis b2c2b4d063 Merge pull request 'crypto: correct aes-siv s2v' (#31623) from sinon/zig:fix-aes-siv into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31623
Reviewed-by: Frank Denis <jedisct1@noreply.codeberg.org>
2026-03-23 03:11:13 +01:00
GasInfinity 1311880eea fix: use no_builtin when including zigc in the Zcu
* oops
2026-03-22 21:11:41 +01:00
rpkak 9857dabfea std.c.MFD: support linux 2026-03-22 18:06:00 +01:00
David Rubin 8efd539305 crypto: correct aes-siv s2v
The first issue is that when len(Sn) >= 128,
we perform Sn xor D instead of the Sn xorend D
that is specified in RFC 5297.

The second issue is that we truncate the Sn
if it is larger than 4096 bytes, which could
lead to collisions between inputs. We solve
this by absoring the Sn into the CMAC state
perform the last 16 bytes, xoring those 16
bytes with D as described in the first issue,
and then updating and squeezing the CMAC.
2026-03-22 07:21:41 -07:00
Jacob Young ccf8e223f4 std.Io.net: disable unix socket test due to presumed windows kernel bug
Tracked by #31499
2026-03-22 09:37:12 -04:00
Nathan Bourgeois 164d01c1dc codegen: notraps on mips causes break and infinite loop on @trap() 2026-03-21 21:32:22 -04:00
Nathan Bourgeois c824ce954e misc: Add allegrex CPU & features, run tool, update semver 2026-03-21 19:39:04 -04:00
Alex Rønne Petersen cb7d2b0563 Revert "std.Progress: use cmpxchgStrong instead of cmpxchgWeak for locking/unlocking IPC"
This reverts commit b6f99a59a3.

https://codeberg.org/ziglang/zig/pulls/31608#issuecomment-11875362
2026-03-21 14:04:24 +01:00
Nathan Bourgeois 2037dba90f std.posix: Minimal set to build an Io on PSP 2026-03-21 06:34:45 -04:00
Matthew Lugg 36c390bf14 Zcu: correctly handle tid when main thread recurses
Resolves: https://codeberg.org/ziglang/zig/issues/31380
2026-03-21 09:56:05 +01:00
Nathan Bourgeois fdf19984b8 std.Target: add psp os 2026-03-21 02:56:24 -04:00
Alex Rønne Petersen b4d134a0d2 Merge pull request 'std: audit (most) usages of cmpxchgWeak' (#31608) from justusk/zig:cmpxchg-xchg into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31608
Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>
2026-03-21 04:14:44 +01:00
Justus Klausecker 1f78e34de0 std.Io.Threaded: make mutexLock() use cmpxchgStrong instead of cmpxchgWeak
As established in 048e38624e and d70bd0b37e, mutexes should use a strong
cmpxchg when attempting to lock to guarantee that they actually succeed
if they aren't locked yet.

Also deletes an unused near-duplicate of `mutexLock()`.
2026-03-21 03:00:50 +01:00
Justus Klausecker b6f99a59a3 std.Progress: use cmpxchgStrong instead of cmpxchgWeak for locking/unlocking IPC
The `cmpxchgWeak` in `setIpcFile` could lead to the IPC file not being set
even though there's still a slot available because one or more slots were
spuriously skipped.

The `cmpxcheWeak` in `serialize` could lead to an unused IPC slot not
being locked and used even though it could be.
2026-03-21 03:00:50 +01:00
Andrew Kelley e938344100 Merge pull request 'linux: fix handling of O_TMPFILE flag on filesystems that do not support it' (#31543) from eshom/zig:tmpfile-not-supported into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31543
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-21 00:04:10 +01:00
Andrew Kelley a9e5c72aa8 Io.Uring: simplify openat error handling 2026-03-20 12:18:25 -07:00
eshom 2054a257c2 std.Io.Uring: handle UnsupportedOperation for O_TMPFILE case
Having `std.Io.Uring` contain OpenError error set
allows handling of OperationUnsupported specifically for `.openat`,
while avoiding propagating this error to the more general
`File.OpenError`.

This more specific subset also eliminated 2 unreachable prongs that
previously inherited from `File.OpenError`.

Added comments when handling OperationUnsupported, making it clear it is
an unexpected error when TMPFILE bit is not set.
2026-03-20 12:12:29 -07:00
eshom 5119cf6ffd std.Io.Threaded: syscall with O_TMPFILE flag can return OPNOTSUPP 2026-03-20 12:12:29 -07:00
squidy239 4c3877069d remove various workarounds for issues that are now fixed (#31567)
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31567
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: squidy239 <sachabarsayuracko@gmail.com>
Co-committed-by: squidy239 <sachabarsayuracko@gmail.com>
2026-03-20 19:58:33 +01:00
Jacob Young 83c7aba127 windows: trigger automatic fetching of root certificates 2026-03-20 19:23:48 +01:00
Andrew Kelley 06b85a4fd0 CLI: use zon format for clang options
- plain old data ftw
- 177K -> 151K
- data bypasses Sema

This change is not really important but it was nice to explore best
practices for data like this.

When I measured building the compiler, I found no statistically
significant difference in compilation time.
2026-03-20 06:46:13 +01:00
Jacob Young 982f26bcdd netReceiveOneWindows: fix typo 2026-03-20 00:37:00 -04:00
fardragon 4acecad933 bootstrap.c: work around the gcc sra miscomp using preprocessor checks rather than CLI arg (#31589)
Closes #31577
I've also extended the "good" ranges to fit versions >14.3 and >13.4, since both of these branches have the fix merged so if they ever make a dot release it should be good.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31589
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: fardragon <michaldrozd@protonmail.ch>
Co-committed-by: fardragon <michaldrozd@protonmail.ch>
2026-03-20 04:55:51 +01:00