1346 Commits

Author SHA1 Message Date
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
Matthew Lugg
c5383173a0
compiler: replace @Type with individual type-creating builtins
The new builtins are:
* `@EnumLiteral`
* `@Int`
* `@Fn`
* `@Pointer`
* `@Tuple`
* `@Enum`
* `@Union`
* `@Struct`

Their usage is documented in the language reference.

There is no `@Array` because arrays can be created like this:

    if (sentinel) |s| [n:s]T else [n]T

There is also no `@Float`. Instead, `std.meta.Float` can serve this use
case if necessary.

There is no `@ErrorSet` and intentionally no way to achieve this.
Likewise, there is intentionally no way to reify tuples with comptime
fields, or function types with comptime parameters. These decisions
simplify the Zig language specification, and moreover make Zig code more
readable by discouraging overly complex metaprogramming.

Co-authored-by: Ali Cheraghi <alichraghi@proton.me>
Resolves: #10710
2025-11-22 22:42:37 +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
Nashwan Azhari
153521279f
docs: remove normal-doc comment interleaving bug note.
Signed-off-by: Nashwan Azhari <aznashwan@icloud.com>
2025-11-22 02:51:16 +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
Zirunis
e1f12124fd
Remove StringAlias because it implies the existence of a String type and is a redundant example anyway
Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2025-11-09 14:05:09 +01:00
Zirunis
4dcc8a80a9
Simplified and unified sentence structure of the naming convention logic 2025-11-09 04:44:05 +01:00
Zirunis
07f50c0351
Update Style Guide to suggest TitleCase for Type aliases 2025-11-09 04:35:01 +01:00
Felipe Cardozo
0ec45050e0 docs: fix handle_error_with_catch_block typo 2025-10-26 05:37:28 +01:00
Ryan Liptak
2ab0ca13bb langref: Bump 0.15.1 to 0.15.2 2025-10-17 15:03:51 +02: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
rohlem
92223ad36f langref: mention union support of @fieldParentPtr 2025-09-17 20:07:30 -07: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
Andrew Kelley
4c01275664
Merge pull request #25163 from ziglang/packed-union-unused
forbid unused bits in packed unions
2025-09-06 12:08:31 -07:00
Andrew Kelley
91b3769b03 langref: update "Choosing an Allocator" section
and delete "Implementing an Allocator" section because it is out of
scope.
2025-09-06 11:51:27 -07:00
Andrew Kelley
8c631ebfee langref: update for new packed union rules 2025-09-05 19:45:18 -07:00
Andrew Kelley
ba726ab65a langref: update nav link 2025-08-21 14:02:12 -07:00
Isaac Freund
52de06c3b0 langref: sync with zig-spec grammar.peg 2025-08-21 17:12:38 +02:00
Andrew Kelley
94cda37d69 Release 0.15.0 2025-08-18 21:32:35 -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
mlugg
bce6a7c215 langref: improve @import documentation
Rewrite to be more clear and correct. Also, explain ZON imports.

Resolves: #23314
2025-07-31 10:39:22 +01:00
Matthew Lugg
032bbd68a7
Merge pull request #24537 from IOKG04/some-documentation-updates-0
some small langref changes
2025-07-31 02:32:32 +01:00
Kendall Condon
cbe6e5b7fe langref: clarify allowed atomic types
Floats are not allowed in @cmpxchg

Packed structs are allowed for all atomic builtins
2025-07-30 09:56:38 +01:00
IOKG04
2dea904d5a .strong, not .Strong
https://github.com/ziglang/zig/pull/24537#issuecomment-3124556900
2025-07-28 15:15:49 +02: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
84ae54fbe6 @rem() and @mod() take denominator != 0, not just denominator > 0
https://github.com/ziglang/zig/issues/23635

I also added tests for `@rem()` with `denominator < 0` cause there were none before
I hope I added them in the correct place, if not I can change it ofc
2025-07-22 13:35:55 +02:00
IOKG04
a91b4aab73 error return traces are *not* enabled for ReleaseSafe
https://github.com/ziglang/zig/issues/24232
2025-07-22 12:35:46 +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
Kendall Condon
f657767b60 langref: upgrade grammar.y for asm clobber change 2025-07-20 19:37:41 +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
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
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
Daniel Kongsgaard
5e3c0b7af7
Allow more operators on bool vectors (#24131)
* Sema: allow binary operations and boolean not on vectors of bool

* langref: Clarify use of operators on vectors (`and` and `or` not allowed)

closes #24093
2025-06-12 15:16:23 -07:00
Andrew Kelley
8b875b17ad
Merge pull request #24072 from jacobly0/x86_64-default
Compilation: enable the x86_64 backend by default for debug builds
2025-06-07 13:08:22 -04:00
Alex Kladov
173bc42744
langref: undefined _is_ materialized in all safe modes (#24107)
* trailing whitespace

* langref: undefined _is_ materialized in all safe modes

I am also not super happy about the clause that immediately follows. I
_believe_ what we want to say here is that, simultaneously:

* undefined is guaranteed to be matrerialized in in all safe modes.
  A Zig implementation that elides `ptr.* = undefined` in ReleaseSafe
  mode would be a non-conforming implementation.
* A Zig program that relies on undefined being materialized is buggy.

But I don't think it's the time to engage this level of language-lawering!
2025-06-07 10:07:53 -07:00
Andrew Kelley
a59d18779f langref: global assembly test depends on llvm
see #24046
2025-06-06 23:42:14 -07:00