80 Commits

Author SHA1 Message Date
Andrew Kelley 571388a93d langref: use the word "namespace" instead of "container" 2026-04-19 10:38:01 -07:00
Sage Hane f0649e7709 langref: Clear up terminology used for top-level doc comments 2026-04-19 10:12:22 -07:00
Andrew Kelley 67a5b6e5e8 delete @cImport from the language
closes #20630
2026-04-15 17:43:53 -07:00
Andrew Kelley 58890066d9 Merge pull request 'Sema: Support peer type resolution for floats and small integers' (#30921) from jayschwa/zig:ptr-small-int-and-floats into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30921
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-03-12 00:41:05 +01:00
Jay Petacat fcf64761d0 Sema: Support peer type resolution for floats and small integers
This builds on the changes in PR #30053 / commit 484cc15366.

Previously, peer type resolution would always result in a conflict for
fixed-width integer and float types. Now that small integer types can
coerce to floats, peer type resolution can take that into account. This
primarily benefits arithmetic with mixed float and integer operands. If
the integer operand can coerce to the float operand's type, it will do
so without requiring an explicit cast. If the integer type can't coerce,
there will be a compiler error; no float widening will occur. Explicit
casting will still be required to make it work.
2026-03-11 11:31:58 -06:00
Justus Klausecker be9b42d707 compiler: allow equality comparisons for packed unions
This was already possible in practice by just wrapping a packed union into
a packed struct. Now it's also possible without doing that.
2026-03-11 16:44:08 +01:00
Matthew Lugg 34d780f4bb langref: update for language changes 2026-03-10 10:38:50 +00:00
Nils Juto 2da1370a7e sync CallModifier in langref with what's actually there 2026-02-27 13:50:12 +01:00
Ivan Agafonov 333055ced7 langref: specific expectEqual* functions instead of expect 2026-02-25 19:34:30 +01:00
Alex Rønne Petersen b7a4756e1d langref: disable @cImport tests on NetBSD
https://github.com/Vexu/arocc/issues/960
2026-01-21 16:42:45 +01:00
Matthew Lugg 01546e68cd compiler: handle switch rewrite review feedback 2026-01-11 14:37:28 +00:00
Justus Klausecker 5a376d97d4 langref: document new switch features
- switch on tagged union with runtime-captured tag
- switch on errors special cases
2026-01-11 11:37:17 +00:00
Jay Petacat 484cc15366 Sema: Allow small integer types to coerce to floats
If the float can store all possible values of the integer without
rounding, coercion is allowed. The integer's precision must be less than
or equal to the float's significand precision.

Closes #18614
2026-01-10 22:19:20 +01:00
Andrew Kelley 6a5bb3ede3 std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
Andrew Kelley 77087f6f31 langref: update to new main API 2026-01-04 00:27:08 -08:00
Andrew Kelley 691afee786 langref: fix build failure 2025-12-23 22:15:12 -08:00
Alex Rønne Petersen 9373a963a1 langref: work around powerpc LLVM miscompilation in runtime_shrExact_overflow
https://github.com/ziglang/zig/issues/24304
2025-12-16 06:22:33 +01:00
meowjesty 755a3d957c langref: convert to unmanaged ArrayList in example 2025-11-23 18:32:05 +00:00
Ali Cheraghi dec1163fbb all: replace all @Type usages
Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
2025-11-22 22:42:38 +00:00
Nashwan Azhari af7dec94c6 docs: use custom error set in values.zig sample.
Signed-off-by: Nashwan Azhari <aznashwan@icloud.com>
2025-11-22 02:56:40 +02:00
Benjamin Jurk 4b5351bc0d update deprecated ArrayListUnmanaged usage (#25958) 2025-11-20 14:46:23 -08:00
Alex Rønne Petersen c82884542f langref: work around s390x LLVM compilation crash in test_defining_variadic_function
https://github.com/ziglang/zig/issues/21350#issuecomment-3543006475
2025-11-19 01:42:45 +01:00
Alex Rønne Petersen 4dd05b5a64 langref: work around s390x LLVM miscompilation in runtime_shrExact_overflow
https://github.com/ziglang/zig/issues/24304
2025-11-19 01:42:45 +01:00
Felipe Cardozo 0ec45050e0 docs: fix handle_error_with_catch_block typo 2025-10-26 05:37:28 +01:00
Andrew Kelley d7d50496d9 langref: don't assume too much about pointer to packed struct field 2025-09-20 18:33:01 -07:00
Alex Rønne Petersen c547a05b65 langref: runtime_shrExact_overflow does not work as expected on LoongArch
https://github.com/ziglang/zig/issues/24304
2025-09-18 10:08:38 +02:00
LukaTD 0b75a2a1b1 langref: added missing newlines to destructuring tuples example
langref: added missing newlines to destructuring tuples example
2025-09-10 02:31:20 +00:00
Andrew Kelley 6673b47685 frontend: vectors and arrays no longer support in-memory coercion
closes #25172
2025-09-07 17:29:36 -07:00
Justus Klausecker cf90a5e451 langref: add documentation for unions with inferred tag and explicit tag values 2025-08-17 19:17:02 -07: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
Andrew Kelley 749f10af49 std.ArrayList: make unmanaged the default 2025-08-11 15:52:49 -07:00
Andrew Kelley 196e36bbb2 std: remove BoundedArray
This use case is handled by ArrayListUnmanaged via the "...Bounded"
method variants, and it's more optimal to share machine code, versus
generating multiple versions of each function for differing array
lengths.
2025-08-05 09:56:02 -07:00
Rue 5381e7891d Merge branch 'ziglang:master' into some-documentation-updates-0 2025-07-28 14:54:52 +02:00
Carl Åstholm 154bd2fd05 Migrate from deprecated Step.Compile APIs 2025-07-26 12:06:43 +02:00
IOKG04 3c046ab9d9 [:x]T coerces into [*:x]T
https://github.com/ziglang/zig/issues/9628
2025-07-22 12:30:19 +02:00
Andrew Kelley c2fa961b63 update docs 2025-07-16 10:27:40 -07:00
Alex Kladov d90646d8fb langref: remove dead code 2025-07-14 17:34:52 +01:00
Alex Kladov 96bb1137c2 langref: don't encourage printing to stderr in tests
The rule: `pub fn main` owns file descriptors 0, 1, and 2. If you didn't
write `pub fn main()` it is, in general, not your business to print to
stderr.
2025-07-14 17:32:50 +01:00
Alex Kladov d045eb7a4a langref: make example more interesting.
As written, I think langref's example is actually a poor reason to use
`inline`.

If you have

     if (foo(1200, 34) != 1234) {
         @compileError("bad");
     }

and you want to make sure that the call is executed at compile time, the
right way to fix it is to add comptime

     if (comptime foo(1200, 34) != 1234) {
         @compileError("bad");
     }

and not to make the function `inline`. I _think_ that inlining functions
just to avoid `comptime` at a call-site is an anti-pattern. When the
reader sees `foo(123)` at the call-site, they _expect_ this to be a
runtime call, as that's the normal rule in Zig.

Inline is still necessary when you can't make the _whole_ call
`comptime`, because it has some runtime effects, but you still want
comptime-known result.

A good example here is

    inline fn findImportPkgHashOrFatal(b: *Build, comptime asking_build_zig: type, comptime dep_name: []const u8) []const u8 {

from Build.zig, where the `b` argument is runtime, and is used for
side-effects, but where the result is comptime.

I don't know of a good small example to demonstrate the subtelty here,
so I went ahead with just adding a runtime print to `foo`. Hopefully
it'll be enough for motivated reader to appreciate the subtelty!
2025-07-14 16:20:33 +01: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 d8e26275f2 update standalone and incremental tests to new API 2025-07-07 22:43:53 -07:00
Andrew Kelley 34f64432b0 remove usingnamespace from the language
closes #20663
2025-07-07 13:39:48 -07:00
Alex Rønne Petersen 9f064dff47 langref: runtime_shrExact_overflow does not work as expected on RISC-V
https://github.com/ziglang/zig/issues/24304
2025-07-01 23:03:15 +02:00
Andrew Kelley a59d18779f langref: global assembly test depends on llvm
see #24046
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
Felix Rabe 561ab59cec langref: Update calling convention (#24022)
* langref: Update calling convention

* Apply suggestions from code review

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>

* langref: Just use .winapi directly

---------

Co-authored-by: Alex Rønne Petersen <alex@alexrp.com>
2025-05-30 01:11:00 +00:00
Andrew Kelley bd38c417fc langref: reword some packed struct text and example 2025-04-15 19:19:23 -07:00
kj4tmp@gmail.com a8621731ec langref: packed struct documentation 2025-04-15 19:17:07 -07:00
Andrew Barchuk 5b4759bd3c Clarify the multidimensional array example
Use a rectangular matrix instead of a square one to distinguish rows and
columns more clearly. Extend the example with row access.
2025-03-26 11:52:52 +01:00
Kiëd Llaentenn 5f7dfc3577 langref: update splat section 2025-03-06 07:26:19 +01:00