| author | |
| committer | |
| log | bc8e1e1de4a2f22c56528240d320f682f1ec4b69 |
| tree | ad2bd1a996d5cb74570e22bda1adc00c59867c08 |
| parent | 658b4db223c24616a95cdf3bb3226caa23a3b50e |
| signature |
* docs(std.math): elaborate on difference between absCast and absInt
* docs(std.rand.Random.weightedIndex): elaborate on likelihood
I think this makes it easier to understand.
* langref: add small reminder
* docs(std.fs.path.extension): brevity
* docs(std.bit_set.StaticBitSet): mention the specific types
* std.debug.TTY: explain what purpose this struct serves
This should also make it clearer that this struct is not supposed to provide unrelated terminal manipulation functionality such as setting the cursor position or something because terminals are complicated and we should keep this struct simple and focused on debugging.
* langref(package listing): brevity
* langref: explain what exactly `threadlocal` causes to happen
* std.array_list: link between swapRemove and orderedRemove
Maybe this can serve as a TLDR and make it easier to decide.
* PrefetchOptions.locality: clarify docs that this is a range
This confused me previously and I thought I can only use either 0 or 3.
* fix typos and more
* std.builtin.CallingConvention: document some CCs
* langref: explain possibly cryptic names
I think it helps knowing what exactly these acronyms (@clz and @ctz) and
abbreviations (@popCount) mean.
* variadic function error: add missing preposition
* std.fmt.format docs: nicely hyphenate
* help menu: say what to optimize for
I think this is slightly more specific than just calling it
"optimizations". These are speed optimizations. I used the word
"performance" here.24 files changed, 83 insertions(+), 44 deletions(-)
doc/langref.html.in+16-11| ... | @@ -1422,7 +1422,8 @@ fn foo() i32 { | ... | @@ -1422,7 +1422,8 @@ fn foo() i32 { |
| 1422 | 1422 | ||
| 1423 | {#header_open|Thread Local Variables#} | 1423 | {#header_open|Thread Local Variables#} |
| 1424 | <p>A variable may be specified to be a thread-local variable using the | 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 | {#code_begin|test|test_thread_local_variables#} | 1427 | {#code_begin|test|test_thread_local_variables#} |
| 1427 | const std = @import("std"); | 1428 | const std = @import("std"); |
| 1428 | const assert = std.debug.assert; | 1429 | const assert = std.debug.assert; |
| ... | @@ -4278,7 +4279,7 @@ const expectError = std.testing.expectError; | ... | @@ -4278,7 +4279,7 @@ const expectError = std.testing.expectError; |
| 4278 | fn isFieldOptional(comptime T: type, field_index: usize) !bool { | 4279 | fn isFieldOptional(comptime T: type, field_index: usize) !bool { |
| 4279 | const fields = @typeInfo(T).Struct.fields; | 4280 | const fields = @typeInfo(T).Struct.fields; |
| 4280 | return switch (field_index) { | 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 | // unique comptime-known value each time. | 4283 | // unique comptime-known value each time. |
| 4283 | inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional, | 4284 | inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional, |
| 4284 | else => return error.IndexOutOfBounds, | 4285 | else => return error.IndexOutOfBounds, |
| ... | @@ -8040,7 +8041,7 @@ pub const CallModifier = enum { | ... | @@ -8040,7 +8041,7 @@ pub const CallModifier = enum { |
| 8040 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p> | 8041 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p> |
| 8041 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> | 8042 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> |
| 8042 | <p> | 8043 | <p> |
| 8043 | 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". |
| 8044 | </p> | 8045 | </p> |
| 8045 | <p> | 8046 | <p> |
| 8046 | If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, | 8047 | If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, |
| ... | @@ -8190,7 +8191,7 @@ test "main" { | ... | @@ -8190,7 +8191,7 @@ test "main" { |
| 8190 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p> | 8191 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.</p> |
| 8191 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> | 8192 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> |
| 8192 | <p> | 8193 | <p> |
| 8193 | 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". |
| 8194 | </p> | 8195 | </p> |
| 8195 | <p> | 8196 | <p> |
| 8196 | If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, | 8197 | If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, |
| ... | @@ -8576,11 +8577,11 @@ test "@hasDecl" { | ... | @@ -8576,11 +8577,11 @@ test "@hasDecl" { |
| 8576 | </p> | 8577 | </p> |
| 8577 | <ul> | 8578 | <ul> |
| 8578 | <li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li> | 8579 | <li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li> |
| 8579 | <li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information. | 8580 | <li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information |
| 8580 | The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference. | 8581 | The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference. |
| 8581 | </li> | 8582 | </li> |
| 8582 | <li>{#syntax#}@import("root"){#endsyntax#} - Points to the root source file. | 8583 | <li>{#syntax#}@import("root"){#endsyntax#} - Root source file |
| 8583 | This is usually <code>src/main.zig</code> but it depends on what file is chosen to be built. | 8584 | This is usually <code>src/main.zig</code> but depends on what file is built. |
| 8584 | </li> | 8585 | </li> |
| 8585 | </ul> | 8586 | </ul> |
| 8586 | {#see_also|Compile Variables|@embedFile#} | 8587 | {#see_also|Compile Variables|@embedFile#} |
| ... | @@ -8803,7 +8804,9 @@ test "@wasmMemoryGrow" { | ... | @@ -8803,7 +8804,9 @@ test "@wasmMemoryGrow" { |
| 8803 | <pre>{#syntax#}@popCount(operand: anytype) anytype{#endsyntax#}</pre> | 8804 | <pre>{#syntax#}@popCount(operand: anytype) anytype{#endsyntax#}</pre> |
| 8804 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.</p> | 8805 | <p>{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.</p> |
| 8805 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> | 8806 | <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p> |
| 8806 | <p>Counts the number of bits set in an integer.</p> | 8807 | <p> |
| 8808 | Counts the number of bits set in an integer - "population count". | ||
| 8809 | </p> | ||
| 8807 | <p> | 8810 | <p> |
| 8808 | If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, | 8811 | If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, |
| 8809 | the return type is {#syntax#}comptime_int{#endsyntax#}. | 8812 | the return type is {#syntax#}comptime_int{#endsyntax#}. |
| ... | @@ -8835,6 +8838,8 @@ test "@wasmMemoryGrow" { | ... | @@ -8835,6 +8838,8 @@ test "@wasmMemoryGrow" { |
| 8835 | pub const PrefetchOptions = struct { | 8838 | pub const PrefetchOptions = struct { |
| 8836 | /// Whether the prefetch should prepare for a read or a write. | 8839 | /// Whether the prefetch should prepare for a read or a write. |
| 8837 | rw: Rw = .read, | 8840 | rw: Rw = .read, |
| 8841 | /// The data's locality in an inclusive range from 0 to 3. | ||
| 8842 | /// | ||
| 8838 | /// 0 means no temporal locality. That is, the data can be immediately | 8843 | /// 0 means no temporal locality. That is, the data can be immediately |
| 8839 | /// dropped from the cache after it is accessed. | 8844 | /// dropped from the cache after it is accessed. |
| 8840 | /// | 8845 | /// |
| ... | @@ -8844,12 +8849,12 @@ pub const PrefetchOptions = struct { | ... | @@ -8844,12 +8849,12 @@ pub const PrefetchOptions = struct { |
| 8844 | /// The cache that the prefetch should be preformed on. | 8849 | /// The cache that the prefetch should be preformed on. |
| 8845 | cache: Cache = .data, | 8850 | cache: Cache = .data, |
| 8846 | 8851 | ||
| 8847 | pub const Rw = enum { | 8852 | pub const Rw = enum(u1) { |
| 8848 | read, | 8853 | read, |
| 8849 | write, | 8854 | write, |
| 8850 | }; | 8855 | }; |
| 8851 | 8856 | ||
| 8852 | pub const Cache = enum { | 8857 | pub const Cache = enum(u1) { |
| 8853 | instruction, | 8858 | instruction, |
| 8854 | data, | 8859 | data, |
| 8855 | }; | 8860 | }; |
| ... | @@ -10971,7 +10976,7 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke | ... | @@ -10971,7 +10976,7 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke |
| 10971 | </p> | 10976 | </p> |
| 10972 | <p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p> | 10977 | <p>{#syntax#}[*c]T{#endsyntax#} - C pointer.</p> |
| 10973 | <ul> | 10978 | <ul> |
| 10974 | <li>Supports all the syntax of the other two pointer types.</li> | 10979 | <li>Supports all the syntax of the other two pointer types ({#syntax#}*T{#endsyntax#}) and ({#syntax#}[*]T{#endsyntax#}).</li> |
| 10975 | <li>Coerces to other pointer types, as well as {#link|Optional Pointers#}. | 10980 | <li>Coerces to other pointer types, as well as {#link|Optional Pointers#}. |
| 10976 | When a C pointer is coerced to a non-optional pointer, safety-checked | 10981 | When a C pointer is coerced to a non-optional pointer, safety-checked |
| 10977 | {#link|Undefined Behavior#} occurs if the address is 0. | 10982 | {#link|Undefined Behavior#} occurs if the address is 0. |
lib/std/Build/Cache.zig+1-1| ... | @@ -184,7 +184,7 @@ pub const File = struct { | ... | @@ -184,7 +184,7 @@ pub const File = struct { |
| 184 | pub const HashHelper = struct { | 184 | pub const HashHelper = struct { |
| 185 | hasher: Hasher = hasher_init, | 185 | hasher: Hasher = hasher_init, |
| 186 | 186 | ||
| 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. |
| 188 | pub fn addBytes(hh: *HashHelper, bytes: []const u8) void { | 188 | pub fn addBytes(hh: *HashHelper, bytes: []const u8) void { |
| 189 | hh.hasher.update(mem.asBytes(&bytes.len)); | 189 | hh.hasher.update(mem.asBytes(&bytes.len)); |
| 190 | hh.hasher.update(bytes); | 190 | hh.hasher.update(bytes); |
lib/std/RingBuffer.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | //! This ring buffer stores read and write indices while being able to utilise | 1 | //! This ring buffer stores read and write indices while being able to utilise |
| 2 | //! the full backing slice by incrementing the indices modulo twice the slice's | 2 | //! the full backing slice by incrementing the indices modulo twice the slice's |
| 3 | //! length and reducing indices modulo the slice's length on slice access. This | 3 | //! 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 |
| 5 | //! looking at the difference between the read and write indices without adding | 5 | //! looking at the difference between the read and write indices without adding |
| 6 | //! an extra boolean flag or having to reserve a slot in the buffer. | 6 | //! an extra boolean flag or having to reserve a slot in the buffer. |
| 7 | //! | 7 | //! |
lib/std/Uri.zig+1-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -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>. |
| 2 | //! Does not do perfect grammar and character class checking, but should be robust against URIs in the wild. | 2 | //! Does not do perfect grammar and character class checking, but should be robust against URIs in the wild. |
| 3 | 3 | ||
| 4 | const Uri = @This(); | 4 | const Uri = @This(); |
lib/std/array_list.zig+2| ... | @@ -221,6 +221,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -221,6 +221,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 221 | /// Asserts the array has at least one item. | 221 | /// Asserts the array has at least one item. |
| 222 | /// Invalidates pointers to end of list. | 222 | /// Invalidates pointers to end of list. |
| 223 | /// This operation is O(N). | 223 | /// This operation is O(N). |
| 224 | /// This preserves item order. Use `swapRemove` if order preservation is not important. | ||
| 224 | pub fn orderedRemove(self: *Self, i: usize) T { | 225 | pub fn orderedRemove(self: *Self, i: usize) T { |
| 225 | const newlen = self.items.len - 1; | 226 | const newlen = self.items.len - 1; |
| 226 | if (newlen == i) return self.pop(); | 227 | if (newlen == i) return self.pop(); |
| ... | @@ -235,6 +236,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -235,6 +236,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 235 | /// Removes the element at the specified index and returns it. | 236 | /// Removes the element at the specified index and returns it. |
| 236 | /// The empty slot is filled from the end of the list. | 237 | /// The empty slot is filled from the end of the list. |
| 237 | /// This operation is O(1). | 238 | /// This operation is O(1). |
| 239 | /// This may not preserve item order. Use `orderedRemove` if you need to preserve order. | ||
| 238 | pub fn swapRemove(self: *Self, i: usize) T { | 240 | pub fn swapRemove(self: *Self, i: usize) T { |
| 239 | if (self.items.len - 1 == i) return self.pop(); | 241 | if (self.items.len - 1 == i) return self.pop(); |
| 240 | 242 |
lib/std/bit_set.zig+3-2| ... | @@ -35,9 +35,10 @@ const assert = std.debug.assert; | ... | @@ -35,9 +35,10 @@ const assert = std.debug.assert; |
| 35 | const Allocator = std.mem.Allocator; | 35 | const Allocator = std.mem.Allocator; |
| 36 | 36 | ||
| 37 | /// Returns the optimal static bit set type for the specified number | 37 | /// 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, | ||
| 39 | /// can be copied by value, and does not require deinitialization. | 41 | /// can be copied by value, and does not require deinitialization. |
| 40 | /// Both possible implementations fulfill the same interface. | ||
| 41 | pub fn StaticBitSet(comptime size: usize) type { | 42 | pub fn StaticBitSet(comptime size: usize) type { |
| 42 | if (size <= @bitSizeOf(usize)) { | 43 | if (size <= @bitSizeOf(usize)) { |
| 43 | return IntegerBitSet(size); | 44 | return IntegerBitSet(size); |
lib/std/builtin.zig+27| ... | @@ -144,22 +144,47 @@ pub const Mode = OptimizeMode; | ... | @@ -144,22 +144,47 @@ pub const Mode = OptimizeMode; |
| 144 | /// This data structure is used by the Zig language code generation and | 144 | /// This data structure is used by the Zig language code generation and |
| 145 | /// therefore must be kept in sync with the compiler implementation. | 145 | /// therefore must be kept in sync with the compiler implementation. |
| 146 | pub const CallingConvention = enum { | 146 | 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. | ||
| 147 | Unspecified, | 149 | 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. | ||
| 148 | C, | 153 | 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. | ||
| 149 | Naked, | 157 | Naked, |
| 158 | /// Functions with this calling convention are called asynchronously, | ||
| 159 | /// as if called as `async function()`. | ||
| 150 | Async, | 160 | Async, |
| 161 | /// Functions with this calling convention are inlined at all call sites. | ||
| 151 | Inline, | 162 | Inline, |
| 163 | /// x86-only. | ||
| 152 | Interrupt, | 164 | Interrupt, |
| 153 | Signal, | 165 | Signal, |
| 166 | /// x86-only. | ||
| 154 | Stdcall, | 167 | Stdcall, |
| 168 | /// x86-only. | ||
| 155 | Fastcall, | 169 | Fastcall, |
| 170 | /// x86-only. | ||
| 156 | Vectorcall, | 171 | Vectorcall, |
| 172 | /// x86-only. | ||
| 157 | Thiscall, | 173 | Thiscall, |
| 174 | /// ARM Procedure Call Standard (obsolete) | ||
| 175 | /// ARM-only. | ||
| 158 | APCS, | 176 | APCS, |
| 177 | /// ARM Architecture Procedure Call Standard (current standard) | ||
| 178 | /// ARM-only. | ||
| 159 | AAPCS, | 179 | AAPCS, |
| 180 | /// ARM Architecture Procedure Call Standard Vector Floating-Point | ||
| 181 | /// ARM-only. | ||
| 160 | AAPCSVFP, | 182 | AAPCSVFP, |
| 183 | /// x86-64-only. | ||
| 161 | SysV, | 184 | SysV, |
| 185 | /// x86-64-only. | ||
| 162 | Win64, | 186 | Win64, |
| 187 | /// AMD GPU, NVPTX, or SPIR-V kernel | ||
| 163 | Kernel, | 188 | Kernel, |
| 164 | }; | 189 | }; |
| 165 | 190 | ||
| ... | @@ -716,6 +741,8 @@ pub const VaList = switch (builtin.cpu.arch) { | ... | @@ -716,6 +741,8 @@ pub const VaList = switch (builtin.cpu.arch) { |
| 716 | pub const PrefetchOptions = struct { | 741 | pub const PrefetchOptions = struct { |
| 717 | /// Whether the prefetch should prepare for a read or a write. | 742 | /// Whether the prefetch should prepare for a read or a write. |
| 718 | rw: Rw = .read, | 743 | rw: Rw = .read, |
| 744 | /// The data's locality in an inclusive range from 0 to 3. | ||
| 745 | /// | ||
| 719 | /// 0 means no temporal locality. That is, the data can be immediately | 746 | /// 0 means no temporal locality. That is, the data can be immediately |
| 720 | /// dropped from the cache after it is accessed. | 747 | /// dropped from the cache after it is accessed. |
| 721 | /// | 748 | /// |
lib/std/compress/zstandard.zig+1-1| ... | @@ -10,7 +10,7 @@ pub const decompress = @import("zstandard/decompress.zig"); | ... | @@ -10,7 +10,7 @@ pub const decompress = @import("zstandard/decompress.zig"); |
| 10 | 10 | ||
| 11 | pub const DecompressStreamOptions = struct { | 11 | pub const DecompressStreamOptions = struct { |
| 12 | verify_checksum: bool = true, | 12 | verify_checksum: bool = true, |
| 13 | window_size_max: usize = 1 << 23, // 8MiB default maximum window size, | 13 | window_size_max: usize = 1 << 23, // 8MiB default maximum window size |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | pub fn DecompressStream( | 16 | pub fn DecompressStream( |
lib/std/compress/zstandard/decode/fse.zig+1-1| ... | @@ -21,7 +21,7 @@ pub fn decodeFseTable( | ... | @@ -21,7 +21,7 @@ pub fn decodeFseTable( |
| 21 | var accumulated_probability: u16 = 0; | 21 | var accumulated_probability: u16 = 0; |
| 22 | 22 | ||
| 23 | while (accumulated_probability < total_probability) { | 23 | while (accumulated_probability < total_probability) { |
| 24 | // WARNING: The RFC in poorly worded, and would suggest std.math.log2_int_ceil is correct here, | 24 | // WARNING: The RFC is poorly worded, and would suggest std.math.log2_int_ceil is correct here, |
| 25 | // but power of two (remaining probabilities + 1) need max bits set to 1 more. | 25 | // but power of two (remaining probabilities + 1) need max bits set to 1 more. |
| 26 | const max_bits = std.math.log2_int(u16, total_probability - accumulated_probability + 1) + 1; | 26 | const max_bits = std.math.log2_int(u16, total_probability - accumulated_probability + 1) + 1; |
| 27 | const small = try bit_reader.readBitsNoEof(u16, max_bits - 1); | 27 | const small = try bit_reader.readBitsNoEof(u16, max_bits - 1); |
lib/std/debug.zig+2| ... | @@ -651,6 +651,8 @@ pub fn writeCurrentStackTraceWindows( | ... | @@ -651,6 +651,8 @@ pub fn writeCurrentStackTraceWindows( |
| 651 | } | 651 | } |
| 652 | } | 652 | } |
| 653 | 653 | ||
| 654 | /// Provides simple functionality for manipulating the terminal in some way, | ||
| 655 | /// for debugging purposes, such as coloring text, etc. | ||
| 654 | pub const TTY = struct { | 656 | pub const TTY = struct { |
| 655 | pub const Color = enum { | 657 | pub const Color = enum { |
| 656 | Red, | 658 | Red, |
lib/std/fmt.zig+1-1| ... | @@ -41,7 +41,7 @@ pub const FormatOptions = struct { | ... | @@ -41,7 +41,7 @@ pub const FormatOptions = struct { |
| 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 text | 43 | /// - *fill* is a single character which is used to pad the formatted text |
| 44 | /// - *alignment* is one of the three characters `<`, `^` or `>`. they define if the text is *left*, *center*, or *right* aligned | 44 | /// - *alignment* is one of the three characters `<`, `^`, or `>` to make the text left-, center-, or right-aligned, respectively |
| 45 | /// - *width* is the total width of the field in characters | 45 | /// - *width* is the total width of the field in characters |
| 46 | /// - *precision* specifies how many decimals a formatted number should have | 46 | /// - *precision* specifies how many decimals a formatted number should have |
| 47 | /// | 47 | /// |
lib/std/fs/path.zig+3-4| ... | @@ -1214,10 +1214,9 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons | ... | @@ -1214,10 +1214,9 @@ fn testRelativeWindows(from: []const u8, to: []const u8, expected_output: []cons |
| 1214 | try testing.expectEqualStrings(expected_output, result); | 1214 | try testing.expectEqualStrings(expected_output, result); |
| 1215 | } | 1215 | } |
| 1216 | 1216 | ||
| 1217 | /// Returns the extension of the file name (if any). | 1217 | /// Searches for a file extension separated by a `.` and returns the string after that `.`. |
| 1218 | /// This function will search for the file extension (separated by a `.`) and will return the text after the `.`. | 1218 | /// Files that end or start with `.` and have no other `.` in their name |
| 1219 | /// Files that end with `.`, or that start with `.` and have no other `.` in their name, | 1219 | /// are considered to have no extension, in which case this returns "". |
| 1220 | /// are considered to have no extension. | ||
| 1221 | /// Examples: | 1220 | /// Examples: |
| 1222 | /// - `"main.zig"` ⇒ `".zig"` | 1221 | /// - `"main.zig"` ⇒ `".zig"` |
| 1223 | /// - `"src/main.zig"` ⇒ `".zig"` | 1222 | /// - `"src/main.zig"` ⇒ `".zig"` |
lib/std/macho.zig+2-2| ... | @@ -540,13 +540,13 @@ pub const dylib_command = extern struct { | ... | @@ -540,13 +540,13 @@ pub const dylib_command = extern struct { |
| 540 | dylib: dylib, | 540 | dylib: dylib, |
| 541 | }; | 541 | }; |
| 542 | 542 | ||
| 543 | /// Dynamicaly linked shared libraries are identified by two things. The | 543 | /// Dynamically linked shared libraries are identified by two things. The |
| 544 | /// pathname (the name of the library as found for execution), and the | 544 | /// pathname (the name of the library as found for execution), and the |
| 545 | /// compatibility version number. The pathname must match and the compatibility | 545 | /// compatibility version number. The pathname must match and the compatibility |
| 546 | /// number in the user of the library must be greater than or equal to the | 546 | /// number in the user of the library must be greater than or equal to the |
| 547 | /// library being used. The time stamp is used to record the time a library was | 547 | /// library being used. The time stamp is used to record the time a library was |
| 548 | /// built and copied into user so it can be use to determined if the library used | 548 | /// built and copied into user so it can be use to determined if the library used |
| 549 | /// at runtime is exactly the same as used to built the program. | 549 | /// at runtime is exactly the same as used to build the program. |
| 550 | pub const dylib = extern struct { | 550 | pub const dylib = extern struct { |
| 551 | /// library's pathname (offset pointing at the end of dylib_command) | 551 | /// library's pathname (offset pointing at the end of dylib_command) |
| 552 | name: u32, | 552 | name: u32, |
lib/std/math.zig+4-3| ... | @@ -782,7 +782,8 @@ fn testOverflow() !void { | ... | @@ -782,7 +782,8 @@ fn testOverflow() !void { |
| 782 | } | 782 | } |
| 783 | 783 | ||
| 784 | /// Returns the absolute value of x, where x is a value of a signed integer type. | 784 | /// Returns the absolute value of x, where x is a value of a signed integer type. |
| 785 | /// See also: `absCast` | 785 | /// Does not convert and returns a value of a signed integer type. |
| 786 | /// Use `absCast` if you want to convert the result and get an unsigned type. | ||
| 786 | pub fn absInt(x: anytype) !@TypeOf(x) { | 787 | pub fn absInt(x: anytype) !@TypeOf(x) { |
| 787 | const T = @TypeOf(x); | 788 | const T = @TypeOf(x); |
| 788 | return switch (@typeInfo(T)) { | 789 | return switch (@typeInfo(T)) { |
| ... | @@ -1015,8 +1016,8 @@ pub inline fn fabs(value: anytype) @TypeOf(value) { | ... | @@ -1015,8 +1016,8 @@ pub inline fn fabs(value: anytype) @TypeOf(value) { |
| 1015 | } | 1016 | } |
| 1016 | 1017 | ||
| 1017 | /// Returns the absolute value of the integer parameter. | 1018 | /// Returns the absolute value of the integer parameter. |
| 1018 | /// Result is an unsigned integer. | 1019 | /// Converts result type to unsigned if needed and returns a value of an unsigned integer type. |
| 1019 | /// See also: `absInt` | 1020 | /// Use `absInt` if you want to keep your integer type signed. |
| 1020 | pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { | 1021 | pub fn absCast(x: anytype) switch (@typeInfo(@TypeOf(x))) { |
| 1021 | .ComptimeInt => comptime_int, | 1022 | .ComptimeInt => comptime_int, |
| 1022 | .Int => |int_info| std.meta.Int(.unsigned, int_info.bits), | 1023 | .Int => |int_info| std.meta.Int(.unsigned, int_info.bits), |
lib/std/mem.zig+1-1| ... | @@ -227,7 +227,7 @@ pub fn set(comptime T: type, dest: []T, value: T) void { | ... | @@ -227,7 +227,7 @@ pub fn set(comptime T: type, dest: []T, value: T) void { |
| 227 | /// interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this | 227 | /// interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this |
| 228 | /// function used, examine closely - it may be a code smell. | 228 | /// function used, examine closely - it may be a code smell. |
| 229 | /// Zero initializes the type. | 229 | /// Zero initializes the type. |
| 230 | /// This can be used to zero initialize a any type for which it makes sense. Structs will be initialized recursively. | 230 | /// This can be used to zero-initialize any type for which it makes sense. Structs will be initialized recursively. |
| 231 | pub fn zeroes(comptime T: type) T { | 231 | pub fn zeroes(comptime T: type) T { |
| 232 | switch (@typeInfo(T)) { | 232 | switch (@typeInfo(T)) { |
| 233 | .ComptimeInt, .Int, .ComptimeFloat, .Float => { | 233 | .ComptimeInt, .Int, .ComptimeFloat, .Float => { |
lib/std/os/linux/seccomp.zig+1-1| ... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
| 20 | //! | 20 | //! |
| 21 | //! 1. Each CPU architecture supported by Linux has its own unique ABI and | 21 | //! 1. Each CPU architecture supported by Linux has its own unique ABI and |
| 22 | //! syscall API. It is not guaranteed that the syscall numbers and arguments | 22 | //! syscall API. It is not guaranteed that the syscall numbers and arguments |
| 23 | //! are the same across architectures, or that they're even implemted. Thus, | 23 | //! are the same across architectures, or that they're even implemented. Thus, |
| 24 | //! filters cannot be assumed to be portable without consulting documentation | 24 | //! filters cannot be assumed to be portable without consulting documentation |
| 25 | //! like syscalls(2) and testing on target hardware. This also requires | 25 | //! like syscalls(2) and testing on target hardware. This also requires |
| 26 | //! checking the value of `data.arch` to make sure that a filter was compiled | 26 | //! checking the value of `data.arch` to make sure that a filter was compiled |
lib/std/rand.zig+2| ... | @@ -389,6 +389,8 @@ pub const Random = struct { | ... | @@ -389,6 +389,8 @@ pub const Random = struct { |
| 389 | 389 | ||
| 390 | /// Randomly selects an index into `proportions`, where the likelihood of each | 390 | /// Randomly selects an index into `proportions`, where the likelihood of each |
| 391 | /// index is weighted by that proportion. | 391 | /// index is weighted by that proportion. |
| 392 | /// It is more likely for the index of the last proportion to be returned | ||
| 393 | /// than the index of the first proportion in the slice, and vice versa. | ||
| 392 | /// | 394 | /// |
| 393 | /// This is useful for selecting an item from a slice where weights are not equal. | 395 | /// This is useful for selecting an item from a slice where weights are not equal. |
| 394 | /// `T` must be a numeric type capable of holding the sum of `proportions`. | 396 | /// `T` must be a numeric type capable of holding the sum of `proportions`. |
src/Air.zig+1-1| ... | @@ -681,7 +681,7 @@ pub const Inst = struct { | ... | @@ -681,7 +681,7 @@ pub const Inst = struct { |
| 681 | /// Uses the `un_op` field. | 681 | /// Uses the `un_op` field. |
| 682 | tag_name, | 682 | tag_name, |
| 683 | 683 | ||
| 684 | /// Given an error value, return the error name. Result type is always `[:0] const u8`. | 684 | /// Given an error value, return the error name. Result type is always `[:0]const u8`. |
| 685 | /// Uses the `un_op` field. | 685 | /// Uses the `un_op` field. |
| 686 | error_name, | 686 | error_name, |
| 687 | 687 |
src/Autodoc.zig+2-2| ... | @@ -4076,7 +4076,7 @@ fn analyzeFancyFunction( | ... | @@ -4076,7 +4076,7 @@ fn analyzeFancyFunction( |
| 4076 | else => null, | 4076 | else => null, |
| 4077 | }; | 4077 | }; |
| 4078 | 4078 | ||
| 4079 | // if we're analyzing a funcion signature (ie without body), we | 4079 | // if we're analyzing a function signature (ie without body), we |
| 4080 | // actually don't have an ast_node reserved for us, but since | 4080 | // actually don't have an ast_node reserved for us, but since |
| 4081 | // we don't have a name, we don't need it. | 4081 | // we don't have a name, we don't need it. |
| 4082 | const src = if (fn_info.body.len == 0) 0 else self_ast_node_index; | 4082 | const src = if (fn_info.body.len == 0) 0 else self_ast_node_index; |
| ... | @@ -4229,7 +4229,7 @@ fn analyzeFunction( | ... | @@ -4229,7 +4229,7 @@ fn analyzeFunction( |
| 4229 | } else break :blk ret_type_ref; | 4229 | } else break :blk ret_type_ref; |
| 4230 | }; | 4230 | }; |
| 4231 | 4231 | ||
| 4232 | // if we're analyzing a funcion signature (ie without body), we | 4232 | // if we're analyzing a function signature (ie without body), we |
| 4233 | // actually don't have an ast_node reserved for us, but since | 4233 | // actually don't have an ast_node reserved for us, but since |
| 4234 | // we don't have a name, we don't need it. | 4234 | // we don't have a name, we don't need it. |
| 4235 | const src = if (fn_info.body.len == 0) 0 else self_ast_node_index; | 4235 | const src = if (fn_info.body.len == 0) 0 else self_ast_node_index; |
src/Sema.zig+5-5| ... | @@ -4155,7 +4155,7 @@ fn validateUnionInit( | ... | @@ -4155,7 +4155,7 @@ fn validateUnionInit( |
| 4155 | const msg = try sema.errMsg( | 4155 | const msg = try sema.errMsg( |
| 4156 | block, | 4156 | block, |
| 4157 | init_src, | 4157 | init_src, |
| 4158 | "cannot initialize multiple union fields at once, unions can only have one active field", | 4158 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 4159 | .{}, | 4159 | .{}, |
| 4160 | ); | 4160 | ); |
| 4161 | errdefer msg.destroy(sema.gpa); | 4161 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -9646,7 +9646,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9646,7 +9646,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9646 | .Union => "union", | 9646 | .Union => "union", |
| 9647 | else => unreachable, | 9647 | else => unreachable, |
| 9648 | }; | 9648 | }; |
| 9649 | return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}', {s} does not have a guaranteed in-memory layout", .{ | 9649 | return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'; {s} does not have a guaranteed in-memory layout", .{ |
| 9650 | dest_ty.fmt(sema.mod), container, | 9650 | dest_ty.fmt(sema.mod), container, |
| 9651 | }); | 9651 | }); |
| 9652 | }, | 9652 | }, |
| ... | @@ -9709,7 +9709,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -9709,7 +9709,7 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 9709 | .Union => "union", | 9709 | .Union => "union", |
| 9710 | else => unreachable, | 9710 | else => unreachable, |
| 9711 | }; | 9711 | }; |
| 9712 | return sema.fail(block, operand_src, "cannot @bitCast from '{}', {s} does not have a guaranteed in-memory layout", .{ | 9712 | return sema.fail(block, operand_src, "cannot @bitCast from '{}'; {s} does not have a guaranteed in-memory layout", .{ |
| 9713 | operand_ty.fmt(sema.mod), container, | 9713 | operand_ty.fmt(sema.mod), container, |
| 9714 | }); | 9714 | }); |
| 9715 | }, | 9715 | }, |
| ... | @@ -26434,7 +26434,7 @@ fn coerceVarArgParam( | ... | @@ -26434,7 +26434,7 @@ fn coerceVarArgParam( |
| 26434 | .ComptimeInt, .ComptimeFloat => return sema.fail( | 26434 | .ComptimeInt, .ComptimeFloat => return sema.fail( |
| 26435 | block, | 26435 | block, |
| 26436 | inst_src, | 26436 | inst_src, |
| 26437 | "integer and float literals passed variadic function must be casted to a fixed-size number type", | 26437 | "integer and float literals passed to variadic function must be casted to a fixed-size number type", |
| 26438 | .{}, | 26438 | .{}, |
| 26439 | ), | 26439 | ), |
| 26440 | .Fn => blk: { | 26440 | .Fn => blk: { |
| ... | @@ -27891,7 +27891,7 @@ fn coerceAnonStructToUnion( | ... | @@ -27891,7 +27891,7 @@ fn coerceAnonStructToUnion( |
| 27891 | const msg = if (field_count > 1) try sema.errMsg( | 27891 | const msg = if (field_count > 1) try sema.errMsg( |
| 27892 | block, | 27892 | block, |
| 27893 | inst_src, | 27893 | inst_src, |
| 27894 | "cannot initialize multiple union fields at once, unions can only have one active field", | 27894 | "cannot initialize multiple union fields at once; unions can only have one active field", |
| 27895 | .{}, | 27895 | .{}, |
| 27896 | ) else try sema.errMsg( | 27896 | ) else try sema.errMsg( |
| 27897 | block, | 27897 | block, |
src/link/NvPtx.zig+1-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | //! NVidia PTX (Paralle Thread Execution) | 1 | //! NVidia PTX (Parallel Thread Execution) |
| 2 | //! https://docs.nvidia.com/cuda/parallel-thread-execution/index.html | 2 | //! https://docs.nvidia.com/cuda/parallel-thread-execution/index.html |
| 3 | //! For this we rely on the nvptx backend of LLVM | 3 | //! For this we rely on the nvptx backend of LLVM |
| 4 | //! Kernel functions need to be marked both as "export" and "callconv(.Kernel)" | 4 | //! Kernel functions need to be marked both as "export" and "callconv(.Kernel)" |
src/main.zig+2-2| ... | @@ -402,8 +402,8 @@ const usage_build_generic = | ... | @@ -402,8 +402,8 @@ const usage_build_generic = |
| 402 | \\ --name [name] Override root name (not a file path) | 402 | \\ --name [name] Override root name (not a file path) |
| 403 | \\ -O [mode] Choose what to optimize for | 403 | \\ -O [mode] Choose what to optimize for |
| 404 | \\ Debug (default) Optimizations off, safety on | 404 | \\ Debug (default) Optimizations off, safety on |
| 405 | \\ ReleaseFast Optimizations on, safety off | 405 | \\ ReleaseFast Optimize for performance, safety off |
| 406 | \\ ReleaseSafe Optimizations on, safety on | 406 | \\ ReleaseSafe Optimize for performance, safety on |
| 407 | \\ ReleaseSmall Optimize for small binary, safety off | 407 | \\ ReleaseSmall Optimize for small binary, safety off |
| 408 | \\ --mod [name]:[deps]:[src] Make a module available for dependency under the given name | 408 | \\ --mod [name]:[deps]:[src] Make a module available for dependency under the given name |
| 409 | \\ deps: [dep],[dep],... | 409 | \\ deps: [dep],[dep],... |
test/cases/compile_errors/union_init_with_none_or_multiple_fields.zig+2-2| ... | @@ -29,10 +29,10 @@ export fn u2m() void { | ... | @@ -29,10 +29,10 @@ export fn u2m() void { |
| 29 | // | 29 | // |
| 30 | // :9:1: error: union initializer must initialize one field | 30 | // :9:1: error: union initializer must initialize one field |
| 31 | // :1:12: note: union declared here | 31 | // :1:12: note: union declared here |
| 32 | // :14:20: error: cannot initialize multiple union fields at once, unions can only have one active field | 32 | // :14:20: error: cannot initialize multiple union fields at once; unions can only have one active field |
| 33 | // :14:31: note: additional initializer here | 33 | // :14:31: note: additional initializer here |
| 34 | // :1:12: note: union declared here | 34 | // :1:12: note: union declared here |
| 35 | // :18:21: error: union initializer must initialize one field | 35 | // :18:21: error: union initializer must initialize one field |
| 36 | // :22:20: error: cannot initialize multiple union fields at once, unions can only have one active field | 36 | // :22:20: error: cannot initialize multiple union fields at once; unions can only have one active field |
| 37 | // :22:31: note: additional initializer here | 37 | // :22:31: note: additional initializer here |
| 38 | // :5:12: note: union declared here | 38 | // :5:12: note: union declared here |
test/cases/compile_errors/variadic_arg_validation.zig+1-1| ... | @@ -21,7 +21,7 @@ pub export fn entry3() void { | ... | @@ -21,7 +21,7 @@ pub export fn entry3() void { |
| 21 | // backend=stage2 | 21 | // backend=stage2 |
| 22 | // target=native | 22 | // target=native |
| 23 | // | 23 | // |
| 24 | // :4:33: error: integer and float literals passed variadic function must be casted to a fixed-size number type | 24 | // :4:33: error: integer and float literals passed to variadic function must be casted to a fixed-size number type |
| 25 | // :9:24: error: arrays must be passed by reference to variadic function | 25 | // :9:24: error: arrays must be passed by reference to variadic function |
| 26 | // :13:24: error: cannot pass 'u48' to variadic function | 26 | // :13:24: error: cannot pass 'u48' to variadic function |
| 27 | // :13:24: note: only integers with power of two bits are extern compatible | 27 | // :13:24: note: only integers with power of two bits are extern compatible |