From bc8e1e1de4a2f22c56528240d320f682f1ec4b69 Mon Sep 17 00:00:00 2001 From: zooster Date: Sun, 23 Apr 2023 20:06:21 +0200 Subject: [PATCH] Improvements to docs and text * 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. --- doc/langref.html.in | 27 +++++++++++-------- lib/std/Build/Cache.zig | 2 +- lib/std/RingBuffer.zig | 2 +- lib/std/Uri.zig | 2 +- lib/std/array_list.zig | 2 ++ lib/std/bit_set.zig | 5 ++-- lib/std/builtin.zig | 27 +++++++++++++++++++ lib/std/compress/zstandard.zig | 2 +- lib/std/compress/zstandard/decode/fse.zig | 2 +- lib/std/debug.zig | 2 ++ lib/std/fmt.zig | 2 +- lib/std/fs/path.zig | 7 +++-- lib/std/macho.zig | 4 +-- lib/std/math.zig | 7 ++--- lib/std/mem.zig | 2 +- lib/std/os/linux/seccomp.zig | 2 +- lib/std/rand.zig | 2 ++ src/Air.zig | 2 +- src/Autodoc.zig | 4 +-- src/Sema.zig | 10 +++---- src/link/NvPtx.zig | 2 +- src/main.zig | 4 +-- ...nion_init_with_none_or_multiple_fields.zig | 4 +-- .../variadic_arg_validation.zig | 2 +- 24 files changed, 83 insertions(+), 44 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index a8af959615..254f119d3d 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -1422,7 +1422,8 @@ fn foo() i32 { {#header_open|Thread Local Variables#}

A variable may be specified to be a thread-local variable using the - {#syntax#}threadlocal{#endsyntax#} keyword:

+ {#syntax#}threadlocal{#endsyntax#} keyword, + which makes each thread work with a separate instance of the variable:

{#code_begin|test|test_thread_local_variables#} const std = @import("std"); const assert = std.debug.assert; @@ -4278,7 +4279,7 @@ const expectError = std.testing.expectError; fn isFieldOptional(comptime T: type, field_index: usize) !bool { const fields = @typeInfo(T).Struct.fields; return switch (field_index) { - // This prong is analyzed `fields.len - 1` times with `idx` being an + // This prong is analyzed `fields.len - 1` times with `idx` being a // unique comptime-known value each time. inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional, else => return error.IndexOutOfBounds, @@ -8040,7 +8041,7 @@ pub const CallModifier = enum {

{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.

{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.

- This function counts the number of most-significant (leading in a big-Endian sense) zeroes in an integer. + Counts the number of most-significant (leading in a big-endian sense) zeroes in an integer - "count leading zeroes".

If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, @@ -8190,7 +8191,7 @@ test "main" {

{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type or an integer vector type.

{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.

- This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in an integer. + Counts the number of least-significant (trailing in a big-endian sense) zeroes in an integer - "count trailing zeroes".

If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, @@ -8576,11 +8577,11 @@ test "@hasDecl" {

{#see_also|Compile Variables|@embedFile#} @@ -8803,7 +8804,9 @@ test "@wasmMemoryGrow" {
{#syntax#}@popCount(operand: anytype) anytype{#endsyntax#}

{#syntax#}@TypeOf(operand){#endsyntax#} must be an integer type.

{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.

-

Counts the number of bits set in an integer.

+

+ Counts the number of bits set in an integer - "population count". +

If {#syntax#}operand{#endsyntax#} is a {#link|comptime#}-known integer, the return type is {#syntax#}comptime_int{#endsyntax#}. @@ -8835,6 +8838,8 @@ test "@wasmMemoryGrow" { pub const PrefetchOptions = struct { /// Whether the prefetch should prepare for a read or a write. rw: Rw = .read, + /// The data's locality in an inclusive range from 0 to 3. + /// /// 0 means no temporal locality. That is, the data can be immediately /// dropped from the cache after it is accessed. /// @@ -8844,12 +8849,12 @@ pub const PrefetchOptions = struct { /// The cache that the prefetch should be preformed on. cache: Cache = .data, - pub const Rw = enum { + pub const Rw = enum(u1) { read, write, }; - pub const Cache = enum { + pub const Cache = enum(u1) { instruction, data, }; @@ -10971,7 +10976,7 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke

{#syntax#}[*c]T{#endsyntax#} - C pointer.