742 Commits

Author SHA1 Message Date
Alex Rønne Petersen 589e564f16 test: delete old stage1 compile_errors tests
generic_function_returning_opaque_type.zig was salvaged as it's still worth
having.
2025-09-16 23:39:29 +02:00
Alex Rønne Petersen 2e3fac3626 test: rename backend=stage2 to backend=selfhosted, and add backend=auto
backend=auto (now the default if backend is omitted) means to let the compiler
pick whatever backend it wants as the default. This is important for platforms
where we don't yet have a self-hosted backend, such as loongarch64.

Also purge a bunch of redundant target=native.
2025-09-16 23:39:26 +02:00
Andrew Kelley 7666d5fc26 add compile error test case 2025-09-07 23:03:06 -07:00
Andrew Kelley 5dc5bf6a6b add compile error test case for new error 2025-09-05 19:55:45 -07:00
mlugg 8adabaa4ed Zcu: don't tell linkers about exports if there are compile errors
In the best case, this is redundant work, because we aren't actually
going to emit a working binary this update. In the worst case, it causes
bugs because the linker may not have *seen* the thing being exported due
to the compile errors.

Resolves: #24417
2025-08-15 20:00:30 +01:00
Will Lillis e9eee8dace fix: print error set members in a consistent order
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-08-15 07:43:46 +01:00
Matthew Lugg a495628862 Merge pull request #24674 from Justus2308/undef-shift-bitwise
Sema: Improve comptime arithmetic undef handling
2025-08-13 14:04:59 +01:00
Justus Klausecker 4ec421372f add remaining undef value tests ; fix @truncate undef retval type 2025-08-12 16:33:58 +02:00
Justus Klausecker f0ffe30f2f add undef shift tests ; mirror zirShl logic for @shlWithOverflow 2025-08-12 16:33:58 +02:00
Justus Klausecker 79756e681d remove redundant test cases 2025-08-12 16:33:58 +02:00
Justus Klausecker 05762ca02f address most comments 2025-08-12 16:33:57 +02:00
Justus Klausecker 0ef26d113a make >> a compile error with any undef arg ; add a bunch of test cases 2025-08-12 16:33:57 +02:00
Justus Klausecker d0586da18e Sema: Improve comptime arithmetic undef handling
This commit expands on the foundations laid by https://github.com/ziglang/zig/pull/23177
and moves even more `Sema`-only functionality from `Value`
to `Sema.arith`. Specifically all shift and bitwise operations,
`@truncate`, `@bitReverse` and `@byteSwap` have been moved and
adapted to the new rules around `undefined`.

Especially the comptime shift operations have been basically
rewritten, fixing many open issues in the process.

New rules applied to operators:
* `<<`, `@shlExact`, `@shlWithOverflow`, `>>`, `@shrExact`: compile error if any operand is undef
* `<<|`, `~`, `^`, `@truncate`, `@bitReverse`, `@byteSwap`: return undef if any operand is undef
* `&`, `|`: Return undef if both operands are undef, turn undef into actual `0xAA` bytes otherwise

Additionally this commit canonicalizes the representation of
aggregates with all-undefined members in the `InternPool` by
disallowing them and enforcing the usage of a single typed
`undef` value instead. This reduces the amount of edge cases
and fixes a bunch of bugs related to partially undefined vecs.

List of operations directly affected by this patch:
* `<<`, `<<|`, `@shlExact`, `@shlWithOverflow`
* `>>`, `@shrExact`
* `&`, `|`, `~`, `^` and their atomic rmw + reduce pendants
* `@truncate`, `@bitReverse`, `@byteSwap`
2025-08-12 16:33:57 +02:00
Justus Klausecker 0ecbd5a0e1 address comments 2025-08-07 13:58:49 +02:00
Justus Klausecker ba549a7d67 Add support for both '_' and 'else' prongs at the same time in switch statements
If both are used, 'else' handles named members and '_' handles
unnamed members. In this case the 'else' prong will be unrolled
to an explicit case containing all remaining named values.
2025-08-07 13:58:47 +02:00
Justus Klausecker 1d9b1c0212 Permit explicit tags with '_' switch prong
Mainly affects ZIR representation of switch_block[_ref]
and special prong (detection) logic for switch.
Adds a new SpecialProng tag 'absorbing_under' that allows
specifying additional explicit tags in a '_' prong which
are respected when checking that every value is handled
during semantic analysis but are not transformed into AIR
and instead 'absorbed' by the '_' branch.
2025-08-07 13:57:57 +02:00
Justus Klausecker 7c35070b90 zig fmt: apply new cast builtin order 2025-08-03 14:59:56 +02:00
David Rubin e82d67233b disallow alignment on packed union fields 2025-08-02 09:51:26 -07:00
David Rubin d6c74a95fd remove usages of .alignment = 0 2025-08-01 14:57:16 -07:00
David Rubin 17330867eb Sema: compile error on reifying align(0) struct fields 2025-08-01 14:57:16 -07:00
Jackson Wambolt 264bd7053e Sema: remove incorrect requireRuntimeBlock calls
Part of #22353

Resolves: #24273
Co-Authored-By: Matthew Lugg <mlugg@mlugg.co.uk>
2025-07-31 22:28:46 +01:00
Matthew Lugg 04d7b491b4 Merge pull request #24632 from mlugg/lossy-int-to-float-coercion
Sema: compile error on lossy int to float coercion
2025-07-31 21:49:37 +01:00
mikastiv 1a15fbe960 Sema: add note suggesting dropping try on non error-unions 2025-07-31 16:55:17 +01:00
dweiller 19fc5f4fb2 Sema: disallow slicing many-item pointer with different sentinel
This change prevents adding or changing the sentinel in the type of a
many-item pointer via the slicing syntax `ptr[a.. :S]`.
2025-07-31 12:02:19 +01:00
mlugg e664bf4d81 Sema: compile error on lossy int to float coercion
Resolves: #21586
2025-07-31 10:57:04 +01:00
Jackson Wambolt eb1a4970da Sema: check min/max operand types 2025-07-30 20:48:38 +00:00
Matthew Lugg 389ccf692a Merge pull request #24278 from gooncreeper/atomic-fixes
atomic fixes and clarification
2025-07-30 21:30:29 +01:00
Krzysztof Wolicki 3d639481d9 Sema: disallow tags on non-auto unions when reifying (#23488) 2025-07-30 18:18:49 +00:00
Kendall Condon b0d6c227d3 Sema: catch error sets in atomic operations
also fix the struct test
2025-07-30 09:56:38 +01:00
Jacob Young 69abc945e4 aarch64: implement some safety checks
Closes #24553
2025-07-26 17:31:04 -04:00
mlugg 67e6df4313 tests: remove more old async tests
The rejection of #6025 indicates that if stackless coroutines return to
Zig, they will look quite different; see #23446 for the working draft
proposal for their return (though it will definitely be tweaked before
being accepted). Some of this test coverage was deleted in 40d11cc, but
because stackless coroutines will take on a new form if re-introduced, I
anticipate that essentially *none* of this coverage will be relevant. Of
course, if it for some reason is, we can always grab it from the Git
history.
2025-07-19 08:52:13 +02:00
Felix Koppe 3ae0ba096d test: Restore and fix deleted tests that relied on intern pool types (#24422) 2025-07-17 22:07:50 +00:00
Linus Groh eb37552536 Remove numerous things deprecated during the 0.14 release cycle
Basically everything that has a direct replacement or no uses left.

Notable omissions:

- std.ArrayHashMap: Too much fallout, needs a separate cleanup.
- std.debug.runtime_safety: Too much fallout.
- std.heap.GeneralPurposeAllocator: Lots of references to it remain, not
  a simple find and replace as "debug allocator" is not equivalent to
  "general purpose allocator".
- std.io.Reader: Is being reworked at the moment.
- std.unicode.utf8Decode(): No replacement, needs a new API first.
- Manifest backwards compat options: Removal would break test data used
  by TestFetchBuilder.
- panic handler needs to be a namespace: Many tests still rely on it
  being a function, needs a separate cleanup.
2025-07-11 08:17:43 +02:00
Andrew Kelley 34f64432b0 remove usingnamespace from the language
closes #20663
2025-07-07 13:39:48 -07:00
Andrew Kelley 40d11cc25a remove async and await keywords
Also remove `@frameSize`, closing #3654.

While the other machinery might remain depending on #23446, it is
settled that there will not be `async`/ `await` keywords in the
language.
2025-07-07 13:39:16 -07:00
Andrew Kelley 7999374b21 Sema: correct OPV for optional empty error set
prevents crashes in backends; improves codegen; provides more
comptime-ness.
2025-06-29 17:20:23 -07:00
Ali Cheraghi 1df79ab895 remove spirv cpu arch 2025-06-23 06:03:03 +02:00
Ali Cheraghi 872f68c9cb rename spirv backend name
`stage2_spirv64` -> `stage2_spirv`
2025-06-16 13:22:19 +03:30
Andrew Kelley dd75e7bcb1 Sema: add missing error and test for bool not on vector of ints 2025-06-13 05:59:25 -04:00
Andrew Kelley 2e31544285 seriously don't put internpool indexes in test cases 2025-06-07 12:42:03 -07:00
Jacob Young 0bf8617d96 x86_64: add support for pie executables 2025-06-06 23:42:14 -07:00
mlugg c1a5caa454 compiler: combine @intCast safety checks
`castTruncatedData` was a poorly worded error (all shrinking casts
"truncate bits", it's just that we assume those bits to be zext/sext of
the other bits!), and `negativeToUnsigned` was a pointless distinction
which forced the compiler to emit worse code (since two separate safety
checks were required for casting e.g. 'i32' to 'u16') and wasn't even
implemented correctly. This commit combines those safety panics into one
function, `integerOutOfBounds`. The name maybe isn't perfect, but that's
not hugely important; what matters is the new default message, which is
clearer than the old ones: "integer does not fit in destination type".
2025-06-01 12:10:57 +01:00
mlugg add2976a9b compiler: implement better shuffle AIR
Runtime `@shuffle` has two cases which backends generally want to handle
differently for efficiency:

* One runtime vector operand; some result elements may be comptime-known
* Two runtime vector operands; some result elements may be undefined

The latter case happens if both vectors given to `@shuffle` are
runtime-known and they are both used (i.e. the mask refers to them).
Otherwise, if the result is not entirely comptime-known, we are in the
former case. `Sema` now diffentiates these two cases in the AIR so that
backends can easily handle them however they want to. Note that this
*doesn't* really involve Sema doing any more work than it would
otherwise need to, so there's not really a negative here!

Most existing backends have their lowerings for `@shuffle` migrated in
this commit. The LLVM backend uses new lowerings suggested by Jacob as
ones which it will handle effectively. The x86_64 backend has not yet
been migrated; for now there's a panic in there. Jacob will implement
that before this is merged anywhere.
2025-06-01 08:24:01 +01:00
Jacob Young b483defc5a Legalize: implement scalarization of binary operations 2025-05-31 18:54:28 -04:00
Jacob Young 8bacf3e757 x86_64: implement integer @reduce(.Max) 2025-05-28 15:10:22 -04:00
Jacob Young 3fd3358f37 x86_64: implement integer @reduce(.Min) 2025-05-28 15:10:22 -04:00
Jacob Young a4a1ebdeed x86_64: implement optimized float @reduce(.Mul) 2025-05-28 15:10:22 -04:00
Jacob Young d69f4c48fc x86_64: rewrite bitwise @reduce 2025-05-28 15:10:22 -04:00
mlugg 92c63126e8 compiler: tlv pointers are not comptime-known
Pointers to thread-local variables do not have their addresses known
until runtime, so it is nonsensical for them to be comptime-known. There
was logic in the compiler which was essentially attempting to treat them
as not being comptime-known despite the pointer being an interned value.
This was a bit of a mess, the check was frequent enough to actually show
up in compiler profiles, and it was very awkward for backends to deal
with, because they had to grapple with the fact that a "constant" they
were lowering might actually require runtime operations.

So, instead, do not consider these pointers to be comptime-known in
*any* way. Never intern such a pointer; instead, when the address of a
threadlocal is taken, emit an AIR instruction which computes the pointer
at runtime. This avoids lots of special handling for TLVs across
basically all codegen backends; of all somewhat-functional backends, the
only one which wasn't improved by this change was the LLVM backend,
because LLVM pretends this complexity around threadlocals doesn't exist.

This change simplifies Sema and codegen, avoids a potential source of
bugs, and potentially improves Sema performance very slightly by
avoiding a non-trivial check on a hot path.
2025-05-27 19:23:11 +01:00
David Rubin 3ed9155f10 Sema: simplify comptime @intFromPtr logic 2025-05-27 02:40:58 +01:00