Commit graph

1310 commits

Author SHA1 Message Date
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
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
4315a57233 langref: update nav link for 0.14.1 2025-05-23 14:43:47 -07:00
dweiller
5cba7c8562 langref: document @memmove 2025-04-26 13:34:17 +10: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
Андрей Краевский
aac800ec65
std.meta.FieldType -> @FieldType 2025-03-27 03:49:38 +00: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
Linus Groh
79460d4a3e Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
Andrew Kelley
5ad91a646a Release 0.14.0 2025-03-04 14:31:02 -08:00
Andrew Kelley
de43f5eb6a rename "nonce" to "fingerprint" 2025-02-26 11:42:04 -08:00
Andrew Kelley
ea516f0e81 bump package id component to 32 bits
and to make the base64 round even, bump sha256 to 200 bits (up from 192)
2025-02-26 11:42:04 -08:00
Andrew Kelley
0fc7c9f57c switch from "id" to "nonce"
mainly this addresses the following use case:

1. Someone creates a template with build.zig.zon, id field included
   (note that zig init does not create this problem since it generates
   fresh id every time it runs).
2. User A uses the template, changing package name to "example" but not
   id field.
3. User B uses the same template, changing package name also to
   "example", also not changing the id field.

Here, both packages have unintentional conflicting logical ids.

By making the field a combination of name checksum + random id, this
accident is avoided. "nonce" is an OK name for this.

Also relaxes errors on remote packages when using `zig fetch`.
2025-02-26 11:42:03 -08:00
Andrew Kelley
d6a88ed74d introduce package id and redo hash format again
Introduces the `id` field to `build.zig.zon`.

Together with name, this represents a globally unique package
identifier. This field should be initialized with a 16-bit random number
when the package is first created, and then *never change*. This allows
Zig to unambiguously detect when one package is an updated version of
another.

When forking a Zig project, this id should be regenerated with a new
random number if the upstream project is still maintained. Otherwise,
the fork is *hostile*, attempting to take control over the original
project's identity.

`0x0000` is invalid because it obviously means a random number wasn't
used.

`0xffff` is reserved to represent "naked" packages.

Tracking issue #14288

Additionally:

* Fix bad path in error messages regarding build.zig.zon file.
* Manifest validates that `name` and `version` field of build.zig.zon
  are maximum 32 bytes.
* Introduce error for root package to not switch to enum literal for
  name.
* Introduce error for root package to omit `id`.
* Update init template to generate `id`
* Update init template to populate `minimum_zig_version`.
* New package hash format changes:
  - name and version limited to 32 bytes via error rather than truncation
  - truncate sha256 to 192 bits rather than 40 bits
  - include the package id

This means that, given only the package hashes for a complete dependency
tree, it is possible to perform version selection and know the final
size on disk, without doing any fetching whatsoever. This prevents
wasted bandwidth since package versions not selected do not need to be
fetched.
2025-02-26 11:42:03 -08:00
mlugg
cc64295a63
langref: document modules, root source files, etc 2025-02-22 21:01:44 +00:00
mlugg
f0b331e95a
langref: embrace the term "illegal behavior"
Also standardise the terms "safety-checked" and "unchecked".
2025-02-22 21:01:44 +00:00
mlugg
def7e2f20a
langref: improve description of @fieldParentPtr 2025-02-22 21:01:44 +00:00
Meghan Denny
933ba935c5
std.BoundedArray: popOrNull() -> pop() [v2] (#22723) 2025-02-09 11:46:15 +00:00
Frank Plowman
bf7bc4ff01 langref/errorset: Replace subset description with union
The previous language using subsets was really just stating a couple
of the properties of the union of a group of sets, and with a minor
error at that.
2025-02-07 03:38:44 +01:00
mlugg
249a20d972 langref: clarify restricted @memcpy semantics 2025-01-29 18:43:57 +00:00
87
183bb8b084
langref: Document destructuring (#21627) 2025-01-28 04:23:13 +00:00
isaac yonemoto
ae5b1a9ca2 langref: fixes incorrect description of cmpxchg functions 2025-01-26 23:22:04 +01:00
bsubei
3f245616a5 link to Tuples section in Hello World docs, and give an example of an empty tuple 2025-01-26 20:53:25 +01:00
rpkak
9c45fb4b09 langref: correct return type of comptime known bitcount ops 2025-01-26 20:30:06 +01:00
kj4tmp@gmail.com
6255ee3d2f fix typo in @typeName langref 2025-01-26 19:40:57 +01:00
ExeVirus
738d813619
Add zig std to langref.html (#22360) 2025-01-26 18:58:30 +01:00
Andrew Kelley
6d67658965 langref: move pointer casting section out of volatile subsection 2024-12-30 22:05:30 -08:00
Jonathan Marler
77c63ac360 doc: mention zig can't use URLs if their content changes
There's been some proliferation of dependency URLs that reference
mutable data such as links to git branches that can change.  This has
resulted in broken projects, i.e.

* 9eef9de94c/build.zig.zon
* 4b64353e9c

There's also disagreement about whether it's fine for URL's to point to
git branches, i.e.

https://github.com/Not-Nik/raylib-zig/pull/130

This updates the docs to mention that zig won't be able to use URLs if
their content changes.
2024-12-21 18:23:01 -05:00
Andrew Kelley
3ce6de8765 revert langref section "common errdefer slip ups"
This does not belong in the language reference.

reverts 91a88a789f
2024-11-26 15:03:24 -08:00
Andrew Kelley
bfcf18c5a7 langref: delete misleading example code about packed structs 2024-11-13 15:35:16 -08:00
Roman Frołow
c39ba682e3 typo: will inlined -> will be inlined 2024-10-29 17:52:55 -07:00
llogick
985b13934d Remove @setAlignStack from the langref 2024-10-25 15:13:41 +02:00
mlugg
04ffc1c963
langref: update enum_export_error.zig for callconv changes 2024-10-19 19:21:33 +01:00
mlugg
097766bba3 compiler: implement @FieldType
Resolves: #21702
2024-10-18 08:50:40 +01:00
wooster0
816dfca0b5 langref: update builtin variadic functions
Documentation was outdated.
2024-10-17 11:51:06 +03:00