Commit graph

35890 commits

Author SHA1 Message Date
Lukas Lalinsky
6bdea35ce5 Fix std.c.MSF.SYNC for freebsd, openbsd, dragonfly 2025-11-14 18:02:53 +01:00
Lukas Lalinsky
6fc5923a54 Define std.c.MADV for openbsd 2025-11-14 18:01:57 +01:00
Lukas Lalinsky
3a08d2f162 Define std.c.MADV for NetBSD
The `.netbsd` branch was completely missing. Validated against the
actual system headers.
2025-11-14 17:48:19 +01:00
Alex Rønne Petersen
b38fb4bff3
Merge pull request #25917 from alexrp/target-features
`std.Target`: add CPU features and models for alpha and hppa
2025-11-14 12:23:09 +01:00
Alex Rønne Petersen
94538d8dd2 std.pie: add missing clobbers on alpha and sparc
Also format all the assembly code in the file.
2025-11-14 12:19:38 +01:00
Alex Rønne Petersen
9ab7eec23e represent Mac Catalyst as aarch64-maccatalyst-none rather than aarch64-ios-macabi
Apple's own headers and tbd files prefer to think of Mac Catalyst as a distinct
OS target. Earlier, when DriverKit support was added to LLVM, it was represented
a distinct OS. So why Apple decided to only represent Mac Catalyst as an ABI in
the target triple is beyond me. But this isn't the first time they've ignored
established target triple norms (see: armv7k and aarch64_32) and it probably
won't be the last.

While doing this, I also audited all Darwin OS prongs throughout the codebase
and made sure they cover all the tags.
2025-11-14 11:33:35 +01:00
0x4a61636f62
2e6f7d36b9 std.Io.net: fix off-by-one in HostName.expand
`HostName.expand` was including the null terminator in the slice passed to `HostName.init`, which caused `HostName.validate` to fail.
2025-11-13 21:04:21 -08:00
Andrew Kelley
813e8614bc
Merge pull request #25817 from castholm/windows-fetch
Fix TLS, `io.async()` and package fetching on Windows
2025-11-13 19:20:13 -08:00
Alex Rønne Petersen
375d873e1e libcxx: use compiler's _LIBCPP_HAS_LIBRARY_ALIGNED_ALLOCATION when set
closes #25911
2025-11-14 02:02:59 +01:00
Alex Rønne Petersen
18a131f3da
ci: enable Forgejo Actions on master pushes 2025-11-13 23:04:40 +01:00
Alex Rønne Petersen
cca2da16bd
ci: only cancel previous PR runs on Forgejo Actions 2025-11-13 23:00:40 +01:00
Alex Rønne Petersen
65b0a2342b
std.Target.x86: refresh from update_cpu_features.zig
Just to get rid of this ordering diff.
2025-11-13 22:29:28 +01:00
Alex Rønne Petersen
39e91deb77
std.Target: add CPU features and models for hppa 2025-11-13 22:29:12 +01:00
Alex Rønne Petersen
2b23f98d2c
std.Target: add CPU features and models for alpha 2025-11-13 22:28:50 +01:00
xdBronch
071453d5b9 fix 'redundant comptime keyword' error source location and add tests 2025-11-13 19:47:36 +00:00
Matthew Lugg
181b25ce4f
Merge pull request #25772 from mlugg/kill-dead-code
compiler: rewrite some legalizations, and remove a bunch of dead code
2025-11-12 23:14:02 +00:00
Alex Rønne Petersen
dfd7b7f233 std.Target: remove Abi.cygnus
There is approximately zero chance of the Zig team ever spending any effort on
supporting Cygwin; the MSVC and MinGW-w64 ABIs are superior in every way that
matters, and not least because they lead to binaries that just run natively on
Windows without needing a POSIX emulation environment installed.
2025-11-12 22:39:04 +01:00
Matthew Lugg
92bc619c49 std.debug: allow fp unwind from context
It's easy to do FP unwinding from a CPU context: you just report the
captured ip/pc value first, and then unwind from the captured fp value.
All this really needed was a couple of new functions on the
`std.debug.cpu_context` implementations so that we don't need to rely on
`std.debug.Dwarf` to access the captured registers.

Resolves: #25576
2025-11-12 21:02:38 +00:00
So1aric
49e19fc94f
Sema: fix inline fn compiler crash (#25586)
Resolves: https://github.com/ziglang/zig/issues/25581
2025-11-12 19:21:28 +00:00
Alex Rønne Petersen
be2a902784
cmake: update ZIG_LLVM_REQUIRED_TARGETS to contain LoongArch and SPIRV 2025-11-12 20:16:58 +01:00
Matthew Lugg
532aa3c575
cbe: work around some miscompilations
The changes to `codegen.c` are blatant hacks, but the problem they work
around isn't a regression: it's an existing miscompilation. This branch
happened to *expose* that miscompilation in more cases by changing how
an incorrect result is *used*.
2025-11-12 16:00:16 +00:00
Matthew Lugg
5df5e2ed26
zig.h: drop dependency on deleted compiler_rt functions
It turns out we did use these in the C backend. However, it's really
just as easy, if not easier, to replicate the logic directly in C.

Synchronizes stage1/zig.h to make sure the bootstrap doesn't depend on
these functions either. The actual zig1 tarball is unmodified because
regenerating it is unnecessary in this instance.
2025-11-12 16:00:16 +00:00
Matthew Lugg
69f39868b4
Air.Legalize: revert to loops for scalarizations
I had tried unrolling the loops to avoid requiring the
`vector_store_elem` instruction, but it's arguably a problem to generate
O(N) code for an operation on `@Vector(N, T)`. In addition, that
lowering emitted a lot of `.aggregate_init` instructions, which is
itself a quite difficult operation to codegen.

This requires reintroducing runtime vector indexing internally. However,
I've put it in a couple of instructions which are intended only for use
by `Air.Legalize`, named `legalize_vec_elem_val` (like `array_elem_val`,
but for indexing a vector with a runtime-known index) and
`legalize_vec_store_elem` (like the old `vector_store_elem`
instruction). These are explicitly documented as *not* being emitted by
Sema, so need only be implemented by backends if they actually use an
`Air.Legalize.Feature` which emits them (otherwise they can be marked as
`unreachable`).
2025-11-12 16:00:16 +00:00
Matthew Lugg
99a7884308
behavior: disable test on cbe
This isn't so much a regression as it is foreshadowing of accepted
proposal https://github.com/ziglang/zig/issues/24657.
2025-11-12 16:00:16 +00:00
Matthew Lugg
6576c3b898
x86_64: spill eflags when initializing bool vector 2025-11-12 16:00:16 +00:00
Matthew Lugg
20bd5e8018
compiler-rt: remove dead code
`__addosi4`, `__addodi4`, `__addoti4`, `__subosi4`, `__subodi4`, and
`__suboti4` were all functions which we invented for no apparent reason.
Neither LLVM, nor GCC, nor the Zig compiler use these functions. It
appears the functions were created in a kind of misunderstanding of an
old language proposal; see https://github.com/ziglang/zig/pull/10824.

There is no benefit to these functions existing; if a Zig compiler
backend needs this operation, it is trivial to implement, and *far*
simpler than calling a compiler-rt routine. Therefore, this commit
deletes them. A small amount of that code was used by other parts of
compiler-rt; the logic is trivial so has just been inlined where needed.
I also chose to quickly implement `__addvdi3` (a standard function)
because it is trivial and we already implement the `sub` parallel.
2025-11-12 16:00:16 +00:00
Matthew Lugg
c091e27aac
compiler: spring cleaning
I started this diff trying to remove a little dead code from the C
backend, but ended up finding a bunch of dead code sprinkled all over
the place:

* `packed` handling in the C backend which was made dead by `Legalize`
* Representation of pointers to runtime-known vector indices
* Handling for the `vector_store_elem` AIR instruction (now removed)
* Old tuple handling from when they used the InternPool repr of structs
* Straightforward unused functions
* TODOs in the LLVM backend for features which Zig just does not support
2025-11-12 16:00:15 +00:00
Matthew Lugg
9a7d28fe58
Legalize: rewrite several legalizations
The main goal of this change was to avoid emitting the
`vector_store_elem` AIR tag, because this represents an operation which
Zig no longer supports (and hence Sema no longer emits) as of 010d9a6
(because runtime vector indices are now forbidden). Backends should not
need to lower this operation, so I rewrote the legalizations which
emitted it (scalarizations of vector operations) to instead unroll the
loop and hence emit comptime-known vector indices.

In doing this, I actually reworked those legalizations to use a
different strategy; instead of using an `alloc` and storing to
individual vector elements, the vector is constructed by-val, for
instance by performing the scalar operation on all elements and passing
them to an `aggregate_init`. This is vastly simpler to implement in
Legalize, conceptually simpler, and doesn't severely pessimise memory
usage, because a non-optimizing backend will store the full vector on
the stack either way.

Given the above rationale, I also ended up reworking several other
legalizations to use simpler lowerings. The legalizations in question
were bitcast scalarization, `struct_field_val` of `packed struct`s
(where we just bitcast to an integer and perform the appropriate
shift/trunc sequence), and `aggregate_init` of a `packed struct` (also
implemented in terms of integer bitwise operations with bitcasts to and
from the actual types). This hugely simplified some parts of `Legalize`.

So, `Legalize` is now much simpler, and the `vector_store_elem`
instruction is no longer emitted by any part of the compiler so can be
removed in a future commit.
2025-11-12 16:00:15 +00:00
Alex Rønne Petersen
ee0a0f119c
cmake: add a - missed in 0f71a9291a 2025-11-12 11:29:36 +01:00
Alex Rønne Petersen
0f71a9291a
cmake: improve host system detection in some more cases 2025-11-12 10:04:30 +01:00
Techatrix
8887346b53 std.Io: fix calls on functions that return an array type 2025-11-11 01:11:51 +01:00
Carl Åstholm
cca2d09950 io: Correctly align async closure contexts
This fixes package fetching on Windows.

Previously, `Async/GroupClosure` allocations were only aligned for the
closure struct type, which resulted in panics when `context_alignment`
(or `result_alignment` for that matter) had a greater alignment.
2025-11-11 01:11:45 +01:00
Carl Åstholm
5f1392247d io: Redefine Clock.real to return timestamps relative to the POSIX/Unix epoch
`Clock.real` being defined to return timestamps relative to an
implementation-specific epoch means that there's currently no way for
the user to translate returned timestamps to actual calendar dates
without digging into implementation details of any particular `Io`
implementation. Redefining it to return timestamps relative to
1970-01-01T00:00:00Z fixes this problem.

There are other ways to solve this, such as adding a new vtable function
for returning the implementation-specific epoch, but in terms of
complexity this redefinition is by far the simplest solution and only
amounts to a simple 96-bit integer addition's worth of overhead on OSes
like Windows that use non-POSIX/Unix epochs.
2025-11-10 22:12:40 +01:00
Carl Åstholm
ed7f2588e4 io: Translate Windows Clock.real timestamps to the POSIX/Unix epoch
This fixes `std.http.Client` TLS certificate validation on Windows.
2025-11-10 22:12:39 +01:00
Matthew Lugg
cbfa87cbea
Merge pull request #25889 from mlugg/incremental-llvm-warn
compiler: warn when using -fincremental with LLVM backend
2025-11-10 21:10:31 +00:00
Alex Rønne Petersen
ca34abbcde
ci: remove TERM=dumb workaround on Forgejo Actions
https://codeberg.org/forgejo/forgejo/issues/9244
2025-11-10 17:02:27 +01:00
Alex Rønne Petersen
d182c7e3bc
Merge pull request #25886 from alexrp/kvx
beginnings of KVX target support (via CBE)
2025-11-10 16:38:23 +01:00
Matthew Lugg
966809862f
Merge pull request #25839 from Rexicon226/socket-bind-fix
Io.net: fix compile error in `receive` and `receiveTimeout`
2025-11-10 14:38:54 +00:00
xdBronch
fb914a9a10 sema: print @panic message at comptime 2025-11-10 14:21:26 +00:00
Mateusz Poliwczak
d942f693c5 std.zig.AstGen: properly handle grouped_expression
This fixes an endless loop in the compiler.
2025-11-10 14:02:37 +00:00
Frank Denis
ce355e0ba5
Add ML-DSA post-quantum signatures (#25862)
ML-DSA is a post-quantum signature scheme that was recently
standardized by NIST.

Keys and signatures are pretty large, not making it a drop-in
replacement for classical signature schemes.

But if you are shipping keys that may still be used in 10 years
or whenever large quantum computers able to break ECC arrive,
it that ever happens, and you don't have the ability to replace
these keys, ML-DSA is for you.

Performance is great, verification is faster than Ed25519 / ECDSA.

I tried manual vectorization, but it wasn't worth it, the compiler
does at good job at auto-vectorization already.
2025-11-10 14:11:30 +01:00
Matthew Lugg
13993c4f62
compiler: warn when using -fincremental with LLVM backend
This configuration hasn't had much work put into it yet, so is all but
guaranteed to miscompile or crash. Since users are starting to try out
`-fincremental`, and LLVM is still the default backend in many cases,
it's worth having this warning to avoid bug reports like
https://github.com/ziglang/zig/issues/25873.
2025-11-10 12:56:35 +00:00
Matthew Lugg
6d280dc1b0
compiler: update logFn to use color
To match the new default implementation. In fact, I implemented this by
simply dispatching *to* the default implementation after the debug log
guard; no need to complicate things!
2025-11-10 12:55:39 +00:00
Alex Rønne Petersen
cde865e06a
llvm: set sub-arch for spirv 1.6 2025-11-10 12:54:04 +01:00
Alex Rønne Petersen
f34b5ce288
std.Target.DynamicLinker: define standard paths for alpha, microblaze, sh on netbsd and openbsd 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
255fc44036
std.Target: fix toElfMachine() for arc/arceb 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
a382b7bfc5
std.simd: suggest 1024-bit vectors for kvx 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
39b5c8ee8a
std.debug.Dwarf: add kvx ip/fp/sp register mappings 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
94b6c7ce5f
std.debug.cpu_context: add kvx context implementation 2025-11-10 09:40:44 +01:00
Alex Rønne Petersen
80e567b6bd
std.pie: add kvx support 2025-11-10 09:40:44 +01:00