Skip to content

Commit 015ea6f

Browse files
authored
Merge branch 'master' into autodoc-pkg-mod
2 parents a260fa8 + 8d88dcd commit 015ea6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1713
-600
lines changed

doc/langref.html.in

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,8 @@ fn foo() i32 {
14221422

14231423
{#header_open|Thread Local Variables#}
14241424
<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>
14261427
{#code_begin|test|test_thread_local_variables#}
14271428
const std = @import("std");
14281429
const assert = std.debug.assert;
@@ -4278,7 +4279,7 @@ const expectError = std.testing.expectError;
42784279
fn isFieldOptional(comptime T: type, field_index: usize) !bool {
42794280
const fields = @typeInfo(T).Struct.fields;
42804281
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
42824283
// unique comptime-known value each time.
42834284
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
42844285
else => return error.IndexOutOfBounds,
@@ -4667,6 +4668,29 @@ test "for basics" {
46674668
sum2 += @intCast(i32, i);
46684669
}
46694670
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);
46704694
}
46714695

46724696
test "for reference" {
@@ -4710,8 +4734,8 @@ const expect = std.testing.expect;
47104734

47114735
test "nested break" {
47124736
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) |_| {
47154739
count += 1;
47164740
break :outer;
47174741
}
@@ -4721,8 +4745,8 @@ test "nested break" {
47214745

47224746
test "nested continue" {
47234747
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) |_| {
47264750
count += 1;
47274751
continue :outer;
47284752
}
@@ -8017,7 +8041,7 @@ pub const CallModifier = enum {
80178041
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p>
80188042
<p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
80198043
<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".
80218045
</p>
80228046
<p>
80238047
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
@@ -8167,7 +8191,7 @@ test "main" {
81678191
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p>
81688192
<p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
81698193
<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".
81718195
</p>
81728196
<p>
81738197
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
@@ -8553,16 +8577,27 @@ test "@hasDecl" {
85538577
</p>
85548578
<ul>
85558579
<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
85578581
The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.
85588582
</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.
85618585
</li>
85628586
</ul>
85638587
{#see_also|Compile Variables|@embedFile#}
85648588
{#header_close#}
85658589

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+
85668601
{#header_open|@intCast#}
85678602
<pre>{#syntax#}@intCast(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre>
85688603
<p>
@@ -8780,7 +8815,9 @@ test "@wasmMemoryGrow" {
87808815
<pre>{#syntax#}@popCount(operand: anytype) anytype{#endsyntax#}</pre>
87818816
<p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.</p>
87828817
<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>
87848821
<p>
87858822
If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer,
87868823
the return type is {#syntax#}comptime_int{#endsyntax#}.
@@ -8812,6 +8849,8 @@ test "@wasmMemoryGrow" {
88128849
pub const PrefetchOptions = struct {
88138850
/// Whether the prefetch should prepare for a read or a write.
88148851
rw: Rw = .read,
8852+
/// The data's locality in an inclusive range from 0 to 3.
8853+
///
88158854
/// 0 means no temporal locality. That is, the data can be immediately
88168855
/// dropped from the cache after it is accessed.
88178856
///
@@ -8821,12 +8860,12 @@ pub const PrefetchOptions = struct {
88218860
/// The cache that the prefetch should be preformed on.
88228861
cache: Cache = .data,
88238862

8824-
pub const Rw = enum {
8863+
pub const Rw = enum(u1) {
88258864
read,
88268865
write,
88278866
};
88288867

8829-
pub const Cache = enum {
8868+
pub const Cache = enum(u1) {
88308869
instruction,
88318870
data,
88328871
};
@@ -10948,7 +10987,7 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke
1094810987
</p>
1094910988
<p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p>
1095010989
<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>
1095210991
<li>Coerces to other pointer types, as well as {#link|Optional Pointers#}.
1095310992
When a C pointer is coerced to a non-optional pointer, safety-checked
1095410993
{#link|Undefined Behavior#} occurs if the address is 0.
@@ -11966,6 +12005,17 @@ fn readU32Be() u32 {}
1196612005
</ul>
1196712006
</td>
1196812007
</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>
1196912019
<tr>
1197012020
<th scope="row">
1197112021
<pre>{#syntax#}nosuspend{#endsyntax#}</pre>

lib/std/Build/Cache.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub const File = struct {
184184
pub const HashHelper = struct {
185185
hasher: Hasher = hasher_init,
186186

187-
/// Record a slice of bytes as an dependency of the process being cached
187+
/// Record a slice of bytes as a dependency of the process being cached.
188188
pub fn addBytes(hh: *HashHelper, bytes: []const u8) void {
189189
hh.hasher.update(mem.asBytes(&bytes.len));
190190
hh.hasher.update(bytes);

lib/std/RingBuffer.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This ring buffer stores read and write indices while being able to utilise
22
//! the full backing slice by incrementing the indices modulo twice the slice's
33
//! length and reducing indices modulo the slice's length on slice access. This
4-
//! means that whether the ring buffer if full or empty can be distinguished by
4+
//! means that whether the ring buffer is full or empty can be distinguished by
55
//! looking at the difference between the read and write indices without adding
66
//! an extra boolean flag or having to reserve a slot in the buffer.
77
//!

lib/std/Uri.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Implements URI parsing roughly adhering to <https://tools.ietf.org/html/rfc3986>.
1+
//! Uniform Resource Identifier (URI) parsing roughly adhering to <https://tools.ietf.org/html/rfc3986>.
22
//! Does not do perfect grammar and character class checking, but should be robust against URIs in the wild.
33

44
const Uri = @This();

lib/std/array_list.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
221221
/// Asserts the array has at least one item.
222222
/// Invalidates pointers to end of list.
223223
/// This operation is O(N).
224+
/// This preserves item order. Use `swapRemove` if order preservation is not important.
224225
pub fn orderedRemove(self: *Self, i: usize) T {
225226
const newlen = self.items.len - 1;
226227
if (newlen == i) return self.pop();
@@ -235,6 +236,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
235236
/// Removes the element at the specified index and returns it.
236237
/// The empty slot is filled from the end of the list.
237238
/// This operation is O(1).
239+
/// This may not preserve item order. Use `orderedRemove` if you need to preserve order.
238240
pub fn swapRemove(self: *Self, i: usize) T {
239241
if (self.items.len - 1 == i) return self.pop();
240242

lib/std/bit_set.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ const assert = std.debug.assert;
3535
const Allocator = std.mem.Allocator;
3636

3737
/// Returns the optimal static bit set type for the specified number
38-
/// of elements. The returned type will perform no allocations,
38+
/// of elements: either `IntegerBitSet` or `ArrayBitSet`,
39+
/// both of which fulfill the same interface.
40+
/// The returned type will perform no allocations,
3941
/// can be copied by value, and does not require deinitialization.
40-
/// Both possible implementations fulfill the same interface.
4142
pub fn StaticBitSet(comptime size: usize) type {
4243
if (size <= @bitSizeOf(usize)) {
4344
return IntegerBitSet(size);

lib/std/builtin.zig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,47 @@ pub const Mode = OptimizeMode;
144144
/// This data structure is used by the Zig language code generation and
145145
/// therefore must be kept in sync with the compiler implementation.
146146
pub const CallingConvention = enum {
147+
/// This is the default Zig calling convention used when not using `export` on `fn`
148+
/// and no other calling convention is specified.
147149
Unspecified,
150+
/// Matches the C ABI for the target.
151+
/// This is the default calling convention when using `export` on `fn`
152+
/// and no other calling convention is specified.
148153
C,
154+
/// This makes a function not have any function prologue or epilogue,
155+
/// making the function itself uncallable in regular Zig code.
156+
/// This can be useful when integrating with assembly.
149157
Naked,
158+
/// Functions with this calling convention are called asynchronously,
159+
/// as if called as `async function()`.
150160
Async,
161+
/// Functions with this calling convention are inlined at all call sites.
151162
Inline,
163+
/// x86-only.
152164
Interrupt,
153165
Signal,
166+
/// x86-only.
154167
Stdcall,
168+
/// x86-only.
155169
Fastcall,
170+
/// x86-only.
156171
Vectorcall,
172+
/// x86-only.
157173
Thiscall,
174+
/// ARM Procedure Call Standard (obsolete)
175+
/// ARM-only.
158176
APCS,
177+
/// ARM Architecture Procedure Call Standard (current standard)
178+
/// ARM-only.
159179
AAPCS,
180+
/// ARM Architecture Procedure Call Standard Vector Floating-Point
181+
/// ARM-only.
160182
AAPCSVFP,
183+
/// x86-64-only.
161184
SysV,
185+
/// x86-64-only.
162186
Win64,
187+
/// AMD GPU, NVPTX, or SPIR-V kernel
163188
Kernel,
164189
};
165190

@@ -716,6 +741,8 @@ pub const VaList = switch (builtin.cpu.arch) {
716741
pub const PrefetchOptions = struct {
717742
/// Whether the prefetch should prepare for a read or a write.
718743
rw: Rw = .read,
744+
/// The data's locality in an inclusive range from 0 to 3.
745+
///
719746
/// 0 means no temporal locality. That is, the data can be immediately
720747
/// dropped from the cache after it is accessed.
721748
///

lib/std/c/darwin.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,3 +3846,11 @@ pub extern "c" fn os_signpost_interval_begin(log: os_log_t, signpos: os_signpost
38463846
pub extern "c" fn os_signpost_interval_end(log: os_log_t, signpos: os_signpost_id_t, func: [*]const u8, ...) void;
38473847
pub extern "c" fn os_signpost_id_make_with_pointer(log: os_log_t, ptr: ?*anyopaque) os_signpost_id_t;
38483848
pub extern "c" fn os_signpost_enabled(log: os_log_t) bool;
3849+
3850+
pub extern "c" fn proc_listpids(tpe: u32, tinfo: u32, buffer: ?*anyopaque, buffersize: c_int) c_int;
3851+
pub extern "c" fn proc_listallpids(buffer: ?*anyopaque, buffersize: c_int) c_int;
3852+
pub extern "c" fn proc_listpgrppids(pgrpid: pid_t, buffer: ?*anyopaque, buffersize: c_int) c_int;
3853+
pub extern "c" fn proc_listchildpids(ppid: pid_t, buffer: ?*anyopaque, buffersize: c_int) c_int;
3854+
pub extern "c" fn proc_pidinfo(pid: c_int, flavor: c_int, arg: u64, buffer: ?*anyopaque, buffersize: c_int) c_int;
3855+
pub extern "c" fn proc_name(pid: c_int, buffer: ?*anyopaque, buffersize: u32) c_int;
3856+
pub extern "c" fn proc_pidpath(pid: c_int, buffer: ?*anyopaque, buffersize: u32) c_int;

lib/std/c/dragonfly.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,3 +1143,20 @@ pub const POLL = struct {
11431143
pub const HUP = 0x0010;
11441144
pub const NVAL = 0x0020;
11451145
};
1146+
1147+
pub const SIGEV = struct {
1148+
pub const NONE = 0;
1149+
pub const SIGNAL = 1;
1150+
pub const THREAD = 2;
1151+
};
1152+
1153+
pub const sigevent = extern struct {
1154+
sigev_notify: c_int,
1155+
__sigev_u: extern union {
1156+
__sigev_signo: c_int,
1157+
__sigev_notify_kqueue: c_int,
1158+
__sigev_notify_attributes: ?*pthread_attr_t,
1159+
},
1160+
sigev_value: sigval,
1161+
sigev_notify_function: ?*const fn (sigval) callconv(.C) void,
1162+
};

0 commit comments

Comments
 (0)