@@ -1422,7 +1422,8 @@ fn foo() i32 {
1422
1422
1423
1423
{#header_open|Thread Local Variables#}
1424
1424
<p>A variable may be specified to be a thread-local variable using the
1425
- {#syntax#}threadlocal{#endsyntax#} keyword:</p>
1425
+ {#syntax#}threadlocal{#endsyntax#} keyword,
1426
+ which makes each thread work with a separate instance of the variable:</p>
1426
1427
{#code_begin|test|test_thread_local_variables#}
1427
1428
const std = @import("std");
1428
1429
const assert = std.debug.assert;
@@ -4278,7 +4279,7 @@ const expectError = std.testing.expectError;
4278
4279
fn isFieldOptional(comptime T: type, field_index: usize) !bool {
4279
4280
const fields = @typeInfo(T).Struct.fields;
4280
4281
return switch (field_index) {
4281
- // This prong is analyzed `fields.len - 1` times with `idx` being an
4282
+ // This prong is analyzed `fields.len - 1` times with `idx` being a
4282
4283
// unique comptime-known value each time.
4283
4284
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
4284
4285
else => return error.IndexOutOfBounds,
@@ -4667,6 +4668,29 @@ test "for basics" {
4667
4668
sum2 += @intCast(i32, i);
4668
4669
}
4669
4670
try expect(sum2 == 10);
4671
+
4672
+ // To iterate over consecutive integers, use the range syntax.
4673
+ // Unbounded range is always a compile error.
4674
+ var sum3 : usize = 0;
4675
+ for (0..5) |i| {
4676
+ sum3 += i;
4677
+ }
4678
+ try expect(sum3 == 10);
4679
+ }
4680
+
4681
+ test "multi object for" {
4682
+ const items = [_]usize{ 1, 2, 3 };
4683
+ const items2 = [_]usize{ 4, 5, 6 };
4684
+ var count: usize = 0;
4685
+
4686
+ // Iterate over multiple objects.
4687
+ // All lengths must be equal at the start of the loop, otherwise detectable
4688
+ // illegal behavior occurs.
4689
+ for (items, items2) |i, j| {
4690
+ count += i + j;
4691
+ }
4692
+
4693
+ try expect(count == 21);
4670
4694
}
4671
4695
4672
4696
test "for reference" {
@@ -4710,8 +4734,8 @@ const expect = std.testing.expect;
4710
4734
4711
4735
test "nested break" {
4712
4736
var count: usize = 0;
4713
- outer: for ([_]i32{ 1, 2, 3, 4, 5 } ) |_| {
4714
- for ([_]i32{ 1, 2, 3, 4, 5 } ) |_| {
4737
+ outer: for (1..6 ) |_| {
4738
+ for (1..6 ) |_| {
4715
4739
count += 1;
4716
4740
break :outer;
4717
4741
}
@@ -4721,8 +4745,8 @@ test "nested break" {
4721
4745
4722
4746
test "nested continue" {
4723
4747
var count: usize = 0;
4724
- outer: for ([_]i32{ 1, 2, 3, 4, 5, 6, 7, 8 } ) |_| {
4725
- for ([_]i32{ 1, 2, 3, 4, 5 } ) |_| {
4748
+ outer: for (1..9 ) |_| {
4749
+ for (1..6 ) |_| {
4726
4750
count += 1;
4727
4751
continue :outer;
4728
4752
}
@@ -8017,7 +8041,7 @@ pub const CallModifier = enum {
8017
8041
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p>
8018
8042
<p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
8019
8043
<p>
8020
- This function counts the number of most-significant (leading in a big-Endian sense) zeroes in an integer.
8044
+ Counts the number of most-significant (leading in a big-endian sense) zeroes in an integer - "count leading zeroes" .
8021
8045
</p>
8022
8046
<p>
8023
8047
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
@@ -8167,7 +8191,7 @@ test "main" {
8167
8191
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p>
8168
8192
<p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
8169
8193
<p>
8170
- This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in an integer.
8194
+ Counts the number of least-significant (trailing in a big-endian sense) zeroes in an integer - "count trailing zeroes" .
8171
8195
</p>
8172
8196
<p>
8173
8197
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
@@ -8553,16 +8577,27 @@ test "@hasDecl" {
8553
8577
</p>
8554
8578
<ul>
8555
8579
<li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li>
8556
- <li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information.
8580
+ <li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information
8557
8581
The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.
8558
8582
</li>
8559
- <li>{#syntax#}@import("root"){#endsyntax#} - Points to the root source file.
8560
- This is usually <code>src/main.zig</code> but it depends on what file is chosen to be built.
8583
+ <li>{#syntax#}@import("root"){#endsyntax#} - Root source file
8584
+ This is usually <code>src/main.zig</code> but depends on what file is built.
8561
8585
</li>
8562
8586
</ul>
8563
8587
{#see_also|Compile Variables|@embedFile#}
8564
8588
{#header_close#}
8565
8589
8590
+ {#header_open|@inComptime#}
8591
+ <pre>{#syntax#}@inComptime() bool{#endsyntax#}</pre>
8592
+ <p>
8593
+ Returns whether the builtin was run in a {#syntax#}comptime{#endsyntax#} context. The result is a compile-time constant.
8594
+ </p>
8595
+ <p>
8596
+ This can be used to provide alternative, comptime-friendly implementations of functions. It should not be used, for instance, to exclude certain functions from being evaluated at comptime.
8597
+ </p>
8598
+ {#see_also|comptime#}
8599
+ {#header_close#}
8600
+
8566
8601
{#header_open|@intCast#}
8567
8602
<pre>{#syntax#}@intCast(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre>
8568
8603
<p>
@@ -8780,7 +8815,9 @@ test "@wasmMemoryGrow" {
8780
8815
<pre>{#syntax#}@popCount(operand: anytype) anytype{#endsyntax#}</pre>
8781
8816
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.</p>
8782
8817
<p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
8783
- <p>Counts the number of bits set in an integer.</p>
8818
+ <p>
8819
+ Counts the number of bits set in an integer - "population count".
8820
+ </p>
8784
8821
<p>
8785
8822
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
8786
8823
the return type is {#syntax#}comptime_int{#endsyntax#}.
@@ -8812,6 +8849,8 @@ test "@wasmMemoryGrow" {
8812
8849
pub const PrefetchOptions = struct {
8813
8850
/// Whether the prefetch should prepare for a read or a write.
8814
8851
rw: Rw = .read,
8852
+ /// The data's locality in an inclusive range from 0 to 3.
8853
+ ///
8815
8854
/// 0 means no temporal locality. That is, the data can be immediately
8816
8855
/// dropped from the cache after it is accessed.
8817
8856
///
@@ -8821,12 +8860,12 @@ pub const PrefetchOptions = struct {
8821
8860
/// The cache that the prefetch should be preformed on.
8822
8861
cache: Cache = .data,
8823
8862
8824
- pub const Rw = enum {
8863
+ pub const Rw = enum(u1) {
8825
8864
read,
8826
8865
write,
8827
8866
};
8828
8867
8829
- pub const Cache = enum {
8868
+ pub const Cache = enum(u1) {
8830
8869
instruction,
8831
8870
data,
8832
8871
};
@@ -10948,7 +10987,7 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke
10948
10987
</p>
10949
10988
<p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p>
10950
10989
<ul>
10951
- <li>Supports all the syntax of the other two pointer types.</li>
10990
+ <li>Supports all the syntax of the other two pointer types ({#syntax#}*T{#endsyntax#}) and ({#syntax#}[*]T{#endsyntax#}) .</li>
10952
10991
<li>Coerces to other pointer types, as well as {#link|Optional Pointers#}.
10953
10992
When a C pointer is coerced to a non-optional pointer, safety-checked
10954
10993
{#link|Undefined Behavior#} occurs if the address is 0.
@@ -11966,6 +12005,17 @@ fn readU32Be() u32 {}
11966
12005
</ul>
11967
12006
</td>
11968
12007
</tr>
12008
+ <tr>
12009
+ <th scope="row">
12010
+ <pre>{#syntax#}noinline{#endsyntax#}</pre>
12011
+ </th>
12012
+ <td>
12013
+ {#syntax#}noinline{#endsyntax#} disallows function to be inlined in all call sites.
12014
+ <ul>
12015
+ <li>See also {#link|Functions#}</li>
12016
+ </ul>
12017
+ </td>
12018
+ </tr>
11969
12019
<tr>
11970
12020
<th scope="row">
11971
12021
<pre>{#syntax#}nosuspend{#endsyntax#}</pre>
0 commit comments