authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-22 02:26:46-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-22 02:26:46-08:00
logb0c8a3f31631a63bca3a2feece38e57b9a1c5060
tree8428815a61dac26778872cc588713593335b4bea
parentfdb4eb3056ee85709f8d1af6c11641481de5e653
parentce7c66e2d0ccaf0265f2c2afce9824c9b9ae6123
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #18644 from ziglang/langref


4 files changed, 245 insertions(+), 396 deletions(-)

doc/langref.html.in+216-365
...@@ -8,7 +8,7 @@...@@ -8,7 +8,7 @@
8 <link rel="icon" href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNTMgMTQwIj48ZyBmaWxsPSIjRjdBNDFEIj48Zz48cG9seWdvbiBwb2ludHM9IjQ2LDIyIDI4LDQ0IDE5LDMwIi8+PHBvbHlnb24gcG9pbnRzPSI0NiwyMiAzMywzMyAyOCw0NCAyMiw0NCAyMiw5NSAzMSw5NSAyMCwxMDAgMTIsMTE3IDAsMTE3IDAsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMzEsOTUgMTIsMTE3IDQsMTA2Ii8+PC9nPjxnPjxwb2x5Z29uIHBvaW50cz0iNTYsMjIgNjIsMzYgMzcsNDQiLz48cG9seWdvbiBwb2ludHM9IjU2LDIyIDExMSwyMiAxMTEsNDQgMzcsNDQgNTYsMzIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTE2LDk1IDk3LDExNyA5MCwxMDQiLz48cG9seWdvbiBwb2ludHM9IjExNiw5NSAxMDAsMTA0IDk3LDExNyA0MiwxMTcgNDIsOTUiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTUwLDAgNTIsMTE3IDMsMTQwIDEwMSwyMiIvPjwvZz48Zz48cG9seWdvbiBwb2ludHM9IjE0MSwyMiAxNDAsNDAgMTIyLDQ1Ii8+PHBvbHlnb24gcG9pbnRzPSIxNTMsMjIgMTUzLDExNyAxMDYsMTE3IDEyMCwxMDUgMTI1LDk1IDEzMSw5NSAxMzEsNDUgMTIyLDQ1IDEzMiwzNiAxNDEsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTI1LDk1IDEzMCwxMTAgMTA2LDExNyIvPjwvZz48L2c+PC9zdmc+">8 <link rel="icon" href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNTMgMTQwIj48ZyBmaWxsPSIjRjdBNDFEIj48Zz48cG9seWdvbiBwb2ludHM9IjQ2LDIyIDI4LDQ0IDE5LDMwIi8+PHBvbHlnb24gcG9pbnRzPSI0NiwyMiAzMywzMyAyOCw0NCAyMiw0NCAyMiw5NSAzMSw5NSAyMCwxMDAgMTIsMTE3IDAsMTE3IDAsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMzEsOTUgMTIsMTE3IDQsMTA2Ii8+PC9nPjxnPjxwb2x5Z29uIHBvaW50cz0iNTYsMjIgNjIsMzYgMzcsNDQiLz48cG9seWdvbiBwb2ludHM9IjU2LDIyIDExMSwyMiAxMTEsNDQgMzcsNDQgNTYsMzIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTE2LDk1IDk3LDExNyA5MCwxMDQiLz48cG9seWdvbiBwb2ludHM9IjExNiw5NSAxMDAsMTA0IDk3LDExNyA0MiwxMTcgNDIsOTUiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTUwLDAgNTIsMTE3IDMsMTQwIDEwMSwyMiIvPjwvZz48Zz48cG9seWdvbiBwb2ludHM9IjE0MSwyMiAxNDAsNDAgMTIyLDQ1Ii8+PHBvbHlnb24gcG9pbnRzPSIxNTMsMjIgMTUzLDExNyAxMDYsMTE3IDEyMCwxMDUgMTI1LDk1IDEzMSw5NSAxMzEsNDUgMTIyLDQ1IDEzMiwzNiAxNDEsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTI1LDk1IDEzMCwxMTAgMTA2LDExNyIvPjwvZz48L2c+PC9zdmc+">
9 <style>9 <style>
10 :root{10 :root{
11 --nav-width: 24em;11 --nav-width: 26em;
12 --nav-margin-l: 1em;12 --nav-margin-l: 1em;
13 }13 }
14 body{14 body{
...@@ -27,6 +27,25 @@...@@ -27,6 +27,25 @@
27 #navigation {27 #navigation {
28 padding: 0 1em;28 padding: 0 1em;
29 }29 }
30 table ul {
31 list-style-type: none;
32 padding: 0em;
33 }
34 table li {
35 padding-bottom: 1em;
36 line-height:1.2em;
37 }
38 table, th, td {
39 border-collapse: collapse;
40 border: 1px solid grey;
41 }
42 th, td {
43 padding: 0.5em;
44 }
45 th[scope=row] {
46 text-align: left;
47 font-weight: normal;
48 }
3049
31 @media screen and (min-width: 1025px) {50 @media screen and (min-width: 1025px) {
32 header {51 header {
...@@ -61,17 +80,6 @@...@@ -61,17 +80,6 @@
61 dt {80 dt {
62 font-weight: bold;81 font-weight: bold;
63 }82 }
64 table, th, td {
65 border-collapse: collapse;
66 border: 1px solid grey;
67 }
68 th, td {
69 padding: 0.1em;
70 }
71 th[scope=row] {
72 text-align: left;
73 font-weight: normal;
74 }
75 .sgr-1m {83 .sgr-1m {
76 font-weight: bold;84 font-weight: bold;
77 }85 }
...@@ -200,24 +208,9 @@...@@ -200,24 +208,9 @@
200 visibility: visible;208 visibility: visible;
201 }209 }
202210
203 pre {
204 counter-reset: line;
205 }
206 pre .line:before {
207 counter-increment: line;
208 content: counter(line);
209 display: inline-block;
210 padding-right: 1em;
211 width: 2em;
212 text-align: right;
213 color: #999;
214 }
215 th pre code {211 th pre code {
216 background: none;212 background: none;
217 }213 }
218 th .line:before {
219 display: none;
220 }
221214
222 @media (prefers-color-scheme: dark) {215 @media (prefers-color-scheme: dark) {
223 body{216 body{
...@@ -301,39 +294,6 @@...@@ -301,39 +294,6 @@
301 color: #fff;294 color: #fff;
302 }295 }
303 }296 }
304
305 @media all {
306 main {
307 counter-reset: section-2;
308 }
309 h2 {
310 counter-reset: section-3;
311 }
312 h2::before {
313 counter-increment: section-2;
314 content: counter(section-2) ". ";
315 font-weight: normal;
316 }
317 h3 {
318 counter-reset: section-4;
319 }
320 h3::before {
321 counter-increment: section-3;
322 content: counter(section-2) "." counter(section-3) ". ";
323 font-weight: normal;
324 }
325 h4::before {
326 counter-increment: section-4;
327 content: counter(section-2) "." counter(section-3) "." counter(section-4) ". ";
328 font-weight: normal;
329 }
330 #zig-version::before {
331 content: "";
332 }
333 #table-of-contents::before {
334 content: "";
335 }
336 }
337 </style>297 </style>
338</head>298</head>
339<body>299<body>
...@@ -410,109 +370,20 @@ pub fn main() !void {...@@ -410,109 +370,20 @@ pub fn main() !void {
410}370}
411 {#code_end#}371 {#code_end#}
412 <p>372 <p>
413 The Zig code sample above demonstrates one way to create a program that will output: <samp>Hello, world!</samp>.373 Most of the time, it more appropriate to write to stderr rather than stdout, and
414 </p>374 whether or not the message is successfully written to the stream is irrelevant.
415 <p>375 For this common case, there is a simpler API:
416 The code sample shows the contents of a file named <code class="file">hello.zig</code>. Files storing Zig
417 source code are {#link|UTF-8 encoded|Source Encoding#} text files. The files storing
418 Zig source code must be named with the <code class="file"><em>.zig</em></code> extension.
419 </p>
420 <p>
421 Following the <code class="file">hello.zig</code> Zig code sample, the {#link|Zig Build System#} is used
422 to build an executable program from the <code class="file">hello.zig</code> source code. Then, the
423 <code class="file">hello</code> program is executed showing its output <samp>Hello, world!</samp>. The
424 lines beginning with <samp>$</samp> represent command line prompts and a command.
425 Everything else is program output.
426 </p>
427 <p>
428 The code sample begins by adding the {#link|Zig Standard Library#} to the build using the {#link|@import#} builtin function.
429 The {#syntax#}@import("std"){#endsyntax#} function call creates a structure that represents the Zig Standard Library.
430 The code then {#link|declares|Container Level Variables#} a
431 {#link|constant identifier|Assignment#}, named {#syntax#}std{#endsyntax#}, that gives access to the features of the Zig Standard Library.
432 </p>
433 <p>
434 Next, a {#link|public function|Functions#}, {#syntax#}pub fn{#endsyntax#}, named {#syntax#}main{#endsyntax#}
435 is declared. The {#syntax#}main{#endsyntax#} function is necessary because it tells the Zig compiler where the program starts. Programs
436 designed to be executed will need a {#syntax#}pub fn main{#endsyntax#} function.
437 </p>
438 <aside role="note" aria-label="Note about main function">
439 <p>
440 For more advanced use cases, Zig offers other features to inform the compiler where the program starts. Also, libraries do not need a
441 {#syntax#}pub fn main{#endsyntax#} function because library code is called by other programs or libraries.
442 </p>
443 </aside>
444 <p>
445 A function is a block of any number of statements and expressions, that as a whole, perform a task.
446 Functions may or may not return data after they are done performing their task. If a function
447 cannot perform its task, it might return an error. Zig makes all of this explicit.
448 </p>
449 <p>
450 In the <code class="file">hello.zig</code> code sample, the <code>main</code> function is declared
451 with the {#syntax#}!void{#endsyntax#} return type. This return type is known as an {#link|Error Union Type#}.
452 This syntax tells the Zig compiler that the function will either return an
453 error or a value. An error union type combines an {#link|Error Set Type#} and any other data type
454 (e.g. a {#link|Primitive Type|Primitive Types#} or a user-defined type such as a {#link|struct#}, {#link|enum#}, or {#link|union#}).
455 The full form of an error union type is
456 <code>&lt;error set type&gt;</code>{#syntax#}!{#endsyntax#}<code>&lt;any data type&gt;</code>. In the code
457 sample, the error set type is not explicitly written on the left side of the {#syntax#}!{#endsyntax#} operator.
458 When written this way, the error set type is an {#link|inferred error set type|Inferred Error Sets#}. The
459 {#syntax#}void{#endsyntax#} after the {#syntax#}!{#endsyntax#} operator
460 tells the compiler that the function will not return a value under normal circumstances (i.e. when no errors occur).
461 </p>
462 <aside role="note" aria-label="Note to disambiguate exclamation mark operator">
463 <p>
464 Note to experienced programmers: Zig also has the boolean {#link|operator|Operators#} {#syntax#}!a{#endsyntax#}
465 where {#syntax#}a{#endsyntax#} is a value of type {#syntax#}bool{#endsyntax#}. Error union types contain the
466 name of the type in the syntax: {#syntax#}!{#endsyntax#}<code>&lt;any data type&gt;</code>.
467 </p>
468 </aside>
469 <p>
470 In Zig, a function's block of statements and expressions are surrounded by an open curly-brace <code>{</code> and
471 close curly-brace <code>}</code>. In <code class="file">hello.zig</code>, the {#syntax#}main{#endsyntax#} function
472 contains two statements.
473 </p>
474 <p>
475 In the first statement, a constant identifier, {#syntax#}stdout{#endsyntax#}, is initialized to represent standard output's
476 writer. In the second statement, the program tries to print the <samp>Hello, world!</samp> message to standard output.
477 </p>
478 <p>
479 Functions sometimes need inputs to perform their task. Inputs are passed, in between parentheses, to functions. These
480 inputs are also known as arguments. When multiple arguments are passed to a function, they are separated by commas.
481 </p>
482 <p>
483 Two arguments are passed to the {#syntax#}stdout.print(){#endsyntax#} function: {#syntax#}"Hello, {s}!\n"{#endsyntax#}
484 and {#syntax#}.{"world"}{#endsyntax#}. The first argument is called a format string, which is a string containing one or
485 more placeholders. {#syntax#}"Hello, {s}!\n"{#endsyntax#} contains the placeholder {#syntax#}{s}{#endsyntax#}, which is
486 replaced with {#syntax#}"world"{#endsyntax#} from the second argument. The file <code class="file">string_literals.zig</code> in
487 {#link|String Literals and Unicode Code Point Literals|String Literals and Unicode Code Point Literals#} contains examples of format
488 strings that can be used with the {#syntax#}stdout.print(){#endsyntax#} function. The <code>\n</code> inside of
489 {#syntax#}"Hello, {s}!\n"{#endsyntax#} is the {#link|escape sequence|Escape Sequences#} for the newline character.
490 </p>
491 <p>
492 The {#link|try#} expression evaluates the result of {#syntax#}stdout.print{#endsyntax#}. If the result is an error, then the
493 {#syntax#}try{#endsyntax#} expression will return from {#syntax#}main{#endsyntax#} with the error. Otherwise, the program will continue.
494 In this case, there are no more statements or expressions left to execute in the {#syntax#}main{#endsyntax#} function, so the program exits.
495 </p>
496 <p>
497 In Zig, the standard output writer's {#syntax#}print{#endsyntax#} function is allowed to fail because
498 it is actually a function defined as part of a generic Writer. Consider a generic Writer that
499 represents writing data to a file. When the disk is full, a write to the file will fail.
500 However, we typically do not expect writing text to the standard output to fail. To avoid having
501 to handle the failure case of printing to standard output, you can use alternate functions: the
502 functions in {#syntax#}std.log{#endsyntax#} for proper logging or the {#syntax#}std.debug.print{#endsyntax#} function.
503 This documentation will use the latter option to print to standard error (stderr) and silently return
504 on failure. The next code sample, <code class="file">hello_again.zig</code> demonstrates the use of
505 {#syntax#}std.debug.print{#endsyntax#}.
506 </p>376 </p>
507 {#code_begin|exe|hello_again#}377 {#code_begin|exe|hello_again#}
508const print = @import("std").debug.print;378const std = @import("std");
509379
510pub fn main() void {380pub fn main() void {
511 print("Hello, world!\n", .{});381 std.debug.print("Hello, world!\n", .{});
512}382}
513 {#code_end#}383 {#code_end#}
514 <p>384 <p>
515 Note that you can leave off the {#syntax#}!{#endsyntax#} from the return type because {#syntax#}std.debug.print{#endsyntax#} cannot fail.385 In this case, the {#syntax#}!{#endsyntax#} may be omitted from the return
386 type because no errors are returned from the function.
516 </p>387 </p>
517 {#see_also|Values|@import|Errors|Root Source File|Source Encoding#}388 {#see_also|Values|@import|Errors|Root Source File|Source Encoding#}
518 {#header_close#}389 {#header_close#}
...@@ -896,42 +767,22 @@ pub fn main() void {...@@ -896,42 +767,22 @@ pub fn main() void {
896 The type of string literals encodes both the length, and the fact that they are null-terminated,767 The type of string literals encodes both the length, and the fact that they are null-terminated,
897 and thus they can be {#link|coerced|Type Coercion#} to both {#link|Slices#} and768 and thus they can be {#link|coerced|Type Coercion#} to both {#link|Slices#} and
898 {#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}.769 {#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}.
770 Dereferencing string literals converts them to {#link|Arrays#}.
899 </p>771 </p>
900 <p>772 <p>
901 Dereferencing string literals converts them to {#link|Arrays#}, allowing you to initialize a buffer with the contents of a string literal.773 Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any
902 </p>774 non-ASCII bytes appearing within a string literal in source code carry
903 {#code_begin|syntax|mutable_string_buffer#}775 their UTF-8 meaning into the content of the string in the Zig program;
904test {776 the bytes are not modified by the compiler. It is possible to embed
905 var buffer = [_]u8{0}**256;777 non-UTF-8 bytes into a string literal using <code>\xNN</code> notation.
906 const home_dir = "C:/Users/root";
907 buffer[0..home_dir.len].* = home_dir.*;
908}
909 {#code_end#}
910 <p>
911 The encoding of a string in Zig is de-facto assumed to be UTF-8.
912 Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any non-ASCII bytes appearing within a string literal
913 in source code carry their UTF-8 meaning into the content of the string in the Zig program;
914 the bytes are not modified by the compiler.
915 However, it is possible to embed non-UTF-8 bytes into a string literal using <code>\xNN</code> notation.
916 </p>
917 <p>
918 Indexing into a string containing non-ASCII bytes will return individual bytes, whether valid
919 UTF-8 or not.
920 The {#link|Zig Standard Library#} provides routines for checking the validity of UTF-8 encoded
921 strings, accessing their code points and other encoding/decoding related tasks in
922 {#syntax#}std.unicode{#endsyntax#}.
923 </p>778 </p>
779 <p>Indexing into a string containing non-ASCII bytes returns individual
780 bytes, whether valid UTF-8 or not.</p>
924 <p>781 <p>
925 Unicode code point literals have type {#syntax#}comptime_int{#endsyntax#}, the same as782 Unicode code point literals have type {#syntax#}comptime_int{#endsyntax#}, the same as
926 {#link|Integer Literals#}. All {#link|Escape Sequences#} are valid in both string literals783 {#link|Integer Literals#}. All {#link|Escape Sequences#} are valid in both string literals
927 and Unicode code point literals.784 and Unicode code point literals.
928 </p>785 </p>
929 <p>
930 In many other programming languages, a Unicode code point literal is called a "character literal".
931 However, there is <a href="https://unicode.org/glossary">no precise technical definition of a "character"</a>
932 in recent versions of the Unicode specification (as of Unicode 13.0).
933 In Zig, a Unicode code point literal corresponds to the Unicode definition of a code point.
934 </p>
935 {#code_begin|exe|string_literals#}786 {#code_begin|exe|string_literals#}
936const print = @import("std").debug.print;787const print = @import("std").debug.print;
937const mem = @import("std").mem; // will be used to compare bytes788const mem = @import("std").mem; // will be used to compare bytes
...@@ -1632,26 +1483,27 @@ pub fn main() void {...@@ -1632,26 +1483,27 @@ pub fn main() void {
1632 {#header_open|Table of Operators#}1483 {#header_open|Table of Operators#}
1633 <div class="table-wrapper">1484 <div class="table-wrapper">
1634 <table>1485 <table>
1635 <caption>Table of Operators</caption>
1636 <thead>1486 <thead>
1637 <tr>1487 <tr>
1488 <th scope="col">Name</th>
1638 <th scope="col">Syntax</th>1489 <th scope="col">Syntax</th>
1639 <th scope="col">Relevant Types</th>1490 <th scope="col">Types</th>
1640 <th scope="col">Description</th>1491 <th scope="col">Remarks</th>
1641 <th scope="col">Example</th>1492 <th scope="col">Example</th>
1642 </tr>1493 </tr>
1643 </thead>1494 </thead>
1644 <tbody>1495 <tbody>
1645 <tr>1496 <tr>
1646 <th scope="row"><pre>{#syntax#}a + b1497 <td>Addition</td>
1647a += b{#endsyntax#}</pre></th>1498 <td><pre>{#syntax#}a + b
1499a += b{#endsyntax#}</pre></td>
1648 <td>1500 <td>
1649 <ul>1501 <ul>
1650 <li>{#link|Integers#}</li>1502 <li>{#link|Integers#}</li>
1651 <li>{#link|Floats#}</li>1503 <li>{#link|Floats#}</li>
1652 </ul>1504 </ul>
1653 </td>1505 </td>
1654 <td>Addition.1506 <td>
1655 <ul>1507 <ul>
1656 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>1508 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
1657 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1509 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
...@@ -1663,51 +1515,54 @@ a += b{#endsyntax#}</pre></th>...@@ -1663,51 +1515,54 @@ a += b{#endsyntax#}</pre></th>
1663 </td>1515 </td>
1664 </tr>1516 </tr>
1665 <tr>1517 <tr>
1666 <th scope="row"><pre>{#syntax#}a +% b1518 <td>Wrapping Addition</td>
1667a +%= b{#endsyntax#}</pre></th>1519 <td><pre>{#syntax#}a +% b
1520a +%= b{#endsyntax#}</pre></td>
1668 <td>1521 <td>
1669 <ul>1522 <ul>
1670 <li>{#link|Integers#}</li>1523 <li>{#link|Integers#}</li>
1671 </ul>1524 </ul>
1672 </td>1525 </td>
1673 <td>Wrapping Addition.1526 <td>
1674 <ul>1527 <ul>
1675 <li>Guaranteed to have twos-complement wrapping behavior.</li>1528 <li>Twos-complement wrapping behavior.</li>
1676 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1529 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1677 <li>See also {#link|@addWithOverflow#}.</li>1530 <li>See also {#link|@addWithOverflow#}.</li>
1678 </ul>1531 </ul>
1679 </td>1532 </td>
1680 <td>1533 <td>
1681 <pre>{#syntax#}@as(u32, std.math.maxInt(u32)) +% 1 == 0{#endsyntax#}</pre>1534 <pre>{#syntax#}@as(u32, 0xffffffff) +% 1 == 0{#endsyntax#}</pre>
1682 </td>1535 </td>
1683 </tr>1536 </tr>
1684 <tr>1537 <tr>
1685 <th scope="row"><pre>{#syntax#}a +| b1538 <td>Saturating Addition</td>
1686a +|= b{#endsyntax#}</pre></th>1539 <td><pre>{#syntax#}a +| b
1540a +|= b{#endsyntax#}</pre></td>
1687 <td>1541 <td>
1688 <ul>1542 <ul>
1689 <li>{#link|Integers#}</li>1543 <li>{#link|Integers#}</li>
1690 </ul>1544 </ul>
1691 </td>1545 </td>
1692 <td>Saturating Addition.1546 <td>
1693 <ul>1547 <ul>
1694 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1548 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1695 </ul>1549 </ul>
1696 </td>1550 </td>
1697 <td>1551 <td>
1698 <pre>{#syntax#}@as(u32, std.math.maxInt(u32)) +| 1 == @as(u32, std.math.maxInt(u32)){#endsyntax#}</pre>1552 <pre>{#syntax#}@as(u8, 255) +| 1 == @as(u8, 255){#endsyntax#}</pre>
1699 </td>1553 </td>
1700 </tr>1554 </tr>
1701 <tr>1555 <tr>
1702 <th scope="row"><pre>{#syntax#}a - b1556 <td>Subtraction</td>
1703a -= b{#endsyntax#}</pre></th>1557 <td><pre>{#syntax#}a - b
1558a -= b{#endsyntax#}</pre></td>
1704 <td>1559 <td>
1705 <ul>1560 <ul>
1706 <li>{#link|Integers#}</li>1561 <li>{#link|Integers#}</li>
1707 <li>{#link|Floats#}</li>1562 <li>{#link|Floats#}</li>
1708 </ul>1563 </ul>
1709 </td>1564 </td>
1710 <td>Subtraction.1565 <td>
1711 <ul>1566 <ul>
1712 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>1567 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
1713 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1568 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
...@@ -1719,33 +1574,35 @@ a -= b{#endsyntax#}</pre></th>...@@ -1719,33 +1574,35 @@ a -= b{#endsyntax#}</pre></th>
1719 </td>1574 </td>
1720 </tr>1575 </tr>
1721 <tr>1576 <tr>
1722 <th scope="row"><pre>{#syntax#}a -% b1577 <td>Wrapping Subtraction</td>
1723a -%= b{#endsyntax#}</pre></th>1578 <td><pre>{#syntax#}a -% b
1579a -%= b{#endsyntax#}</pre></td>
1724 <td>1580 <td>
1725 <ul>1581 <ul>
1726 <li>{#link|Integers#}</li>1582 <li>{#link|Integers#}</li>
1727 </ul>1583 </ul>
1728 </td>1584 </td>
1729 <td>Wrapping Subtraction.1585 <td>
1730 <ul>1586 <ul>
1731 <li>Guaranteed to have twos-complement wrapping behavior.</li>1587 <li>Twos-complement wrapping behavior.</li>
1732 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1588 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1733 <li>See also {#link|@subWithOverflow#}.</li>1589 <li>See also {#link|@subWithOverflow#}.</li>
1734 </ul>1590 </ul>
1735 </td>1591 </td>
1736 <td>1592 <td>
1737 <pre>{#syntax#}@as(u32, 0) -% 1 == std.math.maxInt(u32){#endsyntax#}</pre>1593 <pre>{#syntax#}@as(u8, 0) -% 1 == 255{#endsyntax#}</pre>
1738 </td>1594 </td>
1739 </tr>1595 </tr>
1740 <tr>1596 <tr>
1741 <th scope="row"><pre>{#syntax#}a -| b1597 <td>Saturating Subtraction</td>
1742a -|= b{#endsyntax#}</pre></th>1598 <td><pre>{#syntax#}a -| b
1599a -|= b{#endsyntax#}</pre></td>
1743 <td>1600 <td>
1744 <ul>1601 <ul>
1745 <li>{#link|Integers#}</li>1602 <li>{#link|Integers#}</li>
1746 </ul>1603 </ul>
1747 </td>1604 </td>
1748 <td>Saturating Subtraction.1605 <td>
1749 <ul>1606 <ul>
1750 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1607 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1751 </ul>1608 </ul>
...@@ -1755,7 +1612,8 @@ a -|= b{#endsyntax#}</pre></th>...@@ -1755,7 +1612,8 @@ a -|= b{#endsyntax#}</pre></th>
1755 </td>1612 </td>
1756 </tr>1613 </tr>
1757 <tr>1614 <tr>
1758 <th scope="row"><pre>{#syntax#}-a{#endsyntax#}</pre></th>1615 <td>Negation</td>
1616 <td><pre>{#syntax#}-a{#endsyntax#}</pre></td>
1759 <td>1617 <td>
1760 <ul>1618 <ul>
1761 <li>{#link|Integers#}</li>1619 <li>{#link|Integers#}</li>
...@@ -1763,7 +1621,6 @@ a -|= b{#endsyntax#}</pre></th>...@@ -1763,7 +1621,6 @@ a -|= b{#endsyntax#}</pre></th>
1763 </ul>1621 </ul>
1764 </td>1622 </td>
1765 <td>1623 <td>
1766 Negation.
1767 <ul>1624 <ul>
1768 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>1625 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
1769 </ul>1626 </ul>
...@@ -1773,32 +1630,33 @@ a -|= b{#endsyntax#}</pre></th>...@@ -1773,32 +1630,33 @@ a -|= b{#endsyntax#}</pre></th>
1773 </td>1630 </td>
1774 </tr>1631 </tr>
1775 <tr>1632 <tr>
1776 <th scope="row"><pre>{#syntax#}-%a{#endsyntax#}</pre></th>1633 <td>Wrapping Negation</td>
1634 <td><pre>{#syntax#}-%a{#endsyntax#}</pre></td>
1777 <td>1635 <td>
1778 <ul>1636 <ul>
1779 <li>{#link|Integers#}</li>1637 <li>{#link|Integers#}</li>
1780 </ul>1638 </ul>
1781 </td>1639 </td>
1782 <td>1640 <td>
1783 Wrapping Negation.
1784 <ul>1641 <ul>
1785 <li>Guaranteed to have twos-complement wrapping behavior.</li>1642 <li>Twos-complement wrapping behavior.</li>
1786 </ul>1643 </ul>
1787 </td>1644 </td>
1788 <td>1645 <td>
1789 <pre>{#syntax#}-%@as(i32, std.math.minInt(i32)) == std.math.minInt(i32){#endsyntax#}</pre>1646 <pre>{#syntax#}-%@as(i8, -127) == -127{#endsyntax#}</pre>
1790 </td>1647 </td>
1791 </tr>1648 </tr>
1792 <tr>1649 <tr>
1793 <th scope="row"><pre>{#syntax#}a * b1650 <td>Multiplication</td>
1794a *= b{#endsyntax#}</pre></th>1651 <td><pre>{#syntax#}a * b
1652a *= b{#endsyntax#}</pre></td>
1795 <td>1653 <td>
1796 <ul>1654 <ul>
1797 <li>{#link|Integers#}</li>1655 <li>{#link|Integers#}</li>
1798 <li>{#link|Floats#}</li>1656 <li>{#link|Floats#}</li>
1799 </ul>1657 </ul>
1800 </td>1658 </td>
1801 <td>Multiplication.1659 <td>
1802 <ul>1660 <ul>
1803 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>1661 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
1804 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1662 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
...@@ -1810,16 +1668,17 @@ a *= b{#endsyntax#}</pre></th>...@@ -1810,16 +1668,17 @@ a *= b{#endsyntax#}</pre></th>
1810 </td>1668 </td>
1811 </tr>1669 </tr>
1812 <tr>1670 <tr>
1813 <th scope="row"><pre>{#syntax#}a *% b1671 <td>Wrapping Multiplication</td>
1814a *%= b{#endsyntax#}</pre></th>1672 <td><pre>{#syntax#}a *% b
1673a *%= b{#endsyntax#}</pre></td>
1815 <td>1674 <td>
1816 <ul>1675 <ul>
1817 <li>{#link|Integers#}</li>1676 <li>{#link|Integers#}</li>
1818 </ul>1677 </ul>
1819 </td>1678 </td>
1820 <td>Wrapping Multiplication.1679 <td>
1821 <ul>1680 <ul>
1822 <li>Guaranteed to have twos-complement wrapping behavior.</li>1681 <li>Twos-complement wrapping behavior.</li>
1823 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1682 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1824 <li>See also {#link|@mulWithOverflow#}.</li>1683 <li>See also {#link|@mulWithOverflow#}.</li>
1825 </ul>1684 </ul>
...@@ -1829,14 +1688,15 @@ a *%= b{#endsyntax#}</pre></th>...@@ -1829,14 +1688,15 @@ a *%= b{#endsyntax#}</pre></th>
1829 </td>1688 </td>
1830 </tr>1689 </tr>
1831 <tr>1690 <tr>
1832 <th scope="row"><pre>{#syntax#}a *| b1691 <td>Saturating Multiplication</td>
1833a *|= b{#endsyntax#}</pre></th>1692 <td><pre>{#syntax#}a *| b
1693a *|= b{#endsyntax#}</pre></td>
1834 <td>1694 <td>
1835 <ul>1695 <ul>
1836 <li>{#link|Integers#}</li>1696 <li>{#link|Integers#}</li>
1837 </ul>1697 </ul>
1838 </td>1698 </td>
1839 <td>Saturating Multiplication.1699 <td>
1840 <ul>1700 <ul>
1841 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1701 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1842 </ul>1702 </ul>
...@@ -1846,15 +1706,16 @@ a *|= b{#endsyntax#}</pre></th>...@@ -1846,15 +1706,16 @@ a *|= b{#endsyntax#}</pre></th>
1846 </td>1706 </td>
1847 </tr>1707 </tr>
1848 <tr>1708 <tr>
1849 <th scope="row"><pre>{#syntax#}a / b1709 <td>Division</td>
1850a /= b{#endsyntax#}</pre></th>1710 <td><pre>{#syntax#}a / b
1711a /= b{#endsyntax#}</pre></td>
1851 <td>1712 <td>
1852 <ul>1713 <ul>
1853 <li>{#link|Integers#}</li>1714 <li>{#link|Integers#}</li>
1854 <li>{#link|Floats#}</li>1715 <li>{#link|Floats#}</li>
1855 </ul>1716 </ul>
1856 </td>1717 </td>
1857 <td>Division.1718 <td>
1858 <ul>1719 <ul>
1859 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>1720 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
1860 <li>Can cause {#link|Division by Zero#} for integers.</li>1721 <li>Can cause {#link|Division by Zero#} for integers.</li>
...@@ -1872,15 +1733,16 @@ a /= b{#endsyntax#}</pre></th>...@@ -1872,15 +1733,16 @@ a /= b{#endsyntax#}</pre></th>
1872 </td>1733 </td>
1873 </tr>1734 </tr>
1874 <tr>1735 <tr>
1875 <th scope="row"><pre>{#syntax#}a % b1736 <td>Remainder Division</td>
1876a %= b{#endsyntax#}</pre></th>1737 <td><pre>{#syntax#}a % b
1738a %= b{#endsyntax#}</pre></td>
1877 <td>1739 <td>
1878 <ul>1740 <ul>
1879 <li>{#link|Integers#}</li>1741 <li>{#link|Integers#}</li>
1880 <li>{#link|Floats#}</li>1742 <li>{#link|Floats#}</li>
1881 </ul>1743 </ul>
1882 </td>1744 </td>
1883 <td>Remainder Division.1745 <td>
1884 <ul>1746 <ul>
1885 <li>Can cause {#link|Division by Zero#} for integers.</li>1747 <li>Can cause {#link|Division by Zero#} for integers.</li>
1886 <li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li>1748 <li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li>
...@@ -1896,33 +1758,39 @@ a %= b{#endsyntax#}</pre></th>...@@ -1896,33 +1758,39 @@ a %= b{#endsyntax#}</pre></th>
1896 </td>1758 </td>
1897 </tr>1759 </tr>
1898 <tr>1760 <tr>
1899 <th scope="row"><pre>{#syntax#}a << b1761 <td>Bit Shift Left</td>
1900a <<= b{#endsyntax#}</pre></th>1762 <td><pre>{#syntax#}a << b
1763a <<= b{#endsyntax#}</pre></td>
1901 <td>1764 <td>
1902 <ul>1765 <ul>
1903 <li>{#link|Integers#}</li>1766 <li>{#link|Integers#}</li>
1904 </ul>1767 </ul>
1905 </td>1768 </td>
1906 <td>Bit Shift Left.1769 <td>
1907 <ul>1770 <ul>
1908 <li>{#syntax#}b{#endsyntax#} must be {#link|comptime-known|comptime#} or have a type with log2 number of bits as {#syntax#}a{#endsyntax#}.</li>1771 <li>Moves all bits to the left, inserting new zeroes at the
1772 least-significant bit.</li>
1773 <li>{#syntax#}b{#endsyntax#} must be
1774 {#link|comptime-known|comptime#} or have a type with log2 number
1775 of bits as {#syntax#}a{#endsyntax#}.</li>
1909 <li>See also {#link|@shlExact#}.</li>1776 <li>See also {#link|@shlExact#}.</li>
1910 <li>See also {#link|@shlWithOverflow#}.</li>1777 <li>See also {#link|@shlWithOverflow#}.</li>
1911 </ul>1778 </ul>
1912 </td>1779 </td>
1913 <td>1780 <td>
1914 <pre>{#syntax#}1 << 8 == 256{#endsyntax#}</pre>1781 <pre>{#syntax#}0b1 << 8 == 0b100000000{#endsyntax#}</pre>
1915 </td>1782 </td>
1916 </tr>1783 </tr>
1917 <tr>1784 <tr>
1918 <th scope="row"><pre>{#syntax#}a <<| b1785 <td>Saturating Bit Shift Left</td>
1919a <<|= b{#endsyntax#}</pre></th>1786 <td><pre>{#syntax#}a <<| b
1787a <<|= b{#endsyntax#}</pre></td>
1920 <td>1788 <td>
1921 <ul>1789 <ul>
1922 <li>{#link|Integers#}</li>1790 <li>{#link|Integers#}</li>
1923 </ul>1791 </ul>
1924 </td>1792 </td>
1925 <td>Saturating Bit Shift Left.1793 <td>
1926 <ul>1794 <ul>
1927 <li>See also {#link|@shlExact#}.</li>1795 <li>See also {#link|@shlExact#}.</li>
1928 <li>See also {#link|@shlWithOverflow#}.</li>1796 <li>See also {#link|@shlWithOverflow#}.</li>
...@@ -1933,32 +1801,37 @@ a <<|= b{#endsyntax#}</pre></th>...@@ -1933,32 +1801,37 @@ a <<|= b{#endsyntax#}</pre></th>
1933 </td>1801 </td>
1934 </tr>1802 </tr>
1935 <tr>1803 <tr>
1936 <th scope="row"><pre>{#syntax#}a >> b1804 <td>Bit Shift Right</td>
1937a >>= b{#endsyntax#}</pre></th>1805 <td><pre>{#syntax#}a >> b
1806a >>= b{#endsyntax#}</pre></td>
1938 <td>1807 <td>
1939 <ul>1808 <ul>
1940 <li>{#link|Integers#}</li>1809 <li>{#link|Integers#}</li>
1941 </ul>1810 </ul>
1942 </td>1811 </td>
1943 <td>Bit Shift Right.1812 <td>
1944 <ul>1813 <ul>
1945 <li>{#syntax#}b{#endsyntax#} must be {#link|comptime-known|comptime#} or have a type with log2 number of bits as {#syntax#}a{#endsyntax#}.</li>1814 <li>Moves all bits to the right, inserting zeroes at the most-significant bit.</li>
1815 <li>{#syntax#}b{#endsyntax#} must be
1816 {#link|comptime-known|comptime#} or have a type with log2 number
1817 of bits as {#syntax#}a{#endsyntax#}.</li>
1946 <li>See also {#link|@shrExact#}.</li>1818 <li>See also {#link|@shrExact#}.</li>
1947 </ul>1819 </ul>
1948 </td>1820 </td>
1949 <td>1821 <td>
1950 <pre>{#syntax#}10 >> 1 == 5{#endsyntax#}</pre>1822 <pre>{#syntax#}0b1010 >> 1 == 0b101{#endsyntax#}</pre>
1951 </td>1823 </td>
1952 </tr>1824 </tr>
1953 <tr>1825 <tr>
1954 <th scope="row"><pre>{#syntax#}a & b1826 <td>Bitwise And</td>
1955a &= b{#endsyntax#}</pre></th>1827 <td><pre>{#syntax#}a & b
1828a &= b{#endsyntax#}</pre></td>
1956 <td>1829 <td>
1957 <ul>1830 <ul>
1958 <li>{#link|Integers#}</li>1831 <li>{#link|Integers#}</li>
1959 </ul>1832 </ul>
1960 </td>1833 </td>
1961 <td>Bitwise AND.1834 <td>
1962 <ul>1835 <ul>
1963 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1836 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1964 </ul>1837 </ul>
...@@ -1968,14 +1841,15 @@ a &= b{#endsyntax#}</pre></th>...@@ -1968,14 +1841,15 @@ a &= b{#endsyntax#}</pre></th>
1968 </td>1841 </td>
1969 </tr>1842 </tr>
1970 <tr>1843 <tr>
1971 <th scope="row"><pre>{#syntax#}a | b1844 <td>Bitwise Or</td>
1972a |= b{#endsyntax#}</pre></th>1845 <td><pre>{#syntax#}a | b
1846a |= b{#endsyntax#}</pre></td>
1973 <td>1847 <td>
1974 <ul>1848 <ul>
1975 <li>{#link|Integers#}</li>1849 <li>{#link|Integers#}</li>
1976 </ul>1850 </ul>
1977 </td>1851 </td>
1978 <td>Bitwise OR.1852 <td>
1979 <ul>1853 <ul>
1980 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1854 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1981 </ul>1855 </ul>
...@@ -1985,14 +1859,15 @@ a |= b{#endsyntax#}</pre></th>...@@ -1985,14 +1859,15 @@ a |= b{#endsyntax#}</pre></th>
1985 </td>1859 </td>
1986 </tr>1860 </tr>
1987 <tr>1861 <tr>
1988 <th scope="row"><pre>{#syntax#}a ^ b1862 <td>Bitwise Xor</td>
1989a ^= b{#endsyntax#}</pre></th>1863 <td><pre>{#syntax#}a ^ b
1864a ^= b{#endsyntax#}</pre></td>
1990 <td>1865 <td>
1991 <ul>1866 <ul>
1992 <li>{#link|Integers#}</li>1867 <li>{#link|Integers#}</li>
1993 </ul>1868 </ul>
1994 </td>1869 </td>
1995 <td>Bitwise XOR.1870 <td>
1996 <ul>1871 <ul>
1997 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>1872 <li>Invokes {#link|Peer Type Resolution#} for the operands.</li>
1998 </ul>1873 </ul>
...@@ -2002,30 +1877,30 @@ a ^= b{#endsyntax#}</pre></th>...@@ -2002,30 +1877,30 @@ a ^= b{#endsyntax#}</pre></th>
2002 </td>1877 </td>
2003 </tr>1878 </tr>
2004 <tr>1879 <tr>
2005 <th scope="row"><pre>{#syntax#}~a{#endsyntax#}</pre></th>1880 <td>Bitwise Not</td>
1881 <td><pre>{#syntax#}~a{#endsyntax#}</pre></td>
2006 <td>1882 <td>
2007 <ul>1883 <ul>
2008 <li>{#link|Integers#}</li>1884 <li>{#link|Integers#}</li>
2009 </ul>1885 </ul>
2010 </td>1886 </td>
2011 <td>1887 <td></td>
2012 Bitwise NOT.
2013 </td>
2014 <td>1888 <td>
2015 <pre>{#syntax#}~@as(u8, 0b10101111) == 0b01010000{#endsyntax#}</pre>1889 <pre>{#syntax#}~@as(u8, 0b10101111) == 0b01010000{#endsyntax#}</pre>
2016 </td>1890 </td>
2017 </tr>1891 </tr>
2018 <tr>1892 <tr>
2019 <th scope="row"><pre>{#syntax#}a orelse b{#endsyntax#}</pre></th>1893 <td>Defaulting Optional Unwrap</td>
1894 <td><pre>{#syntax#}a orelse b{#endsyntax#}</pre></td>
2020 <td>1895 <td>
2021 <ul>1896 <ul>
2022 <li>{#link|Optionals#}</li>1897 <li>{#link|Optionals#}</li>
2023 </ul>1898 </ul>
2024 </td>1899 </td>
2025 <td>If {#syntax#}a{#endsyntax#} is {#syntax#}null{#endsyntax#},1900 <td>If {#syntax#}a{#endsyntax#} is {#syntax#}null{#endsyntax#},
2026 returns {#syntax#}b{#endsyntax#} ("default value"),1901 returns {#syntax#}b{#endsyntax#} ("default value"),
2027 otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}.1902 otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}.
2028 Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}.1903 Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}.
2029 </td>1904 </td>
2030 <td>1905 <td>
2031 <pre>{#syntax#}const value: ?u32 = null;1906 <pre>{#syntax#}const value: ?u32 = null;
...@@ -2034,7 +1909,8 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2034,7 +1909,8 @@ unwrapped == 1234{#endsyntax#}</pre>
2034 </td>1909 </td>
2035 </tr>1910 </tr>
2036 <tr>1911 <tr>
2037 <th scope="row"><pre>{#syntax#}a.?{#endsyntax#}</pre></th>1912 <td>Optional Unwrap</td>
1913 <td><pre>{#syntax#}a.?{#endsyntax#}</pre></td>
2038 <td>1914 <td>
2039 <ul>1915 <ul>
2040 <li>{#link|Optionals#}</li>1916 <li>{#link|Optionals#}</li>
...@@ -2050,18 +1926,19 @@ value.? == 5678{#endsyntax#}</pre>...@@ -2050,18 +1926,19 @@ value.? == 5678{#endsyntax#}</pre>
2050 </td>1926 </td>
2051 </tr>1927 </tr>
2052 <tr>1928 <tr>
2053 <th scope="row"><pre>{#syntax#}a catch b1929 <td>Defaulting Error Unwrap</td>
2054a catch |err| b{#endsyntax#}</pre></th>1930 <td><pre>{#syntax#}a catch b
1931a catch |err| b{#endsyntax#}</pre></td>
2055 <td>1932 <td>
2056 <ul>1933 <ul>
2057 <li>{#link|Error Unions|Errors#}</li>1934 <li>{#link|Error Unions|Errors#}</li>
2058 </ul>1935 </ul>
2059 </td>1936 </td>
2060 <td>If {#syntax#}a{#endsyntax#} is an {#syntax#}error{#endsyntax#},1937 <td>If {#syntax#}a{#endsyntax#} is an {#syntax#}error{#endsyntax#},
2061 returns {#syntax#}b{#endsyntax#} ("default value"),1938 returns {#syntax#}b{#endsyntax#} ("default value"),
2062 otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}.1939 otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}.
2063 Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}.1940 Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}.
2064 {#syntax#}err{#endsyntax#} is the {#syntax#}error{#endsyntax#} and is in scope of the expression {#syntax#}b{#endsyntax#}.1941{#syntax#}err{#endsyntax#} is the {#syntax#}error{#endsyntax#} and is in scope of the expression {#syntax#}b{#endsyntax#}.
2065 </td>1942 </td>
2066 <td>1943 <td>
2067 <pre>{#syntax#}const value: anyerror!u32 = error.Broken;1944 <pre>{#syntax#}const value: anyerror!u32 = error.Broken;
...@@ -2070,51 +1947,55 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2070,51 +1947,55 @@ unwrapped == 1234{#endsyntax#}</pre>
2070 </td>1947 </td>
2071 </tr>1948 </tr>
2072 <tr>1949 <tr>
2073 <th scope="row"><pre>{#syntax#}a and b{#endsyntax#}</pre></th>1950 <td>Logical And</td>
1951 <td><pre>{#syntax#}a and b{#endsyntax#}</pre></td>
2074 <td>1952 <td>
2075 <ul>1953 <ul>
2076 <li>{#link|bool|Primitive Types#}</li>1954 <li>{#link|bool|Primitive Types#}</li>
2077 </ul>1955 </ul>
2078 </td>1956 </td>
2079 <td>1957 <td>
2080 If {#syntax#}a{#endsyntax#} is {#syntax#}false{#endsyntax#}, returns {#syntax#}false{#endsyntax#}1958 If {#syntax#}a{#endsyntax#} is {#syntax#}false{#endsyntax#}, returns {#syntax#}false{#endsyntax#}
2081 without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}.1959 without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}.
2082 </td>1960 </td>
2083 <td>1961 <td>
2084 <pre>{#syntax#}(false and true) == false{#endsyntax#}</pre>1962 <pre>{#syntax#}(false and true) == false{#endsyntax#}</pre>
2085 </td>1963 </td>
2086 </tr>1964 </tr>
2087 <tr>1965 <tr>
2088 <th scope="row"><pre>{#syntax#}a or b{#endsyntax#}</pre></th>1966 <td>Logical Or</td>
1967 <td><pre>{#syntax#}a or b{#endsyntax#}</pre></td>
2089 <td>1968 <td>
2090 <ul>1969 <ul>
2091 <li>{#link|bool|Primitive Types#}</li>1970 <li>{#link|bool|Primitive Types#}</li>
2092 </ul>1971 </ul>
2093 </td>1972 </td>
2094 <td>1973 <td>
2095 If {#syntax#}a{#endsyntax#} is {#syntax#}true{#endsyntax#}, returns {#syntax#}true{#endsyntax#}1974 If {#syntax#}a{#endsyntax#} is {#syntax#}true{#endsyntax#},
2096 without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}.1975 returns {#syntax#}true{#endsyntax#} without evaluating
1976 {#syntax#}b{#endsyntax#}. Otherwise, returns
1977 {#syntax#}b{#endsyntax#}.
2097 </td>1978 </td>
2098 <td>1979 <td>
2099 <pre>{#syntax#}(false or true) == true{#endsyntax#}</pre>1980 <pre>{#syntax#}(false or true) == true{#endsyntax#}</pre>
2100 </td>1981 </td>
2101 </tr>1982 </tr>
2102 <tr>1983 <tr>
2103 <th scope="row"><pre>{#syntax#}!a{#endsyntax#}</pre></th>1984 <td>Boolean Not</td>
1985 <td><pre>{#syntax#}!a{#endsyntax#}</pre></td>
2104 <td>1986 <td>
2105 <ul>1987 <ul>
2106 <li>{#link|bool|Primitive Types#}</li>1988 <li>{#link|bool|Primitive Types#}</li>
2107 </ul>1989 </ul>
2108 </td>1990 </td>
2109 <td>1991 <td></td>
2110 Boolean NOT.
2111 </td>
2112 <td>1992 <td>
2113 <pre>{#syntax#}!false == true{#endsyntax#}</pre>1993 <pre>{#syntax#}!false == true{#endsyntax#}</pre>
2114 </td>1994 </td>
2115 </tr>1995 </tr>
2116 <tr>1996 <tr>
2117 <th scope="row"><pre>{#syntax#}a == b{#endsyntax#}</pre></th>1997 <td>Equality</td>
1998 <td><pre>{#syntax#}a == b{#endsyntax#}</pre></td>
2118 <td>1999 <td>
2119 <ul>2000 <ul>
2120 <li>{#link|Integers#}</li>2001 <li>{#link|Integers#}</li>
...@@ -2132,7 +2013,8 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2132,7 +2013,8 @@ unwrapped == 1234{#endsyntax#}</pre>
2132 </td>2013 </td>
2133 </tr>2014 </tr>
2134 <tr>2015 <tr>
2135 <th scope="row"><pre>{#syntax#}a == null{#endsyntax#}</pre></th>2016 <td>Null Check</td>
2017 <td><pre>{#syntax#}a == null{#endsyntax#}</pre></td>
2136 <td>2018 <td>
2137 <ul>2019 <ul>
2138 <li>{#link|Optionals#}</li>2020 <li>{#link|Optionals#}</li>
...@@ -2147,7 +2029,8 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2147,7 +2029,8 @@ unwrapped == 1234{#endsyntax#}</pre>
2147 </td>2029 </td>
2148 </tr>2030 </tr>
2149 <tr>2031 <tr>
2150 <th scope="row"><pre>{#syntax#}a != b{#endsyntax#}</pre></th>2032 <td>Inequality</td>
2033 <td><pre>{#syntax#}a != b{#endsyntax#}</pre></td>
2151 <td>2034 <td>
2152 <ul>2035 <ul>
2153 <li>{#link|Integers#}</li>2036 <li>{#link|Integers#}</li>
...@@ -2165,7 +2048,8 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2165,7 +2048,8 @@ unwrapped == 1234{#endsyntax#}</pre>
2165 </td>2048 </td>
2166 </tr>2049 </tr>
2167 <tr>2050 <tr>
2168 <th scope="row"><pre>{#syntax#}a != null{#endsyntax#}</pre></th>2051 <td>Non-Null Check</td>
2052 <td><pre>{#syntax#}a != null{#endsyntax#}</pre></td>
2169 <td>2053 <td>
2170 <ul>2054 <ul>
2171 <li>{#link|Optionals#}</li>2055 <li>{#link|Optionals#}</li>
...@@ -2180,7 +2064,8 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2180,7 +2064,8 @@ unwrapped == 1234{#endsyntax#}</pre>
2180 </td>2064 </td>
2181 </tr>2065 </tr>
2182 <tr>2066 <tr>
2183 <th scope="row"><pre>{#syntax#}a > b{#endsyntax#}</pre></th>2067 <td>Greater Than</td>
2068 <td><pre>{#syntax#}a > b{#endsyntax#}</pre></td>
2184 <td>2069 <td>
2185 <ul>2070 <ul>
2186 <li>{#link|Integers#}</li>2071 <li>{#link|Integers#}</li>
...@@ -2196,7 +2081,8 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2196,7 +2081,8 @@ unwrapped == 1234{#endsyntax#}</pre>
2196 </td>2081 </td>
2197 </tr>2082 </tr>
2198 <tr>2083 <tr>
2199 <th scope="row"><pre>{#syntax#}a >= b{#endsyntax#}</pre></th>2084 <td>Greater or Equal</td>
2085 <td><pre>{#syntax#}a >= b{#endsyntax#}</pre></td>
2200 <td>2086 <td>
2201 <ul>2087 <ul>
2202 <li>{#link|Integers#}</li>2088 <li>{#link|Integers#}</li>
...@@ -2212,7 +2098,8 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2212,7 +2098,8 @@ unwrapped == 1234{#endsyntax#}</pre>
2212 </td>2098 </td>
2213 </tr>2099 </tr>
2214 <tr>2100 <tr>
2215 <th scope="row"><pre>{#syntax#}a < b{#endsyntax#}</pre></th>2101 <td>Less Than</td>
2102 <td><pre>{#syntax#}a < b{#endsyntax#}</pre></td>
2216 <td>2103 <td>
2217 <ul>2104 <ul>
2218 <li>{#link|Integers#}</li>2105 <li>{#link|Integers#}</li>
...@@ -2228,7 +2115,8 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2228,7 +2115,8 @@ unwrapped == 1234{#endsyntax#}</pre>
2228 </td>2115 </td>
2229 </tr>2116 </tr>
2230 <tr>2117 <tr>
2231 <th scope="row"><pre>{#syntax#}a <= b{#endsyntax#}</pre></th>2118 <td>Lesser or Equal</td>
2119 <td><pre>{#syntax#}a <= b{#endsyntax#}</pre></td>
2232 <td>2120 <td>
2233 <ul>2121 <ul>
2234 <li>{#link|Integers#}</li>2122 <li>{#link|Integers#}</li>
...@@ -2244,14 +2132,14 @@ unwrapped == 1234{#endsyntax#}</pre>...@@ -2244,14 +2132,14 @@ unwrapped == 1234{#endsyntax#}</pre>
2244 </td>2132 </td>
2245 </tr>2133 </tr>
2246 <tr>2134 <tr>
2247 <th scope="row"><pre>{#syntax#}a ++ b{#endsyntax#}</pre></th>2135 <td>Array Concatenation</td>
2136 <td><pre>{#syntax#}a ++ b{#endsyntax#}</pre></td>
2248 <td>2137 <td>
2249 <ul>2138 <ul>
2250 <li>{#link|Arrays#}</li>2139 <li>{#link|Arrays#}</li>
2251 </ul>2140 </ul>
2252 </td>2141 </td>
2253 <td>2142 <td>
2254 Array concatenation.
2255 <ul>2143 <ul>
2256 <li>Only available when the lengths of both {#syntax#}a{#endsyntax#} and {#syntax#}b{#endsyntax#} are {#link|compile-time known|comptime#}.</li>2144 <li>Only available when the lengths of both {#syntax#}a{#endsyntax#} and {#syntax#}b{#endsyntax#} are {#link|compile-time known|comptime#}.</li>
2257 </ul>2145 </ul>
...@@ -2265,14 +2153,14 @@ mem.eql(u32, &together, &[_]u32{1,2,3,4}){#endsyntax#}</pre>...@@ -2265,14 +2153,14 @@ mem.eql(u32, &together, &[_]u32{1,2,3,4}){#endsyntax#}</pre>
2265 </td>2153 </td>
2266 </tr>2154 </tr>
2267 <tr>2155 <tr>
2268 <th scope="row"><pre>{#syntax#}a ** b{#endsyntax#}</pre></th>2156 <td>Array Multiplication</td>
2157 <td><pre>{#syntax#}a ** b{#endsyntax#}</pre></td>
2269 <td>2158 <td>
2270 <ul>2159 <ul>
2271 <li>{#link|Arrays#}</li>2160 <li>{#link|Arrays#}</li>
2272 </ul>2161 </ul>
2273 </td>2162 </td>
2274 <td>2163 <td>
2275 Array multiplication.
2276 <ul>2164 <ul>
2277 <li>Only available when the length of {#syntax#}a{#endsyntax#} and {#syntax#}b{#endsyntax#} are {#link|compile-time known|comptime#}.</li>2165 <li>Only available when the length of {#syntax#}a{#endsyntax#} and {#syntax#}b{#endsyntax#} are {#link|compile-time known|comptime#}.</li>
2278 </ul>2166 </ul>
...@@ -2284,7 +2172,8 @@ mem.eql(u8, pattern, "ababab"){#endsyntax#}</pre>...@@ -2284,7 +2172,8 @@ mem.eql(u8, pattern, "ababab"){#endsyntax#}</pre>
2284 </td>2172 </td>
2285 </tr>2173 </tr>
2286 <tr>2174 <tr>
2287 <th scope="row"><pre>{#syntax#}a.*{#endsyntax#}</pre></th>2175 <td>Pointer Dereference</td>
2176 <td><pre>{#syntax#}a.*{#endsyntax#}</pre></td>
2288 <td>2177 <td>
2289 <ul>2178 <ul>
2290 <li>{#link|Pointers#}</li>2179 <li>{#link|Pointers#}</li>
...@@ -2300,12 +2189,12 @@ ptr.* == 1234{#endsyntax#}</pre>...@@ -2300,12 +2189,12 @@ ptr.* == 1234{#endsyntax#}</pre>
2300 </td>2189 </td>
2301 </tr>2190 </tr>
2302 <tr>2191 <tr>
2303 <th scope="row"><pre>{#syntax#}&a{#endsyntax#}</pre></th>2192 <td>Address Of</td>
2193 <td><pre>{#syntax#}&a{#endsyntax#}</pre></td>
2304 <td>2194 <td>
2305 All types2195 All types
2306 </td>2196 </td>
2307 <td>2197 <td>
2308 Address of.
2309 </td>2198 </td>
2310 <td>2199 <td>
2311 <pre>{#syntax#}const x: u32 = 1234;2200 <pre>{#syntax#}const x: u32 = 1234;
...@@ -2314,7 +2203,8 @@ ptr.* == 1234{#endsyntax#}</pre>...@@ -2314,7 +2203,8 @@ ptr.* == 1234{#endsyntax#}</pre>
2314 </td>2203 </td>
2315 </tr>2204 </tr>
2316 <tr>2205 <tr>
2317 <th scope="row"><pre>{#syntax#}a || b{#endsyntax#}</pre></th>2206 <td>Error Set Merge</td>
2207 <td><pre>{#syntax#}a || b{#endsyntax#}</pre></td>
2318 <td>2208 <td>
2319 <ul>2209 <ul>
2320 <li>{#link|Error Set Type#}</li>2210 <li>{#link|Error Set Type#}</li>
...@@ -4311,10 +4201,11 @@ test "enum literals with switch" {...@@ -4311,10 +4201,11 @@ test "enum literals with switch" {
4311 {#code_end#}4201 {#code_end#}
4312 {#header_close#}4202 {#header_close#}
43134203
4314 {#header_open|Inline switch#}4204 {#header_open|Inline Switch Prongs#}
4315 <p>4205 <p>
4316 Switch prongs can be marked as {#syntax#}inline{#endsyntax#} to generate4206 Switch prongs can be marked as {#syntax#}inline{#endsyntax#} to generate
4317 the prong's body for each possible value it could have:4207 the prong's body for each possible value it could have, making the
4208 captured value {#link|comptime#}.
4318 </p>4209 </p>
4319 {#code_begin|test|test_inline_switch#}4210 {#code_begin|test|test_inline_switch#}
4320const std = @import("std");4211const std = @import("std");
...@@ -4324,9 +4215,9 @@ const expectError = std.testing.expectError;...@@ -4324,9 +4215,9 @@ const expectError = std.testing.expectError;
4324fn isFieldOptional(comptime T: type, field_index: usize) !bool {4215fn isFieldOptional(comptime T: type, field_index: usize) !bool {
4325 const fields = @typeInfo(T).Struct.fields;4216 const fields = @typeInfo(T).Struct.fields;
4326 return switch (field_index) {4217 return switch (field_index) {
4327 // This prong is analyzed `fields.len - 1` times with `idx` being a4218 // This prong is analyzed twice with `idx` being a
4328 // unique comptime-known value each time.4219 // comptime-known value each time.
4329 inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,4220 inline 0, 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
4330 else => return error.IndexOutOfBounds,4221 else => return error.IndexOutOfBounds,
4331 };4222 };
4332}4223}
...@@ -4350,6 +4241,16 @@ fn isFieldOptionalUnrolled(field_index: usize) !bool {...@@ -4350,6 +4241,16 @@ fn isFieldOptionalUnrolled(field_index: usize) !bool {
4350 1 => true,4241 1 => true,
4351 else => return error.IndexOutOfBounds,4242 else => return error.IndexOutOfBounds,
4352 };4243 };
4244}
4245 {#code_end#}
4246 <p>The {#syntax#}inline{#endsyntax#} keyword may also be combined with ranges:</p>
4247 {#code_begin|syntax|inline_prong_range#}
4248fn isFieldOptional(comptime T: type, field_index: usize) !bool {
4249 const fields = @typeInfo(T).Struct.fields;
4250 return switch (field_index) {
4251 inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
4252 else => return error.IndexOutOfBounds,
4253 };
4353}4254}
4354 {#code_end#}4255 {#code_end#}
4355 <p>4256 <p>
...@@ -7853,7 +7754,7 @@ comptime {...@@ -7853,7 +7754,7 @@ comptime {
7853 {#header_close#}7754 {#header_close#}
78547755
7855 {#header_open|@atomicLoad#}7756 {#header_open|@atomicLoad#}
7856 <pre>{#syntax#}@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: builtin.AtomicOrder) T{#endsyntax#}</pre>7757 <pre>{#syntax#}@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: AtomicOrder) T{#endsyntax#}</pre>
7857 <p>7758 <p>
7858 This builtin function atomically dereferences a pointer to a {#syntax#}T{#endsyntax#} and returns the value.7759 This builtin function atomically dereferences a pointer to a {#syntax#}T{#endsyntax#} and returns the value.
7859 </p>7760 </p>
...@@ -7861,11 +7762,12 @@ comptime {...@@ -7861,11 +7762,12 @@ comptime {
7861 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,7762 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
7862 an integer or an enum.7763 an integer or an enum.
7863 </p>7764 </p>
7765 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
7864 {#see_also|@atomicStore|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#}7766 {#see_also|@atomicStore|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#}
7865 {#header_close#}7767 {#header_close#}
78667768
7867 {#header_open|@atomicRmw#}7769 {#header_open|@atomicRmw#}
7868 <pre>{#syntax#}@atomicRmw(comptime T: type, ptr: *T, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T{#endsyntax#}</pre>7770 <pre>{#syntax#}@atomicRmw(comptime T: type, ptr: *T, comptime op: AtomicRmwOp, operand: T, comptime ordering: AtomicOrder) T{#endsyntax#}</pre>
7869 <p>7771 <p>
7870 This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically7772 This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically
7871 modifies the value and returns the previous value.7773 modifies the value and returns the previous value.
...@@ -7874,27 +7776,13 @@ comptime {...@@ -7874,27 +7776,13 @@ comptime {
7874 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,7776 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
7875 an integer or an enum.7777 an integer or an enum.
7876 </p>7778 </p>
7877 <p>7779 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
7878 Supported values for the {#syntax#}op{#endsyntax#} parameter:7780 <p>{#syntax#}AtomicRmwOp{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicRmwOp{#endsyntax#}.</p>
7879 </p>
7880 <ul>
7881 <li>{#syntax#}.Xchg{#endsyntax#} - stores the operand unmodified. Supports enums, integers and floats.</li>
7882 <li>{#syntax#}.Add{#endsyntax#} - for integers, twos complement wraparound addition.
7883 Also supports {#link|Floats#}.</li>
7884 <li>{#syntax#}.Sub{#endsyntax#} - for integers, twos complement wraparound subtraction.
7885 Also supports {#link|Floats#}.</li>
7886 <li>{#syntax#}.And{#endsyntax#} - bitwise and</li>
7887 <li>{#syntax#}.Nand{#endsyntax#} - bitwise nand</li>
7888 <li>{#syntax#}.Or{#endsyntax#} - bitwise or</li>
7889 <li>{#syntax#}.Xor{#endsyntax#} - bitwise xor</li>
7890 <li>{#syntax#}.Max{#endsyntax#} - stores the operand if it is larger. Supports integers and floats.</li>
7891 <li>{#syntax#}.Min{#endsyntax#} - stores the operand if it is smaller. Supports integers and floats.</li>
7892 </ul>
7893 {#see_also|@atomicStore|@atomicLoad|@fence|@cmpxchgWeak|@cmpxchgStrong#}7781 {#see_also|@atomicStore|@atomicLoad|@fence|@cmpxchgWeak|@cmpxchgStrong#}
7894 {#header_close#}7782 {#header_close#}
78957783
7896 {#header_open|@atomicStore#}7784 {#header_open|@atomicStore#}
7897 <pre>{#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: builtin.AtomicOrder) void{#endsyntax#}</pre>7785 <pre>{#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: AtomicOrder) void{#endsyntax#}</pre>
7898 <p>7786 <p>
7899 This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically stores the given value.7787 This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically stores the given value.
7900 </p>7788 </p>
...@@ -7902,6 +7790,7 @@ comptime {...@@ -7902,6 +7790,7 @@ comptime {
7902 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,7790 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
7903 an integer or an enum.7791 an integer or an enum.
7904 </p>7792 </p>
7793 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
7905 {#see_also|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#}7794 {#see_also|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#}
7906 {#header_close#}7795 {#header_close#}
79077796
...@@ -8178,6 +8067,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v...@@ -8178,6 +8067,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v
8178 an integer or an enum.8067 an integer or an enum.
8179 </p>8068 </p>
8180 <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>8069 <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
8070 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
8181 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak#}8071 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak#}
8182 {#header_close#}8072 {#header_close#}
81838073
...@@ -8209,6 +8099,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -8209,6 +8099,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
8209 an integer or an enum.8099 an integer or an enum.
8210 </p>8100 </p>
8211 <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>8101 <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
8102 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
8212 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgStrong#}8103 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgStrong#}
8213 {#header_close#}8104 {#header_close#}
82148105
...@@ -8499,9 +8390,7 @@ export fn @"A function name that is a complete sentence."() void {}...@@ -8499,9 +8390,7 @@ export fn @"A function name that is a complete sentence."() void {}
8499 <p>8390 <p>
8500 The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.8391 The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.
8501 </p>8392 </p>
8502 <p>8393 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
8503 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.
8504 </p>
8505 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@cmpxchgWeak|@cmpxchgStrong#}8394 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@cmpxchgWeak|@cmpxchgStrong#}
8506 {#header_close#}8395 {#header_close#}
85078396
...@@ -8909,7 +8798,7 @@ test "@wasmMemoryGrow" {...@@ -8909,7 +8798,7 @@ test "@wasmMemoryGrow" {
8909 {#header_close#}8798 {#header_close#}
89108799
8911 {#header_open|@prefetch#}8800 {#header_open|@prefetch#}
8912 <pre>{#syntax#}@prefetch(ptr: anytype, comptime options: std.builtin.PrefetchOptions) void{#endsyntax#}</pre>8801 <pre>{#syntax#}@prefetch(ptr: anytype, comptime options: PrefetchOptions) void{#endsyntax#}</pre>
8913 <p>8802 <p>
8914 This builtin tells the compiler to emit a prefetch instruction if supported by the8803 This builtin tells the compiler to emit a prefetch instruction if supported by the
8915 target CPU. If the target CPU does not support the requested prefetch instruction,8804 target CPU. If the target CPU does not support the requested prefetch instruction,
...@@ -8921,37 +8810,7 @@ test "@wasmMemoryGrow" {...@@ -8921,37 +8810,7 @@ test "@wasmMemoryGrow" {
8921 address to prefetch. This function does not dereference the pointer, it is perfectly legal8810 address to prefetch. This function does not dereference the pointer, it is perfectly legal
8922 to pass a pointer to invalid memory to this function and no illegal behavior will result.8811 to pass a pointer to invalid memory to this function and no illegal behavior will result.
8923 </p>8812 </p>
8924 <p>8813 <p>{#syntax#}PrefetchOptions{#endsyntax#} can be found with {#syntax#}@import("std").builtin.PrefetchOptions{#endsyntax#}.</p>
8925 The {#syntax#}options{#endsyntax#} argument is the following struct:
8926 </p>
8927 {#code_begin|syntax|builtin#}
8928/// This data structure is used by the Zig language code generation and
8929/// therefore must be kept in sync with the compiler implementation.
8930pub const PrefetchOptions = struct {
8931 /// Whether the prefetch should prepare for a read or a write.
8932 rw: Rw = .read,
8933 /// The data's locality in an inclusive range from 0 to 3.
8934 ///
8935 /// 0 means no temporal locality. That is, the data can be immediately
8936 /// dropped from the cache after it is accessed.
8937 ///
8938 /// 3 means high temporal locality. That is, the data should be kept in
8939 /// the cache as it is likely to be accessed again soon.
8940 locality: u2 = 3,
8941 /// The cache that the prefetch should be preformed on.
8942 cache: Cache = .data,
8943
8944 pub const Rw = enum(u1) {
8945 read,
8946 write,
8947 };
8948
8949 pub const Cache = enum(u1) {
8950 instruction,
8951 data,
8952 };
8953};
8954 {#code_end#}
8955 {#header_close#}8814 {#header_close#}
89568815
8957 {#header_open|@ptrCast#}8816 {#header_open|@ptrCast#}
...@@ -9080,16 +8939,8 @@ test "foo" {...@@ -9080,16 +8939,8 @@ test "foo" {
9080 {#header_close#}8939 {#header_close#}
90818940
9082 {#header_open|@setFloatMode#}8941 {#header_open|@setFloatMode#}
9083 <pre>{#syntax#}@setFloatMode(comptime mode: @import("std").builtin.FloatMode) void{#endsyntax#}</pre>8942 <pre>{#syntax#}@setFloatMode(comptime mode: FloatMode) void{#endsyntax#}</pre>
9084 <p>8943 <p>Changes the current scope's rules about how floating point operations are defined.</p>
9085 Sets the floating point mode of the current scope. Possible values are:
9086 </p>
9087 {#code_begin|syntax|FloatMode#}
9088pub const FloatMode = enum {
9089 Strict,
9090 Optimized,
9091};
9092 {#code_end#}
9093 <ul>8944 <ul>
9094 <li>8945 <li>
9095 {#syntax#}Strict{#endsyntax#} (default) - Floating point operations follow strict IEEE compliance.8946 {#syntax#}Strict{#endsyntax#} (default) - Floating point operations follow strict IEEE compliance.
...@@ -9111,6 +8962,7 @@ pub const FloatMode = enum {...@@ -9111,6 +8962,7 @@ pub const FloatMode = enum {
9111 The floating point mode is inherited by child scopes, and can be overridden in any scope.8962 The floating point mode is inherited by child scopes, and can be overridden in any scope.
9112 You can set the floating point mode in a struct or module scope by using a comptime block.8963 You can set the floating point mode in a struct or module scope by using a comptime block.
9113 </p>8964 </p>
8965 <p>{#syntax#}FloatMode{#endsyntax#} can be found with {#syntax#}@import("std").builtin.FloatMode{#endsyntax#}.</p>
9114 {#see_also|Floating Point Operations#}8966 {#see_also|Floating Point Operations#}
9115 {#header_close#}8967 {#header_close#}
91168968
...@@ -11522,7 +11374,6 @@ fn readU32Be() u32 {}...@@ -11522,7 +11374,6 @@ fn readU32Be() u32 {}
11522 {#header_open|Keyword Reference#}11374 {#header_open|Keyword Reference#}
11523 <div class="table-wrapper">11375 <div class="table-wrapper">
11524 <table>11376 <table>
11525 <caption>Keywords</caption>
11526 <thead>11377 <thead>
11527 <tr>11378 <tr>
11528 <th scope="col">Keyword</th>11379 <th scope="col">Keyword</th>
lib/std/builtin.zig+20
...@@ -102,14 +102,34 @@ pub const ReduceOp = enum {...@@ -102,14 +102,34 @@ pub const ReduceOp = enum {
102/// This data structure is used by the Zig language code generation and102/// This data structure is used by the Zig language code generation and
103/// therefore must be kept in sync with the compiler implementation.103/// therefore must be kept in sync with the compiler implementation.
104pub const AtomicRmwOp = enum {104pub const AtomicRmwOp = enum {
105 /// Exchange - store the operand unmodified.
106 /// Supports enums, integers, and floats.
105 Xchg,107 Xchg,
108 /// Add operand to existing value.
109 /// Supports integers and floats.
110 /// For integers, two's complement wraparound applies.
106 Add,111 Add,
112 /// Subtract operand from existing value.
113 /// Supports integers and floats.
114 /// For integers, two's complement wraparound applies.
107 Sub,115 Sub,
116 /// Perform bitwise AND on existing value with operand.
117 /// Supports integers.
108 And,118 And,
119 /// Perform bitwise NAND on existing value with operand.
120 /// Supports integers.
109 Nand,121 Nand,
122 /// Perform bitwise OR on existing value with operand.
123 /// Supports integers.
110 Or,124 Or,
125 /// Perform bitwise XOR on existing value with operand.
126 /// Supports integers.
111 Xor,127 Xor,
128 /// Store operand if it is larger than the existing value.
129 /// Supports integers and floats.
112 Max,130 Max,
131 /// Store operand if it is smaller than the existing value.
132 /// Supports integers and floats.
113 Min,133 Min,
114};134};
115135
lib/std/fmt.zig+3-3
...@@ -40,9 +40,9 @@ pub const FormatOptions = struct {...@@ -40,9 +40,9 @@ pub const FormatOptions = struct {
40/// - when using a field name, you are required to enclose the field name (an identifier) in square40/// - when using a field name, you are required to enclose the field name (an identifier) in square
41/// brackets, e.g. {[score]...} as opposed to the numeric index form which can be written e.g. {2...}41/// brackets, e.g. {[score]...} as opposed to the numeric index form which can be written e.g. {2...}
42/// - *specifier* is a type-dependent formatting option that determines how a type should formatted (see below)42/// - *specifier* is a type-dependent formatting option that determines how a type should formatted (see below)
43/// - *fill* is a single character which is used to pad the formatted text43/// - *fill* is a single unicode codepoint which is used to pad the formatted text
44/// - *alignment* is one of the three characters `<`, `^`, or `>` to make the text left-, center-, or right-aligned, respectively44/// - *alignment* is one of the three bytes '<', '^', or '>' to make the text left-, center-, or right-aligned, respectively
45/// - *width* is the total width of the field in characters45/// - *width* is the total width of the field in unicode codepoints
46/// - *precision* specifies how many decimals a formatted number should have46/// - *precision* specifies how many decimals a formatted number should have
47///47///
48/// Note that most of the parameters are optional and may be omitted. Also you can leave out separators like `:` and `.` when48/// Note that most of the parameters are optional and may be omitted. Also you can leave out separators like `:` and `.` when
tools/docgen.zig+6-28
...@@ -947,19 +947,8 @@ fn isType(name: []const u8) bool {...@@ -947,19 +947,8 @@ fn isType(name: []const u8) bool {
947 return false;947 return false;
948}948}
949949
950const start_line = "<span class=\"line\">";
951const end_line = "</span>";
952
953fn writeEscapedLines(out: anytype, text: []const u8) !void {950fn writeEscapedLines(out: anytype, text: []const u8) !void {
954 for (text) |char| {951 return writeEscaped(out, text);
955 if (char == '\n') {
956 try out.writeAll(end_line);
957 try out.writeAll("\n");
958 try out.writeAll(start_line);
959 } else {
960 try writeEscaped(out, &[_]u8{char});
961 }
962 }
963}952}
964953
965fn tokenizeAndPrintRaw(954fn tokenizeAndPrintRaw(
...@@ -972,7 +961,7 @@ fn tokenizeAndPrintRaw(...@@ -972,7 +961,7 @@ fn tokenizeAndPrintRaw(
972 const src_non_terminated = mem.trim(u8, raw_src, " \r\n");961 const src_non_terminated = mem.trim(u8, raw_src, " \r\n");
973 const src = try allocator.dupeZ(u8, src_non_terminated);962 const src = try allocator.dupeZ(u8, src_non_terminated);
974963
975 try out.writeAll("<code>" ++ start_line);964 try out.writeAll("<code>");
976 var tokenizer = std.zig.Tokenizer.init(src);965 var tokenizer = std.zig.Tokenizer.init(src);
977 var index: usize = 0;966 var index: usize = 0;
978 var next_tok_is_fn = false;967 var next_tok_is_fn = false;
...@@ -1062,6 +1051,7 @@ fn tokenizeAndPrintRaw(...@@ -1062,6 +1051,7 @@ fn tokenizeAndPrintRaw(
1062 },1051 },
10631052
1064 .string_literal,1053 .string_literal,
1054 .multiline_string_literal_line,
1065 .char_literal,1055 .char_literal,
1066 => {1056 => {
1067 try out.writeAll("<span class=\"tok-str\">");1057 try out.writeAll("<span class=\"tok-str\">");
...@@ -1069,18 +1059,6 @@ fn tokenizeAndPrintRaw(...@@ -1069,18 +1059,6 @@ fn tokenizeAndPrintRaw(
1069 try out.writeAll("</span>");1059 try out.writeAll("</span>");
1070 },1060 },
10711061
1072 .multiline_string_literal_line => {
1073 if (src[token.loc.end - 1] == '\n') {
1074 try out.writeAll("<span class=\"tok-str\">");
1075 try writeEscaped(out, src[token.loc.start .. token.loc.end - 1]);
1076 try out.writeAll("</span>" ++ end_line ++ "\n" ++ start_line);
1077 } else {
1078 try out.writeAll("<span class=\"tok-str\">");
1079 try writeEscaped(out, src[token.loc.start..token.loc.end]);
1080 try out.writeAll("</span>");
1081 }
1082 },
1083
1084 .builtin => {1062 .builtin => {
1085 try out.writeAll("<span class=\"tok-builtin\">");1063 try out.writeAll("<span class=\"tok-builtin\">");
1086 try writeEscaped(out, src[token.loc.start..token.loc.end]);1064 try writeEscaped(out, src[token.loc.start..token.loc.end]);
...@@ -1211,7 +1189,7 @@ fn tokenizeAndPrintRaw(...@@ -1211,7 +1189,7 @@ fn tokenizeAndPrintRaw(
1211 }1189 }
1212 index = token.loc.end;1190 index = token.loc.end;
1213 }1191 }
1214 try out.writeAll(end_line ++ "</code>");1192 try out.writeAll("</code>");
1215}1193}
12161194
1217fn tokenizeAndPrint(1195fn tokenizeAndPrint(
...@@ -1234,9 +1212,9 @@ fn printSourceBlock(allocator: Allocator, docgen_tokenizer: *Tokenizer, out: any...@@ -1234,9 +1212,9 @@ fn printSourceBlock(allocator: Allocator, docgen_tokenizer: *Tokenizer, out: any
1234 const raw_source = docgen_tokenizer.buffer[syntax_block.source_token.start..syntax_block.source_token.end];1212 const raw_source = docgen_tokenizer.buffer[syntax_block.source_token.start..syntax_block.source_token.end];
1235 const trimmed_raw_source = mem.trim(u8, raw_source, " \r\n");1213 const trimmed_raw_source = mem.trim(u8, raw_source, " \r\n");
12361214
1237 try out.writeAll("<code>" ++ start_line);1215 try out.writeAll("<code>");
1238 try writeEscapedLines(out, trimmed_raw_source);1216 try writeEscapedLines(out, trimmed_raw_source);
1239 try out.writeAll(end_line ++ "</code>");1217 try out.writeAll("</code>");
1240 },1218 },
1241 }1219 }
1242 try out.writeAll("</pre></figure>");1220 try out.writeAll("</pre></figure>");