Commit Graph
1504 Commits
Author SHA1 Message Date
Guy Fischman 070276d8f1 compiler: add x86_64, aarch64, riscv, and loongarch preserve_most calling convention support 2026-10-12 10:49:23 +02:00
Alex Rønne Petersen 1b2f003f06 test: move issue_7030 from test-standalone simple cases to test-cases 2026-10-10 08:36:08 +02:00
Alex Rønne Petersen 4fb39f82c2 test: move some test-standalone simple tests to test-cases 2026-10-10 08:36:08 +02:00
Alex Rønne Petersen c3ee048475 test-cases: remove hello_world.zig
Covered by test/standalone/simple/hello_world/*.
2026-10-10 08:36:07 +02:00
Alex Rønne Petersen d7061f3378 test: move empty_global_error_set from test-standalone to test-cases 2026-10-10 08:36:07 +02:00
Andrew Kelley 0fd39f9e92 Merge pull request 'AstGen: increment baseline when inside backing tag' (#37074) from sinon/zig:astgen-offset-fix into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/37074
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-10-10 08:28:33 +02:00
pentuppup 85c863e348 Sema: fix array sentinel being discarded when coerced to slice 2026-10-10 00:22:23 +02:00
Andrew Kelley 4a7f1339ac Merge pull request 'InternPool: inherit captures from owner union in generated enums' (#37043) from pentuppup/zig:push-srptskmumtto into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/37043
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-10-10 00:20:25 +02:00
David Rubin 09eb81de8b AstGen: increment baseline when inside backing tag 2026-10-09 10:15:11 +02:00
Kendall Condon 7287181ff5 AstGen: add missing cursor restores 2026-10-09 10:09:42 +02:00
Kendall Condon 9195b36a6c AstGen: move error capture asserts outside loop 2026-10-09 10:09:42 +02:00
Kendall Condon b7b6d66675 AstGen: properly advance cursor for decl qualifiers
Reorders the parsing code so the expressions are parsed in the same
order as in source and removes unnecessary cursor restores when parsing
function qualifiers.
2026-10-09 10:09:42 +02:00
Alex Rønne Petersen 5e754304de remove support for wasi-libc
closes https://github.com/ziglang/zig/issues/9342
closes https://github.com/ziglang/zig/issues/15005
closes https://github.com/ziglang/zig/issues/20747
closes https://github.com/ziglang/zig/issues/22570
closes https://codeberg.org/ziglang/zig/issues/30977
2026-10-04 18:23:18 +02:00
whatisaphone 996321250d Fix simple_panic 2026-10-03 19:36:46 +02:00
pentuppup 04742ad6f5 Sema: fix error on undefined tagged union values 2026-10-01 17:45:54 -04:00
Matthew Lugg 1b7a78122e Sema: disallow in-memory coercion of tuples with incompatible comptime field values
Resolves: https://codeberg.org/ziglang/zig/issues/36612
2026-09-26 18:58:35 +02:00
Matthew Lugg 62f13ef4ef Zcu: fix overriding weak export with strong
Our "multiple definitions" check in the frontend was a little
overzealous! The only case which should actually be an error is when
there are multiple *strong* definitions.

In the future we will eliminate this frontend check entirely, because
it's redundant with the check the linker will perform---but for now it's
worth keeping since our linkers do not yet print useful source location
information for Zig exports.

Resolves: https://codeberg.org/ziglang/zig/issues/36678
2026-09-26 18:57:55 +02:00
Ali Cheraghi 2d6970dd2c spirv: accept all image type access qualifiers for vulkan 2026-09-18 16:36:24 +03:30
Ali Cheraghi b3727d9bd1 spirv: rewrite linker
Previously, the SPIR-V linker would merge every function's MIR into one module, then parsed
it in `BinaryModule`, and run three passes over it:
- `prune_unused` walked the module from its entry points to drop dead declarations
- `dedup_types` deduplicated types and constants
- `lower_invocation_globals` rewrote function signatures to pass a pointer to global
  variables as function parameter

Now codegen emits instructions in the order it resolves them (not the spec specified order)
into one section per function. then the linker sorts them into the correct order while also
interning types, constants, strings, etc in the flush step.

Navs the frontend no longer references are now skipped using `Zcu.resolveReferences` instead
of a pass like `prune_unused`. Extern variables are also only loaded when an MIR references them.

`lower_invocation_globals` is gone too. non-`threadlocal` globals on SPIR-V targets are disallowed now.
Currently only vulkan supports them via the newly added `private` address space. See #36715

The new linker also supports incremental compilation now!
2026-09-18 16:36:23 +03:30
Andrew Kelley 31ffe4be43 test-cases: update some expected error messages 2026-09-16 13:12:47 -07:00
Andrew Kelley 514989908c test-cases: update to match new compile error formatting 2026-09-16 13:12:47 -07:00
c-kappelandc-kappel fd3048c5a9 Sema: prevent reference to comptime memory at runtime (#36480)
Co-authored-by: c-kappel <kcapcode@gmail.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36480
2026-08-31 11:50:41 +02:00
Ali Cheraghi 4d2e831300 spirv: only Block-decorate elements of descriptor array variables 2026-08-29 22:30:18 +03:30
Ali Cheraghi e266901590 add missing local workgroup sizes to spirv_mesh's callconv info 2026-08-29 20:05:55 +02:00
brianferri 15435597d9 Sema: reject non-integer lhs of a saturating shift
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36510
Reviewed-by: mlugg <mlugg@mlugg.co.uk>
2026-08-28 09:18:00 +02:00
Ali Cheraghi 62e61e2e9b test: do not skip spirv32 in selfhosted backend allowlist
These cases were never ran!
2026-08-26 08:13:06 +03:30
Ali Cheraghi e8e47b3428 spirv: reject unrepresentable pointer casts and operations 2026-08-26 08:13:06 +03:30
Ali Cheraghi 21575a4483 spirv: validate extern var address space 2026-08-26 08:13:06 +03:30
Subo2002 25890f9080 callconv_spirv_on_unsupported_platform test was missing initiailization
for the new x, y, z fields and so failing the wrong way
2026-08-24 23:28:31 +01:00
Subo2002 4ddb82ec2c Added missing local workgroup sizes to spirv_mesh's SpirvMeshOptions and
associated decorations
2026-08-24 17:49:49 +01:00
K4 2c93c6e91b std.lang.OptimizeMode -> std.lang.Optimize migration progress 2026-08-23 14:30:48 +02:00
Rue04andrue04 02c49f2911 Sema: fix crash on @as(comptime_int, @floatFromInt(1))
Fixes: https://codeberg.org/ziglang/zig/issues/32147
Co-authored-by: rue04 <rue04@rue04.de>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35663
Reviewed-by: mlugg <mlugg@mlugg.co.uk>
2026-08-08 09:54:04 +02:00
Meghan Denny e88566253d sema: improve @errorCast safety check message 2026-08-05 03:29:37 +02:00
Matthew Lugg 5f74e4f3f8 Sema: make loading uninstantiable types a runtime safety panic
For generic code, it is far more useful to consider this equivalent to
`unreachable`. Meanwhile, it is difficult to accidentally write concrete
code which performs this operation, so very little is actually lost from
not having a compile error.

If we accept that this operation does not trigger a compile error, then
it already has the potential to invoke Illegal Behavior today, because
uninstantiable types have an unspecified size in memory, so the
dereference always potentially exceeds the pointer's provenance. (That
said, this only means it is *possible* for the operation to invoke IB,
so the langspec should nonetheless explicitly specify that dereferencing
a pointer to an uninstantiable type is itself Illegal Behavior.)

Storing uninstantiable types into memory does not require any specific
language rules, because that operation can never be reached anyway due
to it requiring an operand (the RHS of `a = b`) whose type is the store
type, which is (by definition) impossible for uninstantiable types.

Resolves: https://codeberg.org/ziglang/zig/issues/36247
2026-08-04 22:29:50 +02:00
c-kappelandc-kappel 8cb4459f36 Sema: correctly check packed_offset when coercing to c pointer (#36097)
Co-authored-by: c-kappel <kcapcode@gmail.com>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36097
Reviewed-by: Justus Klausecker <justusk@noreply.codeberg.org>
2026-08-04 22:15:44 +02:00
Justus Klausecker adef113102 Sema: allow coercion from []T to *[n]T if length is comptime-known
A comptime-known `[]T` should behave as similarly as possible to a comptime-
known `*[n]T`. It is now possible to coerce the former to the latter if
their length matches.
2026-08-02 14:41:10 +02:00
Justus Klausecker e69d19d1ee Sema: allow direct dereference of comptime-known slices
A comptime-known `[]T` should behave as similarly as possible to a comptime-
known `*[n]T`. It is now possible to directly dereference both to an array.

Also adds checks for slices with undefined length in code paths where a
slice is dereferenced as an array which would previously crash.
2026-08-02 14:41:10 +02:00
Meghan Denny 9bc98f5911 sema: improve ignored error value compile error message 2026-08-02 12:18:32 +02:00
Ömer Faruk IRMAKandyarn bb296ab9b9 Add and lower preserve_none call convention for x86_64 & aarch64
std declarations, llvm lowering, c_abi test, compiler warning test

Co-authored-by: yarn <aethnem@gmail.com>
2026-07-29 03:13:48 +02:00
Justus Klausecker c1682a01c1 Sema: improve switch duplicate item/range errors
Now reports which values are duplicated and the overlap of duplicate ranges.
2026-07-24 17:48:10 +02:00
Justus Klausecker e48779fe1f Sema: improve invalid switch type compile errors
Makes them more similar to other existing compile errors.
2026-07-24 17:48:10 +02:00
Justus Klausecker d3056114f6 Sema: disallow unreachable else prong for tagged unions with nonexhaustive tag types 2026-07-24 17:48:10 +02:00
Justus Klausecker 619e54c813 AstGen: add missing pointer modifier invalid on discard failure for switch
This:
```
fn foo() void {
    if ({}) |*_| {} else |err| switch (err) {}
}
```
now correctly produces the same compile error in `switchExpr` as this:
```
fn foo() void {
    if ({}) |*_| {} else |err| (switch (err) {})
}
```
does in `ifExpr`.
2026-07-24 14:35:19 +02:00
Andrew Kelley ae4e835a66 std.lang: rename OptimizeMode to Optimize
and remove "release" from the enum tag names.

no functional change, however, despite the addition of
backwards-compatibile declarations in this patch, it is breaking because
expressions that use `==` or `!=` operators will not able to use the
deprecated names.

I predict these names to survive until the 1.0 tag without any more
breakage.
2026-07-20 17:26:50 -07:00
Justus Klausecker cb4c344e19 compiler: add @backingInt and @fromBackingInt
This commit implements the `@backingInt` and `@fromBackingInt` builtins.
These builtins are meant to replace the now-deprecated `@intFromEnum` and
`@enumFromInt` builtins.

`@backingInt` works with all enums and with bitpacks with *explicit* backing
integer types only. It also works with tagged unions, returning the backing
integer of the active tag value.
An `undefined` enum or bitpack yields an `undefined` backing integer.
The builtin is lowered to `bit_cast`.

`@fromBackingInt` infers its result type, which may be any enum or a bitpack
with an *explicit* backing integer type. It takes a parameter of exactly
that backing integer type.
For enums, passing a backing integer that is either `undefined` or would
yield an invalid tag value results in safety-checked Illegal Behavior.
For bitpacks, passing an `undefined` backing integer yields an `undefined`
bitpack.
The builtin is lowered to `bit_cast` or `bit_cast_safe` (more details below).

`@bitCast` now also performs a safety check for invalid tag values if its
destination type is an `enum`.

This commit also introduces a new AIR instruction, `bit_cast_safe`.
Similarly to `int_cast_safe`, it includes a safety check for invalid enum
tag values. When `@enumFromInt` is eventually removed, `int_cast_safe` won't
need to perform this safety check anymore.

Legalize only implements `expand_bit_cast_safe`, and no additional insts
to scalarize `bit_cast_safe` with vector/array operands. That is because
it can just reuse the existing scalarizations for regular `bit_cast`.

The safety check mandated by `bit_cast_safe` is only desired if the result
type is a scalar enum tag value, so the scalarization process is exactly
equivalent. The only difference is that we have to perform a safety check
on the result of the scalarization.

This means that there's no reason for a backend to want scalarization of
regular `bit_cast`, but not of `bit_cast_safe` (or the other way round).
If a backend is having trouble with the `bit_cast_safe` safety check it
should just use `expand_bit_cast_safe` instead.

Also adds a `std.meta.BackingInt()` function to conveniently get the result
type of `@backingInt` and for use in the langref.
2026-07-17 09:43:53 +01:00
Justus Klausecker 9aeac329a2 Sema: require noreturn as backing integer of empty enums
Empty enums are uninstantiable, so their backing integer should be too.
This avoids a bunch of weird special cases during semantic analysis.

If you were previously using `enum {}`, your code should continue to work
fine.
If you were previously using `enum(uN) {}` (where `uN` is any integer type),
you'll probably want to use `enum(uN) { _ }` instead.
2026-07-17 00:02:41 +02:00
Ryan Liptak 5d08e47160 Merge pull request 'Ensure that parseNumberLiteral fails for all inputs that parseFloat fails on' (#36170) from squeek502/zig:number-literal-parsing into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36170
2026-07-16 01:28:37 +02:00
Rue04 20befa4e64 Sema: fix crash on invalid coercion from error union or optional
It seems the destination and source types were switched by accident, leading to an `unreachable` being reached in the following cases:

```zig
test {
    const eu: anyerror!u8 = 10;
    const i: comptime_int = eu;
    _ = i;
}

test {
    const op: ?u8 = 10;
    const i: comptime_int = op;
    _ = i;
}
```

Resolves: https://codeberg.org/ziglang/zig/issues/30597
Resolves: https://github.com/ziglang/zig/issues/25645
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35662
Reviewed-by: mlugg <mlugg@noreply.codeberg.org>
2026-07-15 23:04:54 +02:00
Ryan Liptak 569381f60b parseNumberLiteral: Make "invalid base for float literal" errors point to the base 2026-07-14 15:04:40 -07:00
Ryan Liptak a52363468a Ensure that parseNumberLiteral fails for all inputs that parseFloat fails on
AstGen relies on this behavior, since it marks InvalidCharacter from parseFloat as unreachable after parseNumberLiteral returns float. Before this commit, there was a mismatch, since parseNumberLiteral was not failing on literals with a period in the exponent.

Fixes #36161
2026-07-14 15:04:40 -07:00