diff --git a/README.md b/README.md index c236285..2b36a5f 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,13 @@ zig build -Drelease-safe | --- | --- | --- | --- | | `-Ddata_version` | `string` (master, 0.7.0 or 0.7.1) | master | The data file version. This selects the files in the `src/data` folder that correspond to the Zig version being served.| +#### Updating Data Files + +There is a `generate-data.py` in the `src/data` folder, run this file to update data files. +It writes to stdout and you can redirect output to a zig file like `master.zig`. By default it generates data file for `master`, but can be configured to generate for a different version by modifying the `zig_version` variable. Files generated by this tool **contains** formatting information. + +There is also a `generate-data.js` in the `src/data` folder, you'll need to run this inside a Chrome DevTools console and copy the output. Files generated by this tool **does not contain** formatting information. + ### Configuration Options You can configure zls by running `zls config` or manually creating your own `zls.json` configuration file. diff --git a/src/data/generate-data.py b/src/data/generate-data.py new file mode 100644 index 0000000..c8f12c4 --- /dev/null +++ b/src/data/generate-data.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 +import urllib.request +import re +import minify_html + +zig_version = 'master' + + +def fix_ul(s): + l = s.split('
  • ') + l.insert(0, '') + return '\n - '.join(l) + + +url = f'https://raw.githubusercontent.com/ziglang/zig/{zig_version}/doc/langref.html.in' +res = urllib.request.urlopen(url) +page = res.read().decode('utf-8') +print('''const Builtin = struct { + name: []const u8, + signature: []const u8, + snippet: []const u8, + documentation: []const u8, + arguments: []const []const u8, +}; + +pub const builtins = [_]Builtin{''') +pattern = r'{#header_open\|(@\S+?)#}(.+?){#header_close#}' +for match in re.finditer(pattern, page, re.M | re.S): + blk = match[2].strip(' \n') + name = match[1] + signature = re.search(r'
    {#syntax#}(.+?){#endsyntax#}
    ', blk, + re.M | re.S)[1].replace('\n ', '').replace('"', '\\"') + snippet = name + if f'{name}()' in signature: + params = None + snippet += '()' + else: + params = [] + i = signature.index('(') + 1 + level = 1 + j = i + while i < len(signature): + if signature[i] == '(': + level += 1 + elif signature[i] == ')': + level -= 1 + if signature[i] == ',' and level == 1: + params.append(signature[j:i]) + j = i + 2 + if level == 0: + break + i += 1 + params.append(signature[j:i]) + snippet += '(${' + i = 1 + for param in params: + snippet += f'{i}:{param}}}, ${{' + i += 1 + snippet = snippet[:-4] + ')' + docs = re.sub(r'{#see_also\|[^#]+#}', '', blk) + docs = re.sub( + r' {#code_begin\|(obj|syntax|(test(\|(call|truncate))?))#}\n', '
    {#syntax#}', docs)
    +    docs = re.sub(
    +        r'      {#code_begin\|test_(err|safety)\|[^#]+#}\n', '      
    {#syntax#}', docs)
    +    docs = docs.replace('      {#code_release_fast#}\n', '')
    +    docs = docs.replace('      {#code_end#}', '{#endsyntax#}
    ') + docs = docs.replace('\n{#endsyntax#}
    ', '{#endsyntax#}') + docs = minify_html.minify(docs) + prefix = '

    ' + docs = docs[docs.index(prefix)+len(prefix):] + docs = docs.replace('

    ', '\n\n') + docs = re.sub(r'{#(end)?syntax#}', '`', docs) + # @cDefine + docs = re.sub(r'

    ]+>([^<]+)
    ', '`\\1`', docs) + docs = re.sub(r'', '`', docs) + docs = docs.replace('
    `', '\n\n```zig\n')
    +    docs = docs.replace('`
    ', '\n```') + # @setFloatMode + docs = docs.replace('```<', '```\n<') + # @TypeOf + docs = re.sub(r'', '*', docs) + docs = re.sub(r']+)>([^<]+)', '[\\2](\\1)', docs) + docs = re.sub(r'{#link\|([^|#]+)\|([^|#]+)#}', + lambda m: f'[{m[1]}](https://ziglang.org/documentation/{zig_version}/#{m[2].replace(" ","-")})', docs) + docs = re.sub( + r'{#link\|([^|#]+)#}', lambda m: f'[{m[1]}](https://ziglang.org/documentation/{zig_version}/#{m[1].replace(" ","-").replace("@","")})', docs) + docs = re.sub(r'', lambda m: fix_ul(m[1]), docs) + + print(' .{') + print(f' .name = "{name}",') + print(f' .signature = "{signature}",') + print(f' .snippet = "{snippet}",') + print(' .documentation =') + for line in docs.splitlines(): + print(r' \\' + line) + print(' ,') + if params is None: + print(' .arguments = &.{},') + else: + print(' .arguments = &.{') + for param in params: + print(f' "{param}",') + print(' },') + print(' },') +print('};') diff --git a/src/data/master.zig b/src/data/master.zig index aa18436..eb98223 100644 --- a/src/data/master.zig +++ b/src/data/master.zig @@ -12,7 +12,7 @@ pub const builtins = [_]Builtin{ .signature = "@addWithOverflow(comptime T: type, a: T, b: T, result: *T) bool", .snippet = "@addWithOverflow(${1:comptime T: type}, ${2:a: T}, ${3:b: T}, ${4:result: *T})", .documentation = - \\ Performs `result.* = a + b`. If overflow or underflow occurs, stores the overflowed bits in `result` and returns `true`. If no overflow or underflow occurs, returns `false`. + \\Performs `result.* = a + b`. If overflow or underflow occurs, stores the overflowed bits in `result` and returns `true`. If no overflow or underflow occurs, returns `false`. , .arguments = &.{ "comptime T: type", @@ -26,8 +26,9 @@ pub const builtins = [_]Builtin{ .signature = "@alignCast(comptime alignment: u29, ptr: anytype) anytype", .snippet = "@alignCast(${1:comptime alignment: u29}, ${2:ptr: anytype})", .documentation = - \\ `ptr` can be `*T`, `fn()`, `?*T`, `?fn()`, or `[]T`. It returns the same type as `ptr` except with the alignment adjusted to the new value. - \\A pointer alignment safety check is added to the generated code to make sure the pointer is aligned as promised. + \\`ptr` can be `*T`, `fn()`, `?*T`, `?fn()`, or `[]T`. It returns the same type as `ptr` except with the alignment adjusted to the new value. + \\ + \\A [pointer alignment safety check](https://ziglang.org/documentation/master/#Incorrect-Pointer-Alignment) is added to the generated code to make sure the pointer is aligned as promised. , .arguments = &.{ "comptime alignment: u29", @@ -39,14 +40,16 @@ pub const builtins = [_]Builtin{ .signature = "@alignOf(comptime T: type) comptime_int", .snippet = "@alignOf(${1:comptime T: type})", .documentation = - \\ This function returns the number of bytes that this type should be aligned to for the current target to match the C ABI. When the child type of a pointer has this alignment, the alignment can be omitted from the type. + \\This function returns the number of bytes that this type should be aligned to for the current target to match the C ABI. When the child type of a pointer has this alignment, the alignment can be omitted from the type. + \\ \\```zig \\const expect = @import("std").debug.assert; \\comptime { \\ assert(*u32 == *align(@alignOf(u32)) u32); \\} \\``` - \\ The result is a target-specific compile time constant. It is guaranteed to be less than or equal to @sizeOf(T). + \\ + \\The result is a target-specific compile time constant. It is guaranteed to be less than or equal to [@sizeOf(T)](https://ziglang.org/documentation/master/#@sizeOf). , .arguments = &.{ "comptime T: type", @@ -57,7 +60,7 @@ pub const builtins = [_]Builtin{ .signature = "@as(comptime T: type, expression) T", .snippet = "@as(${1:comptime T: type}, ${2:expression})", .documentation = - \\ Performs Type Coercion. This cast is allowed when the conversion is unambiguous and safe, and is the preferred way to convert between types, whenever possible. + \\Performs [Type Coercion](https://ziglang.org/documentation/master/#Type-Coercion). This cast is allowed when the conversion is unambiguous and safe, and is the preferred way to convert between types, whenever possible. , .arguments = &.{ "comptime T: type", @@ -69,10 +72,12 @@ pub const builtins = [_]Builtin{ .signature = "@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: anytype) anyframe->T", .snippet = "@asyncCall(${1:frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8}, ${2:result_ptr}, ${3:function_ptr}, ${4:args: anytype})", .documentation = - \\ `@asyncCall` performs an `async` call on a function pointer, which may or may not be an async function. - \\ The provided `frame_buffer` must be large enough to fit the entire function frame. This size can be determined with @frameSize. To provide a too-small buffer invokes safety-checked Undefined Behavior. - \\ `result_ptr` is optional (null may be provided). If provided, the function call will write its result directly to the result pointer, which will be available to read after await completes. Any result location provided to `await` will copy the result from `result_ptr`. - \\test.zig + \\`@asyncCall` performs an `async` call on a function pointer, which may or may not be an [async function](https://ziglang.org/documentation/master/#Async-Functions). + \\ + \\The provided `frame_buffer` must be large enough to fit the entire function frame. This size can be determined with [@frameSize](https://ziglang.org/documentation/master/#frameSize). To provide a too-small buffer invokes safety-checked [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). + \\ + \\`result_ptr` is optional ([null](https://ziglang.org/documentation/master/#null) may be provided). If provided, the function call will write its result directly to the result pointer, which will be available to read after [await](https://ziglang.org/documentation/master/#Async-and-Await) completes. Any result location provided to `await` will copy the result from `result_ptr`. + \\ \\```zig \\const std = @import("std"); \\const expect = std.testing.expect; @@ -96,13 +101,6 @@ pub const builtins = [_]Builtin{ \\ suspend {} \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "async fn pointer in a struct field"... - \\ - \\All 1 tests passed. - \\ - \\``` , .arguments = &.{ "frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8", @@ -116,8 +114,9 @@ pub const builtins = [_]Builtin{ .signature = "@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: builtin.AtomicOrder) T", .snippet = "@atomicLoad(${1:comptime T: type}, ${2:ptr: *const T}, ${3:comptime ordering: builtin.AtomicOrder})", .documentation = - \\ This builtin function atomically dereferences a pointer and returns the value. - \\ `T` must be a pointer, a `bool`, a float, an integer or an enum. + \\This builtin function atomically dereferences a pointer and returns the value. + \\ + \\`T` must be a pointer, a `bool`, a float, an integer or an enum. , .arguments = &.{ "comptime T: type", @@ -130,9 +129,20 @@ pub const builtins = [_]Builtin{ .signature = "@atomicRmw(comptime T: type, ptr: *T, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T", .snippet = "@atomicRmw(${1:comptime T: type}, ${2:ptr: *T}, ${3:comptime op: builtin.AtomicRmwOp}, ${4:operand: T}, ${5:comptime ordering: builtin.AtomicOrder})", .documentation = - \\ This builtin function atomically modifies memory and then returns the previous value. - \\ `T` must be a pointer, a `bool`, a float, an integer or an enum. - \\ Supported operations: + \\This builtin function atomically modifies memory and then returns the previous value. + \\ + \\`T` must be a pointer, a `bool`, a float, an integer or an enum. + \\ + \\Supported operations: + \\ - `.Xchg` - stores the operand unmodified. Supports enums, integers and floats. + \\ - `.Add` - for integers, twos complement wraparound addition. Also supports [Floats](https://ziglang.org/documentation/master/#Floats). + \\ - `.Sub` - for integers, twos complement wraparound subtraction. Also supports [Floats](https://ziglang.org/documentation/master/#Floats). + \\ - `.And` - bitwise and + \\ - `.Nand` - bitwise nand + \\ - `.Or` - bitwise or + \\ - `.Xor` - bitwise xor + \\ - `.Max` - stores the operand if it is larger. Supports integers and floats. + \\ - `.Min` - stores the operand if it is smaller. Supports integers and floats. , .arguments = &.{ "comptime T: type", @@ -147,8 +157,9 @@ pub const builtins = [_]Builtin{ .signature = "@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: builtin.AtomicOrder) void", .snippet = "@atomicStore(${1:comptime T: type}, ${2:ptr: *T}, ${3:value: T}, ${4:comptime ordering: builtin.AtomicOrder})", .documentation = - \\ This builtin function atomically stores a value. - \\ `T` must be a pointer, a `bool`, a float, an integer or an enum. + \\This builtin function atomically stores a value. + \\ + \\`T` must be a pointer, a `bool`, a float, an integer or an enum. , .arguments = &.{ "comptime T: type", @@ -162,10 +173,17 @@ pub const builtins = [_]Builtin{ .signature = "@bitCast(comptime DestType: type, value: anytype) DestType", .snippet = "@bitCast(${1:comptime DestType: type}, ${2:value: anytype})", .documentation = - \\ Converts a value of one type to another type. - \\ Asserts that `@sizeOf(@TypeOf(value)) == @sizeOf(DestType)`. - \\ Asserts that `@typeInfo(DestType) != .Pointer`. Use `@ptrCast` or `@intToPtr` if you need this. - \\ Can be used for these things for example: + \\Converts a value of one type to another type. + \\ + \\Asserts that `@sizeOf(@TypeOf(value)) == @sizeOf(DestType)`. + \\ + \\Asserts that `@typeInfo(DestType) != .Pointer`. Use `@ptrCast` or `@intToPtr` if you need this. + \\ + \\Can be used for these things for example: + \\ - Convert `f32` to `u32` bits + \\ - Convert `i32` to `u32` preserving twos complement + \\ + \\Works at compile-time if `value` is known at compile time. It's a compile error to bitcast a struct to a scalar type of the same size since structs have undefined layout. However if the struct is packed then it works. , .arguments = &.{ "comptime DestType: type", @@ -177,8 +195,9 @@ pub const builtins = [_]Builtin{ .signature = "@bitOffsetOf(comptime T: type, comptime field_name: []const u8) comptime_int", .snippet = "@bitOffsetOf(${1:comptime T: type}, ${2:comptime field_name: []const u8})", .documentation = - \\ Returns the bit offset of a field relative to its containing struct. - \\ For non packed structs, this will always be divisible by `8`. For packed structs, non-byte-aligned fields will share a byte offset, but they will have different bit offsets. + \\Returns the bit offset of a field relative to its containing struct. + \\ + \\For non [packed structs](https://ziglang.org/documentation/master/#packed-struct), this will always be divisible by `8`. For packed structs, non-byte-aligned fields will share a byte offset, but they will have different bit offsets. , .arguments = &.{ "comptime T: type", @@ -190,8 +209,9 @@ pub const builtins = [_]Builtin{ .signature = "@boolToInt(value: bool) u1", .snippet = "@boolToInt(${1:value: bool})", .documentation = - \\ Converts `true` to `u1(1)` and `false` to `u1(0)`. - \\ If the value is known at compile-time, the return type is `comptime_int` instead of `u1`. + \\Converts `true` to `u1(1)` and `false` to `u1(0)`. + \\ + \\If the value is known at compile-time, the return type is `comptime_int` instead of `u1`. , .arguments = &.{ "value: bool", @@ -202,8 +222,9 @@ pub const builtins = [_]Builtin{ .signature = "@bitSizeOf(comptime T: type) comptime_int", .snippet = "@bitSizeOf(${1:comptime T: type})", .documentation = - \\ This function returns the number of bits it takes to store `T` in memory. The result is a target-specific compile time constant. - \\ This function measures the size at runtime. For types that are disallowed at runtime, such as `comptime_int` and `type`, the result is `0`. + \\This function returns the number of bits it takes to store `T` in memory. The result is a target-specific compile time constant. + \\ + \\This function measures the size at runtime. For types that are disallowed at runtime, such as `comptime_int` and `type`, the result is `0`. , .arguments = &.{ "comptime T: type", @@ -214,8 +235,9 @@ pub const builtins = [_]Builtin{ .signature = "@breakpoint()", .snippet = "@breakpoint()", .documentation = - \\ This function inserts a platform-specific debug trap instruction which causes debuggers to break there. - \\ This function is only valid within function scope. + \\This function inserts a platform-specific debug trap instruction which causes debuggers to break there. + \\ + \\This function is only valid within function scope. , .arguments = &.{}, }, @@ -224,8 +246,9 @@ pub const builtins = [_]Builtin{ .signature = "@mulAdd(comptime T: type, a: T, b: T, c: T) T", .snippet = "@mulAdd(${1:comptime T: type}, ${2:a: T}, ${3:b: T}, ${4:c: T})", .documentation = - \\ Fused multiply add, similar to `(a * b) + c`, except only rounds once, and is thus more accurate. - \\ Supports Floats and Vectors of floats. + \\Fused multiply add, similar to `(a * b) + c`, except only rounds once, and is thus more accurate. + \\ + \\Supports Floats and Vectors of floats. , .arguments = &.{ "comptime T: type", @@ -240,9 +263,12 @@ pub const builtins = [_]Builtin{ .snippet = "@byteSwap(${1:comptime T: type}, ${2:operand: T})", .documentation = \\`T` must be an integer type with bit count evenly divisible by 8. - \\`operand` may be an integer or vector. - \\ Swaps the byte order of the integer. This converts a big endian integer to a little endian integer, and converts a little endian integer to a big endian integer. - \\ Note that for the purposes of memory layout with respect to endianness, the integer type should be related to the number of bytes reported by @sizeOf bytes. This is demonstrated with `u24`. `@sizeOf(u24) == 4`, which means that a `u24` stored in memory takes 4 bytes, and those 4 bytes are what are swapped on a little vs big endian system. On the other hand, if `T` is specified to be `u24`, then only 3 bytes are reversed. + \\ + \\`operand` may be an [integer](https://ziglang.org/documentation/master/#Integers) or [vector](https://ziglang.org/documentation/master/#Vectors). + \\ + \\Swaps the byte order of the integer. This converts a big endian integer to a little endian integer, and converts a little endian integer to a big endian integer. + \\ + \\Note that for the purposes of memory layout with respect to endianness, the integer type should be related to the number of bytes reported by [@sizeOf](https://ziglang.org/documentation/master/#sizeOf) bytes. This is demonstrated with `u24`. `@sizeOf(u24) == 4`, which means that a `u24` stored in memory takes 4 bytes, and those 4 bytes are what are swapped on a little vs big endian system. On the other hand, if `T` is specified to be `u24`, then only 3 bytes are reversed. , .arguments = &.{ "comptime T: type", @@ -255,8 +281,10 @@ pub const builtins = [_]Builtin{ .snippet = "@bitReverse(${1:comptime T: type}, ${2:integer: T})", .documentation = \\`T` accepts any integer type. - \\ Reverses the bitpattern of an integer value, including the sign bit if applicable. - \\ For example 0b10110110 (`u8 = 182`, `i8 = -74`) becomes 0b01101101 (`u8 = 109`, `i8 = 109`). + \\ + \\Reverses the bitpattern of an integer value, including the sign bit if applicable. + \\ + \\For example 0b10110110 (`u8 = 182`, `i8 = -74`) becomes 0b01101101 (`u8 = 109`, `i8 = 109`). , .arguments = &.{ "comptime T: type", @@ -268,7 +296,7 @@ pub const builtins = [_]Builtin{ .signature = "@offsetOf(comptime T: type, comptime field_name: []const u8) comptime_int", .snippet = "@offsetOf(${1:comptime T: type}, ${2:comptime field_name: []const u8})", .documentation = - \\ Returns the byte offset of a field relative to its containing struct. + \\Returns the byte offset of a field relative to its containing struct. , .arguments = &.{ "comptime T: type", @@ -280,8 +308,8 @@ pub const builtins = [_]Builtin{ .signature = "@call(options: std.builtin.CallOptions, function: anytype, args: anytype) anytype", .snippet = "@call(${1:options: std.builtin.CallOptions}, ${2:function: anytype}, ${3:args: anytype})", .documentation = - \\ Calls a function, in the same way that invoking an expression with parentheses does: - \\call.zig + \\Calls a function, in the same way that invoking an expression with parentheses does: + \\ \\```zig \\const expect = @import("std").testing.expect; \\ @@ -293,14 +321,9 @@ pub const builtins = [_]Builtin{ \\ return a + b; \\} \\``` - \\```zig - \\$ zig test call.zig - \\Test [1/1] test "noinline function call"... \\ - \\All 1 tests passed. + \\`@call` allows more flexibility than normal function call syntax does. The `CallOptions` struct is reproduced here: \\ - \\``` - \\ `@call` allows more flexibility than normal function call syntax does. The `CallOptions` struct is reproduced here: \\```zig \\pub const CallOptions = struct { \\ modifier: Modifier = .auto, @@ -353,13 +376,14 @@ pub const builtins = [_]Builtin{ .signature = "@cDefine(comptime name: []u8, value)", .snippet = "@cDefine(${1:comptime name: []u8}, ${2:value})", .documentation = - \\ This function can only occur inside `@cImport`. - \\ This appends `#define $name $value` to the `@cImport` temporary buffer. - \\ To define without a value, like this: - \\```zig - \\#define _GNU_SOURCE - \\``` - \\ Use the void value, like this: + \\This function can only occur inside `@cImport`. + \\ + \\This appends `#define $name $value` to the `@cImport` temporary buffer. + \\ + \\To define without a value, like this:`#define _GNU_SOURCE` + \\ + \\Use the void value, like this: + \\ \\```zig \\@cDefine("_GNU_SOURCE", {}) \\``` @@ -374,10 +398,15 @@ pub const builtins = [_]Builtin{ .signature = "@cImport(expression) type", .snippet = "@cImport(${1:expression})", .documentation = - \\ This function parses C code and imports the functions, types, variables, and compatible macro definitions into a new empty struct type, and then returns that type. - \\ `expression` is interpreted at compile time. The builtin functions `@cInclude`, `@cDefine`, and `@cUndef` work within this expression, appending to a temporary buffer which is then parsed as C code. - \\ Usually you should only have one `@cImport` in your entire application, because it saves the compiler from invoking clang multiple times, and prevents inline functions from being duplicated. - \\ Reasons for having multiple `@cImport` expressions would be: + \\This function parses C code and imports the functions, types, variables, and compatible macro definitions into a new empty struct type, and then returns that type. + \\ + \\`expression` is interpreted at compile time. The builtin functions `@cInclude`, `@cDefine`, and `@cUndef` work within this expression, appending to a temporary buffer which is then parsed as C code. + \\ + \\Usually you should only have one `@cImport` in your entire application, because it saves the compiler from invoking clang multiple times, and prevents inline functions from being duplicated. + \\ + \\Reasons for having multiple `@cImport` expressions would be: + \\ - To avoid a symbol collision, for example if foo.h and bar.h both `#define CONNECTION_COUNT` + \\ - To analyze the C code with different preprocessor defines , .arguments = &.{ "expression", @@ -388,8 +417,9 @@ pub const builtins = [_]Builtin{ .signature = "@cInclude(comptime path: []u8)", .snippet = "@cInclude(${1:comptime path: []u8})", .documentation = - \\ This function can only occur inside `@cImport`. - \\ This appends `#include <$path>\n` to the `c_import` temporary buffer. + \\This function can only occur inside `@cImport`. + \\ + \\This appends `#include <$path>\n` to the `c_import` temporary buffer. , .arguments = &.{ "comptime path: []u8", @@ -400,9 +430,11 @@ pub const builtins = [_]Builtin{ .signature = "@clz(comptime T: type, integer: T)", .snippet = "@clz(${1:comptime T: type}, ${2:integer: T})", .documentation = - \\ This function counts the number of most-significant (leading in a big-Endian sense) zeroes in `integer`. - \\ If `integer` is known at comptime, the return type is `comptime_int`. Otherwise, the return type is an unsigned integer with the minimum number of bits that can represent the bit count of the integer type. - \\ If `integer` is zero, `@clz` returns the bit width of integer type `T`. + \\This function counts the number of most-significant (leading in a big-Endian sense) zeroes in `integer`. + \\ + \\If `integer` is known at [comptime](https://ziglang.org/documentation/master/#comptime), the return type is `comptime_int`. Otherwise, the return type is an unsigned integer with the minimum number of bits that can represent the bit count of the integer type. + \\ + \\If `integer` is zero, `@clz` returns the bit width of integer type `T`. , .arguments = &.{ "comptime T: type", @@ -414,7 +446,8 @@ pub const builtins = [_]Builtin{ .signature = "@cmpxchgStrong(comptime T: type, ptr: *T, expected_value: T, new_value: T, success_order: AtomicOrder, fail_order: AtomicOrder) ?T", .snippet = "@cmpxchgStrong(${1:comptime T: type}, ${2:ptr: *T}, ${3:expected_value: T}, ${4:new_value: T}, ${5:success_order: AtomicOrder}, ${6:fail_order: AtomicOrder})", .documentation = - \\ This function performs a strong atomic compare exchange operation. It's the equivalent of this code, except atomic: + \\This function performs a strong atomic compare exchange operation. It's the equivalent of this code, except atomic: + \\ \\```zig \\fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T { \\ const old_value = ptr.*; @@ -426,9 +459,12 @@ pub const builtins = [_]Builtin{ \\ } \\} \\``` - \\ If you are using cmpxchg in a loop, @cmpxchgWeak is the better choice, because it can be implemented more efficiently in machine instructions. - \\ `T` must be a pointer, a `bool`, a float, an integer or an enum. - \\`@typeInfo(@TypeOf(ptr)).Pointer.alignment` must be `>= @sizeOf(T).` + \\ + \\If you are using cmpxchg in a loop, [@cmpxchgWeak](https://ziglang.org/documentation/master/#cmpxchgWeak) is the better choice, because it can be implemented more efficiently in machine instructions. + \\ + \\`T` must be a pointer, a `bool`, a float, an integer or an enum. + \\ + \\`@typeInfo(@TypeOf(ptr)).Pointer.alignment` must be `>= @sizeOf(T).` , .arguments = &.{ "comptime T: type", @@ -444,7 +480,8 @@ pub const builtins = [_]Builtin{ .signature = "@cmpxchgWeak(comptime T: type, ptr: *T, expected_value: T, new_value: T, success_order: AtomicOrder, fail_order: AtomicOrder) ?T", .snippet = "@cmpxchgWeak(${1:comptime T: type}, ${2:ptr: *T}, ${3:expected_value: T}, ${4:new_value: T}, ${5:success_order: AtomicOrder}, ${6:fail_order: AtomicOrder})", .documentation = - \\ This function performs a weak atomic compare exchange operation. It's the equivalent of this code, except atomic: + \\This function performs a weak atomic compare exchange operation. It's the equivalent of this code, except atomic: + \\ \\```zig \\fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T { \\ const old_value = ptr.*; @@ -456,9 +493,12 @@ pub const builtins = [_]Builtin{ \\ } \\} \\``` - \\ If you are using cmpxchg in a loop, the sporadic failure will be no problem, and `cmpxchgWeak` is the better choice, because it can be implemented more efficiently in machine instructions. However if you need a stronger guarantee, use @cmpxchgStrong. - \\ `T` must be a pointer, a `bool`, a float, an integer or an enum. - \\`@typeInfo(@TypeOf(ptr)).Pointer.alignment` must be `>= @sizeOf(T).` + \\ + \\If you are using cmpxchg in a loop, the sporadic failure will be no problem, and `cmpxchgWeak` is the better choice, because it can be implemented more efficiently in machine instructions. However if you need a stronger guarantee, use [@cmpxchgStrong](https://ziglang.org/documentation/master/#cmpxchgStrong). + \\ + \\`T` must be a pointer, a `bool`, a float, an integer or an enum. + \\ + \\`@typeInfo(@TypeOf(ptr)).Pointer.alignment` must be `>= @sizeOf(T).` , .arguments = &.{ "comptime T: type", @@ -474,8 +514,9 @@ pub const builtins = [_]Builtin{ .signature = "@compileError(comptime msg: []u8)", .snippet = "@compileError(${1:comptime msg: []u8})", .documentation = - \\ This function, when semantically analyzed, causes a compile error with the message `msg`. - \\ There are several ways that code avoids being semantically checked, such as using `if` or `switch` with compile time constants, and `comptime` functions. + \\This function, when semantically analyzed, causes a compile error with the message `msg`. + \\ + \\There are several ways that code avoids being semantically checked, such as using `if` or `switch` with compile time constants, and `comptime` functions. , .arguments = &.{ "comptime msg: []u8", @@ -486,10 +527,12 @@ pub const builtins = [_]Builtin{ .signature = "@compileLog(args: ...)", .snippet = "@compileLog(${1:args: ...})", .documentation = - \\ This function prints the arguments passed to it at compile-time. - \\ To prevent accidentally leaving compile log statements in a codebase, a compilation error is added to the build, pointing to the compile log statement. This error prevents code from being generated, but does not otherwise interfere with analysis. - \\ This function can be used to do "printf debugging" on compile-time executing code. - \\test.zig + \\This function prints the arguments passed to it at compile-time. + \\ + \\To prevent accidentally leaving compile log statements in a codebase, a compilation error is added to the build, pointing to the compile log statement. This error prevents code from being generated, but does not otherwise interfere with analysis. + \\ + \\This function can be used to do "printf debugging" on compile-time executing code. + \\ \\```zig \\const print = @import("std").debug.print; \\ @@ -506,30 +549,11 @@ pub const builtins = [_]Builtin{ \\ print("Runtime in main, num1 = {}.\n", .{num1}); \\} \\``` - \\```zig - \\$ zig test test.zig - \\| *"comptime in main" - \\| *"comptime val1 = ", 99 - \\./docgen_tmp/test.zig:11:5: error: found compile log statement - \\ @compileLog("comptime in main"); - \\ ^ - \\./docgen_tmp/test.zig:1:35: note: referenced here - \\const print = @import("std").debug.print; - \\ ^ - \\./docgen_tmp/test.zig:13:5: note: referenced here - \\ print("Runtime in main, num1 = {}.\n", .{num1}); - \\ ^ - \\./docgen_tmp/test.zig:5:5: error: found compile log statement - \\ @compileLog("comptime val1 = ", val1); - \\ ^ - \\./docgen_tmp/test.zig:13:46: note: referenced here - \\ print("Runtime in main, num1 = {}.\n", .{num1}); - \\ ^ \\ - \\``` - \\ will ouput: - \\ If all `@compileLog` calls are removed or not encountered by analysis, the program compiles successfully and the generated executable prints: - \\test.zig + \\will ouput: + \\ + \\If all `@compileLog` calls are removed or not encountered by analysis, the program compiles successfully and the generated executable prints: + \\ \\```zig \\const print = @import("std").debug.print; \\ @@ -543,14 +567,6 @@ pub const builtins = [_]Builtin{ \\ print("Runtime in main, num1 = {}.\n", .{num1}); \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "main"... - \\Runtime in main, num1 = 100. - \\ - \\All 1 tests passed. - \\ - \\``` , .arguments = &.{ "args: ...", @@ -561,9 +577,11 @@ pub const builtins = [_]Builtin{ .signature = "@ctz(comptime T: type, integer: T)", .snippet = "@ctz(${1:comptime T: type}, ${2:integer: T})", .documentation = - \\ This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in `integer`. - \\ If `integer` is known at comptime, the return type is `comptime_int`. Otherwise, the return type is an unsigned integer with the minimum number of bits that can represent the bit count of the integer type. - \\ If `integer` is zero, `@ctz` returns the bit width of integer type `T`. + \\This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in `integer`. + \\ + \\If `integer` is known at [comptime](https://ziglang.org/documentation/master/#comptime), the return type is `comptime_int`. Otherwise, the return type is an unsigned integer with the minimum number of bits that can represent the bit count of the integer type. + \\ + \\If `integer` is zero, `@ctz` returns the bit width of integer type `T`. , .arguments = &.{ "comptime T: type", @@ -575,8 +593,9 @@ pub const builtins = [_]Builtin{ .signature = "@cUndef(comptime name: []u8)", .snippet = "@cUndef(${1:comptime name: []u8})", .documentation = - \\ This function can only occur inside `@cImport`. - \\ This appends `#undef $name` to the `@cImport` temporary buffer. + \\This function can only occur inside `@cImport`. + \\ + \\This appends `#undef $name` to the `@cImport` temporary buffer. , .arguments = &.{ "comptime name: []u8", @@ -587,7 +606,11 @@ pub const builtins = [_]Builtin{ .signature = "@divExact(numerator: T, denominator: T) T", .snippet = "@divExact(${1:numerator: T}, ${2:denominator: T})", .documentation = - \\ Exact division. Caller guarantees `denominator != 0` and `@divTrunc(numerator, denominator) * denominator == numerator`. + \\Exact division. Caller guarantees `denominator != 0` and `@divTrunc(numerator, denominator) * denominator == numerator`. + \\ - `@divExact(6, 3) == 2` + \\ - `@divExact(a, b) * b == a` + \\ + \\For a function that returns a possible error code, use `@import("std").math.divExact`. , .arguments = &.{ "numerator: T", @@ -599,7 +622,11 @@ pub const builtins = [_]Builtin{ .signature = "@divFloor(numerator: T, denominator: T) T", .snippet = "@divFloor(${1:numerator: T}, ${2:denominator: T})", .documentation = - \\ Floored division. Rounds toward negative infinity. For unsigned integers it is the same as `numerator / denominator`. Caller guarantees `denominator != 0` and `!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1)`. + \\Floored division. Rounds toward negative infinity. For unsigned integers it is the same as `numerator / denominator`. Caller guarantees `denominator != 0` and `!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1)`. + \\ - `@divFloor(-5, 3) == -2` + \\ - `(@divFloor(a, b) * b) + @mod(a, b) == a` + \\ + \\For a function that returns a possible error code, use `@import("std").math.divFloor`. , .arguments = &.{ "numerator: T", @@ -611,7 +638,11 @@ pub const builtins = [_]Builtin{ .signature = "@divTrunc(numerator: T, denominator: T) T", .snippet = "@divTrunc(${1:numerator: T}, ${2:denominator: T})", .documentation = - \\ Truncated division. Rounds toward zero. For unsigned integers it is the same as `numerator / denominator`. Caller guarantees `denominator != 0` and `!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1)`. + \\Truncated division. Rounds toward zero. For unsigned integers it is the same as `numerator / denominator`. Caller guarantees `denominator != 0` and `!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1)`. + \\ - `@divTrunc(-5, 3) == -1` + \\ - `(@divTrunc(a, b) * b) + @rem(a, b) == a` + \\ + \\For a function that returns a possible error code, use `@import("std").math.divTrunc`. , .arguments = &.{ "numerator: T", @@ -623,8 +654,9 @@ pub const builtins = [_]Builtin{ .signature = "@embedFile(comptime path: []const u8) *const [N:0]u8", .snippet = "@embedFile(${1:comptime path: []const u8})", .documentation = - \\ This function returns a compile time constant pointer to null-terminated, fixed-size array with length equal to the byte count of the file given by `path`. The contents of the array are the contents of the file. This is equivalent to a string literal with the file contents. - \\ `path` is absolute or relative to the current file, just like `@import`. + \\This function returns a compile time constant pointer to null-terminated, fixed-size array with length equal to the byte count of the file given by `path`. The contents of the array are the contents of the file. This is equivalent to a [string literal](https://ziglang.org/documentation/master/#String-Literals-and-Unicode-Code-Point-Literals) with the file contents. + \\ + \\`path` is absolute or relative to the current file, just like `@import`. , .arguments = &.{ "comptime path: []const u8", @@ -635,8 +667,9 @@ pub const builtins = [_]Builtin{ .signature = "@enumToInt(enum_or_tagged_union: anytype) anytype", .snippet = "@enumToInt(${1:enum_or_tagged_union: anytype})", .documentation = - \\ Converts an enumeration value into its integer tag type. When a tagged union is passed, the tag value is used as the enumeration value. - \\ If there is only one possible enum value, the resut is a `comptime_int` known at comptime. + \\Converts an enumeration value into its integer tag type. When a tagged union is passed, the tag value is used as the enumeration value. + \\ + \\If there is only one possible enum value, the resut is a `comptime_int` known at [comptime](https://ziglang.org/documentation/master/#comptime). , .arguments = &.{ "enum_or_tagged_union: anytype", @@ -647,8 +680,9 @@ pub const builtins = [_]Builtin{ .signature = "@errorName(err: anyerror) [:0]const u8", .snippet = "@errorName(${1:err: anyerror})", .documentation = - \\ This function returns the string representation of an error. The string representation of `error.OutOfMem` is `"OutOfMem"`. - \\ If there are no calls to `@errorName` in an entire application, or all calls have a compile-time known value for `err`, then no error name table will be generated. + \\This function returns the string representation of an error. The string representation of `error.OutOfMem` is `"OutOfMem"`. + \\ + \\If there are no calls to `@errorName` in an entire application, or all calls have a compile-time known value for `err`, then no error name table will be generated. , .arguments = &.{ "err: anyerror", @@ -659,7 +693,7 @@ pub const builtins = [_]Builtin{ .signature = "@errorReturnTrace() ?*builtin.StackTrace", .snippet = "@errorReturnTrace()", .documentation = - \\ If the binary is built with error return tracing, and this function is invoked in a function that calls a function with an error or error union return type, returns a stack trace object. Otherwise returns null. + \\If the binary is built with error return tracing, and this function is invoked in a function that calls a function with an error or error union return type, returns a stack trace object. Otherwise returns [null](https://ziglang.org/documentation/master/#null). , .arguments = &.{}, }, @@ -668,7 +702,14 @@ pub const builtins = [_]Builtin{ .signature = "@errorToInt(err: anytype) std.meta.Int(.unsigned, @sizeOf(anyerror) * 8)", .snippet = "@errorToInt(${1:err: anytype})", .documentation = - \\ Supports the following types: + \\Supports the following types: + \\ - [The Global Error Set](https://ziglang.org/documentation/master/#The-Global-Error-Set) + \\ - [Error Set Type](https://ziglang.org/documentation/master/#Error-Set-Type) + \\ - [Error Union Type](https://ziglang.org/documentation/master/#Error-Union-Type) + \\ + \\Converts an error to the integer representation of an error. + \\ + \\It is generally recommended to avoid this cast, as the integer representation of an error is not stable across source code changes. , .arguments = &.{ "err: anytype", @@ -679,7 +720,7 @@ pub const builtins = [_]Builtin{ .signature = "@errSetCast(comptime T: DestType, value: anytype) DestType", .snippet = "@errSetCast(${1:comptime T: DestType}, ${2:value: anytype})", .documentation = - \\ Converts an error value from one error set to another error set. Attempting to convert an error which is not in the destination error set results in safety-protected Undefined Behavior. + \\Converts an error value from one error set to another error set. Attempting to convert an error which is not in the destination error set results in safety-protected [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). , .arguments = &.{ "comptime T: DestType", @@ -691,8 +732,39 @@ pub const builtins = [_]Builtin{ .signature = "@export(declaration, comptime options: std.builtin.ExportOptions) void", .snippet = "@export(${1:declaration}, ${2:comptime options: std.builtin.ExportOptions})", .documentation = - \\ Creates a symbol in the output object file. - \\ `declaration` must be one of two things: + \\Creates a symbol in the output object file. + \\ + \\`declaration` must be one of two things: + \\ - An identifier (`x`) identifying a [function](https://ziglang.org/documentation/master/#Functions) or a [variable](https://ziglang.org/documentation/master/#Container-Level-Variables). + \\ - Field access (`x.y`) looking up a [function](https://ziglang.org/documentation/master/#Functions) or a [variable](https://ziglang.org/documentation/master/#Container-Level-Variables). + \\ + \\This builtin can be called from a [comptime](https://ziglang.org/documentation/master/#comptime) block to conditionally export symbols. When `declaration` is a function with the C calling convention and `options.linkage` is `Strong`, this is equivalent to the `export` keyword used on a function: + \\ + \\```zig + \\comptime { + \\ @export(internalName, .{ .name = "foo", .linkage = .Strong }); + \\} + \\ + \\fn internalName() callconv(.C) void {} + \\``` + \\ + \\This is equivalent to: + \\ + \\```zig + \\export fn foo() void {} + \\``` + \\ + \\Note that even when using `export`, `@"foo"` syntax can be used to choose any string for the symbol name: + \\ + \\```zig + \\export fn @"A function name that is a complete sentence."() void {} + \\``` + \\ + \\When looking at the resulting object, you can see the symbol is used verbatim: + \\ + \\```zig + \\00000000000001f0 T A function name that is a complete sentence. + \\``` , .arguments = &.{ "declaration", @@ -704,7 +776,7 @@ pub const builtins = [_]Builtin{ .signature = "@extern(T: type, comptime options: std.builtin.ExternOptions) *T", .snippet = "@extern(${1:T: type}, ${2:comptime options: std.builtin.ExternOptions})", .documentation = - \\ Creates a reference to an external symbol in the output object file. + \\Creates a reference to an external symbol in the output object file. , .arguments = &.{ "T: type", @@ -716,8 +788,9 @@ pub const builtins = [_]Builtin{ .signature = "@fence(order: AtomicOrder)", .snippet = "@fence(${1:order: AtomicOrder})", .documentation = - \\ The `fence` function is used to introduce happens-before edges between operations. - \\ `AtomicOrder` can be found with `@import("std").builtin.AtomicOrder`. + \\The `fence` function is used to introduce happens-before edges between operations. + \\ + \\`AtomicOrder` can be found with `@import("std").builtin.AtomicOrder`. , .arguments = &.{ "order: AtomicOrder", @@ -729,7 +802,7 @@ pub const builtins = [_]Builtin{ .snippet = "@field(${1:lhs: anytype}, ${2:comptime field_name: []const u8})", .documentation = \\Performs field access by a compile-time string. Works on both fields and declarations. - \\test.zig + \\ \\```zig \\const std = @import("std"); \\ @@ -760,14 +833,6 @@ pub const builtins = [_]Builtin{ \\ try expect(@field(Point, "z") == 2); \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/2] test "field access by string"... - \\Test [2/2] test "decl access by string"... - \\ - \\All 2 tests passed. - \\ - \\``` , .arguments = &.{ "lhs: anytype", @@ -776,10 +841,10 @@ pub const builtins = [_]Builtin{ }, .{ .name = "@fieldParentPtr", - .signature = "@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8, field_ptr: *T) *ParentType", + .signature = "@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8, field_ptr: *T) *ParentType", .snippet = "@fieldParentPtr(${1:comptime ParentType: type}, ${2:comptime field_name: []const u8}, ${3:field_ptr: *T})", .documentation = - \\ Given a pointer to a field, returns the base pointer of a struct. + \\Given a pointer to a field, returns the base pointer of a struct. , .arguments = &.{ "comptime ParentType: type", @@ -792,7 +857,7 @@ pub const builtins = [_]Builtin{ .signature = "@floatCast(comptime DestType: type, value: anytype) DestType", .snippet = "@floatCast(${1:comptime DestType: type}, ${2:value: anytype})", .documentation = - \\ Convert from one float type to another. This cast is safe, but may cause the numeric value to lose precision. + \\Convert from one float type to another. This cast is safe, but may cause the numeric value to lose precision. , .arguments = &.{ "comptime DestType: type", @@ -804,8 +869,9 @@ pub const builtins = [_]Builtin{ .signature = "@floatToInt(comptime DestType: type, float: anytype) DestType", .snippet = "@floatToInt(${1:comptime DestType: type}, ${2:float: anytype})", .documentation = - \\ Converts the integer part of a floating point number to the destination type. - \\ If the integer part of the floating point number cannot fit in the destination type, it invokes safety-checked Undefined Behavior. + \\Converts the integer part of a floating point number to the destination type. + \\ + \\If the integer part of the floating point number cannot fit in the destination type, it invokes safety-checked [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). , .arguments = &.{ "comptime DestType: type", @@ -817,8 +883,9 @@ pub const builtins = [_]Builtin{ .signature = "@frame() *@Frame(func)", .snippet = "@frame()", .documentation = - \\ This function returns a pointer to the frame for a given function. This type can be coerced to `anyframe->T` and to `anyframe`, where `T` is the return type of the function in scope. - \\ This function does not mark a suspension point, but it does cause the function in scope to become an async function. + \\This function returns a pointer to the frame for a given function. This type can be [coerced](https://ziglang.org/documentation/master/#Type-Coercion) to `anyframe->T` and to `anyframe`, where `T` is the return type of the function in scope. + \\ + \\This function does not mark a suspension point, but it does cause the function in scope to become an [async function](https://ziglang.org/documentation/master/#Async-Functions). , .arguments = &.{}, }, @@ -827,9 +894,10 @@ pub const builtins = [_]Builtin{ .signature = "@Frame(func: anytype) type", .snippet = "@Frame(${1:func: anytype})", .documentation = - \\ This function returns the frame type of a function. This works for Async Functions as well as any function without a specific calling convention. - \\ This type is suitable to be used as the return type of async which allows one to, for example, heap-allocate an async function frame: - \\test.zig + \\This function returns the frame type of a function. This works for [Async Functions](https://ziglang.org/documentation/master/#Async-Functions) as well as any function without a specific calling convention. + \\ + \\This type is suitable to be used as the return type of [async](https://ziglang.org/documentation/master/#Async-and-Await) which allows one to, for example, heap-allocate an async function frame: + \\ \\```zig \\const std = @import("std"); \\ @@ -842,13 +910,6 @@ pub const builtins = [_]Builtin{ \\ suspend {} \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "heap allocated frame"... - \\ - \\All 1 tests passed. - \\ - \\``` , .arguments = &.{ "func: anytype", @@ -859,9 +920,11 @@ pub const builtins = [_]Builtin{ .signature = "@frameAddress() usize", .snippet = "@frameAddress()", .documentation = - \\ This function returns the base pointer of the current stack frame. - \\ The implications of this are target specific and not consistent across all platforms. The frame address may not be available in release mode due to aggressive optimizations. - \\ This function is only valid within function scope. + \\This function returns the base pointer of the current stack frame. + \\ + \\The implications of this are target specific and not consistent across all platforms. The frame address may not be available in release mode due to aggressive optimizations. + \\ + \\This function is only valid within function scope. , .arguments = &.{}, }, @@ -870,8 +933,9 @@ pub const builtins = [_]Builtin{ .signature = "@frameSize() usize", .snippet = "@frameSize()", .documentation = - \\ This is the same as `@sizeOf(@Frame(func))`, where `func` may be runtime-known. - \\ This function is typically used in conjunction with @asyncCall. + \\This is the same as `@sizeOf(@Frame(func))`, where `func` may be runtime-known. + \\ + \\This function is typically used in conjunction with [@asyncCall](https://ziglang.org/documentation/master/#asyncCall). , .arguments = &.{}, }, @@ -880,8 +944,8 @@ pub const builtins = [_]Builtin{ .signature = "@hasDecl(comptime Container: type, comptime name: []const u8) bool", .snippet = "@hasDecl(${1:comptime Container: type}, ${2:comptime name: []const u8})", .documentation = - \\ Returns whether or not a struct, enum, or union has a declaration matching `name`. - \\test.zig + \\Returns whether or not a [struct](https://ziglang.org/documentation/master/#struct), [enum](https://ziglang.org/documentation/master/#enum), or [union](https://ziglang.org/documentation/master/#union) has a declaration matching `name`. + \\ \\```zig \\const std = @import("std"); \\const expect = std.testing.expect; @@ -906,13 +970,6 @@ pub const builtins = [_]Builtin{ \\ try expect(!@hasDecl(Foo, "nope1234")); \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "@hasDecl"... - \\ - \\All 1 tests passed. - \\ - \\``` , .arguments = &.{ "comptime Container: type", @@ -925,8 +982,10 @@ pub const builtins = [_]Builtin{ .snippet = "@hasField(${1:comptime Container: type}, ${2:comptime name: []const u8})", .documentation = \\Returns whether the field name of a struct, union, or enum exists. - \\ The result is a compile time constant. - \\ It does not include functions, variables, or constants. + \\ + \\The result is a compile time constant. + \\ + \\It does not include functions, variables, or constants. , .arguments = &.{ "comptime Container: type", @@ -938,11 +997,17 @@ pub const builtins = [_]Builtin{ .signature = "@import(comptime path: []u8) type", .snippet = "@import(${1:comptime path: []u8})", .documentation = - \\ This function finds a zig file corresponding to `path` and adds it to the build, if it is not already added. - \\ Zig source files are implicitly structs, with a name equal to the file's basename with the extension truncated. `@import` returns the struct type corresponding to the file. - \\ Declarations which have the `pub` keyword may be referenced from a different source file than the one they are declared in. - \\ `path` can be a relative path or it can be the name of a package. If it is a relative path, it is relative to the file that contains the `@import` function call. - \\ The following packages are always available: + \\This function finds a zig file corresponding to `path` and adds it to the build, if it is not already added. + \\ + \\Zig source files are implicitly structs, with a name equal to the file's basename with the extension truncated. `@import` returns the struct type corresponding to the file. + \\ + \\Declarations which have the `pub` keyword may be referenced from a different source file than the one they are declared in. + \\ + \\`path` can be a relative path or it can be the name of a package. If it is a relative path, it is relative to the file that contains the `@import` function call. + \\ + \\The following packages are always available: + \\ - `@import("std")` - Zig Standard Library + \\ - `@import("builtin")` - Target-specific information The command `zig build-exe --show-builtin` outputs the source to stdout for reference. , .arguments = &.{ "comptime path: []u8", @@ -953,8 +1018,9 @@ pub const builtins = [_]Builtin{ .signature = "@intCast(comptime DestType: type, int: anytype) DestType", .snippet = "@intCast(${1:comptime DestType: type}, ${2:int: anytype})", .documentation = - \\ Converts an integer to another integer while keeping the same numerical value. Attempting to convert a number which is out of range of the destination type results in safety-protected Undefined Behavior. - \\ If `T` is `comptime_int`, then this is semantically equivalent to Type Coercion. + \\Converts an integer to another integer while keeping the same numerical value. Attempting to convert a number which is out of range of the destination type results in safety-protected [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). + \\ + \\If `T` is `comptime_int`, then this is semantically equivalent to [Type Coercion](https://ziglang.org/documentation/master/#Type-Coercion). , .arguments = &.{ "comptime DestType: type", @@ -966,8 +1032,9 @@ pub const builtins = [_]Builtin{ .signature = "@intToEnum(comptime DestType: type, int_value: std.meta.Tag(DestType)) DestType", .snippet = "@intToEnum(${1:comptime DestType: type}, ${2:int_value: std.meta.Tag(DestType)})", .documentation = - \\ Converts an integer into an enum value. - \\ Attempting to convert an integer which represents no value in the chosen enum type invokes safety-checked Undefined Behavior. + \\Converts an integer into an [enum](https://ziglang.org/documentation/master/#enum) value. + \\ + \\Attempting to convert an integer which represents no value in the chosen enum type invokes safety-checked [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). , .arguments = &.{ "comptime DestType: type", @@ -979,9 +1046,11 @@ pub const builtins = [_]Builtin{ .signature = "@intToError(value: std.meta.Int(.unsigned, @sizeOf(anyerror) * 8)) anyerror", .snippet = "@intToError(${1:value: std.meta.Int(.unsigned, @sizeOf(anyerror) * 8)})", .documentation = - \\ Converts from the integer representation of an error into The Global Error Set type. - \\ It is generally recommended to avoid this cast, as the integer representation of an error is not stable across source code changes. - \\ Attempting to convert an integer that does not correspond to any error results in safety-protected Undefined Behavior. + \\Converts from the integer representation of an error into [The Global Error Set](https://ziglang.org/documentation/master/#The-Global-Error-Set) type. + \\ + \\It is generally recommended to avoid this cast, as the integer representation of an error is not stable across source code changes. + \\ + \\Attempting to convert an integer that does not correspond to any error results in safety-protected [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). , .arguments = &.{ "value: std.meta.Int(.unsigned, @sizeOf(anyerror) * 8)", @@ -992,7 +1061,7 @@ pub const builtins = [_]Builtin{ .signature = "@intToFloat(comptime DestType: type, int: anytype) DestType", .snippet = "@intToFloat(${1:comptime DestType: type}, ${2:int: anytype})", .documentation = - \\ Converts an integer to the closest floating point representation. To convert the other way, use @floatToInt. This cast is always safe. + \\Converts an integer to the closest floating point representation. To convert the other way, use [@floatToInt](https://ziglang.org/documentation/master/#floatToInt). This cast is always safe. , .arguments = &.{ "comptime DestType: type", @@ -1004,8 +1073,9 @@ pub const builtins = [_]Builtin{ .signature = "@intToPtr(comptime DestType: type, address: usize) DestType", .snippet = "@intToPtr(${1:comptime DestType: type}, ${2:address: usize})", .documentation = - \\ Converts an integer to a pointer. To convert the other way, use @ptrToInt. - \\ If the destination pointer type does not allow address zero and `address` is zero, this invokes safety-checked Undefined Behavior. + \\Converts an integer to a [pointer](https://ziglang.org/documentation/master/#Pointers). To convert the other way, use [@ptrToInt](https://ziglang.org/documentation/master/#ptrToInt). + \\ + \\If the destination pointer type does not allow address zero and `address` is zero, this invokes safety-checked [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). , .arguments = &.{ "comptime DestType: type", @@ -1017,13 +1087,18 @@ pub const builtins = [_]Builtin{ .signature = "@memcpy(noalias dest: [*]u8, noalias source: [*]const u8, byte_count: usize)", .snippet = "@memcpy(${1:noalias dest: [*]u8}, ${2:noalias source: [*]const u8}, ${3:byte_count: usize})", .documentation = - \\ This function copies bytes from one region of memory to another. `dest` and `source` are both pointers and must not overlap. - \\ This function is a low level intrinsic with no safety mechanisms. Most code should not use this function, instead using something like this: + \\This function copies bytes from one region of memory to another. `dest` and `source` are both pointers and must not overlap. + \\ + \\This function is a low level intrinsic with no safety mechanisms. Most code should not use this function, instead using something like this: + \\ \\```zig \\for (source[0..byte_count]) |b, i| dest[i] = b; \\``` - \\ The optimizer is intelligent enough to turn the above snippet into a memcpy. + \\ + \\The optimizer is intelligent enough to turn the above snippet into a memcpy. + \\ \\There is also a standard library function for this: + \\ \\```zig \\const mem = @import("std").mem; \\mem.copy(u8, dest[0..byte_count], source[0..byte_count]); @@ -1040,13 +1115,18 @@ pub const builtins = [_]Builtin{ .signature = "@memset(dest: [*]u8, c: u8, byte_count: usize)", .snippet = "@memset(${1:dest: [*]u8}, ${2:c: u8}, ${3:byte_count: usize})", .documentation = - \\ This function sets a region of memory to `c`. `dest` is a pointer. - \\ This function is a low level intrinsic with no safety mechanisms. Most code should not use this function, instead using something like this: + \\This function sets a region of memory to `c`. `dest` is a pointer. + \\ + \\This function is a low level intrinsic with no safety mechanisms. Most code should not use this function, instead using something like this: + \\ \\```zig \\for (dest[0..byte_count]) |*b| b.* = c; \\``` - \\ The optimizer is intelligent enough to turn the above snippet into a memset. + \\ + \\The optimizer is intelligent enough to turn the above snippet into a memset. + \\ \\There is also a standard library function for this: + \\ \\```zig \\const mem = @import("std").mem; \\mem.set(u8, dest, c); @@ -1063,8 +1143,9 @@ pub const builtins = [_]Builtin{ .signature = "@wasmMemorySize(index: u32) u32", .snippet = "@wasmMemorySize(${1:index: u32})", .documentation = - \\ This function returns the size of the Wasm memory identified by `index` as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. - \\ This function is a low level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like `@import("std").heap.WasmPageAllocator`. + \\This function returns the size of the Wasm memory identified by `index` as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. + \\ + \\This function is a low level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like `@import("std").heap.WasmPageAllocator`. , .arguments = &.{ "index: u32", @@ -1075,9 +1156,10 @@ pub const builtins = [_]Builtin{ .signature = "@wasmMemoryGrow(index: u32, delta: u32) i32", .snippet = "@wasmMemoryGrow(${1:index: u32}, ${2:delta: u32})", .documentation = - \\ This function increases the size of the Wasm memory identified by `index` by `delta` in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous memory size; on failure, if the allocation fails, returns -1. - \\ This function is a low level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like `@import("std").heap.WasmPageAllocator`. - \\test.zig + \\This function increases the size of the Wasm memory identified by `index` by `delta` in units of unsigned number of Wasm pages. Note that each Wasm page is 64KB in size. On success, returns previous memory size; on failure, if the allocation fails, returns -1. + \\ + \\This function is a low level intrinsic with no safety mechanisms usually useful for allocator designers targeting Wasm. So unless you are writing a new allocator from scratch, you should use something like `@import("std").heap.WasmPageAllocator`. + \\ \\```zig \\const std = @import("std"); \\const native_arch = @import("builtin").target.cpu.arch; @@ -1091,15 +1173,6 @@ pub const builtins = [_]Builtin{ \\ try expect(prev + 1 == @wasmMemorySize(0)); \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "@wasmMemoryGrow"... - \\Test [2/1] - \\test "@wasmMemoryGrow"... SKIP - \\ - \\0 passed; 1 skipped; 0 failed. - \\ - \\``` , .arguments = &.{ "index: u32", @@ -1111,7 +1184,11 @@ pub const builtins = [_]Builtin{ .signature = "@mod(numerator: T, denominator: T) T", .snippet = "@mod(${1:numerator: T}, ${2:denominator: T})", .documentation = - \\ Modulus division. For unsigned integers this is the same as `numerator % denominator`. Caller guarantees `denominator > 0`. + \\Modulus division. For unsigned integers this is the same as `numerator % denominator`. Caller guarantees `denominator > 0`. + \\ - `@mod(-5, 3) == 1` + \\ - `(@divFloor(a, b) * b) + @mod(a, b) == a` + \\ + \\For a function that returns an error code, see `@import("std").math.mod`. , .arguments = &.{ "numerator: T", @@ -1123,7 +1200,7 @@ pub const builtins = [_]Builtin{ .signature = "@mulWithOverflow(comptime T: type, a: T, b: T, result: *T) bool", .snippet = "@mulWithOverflow(${1:comptime T: type}, ${2:a: T}, ${3:b: T}, ${4:result: *T})", .documentation = - \\ Performs `result.* = a * b`. If overflow or underflow occurs, stores the overflowed bits in `result` and returns `true`. If no overflow or underflow occurs, returns `false`. + \\Performs `result.* = a * b`. If overflow or underflow occurs, stores the overflowed bits in `result` and returns `true`. If no overflow or underflow occurs, returns `false`. , .arguments = &.{ "comptime T: type", @@ -1137,8 +1214,11 @@ pub const builtins = [_]Builtin{ .signature = "@panic(message: []const u8) noreturn", .snippet = "@panic(${1:message: []const u8})", .documentation = - \\ Invokes the panic handler function. By default the panic handler function calls the public `panic` function exposed in the root source file, or if there is not one specified, the `std.builtin.default_panic` function from `std/builtin.zig`. + \\Invokes the panic handler function. By default the panic handler function calls the public `panic` function exposed in the root source file, or if there is not one specified, the `std.builtin.default_panic` function from `std/builtin.zig`. + \\ \\Generally it is better to use `@import("std").debug.panic`. However, `@panic` can be useful for 2 scenarios: + \\ - From library code, calling the programmer's panic function if they exposed one in the root source file. + \\ - When mixing C and Zig code, calling the canonical panic implementation across multiple .o files. , .arguments = &.{ "message: []const u8", @@ -1150,7 +1230,8 @@ pub const builtins = [_]Builtin{ .snippet = "@popCount(${1:comptime T: type}, ${2:integer: T})", .documentation = \\Counts the number of bits set in an integer. - \\ If `integer` is known at comptime, the return type is `comptime_int`. Otherwise, the return type is an unsigned integer with the minimum number of bits that can represent the bit count of the integer type. + \\ + \\If `integer` is known at [comptime](https://ziglang.org/documentation/master/#comptime), the return type is `comptime_int`. Otherwise, the return type is an unsigned integer with the minimum number of bits that can represent the bit count of the integer type. , .arguments = &.{ "comptime T: type", @@ -1162,8 +1243,9 @@ pub const builtins = [_]Builtin{ .signature = "@ptrCast(comptime DestType: type, value: anytype) DestType", .snippet = "@ptrCast(${1:comptime DestType: type}, ${2:value: anytype})", .documentation = - \\ Converts a pointer of one type to a pointer of another type. - \\ Optional Pointers are allowed. Casting an optional pointer which is null to a non-optional pointer invokes safety-checked Undefined Behavior. + \\Converts a pointer of one type to a pointer of another type. + \\ + \\[Optional Pointers](https://ziglang.org/documentation/master/#Optional-Pointers) are allowed. Casting an optional pointer which is [null](https://ziglang.org/documentation/master/#null) to a non-optional pointer invokes safety-checked [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). , .arguments = &.{ "comptime DestType: type", @@ -1175,7 +1257,13 @@ pub const builtins = [_]Builtin{ .signature = "@ptrToInt(value: anytype) usize", .snippet = "@ptrToInt(${1:value: anytype})", .documentation = - \\ Converts `value` to a `usize` which is the address of the pointer. `value` can be one of these types: + \\Converts `value` to a `usize` which is the address of the pointer. `value` can be one of these types: + \\ - `*T` + \\ - `?*T` + \\ - `fn()` + \\ - `?fn()` + \\ + \\To convert the other way, use [@intToPtr](https://ziglang.org/documentation/master/#intToPtr) , .arguments = &.{ "value: anytype", @@ -1186,7 +1274,11 @@ pub const builtins = [_]Builtin{ .signature = "@rem(numerator: T, denominator: T) T", .snippet = "@rem(${1:numerator: T}, ${2:denominator: T})", .documentation = - \\ Remainder division. For unsigned integers this is the same as `numerator % denominator`. Caller guarantees `denominator > 0`. + \\Remainder division. For unsigned integers this is the same as `numerator % denominator`. Caller guarantees `denominator > 0`. + \\ - `@rem(-5, 3) == -2` + \\ - `(@divTrunc(a, b) * b) + @rem(a, b) == a` + \\ + \\For a function that returns an error code, see `@import("std").math.rem`. , .arguments = &.{ "numerator: T", @@ -1198,9 +1290,11 @@ pub const builtins = [_]Builtin{ .signature = "@returnAddress() usize", .snippet = "@returnAddress()", .documentation = - \\ This function returns the address of the next machine code instruction that will be executed when the current function returns. - \\ The implications of this are target specific and not consistent across all platforms. - \\ This function is only valid within function scope. If the function gets inlined into a calling function, the returned address will apply to the calling function. + \\This function returns the address of the next machine code instruction that will be executed when the current function returns. + \\ + \\The implications of this are target specific and not consistent across all platforms. + \\ + \\This function is only valid within function scope. If the function gets inlined into a calling function, the returned address will apply to the calling function. , .arguments = &.{}, }, @@ -1209,7 +1303,7 @@ pub const builtins = [_]Builtin{ .signature = "@setAlignStack(comptime alignment: u29)", .snippet = "@setAlignStack(${1:comptime alignment: u29})", .documentation = - \\ Ensures that a function will have a stack alignment of at least `alignment` bytes. + \\Ensures that a function will have a stack alignment of at least `alignment` bytes. , .arguments = &.{ "comptime alignment: u29", @@ -1220,7 +1314,7 @@ pub const builtins = [_]Builtin{ .signature = "@setCold(is_cold: bool)", .snippet = "@setCold(${1:is_cold: bool})", .documentation = - \\ Tells the optimizer that a function is rarely called. + \\Tells the optimizer that a function is rarely called. , .arguments = &.{ "is_cold: bool", @@ -1231,10 +1325,12 @@ pub const builtins = [_]Builtin{ .signature = "@setEvalBranchQuota(new_quota: u32)", .snippet = "@setEvalBranchQuota(${1:new_quota: u32})", .documentation = - \\ Changes the maximum number of backwards branches that compile-time code execution can use before giving up and making a compile error. - \\ If the `new_quota` is smaller than the default quota (`1000`) or a previously explicitly set quota, it is ignored. - \\ Example: - \\test.zig + \\Changes the maximum number of backwards branches that compile-time code execution can use before giving up and making a compile error. + \\ + \\If the `new_quota` is smaller than the default quota (`1000`) or a previously explicitly set quota, it is ignored. + \\ + \\Example: + \\ \\```zig \\test "foo" { \\ comptime { @@ -1243,18 +1339,9 @@ pub const builtins = [_]Builtin{ \\ } \\} \\``` - \\```zig - \\$ zig test test.zig - \\./docgen_tmp/test.zig:4:9: error: evaluation exceeded 1000 backwards branches - \\ while (i < 1001) : (i += 1) {} - \\ ^ - \\./docgen_tmp/test.zig:1:12: note: referenced here - \\test "foo" { - \\ ^ \\ - \\``` \\Now we use `@setEvalBranchQuota`: - \\test.zig + \\ \\```zig \\test "foo" { \\ comptime { @@ -1264,13 +1351,6 @@ pub const builtins = [_]Builtin{ \\ } \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "foo"... - \\ - \\All 1 tests passed. - \\ - \\``` , .arguments = &.{ "new_quota: u32", @@ -1281,13 +1361,25 @@ pub const builtins = [_]Builtin{ .signature = "@setFloatMode(mode: @import(\"std\").builtin.FloatMode)", .snippet = "@setFloatMode(${1:mode: @import(\"std\").builtin.FloatMode})", .documentation = - \\ Sets the floating point mode of the current scope. Possible values are: + \\Sets the floating point mode of the current scope. Possible values are: + \\ \\```zig \\pub const FloatMode = enum { \\ Strict, \\ Optimized, \\}; \\``` + \\ + \\ - `Strict` (default) - Floating point operations follow strict IEEE compliance. + \\ - `Optimized` - Floating point operations may do all of the following: + \\ + \\The floating point mode is inherited by child scopes, and can be overridden in any scope. You can set the floating point mode in a struct or module scope by using a comptime block. , .arguments = &.{ "mode: @import(\"std\").builtin.FloatMode", @@ -1298,8 +1390,8 @@ pub const builtins = [_]Builtin{ .signature = "@setRuntimeSafety(safety_on: bool) void", .snippet = "@setRuntimeSafety(${1:safety_on: bool})", .documentation = - \\ Sets whether runtime safety checks are enabled for the scope that contains the function call. - \\test.zig + \\Sets whether runtime safety checks are enabled for the scope that contains the function call. + \\ \\```zig \\test "@setRuntimeSafety" { \\ // The builtin applies to the scope that it is called in. So here, integer overflow @@ -1323,15 +1415,8 @@ pub const builtins = [_]Builtin{ \\ } \\} \\``` - \\```zig - \\$ zig test test.zig -OReleaseFast - \\Test [1/1] test "@setRuntimeSafety"... - \\thread 25869 panic: integer overflow - \\error: the following test command crashed: - \\docgen_tmp/zig-cache/o/1dcfcf225d1af94cea55a9c1ad33baf5/test /home/vsts/work/1/s/build/release/bin/zig \\ - \\``` - \\Note: it is planned to replace `@setRuntimeSafety` with `@optimizeFor` + \\Note: it is [planned](https://github.com/ziglang/zig/issues/978) to replace `@setRuntimeSafety` with `@optimizeFor` , .arguments = &.{ "safety_on: bool", @@ -1342,8 +1427,9 @@ pub const builtins = [_]Builtin{ .signature = "@shlExact(value: T, shift_amt: Log2T) T", .snippet = "@shlExact(${1:value: T}, ${2:shift_amt: Log2T})", .documentation = - \\ Performs the left shift operation (`<<`). Caller guarantees that the shift will not shift any 1 bits out. - \\ The type of `shift_amt` is an unsigned integer with `log2(T.bit_count)` bits. This is because `shift_amt >= T.bit_count` is undefined behavior. + \\Performs the left shift operation (`<<`). Caller guarantees that the shift will not shift any 1 bits out. + \\ + \\The type of `shift_amt` is an unsigned integer with `log2(T.bit_count)` bits. This is because `shift_amt >= T.bit_count` is undefined behavior. , .arguments = &.{ "value: T", @@ -1355,8 +1441,9 @@ pub const builtins = [_]Builtin{ .signature = "@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: *T) bool", .snippet = "@shlWithOverflow(${1:comptime T: type}, ${2:a: T}, ${3:shift_amt: Log2T}, ${4:result: *T})", .documentation = - \\ Performs `result.* = a << b`. If overflow or underflow occurs, stores the overflowed bits in `result` and returns `true`. If no overflow or underflow occurs, returns `false`. - \\ The type of `shift_amt` is an unsigned integer with `log2(T.bit_count)` bits. This is because `shift_amt >= T.bit_count` is undefined behavior. + \\Performs `result.* = a << b`. If overflow or underflow occurs, stores the overflowed bits in `result` and returns `true`. If no overflow or underflow occurs, returns `false`. + \\ + \\The type of `shift_amt` is an unsigned integer with `log2(T.bit_count)` bits. This is because `shift_amt >= T.bit_count` is undefined behavior. , .arguments = &.{ "comptime T: type", @@ -1370,8 +1457,9 @@ pub const builtins = [_]Builtin{ .signature = "@shrExact(value: T, shift_amt: Log2T) T", .snippet = "@shrExact(${1:value: T}, ${2:shift_amt: Log2T})", .documentation = - \\ Performs the right shift operation (`>>`). Caller guarantees that the shift will not shift any 1 bits out. - \\ The type of `shift_amt` is an unsigned integer with `log2(T.bit_count)` bits. This is because `shift_amt >= T.bit_count` is undefined behavior. + \\Performs the right shift operation (`>>`). Caller guarantees that the shift will not shift any 1 bits out. + \\ + \\The type of `shift_amt` is an unsigned integer with `log2(T.bit_count)` bits. This is because `shift_amt >= T.bit_count` is undefined behavior. , .arguments = &.{ "value: T", @@ -1383,12 +1471,17 @@ pub const builtins = [_]Builtin{ .signature = "@shuffle(comptime E: type, a: std.meta.Vector(a_len, E), b: std.meta.Vector(b_len, E), comptime mask: std.meta.Vector(mask_len, i32)) std.meta.Vector(mask_len, E)", .snippet = "@shuffle(${1:comptime E: type}, ${2:a: std.meta.Vector(a_len, E)}, ${3:b: std.meta.Vector(b_len, E)}, ${4:comptime mask: std.meta.Vector(mask_len, i32)})", .documentation = - \\ Constructs a new vector by selecting elements from `a` and `b` based on `mask`. - \\ Each element in `mask` selects an element from either `a` or `b`. Positive numbers select from `a` starting at 0. Negative values select from `b`, starting at `-1` and going down. It is recommended to use the `~` operator from indexes from `b` so that both indexes can start from `0` (i.e. `~@as(i32, 0)` is `-1`). - \\ For each element of `mask`, if it or the selected value from `a` or `b` is `undefined`, then the resulting element is `undefined`. - \\ `a_len` and `b_len` may differ in length. Out-of-bounds element indexes in `mask` result in compile errors. - \\ If `a` or `b` is `undefined`, it is equivalent to a vector of all `undefined` with the same length as the other vector. If both vectors are `undefined`, `@shuffle` returns a vector with all elements `undefined`. - \\ `E` must be an integer, float, pointer, or `bool`. The mask may be any vector length, and its length determines the result length. + \\Constructs a new [vector](https://ziglang.org/documentation/master/#Vectors) by selecting elements from `a` and `b` based on `mask`. + \\ + \\Each element in `mask` selects an element from either `a` or `b`. Positive numbers select from `a` starting at 0. Negative values select from `b`, starting at `-1` and going down. It is recommended to use the `~` operator from indexes from `b` so that both indexes can start from `0` (i.e. `~@as(i32, 0)` is `-1`). + \\ + \\For each element of `mask`, if it or the selected value from `a` or `b` is `undefined`, then the resulting element is `undefined`. + \\ + \\`a_len` and `b_len` may differ in length. Out-of-bounds element indexes in `mask` result in compile errors. + \\ + \\If `a` or `b` is `undefined`, it is equivalent to a vector of all `undefined` with the same length as the other vector. If both vectors are `undefined`, `@shuffle` returns a vector with all elements `undefined`. + \\ + \\`E` must be an [integer](https://ziglang.org/documentation/master/#Integers), [float](https://ziglang.org/documentation/master/#Floats), [pointer](https://ziglang.org/documentation/master/#Pointers), or `bool`. The mask may be any vector length, and its length determines the result length. , .arguments = &.{ "comptime E: type", @@ -1402,9 +1495,11 @@ pub const builtins = [_]Builtin{ .signature = "@sizeOf(comptime T: type) comptime_int", .snippet = "@sizeOf(${1:comptime T: type})", .documentation = - \\ This function returns the number of bytes it takes to store `T` in memory. The result is a target-specific compile time constant. - \\ This size may contain padding bytes. If there were two consecutive T in memory, this would be the offset in bytes between element at index 0 and the element at index 1. For integer, consider whether you want to use `@sizeOf(T)` or `@typeInfo(T).Int.bits`. - \\ This function measures the size at runtime. For types that are disallowed at runtime, such as `comptime_int` and `type`, the result is `0`. + \\This function returns the number of bytes it takes to store `T` in memory. The result is a target-specific compile time constant. + \\ + \\This size may contain padding bytes. If there were two consecutive T in memory, this would be the offset in bytes between element at index 0 and the element at index 1. For [integer](https://ziglang.org/documentation/master/#Integers), consider whether you want to use `@sizeOf(T)` or `@typeInfo(T).Int.bits`. + \\ + \\This function measures the size at runtime. For types that are disallowed at runtime, such as `comptime_int` and `type`, the result is `0`. , .arguments = &.{ "comptime T: type", @@ -1415,8 +1510,8 @@ pub const builtins = [_]Builtin{ .signature = "@splat(comptime len: u32, scalar: anytype) std.meta.Vector(len, @TypeOf(scalar))", .snippet = "@splat(${1:comptime len: u32}, ${2:scalar: anytype})", .documentation = - \\ Produces a vector of length `len` where each element is the value `scalar`: - \\test.zig + \\Produces a vector of length `len` where each element is the value `scalar`: + \\ \\```zig \\const std = @import("std"); \\const expect = std.testing.expect; @@ -1428,14 +1523,8 @@ pub const builtins = [_]Builtin{ \\ try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "vector @splat"... \\ - \\All 1 tests passed. - \\ - \\``` - \\ `scalar` must be an integer, bool, float, or pointer. + \\`scalar` must be an [integer](https://ziglang.org/documentation/master/#Integers), [bool](https://ziglang.org/documentation/master/#Primitive-Types), [float](https://ziglang.org/documentation/master/#Floats), or [pointer](https://ziglang.org/documentation/master/#Pointers). , .arguments = &.{ "comptime len: u32", @@ -1447,8 +1536,29 @@ pub const builtins = [_]Builtin{ .signature = "@reduce(comptime op: std.builtin.ReduceOp, value: anytype) std.meta.Child(value)", .snippet = "@reduce(${1:comptime op: std.builtin.ReduceOp}, ${2:value: anytype})", .documentation = - \\ Transforms a vector into a scalar value by performing a sequential horizontal reduction of its elements using the specified operator `op`. - \\ Not every operator is available for every vector element type: + \\Transforms a [vector](https://ziglang.org/documentation/master/#Vectors) into a scalar value by performing a sequential horizontal reduction of its elements using the specified operator `op`. + \\ + \\Not every operator is available for every vector element type: + \\ - `.And`, `.Or`, `.Xor` are available for `bool` vectors, + \\ - `.Min`, `.Max`, `.Add`, `.Mul` are available for [floating point](https://ziglang.org/documentation/master/#Floats) vectors, + \\ - Every operator is available for [integer](https://ziglang.org/documentation/master/#Integers) vectors. + \\ + \\Note that `.Add` and `.Mul` reductions on integral types are wrapping; when applied on floating point types the operation associativity is preserved, unless the float mode is set to `Optimized`. + \\ + \\```zig + \\const std = @import("std"); + \\const expect = std.testing.expect; + \\ + \\test "vector @reduce" { + \\ const value: std.meta.Vector(4, i32) = [_]i32{ 1, -1, 1, -1 }; + \\ const result = value > @splat(4, @as(i32, 0)); + \\ // result is { true, false, true, false }; + \\ comptime try expect(@TypeOf(result) == std.meta.Vector(4, bool)); + \\ const is_all_true = @reduce(.And, result); + \\ comptime try expect(@TypeOf(is_all_true) == bool); + \\ try expect(is_all_true == false); + \\} + \\``` , .arguments = &.{ "comptime op: std.builtin.ReduceOp", @@ -1460,8 +1570,8 @@ pub const builtins = [_]Builtin{ .signature = "@src() std.builtin.SourceLocation", .snippet = "@src()", .documentation = - \\ Returns a `SourceLocation` struct representing the function's name and location in the source code. This must be called in a function. - \\test.zig + \\Returns a `SourceLocation` struct representing the function's name and location in the source code. This must be called in a function. + \\ \\```zig \\const std = @import("std"); \\const expect = std.testing.expect; @@ -1479,13 +1589,6 @@ pub const builtins = [_]Builtin{ \\ try expect(std.mem.endsWith(u8, src.file, "test.zig")); \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "@src"... - \\ - \\All 1 tests passed. - \\ - \\``` , .arguments = &.{}, }, @@ -1494,8 +1597,9 @@ pub const builtins = [_]Builtin{ .signature = "@sqrt(value: anytype) @TypeOf(value)", .snippet = "@sqrt(${1:value: anytype})", .documentation = - \\ Performs the square root of a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Performs the square root of a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1506,8 +1610,9 @@ pub const builtins = [_]Builtin{ .signature = "@sin(value: anytype) @TypeOf(value)", .snippet = "@sin(${1:value: anytype})", .documentation = - \\ Sine trigometric function on a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Sine trigometric function on a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1518,8 +1623,9 @@ pub const builtins = [_]Builtin{ .signature = "@cos(value: anytype) @TypeOf(value)", .snippet = "@cos(${1:value: anytype})", .documentation = - \\ Cosine trigometric function on a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Cosine trigometric function on a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1530,8 +1636,9 @@ pub const builtins = [_]Builtin{ .signature = "@exp(value: anytype) @TypeOf(value)", .snippet = "@exp(${1:value: anytype})", .documentation = - \\ Base-e exponential function on a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Base-e exponential function on a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1542,8 +1649,9 @@ pub const builtins = [_]Builtin{ .signature = "@exp2(value: anytype) @TypeOf(value)", .snippet = "@exp2(${1:value: anytype})", .documentation = - \\ Base-2 exponential function on a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Base-2 exponential function on a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1554,8 +1662,9 @@ pub const builtins = [_]Builtin{ .signature = "@log(value: anytype) @TypeOf(value)", .snippet = "@log(${1:value: anytype})", .documentation = - \\ Returns the natural logarithm of a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Returns the natural logarithm of a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1566,8 +1675,9 @@ pub const builtins = [_]Builtin{ .signature = "@log2(value: anytype) @TypeOf(value)", .snippet = "@log2(${1:value: anytype})", .documentation = - \\ Returns the logarithm to the base 2 of a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Returns the logarithm to the base 2 of a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1578,8 +1688,9 @@ pub const builtins = [_]Builtin{ .signature = "@log10(value: anytype) @TypeOf(value)", .snippet = "@log10(${1:value: anytype})", .documentation = - \\ Returns the logarithm to the base 10 of a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Returns the logarithm to the base 10 of a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1590,8 +1701,9 @@ pub const builtins = [_]Builtin{ .signature = "@fabs(value: anytype) @TypeOf(value)", .snippet = "@fabs(${1:value: anytype})", .documentation = - \\ Returns the absolute value of a floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Returns the absolute value of a floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1602,8 +1714,9 @@ pub const builtins = [_]Builtin{ .signature = "@floor(value: anytype) @TypeOf(value)", .snippet = "@floor(${1:value: anytype})", .documentation = - \\ Returns the largest integral value not greater than the given floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Returns the largest integral value not greater than the given floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1614,8 +1727,9 @@ pub const builtins = [_]Builtin{ .signature = "@ceil(value: anytype) @TypeOf(value)", .snippet = "@ceil(${1:value: anytype})", .documentation = - \\ Returns the largest integral value not less than the given floating point number. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Returns the largest integral value not less than the given floating point number. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1626,8 +1740,9 @@ pub const builtins = [_]Builtin{ .signature = "@trunc(value: anytype) @TypeOf(value)", .snippet = "@trunc(${1:value: anytype})", .documentation = - \\ Rounds the given floating point number to an integer, towards zero. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Rounds the given floating point number to an integer, towards zero. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1638,8 +1753,9 @@ pub const builtins = [_]Builtin{ .signature = "@round(value: anytype) @TypeOf(value)", .snippet = "@round(${1:value: anytype})", .documentation = - \\ Rounds the given floating point number to an integer, away from zero. Uses a dedicated hardware instruction when available. - \\ Supports Floats and Vectors of floats, with the caveat that some float operations are not yet implemented for all float types. + \\Rounds the given floating point number to an integer, away from zero. Uses a dedicated hardware instruction when available. + \\ + \\Supports [Floats](https://ziglang.org/documentation/master/#Floats) and [Vectors](https://ziglang.org/documentation/master/#Vectors) of floats, with the caveat that [some float operations are not yet implemented for all float types](https://github.com/ziglang/zig/issues/4026). , .arguments = &.{ "value: anytype", @@ -1650,7 +1766,7 @@ pub const builtins = [_]Builtin{ .signature = "@subWithOverflow(comptime T: type, a: T, b: T, result: *T) bool", .snippet = "@subWithOverflow(${1:comptime T: type}, ${2:a: T}, ${3:b: T}, ${4:result: *T})", .documentation = - \\ Performs `result.* = a - b`. If overflow or underflow occurs, stores the overflowed bits in `result` and returns `true`. If no overflow or underflow occurs, returns `false`. + \\Performs `result.* = a - b`. If overflow or underflow occurs, stores the overflowed bits in `result` and returns `true`. If no overflow or underflow occurs, returns `false`. , .arguments = &.{ "comptime T: type", @@ -1664,8 +1780,9 @@ pub const builtins = [_]Builtin{ .signature = "@tagName(value: anytype) [:0]const u8", .snippet = "@tagName(${1:value: anytype})", .documentation = - \\ Converts an enum value or union value to a string literal representing the name. - \\If the enum is non-exhaustive and the tag value does not map to a name, it invokes safety-checked Undefined Behavior. + \\Converts an enum value or union value to a string literal representing the name. + \\ + \\If the enum is non-exhaustive and the tag value does not map to a name, it invokes safety-checked [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior). , .arguments = &.{ "value: anytype", @@ -1676,8 +1793,8 @@ pub const builtins = [_]Builtin{ .signature = "@This() type", .snippet = "@This()", .documentation = - \\ Returns the innermost struct, enum, or union that this function call is inside. This can be useful for an anonymous struct that needs to refer to itself: - \\test.zig + \\Returns the innermost struct, enum, or union that this function call is inside. This can be useful for an anonymous struct that needs to refer to itself: + \\ \\```zig \\const std = @import("std"); \\const expect = std.testing.expect; @@ -1700,14 +1817,8 @@ pub const builtins = [_]Builtin{ \\ }; \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "@This()"... \\ - \\All 1 tests passed. - \\ - \\``` - \\ When `@This()` is used at file scope, it returns a reference to the struct that corresponds to the current file. + \\When `@This()` is used at file scope, it returns a reference to the struct that corresponds to the current file. , .arguments = &.{}, }, @@ -1716,9 +1827,10 @@ pub const builtins = [_]Builtin{ .signature = "@truncate(comptime T: type, integer: anytype) T", .snippet = "@truncate(${1:comptime T: type}, ${2:integer: anytype})", .documentation = - \\ This function truncates bits from an integer type, resulting in a smaller or same-sized integer type. - \\ The following produces safety-checked Undefined Behavior: - \\test.zig + \\This function truncates bits from an integer type, resulting in a smaller or same-sized integer type. + \\ + \\The following produces safety-checked [Undefined Behavior](https://ziglang.org/documentation/master/#Undefined-Behavior): + \\ \\```zig \\test "integer cast panic" { \\ var a: u16 = 0xabcd; @@ -1726,34 +1838,9 @@ pub const builtins = [_]Builtin{ \\ _ = b; \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "integer cast panic"... - \\thread 25915 panic: integer cast truncated bits - \\/home/vsts/work/1/s/docgen_tmp/test.zig:3:17: 0x206765 in test "integer cast panic" (test) - \\ var b: u8 = @intCast(u8, a); - \\ ^ - \\/home/vsts/work/1/s/build/release/lib/zig/std/special/test_runner.zig:76:28: 0x22ce4a in std.special.main (test) - \\ } else test_fn.func(); - \\ ^ - \\/home/vsts/work/1/s/build/release/lib/zig/std/start.zig:499:37: 0x22538a in std.start.callMain (test) - \\ const result = root.main() catch |err| { - \\ ^ - \\/home/vsts/work/1/s/build/release/lib/zig/std/start.zig:441:12: 0x20936e in std.start.callMainWithArgs (test) - \\ return @call(.{ .modifier = .always_inline }, callMain, .{}); - \\ ^ - \\/home/vsts/work/1/s/build/release/lib/zig/std/start.zig:360:17: 0x208396 in std.start.posixCallMainAndExit (test) - \\ std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp })); - \\ ^ - \\/home/vsts/work/1/s/build/release/lib/zig/std/start.zig:273:5: 0x2081a2 in std.start._start (test) - \\ @call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{}); - \\ ^ - \\error: the following test command crashed: - \\docgen_tmp/zig-cache/o/b57c87929c329ced471b9562bfc99d57/test /home/vsts/work/1/s/build/release/bin/zig \\ - \\``` - \\ However this is well defined and working code: - \\truncate.zig + \\However this is well defined and working code: + \\ \\```zig \\const std = @import("std"); \\const expect = std.testing.expect; @@ -1764,14 +1851,8 @@ pub const builtins = [_]Builtin{ \\ try expect(b == 0xcd); \\} \\``` - \\```zig - \\$ zig test truncate.zig - \\Test [1/1] test "integer truncation"... \\ - \\All 1 tests passed. - \\ - \\``` - \\ This function always truncates the significant bits of the integer, regardless of endianness on the target platform. + \\This function always truncates the significant bits of the integer, regardless of endianness on the target platform. , .arguments = &.{ "comptime T: type", @@ -1783,8 +1864,36 @@ pub const builtins = [_]Builtin{ .signature = "@Type(comptime info: std.builtin.TypeInfo) type", .snippet = "@Type(${1:comptime info: std.builtin.TypeInfo})", .documentation = - \\ This function is the inverse of @typeInfo. It reifies type information into a `type`. - \\ It is available for the following types: + \\This function is the inverse of [@typeInfo](https://ziglang.org/documentation/master/#typeInfo). It reifies type information into a `type`. + \\ + \\It is available for the following types: + \\ - `type` + \\ - `noreturn` + \\ - `void` + \\ - `bool` + \\ - [Integers](https://ziglang.org/documentation/master/#Integers) - The maximum bit count for an integer type is `65535`. + \\ - [Floats](https://ziglang.org/documentation/master/#Floats) + \\ - [Pointers](https://ziglang.org/documentation/master/#Pointers) + \\ - `comptime_int` + \\ - `comptime_float` + \\ - `@TypeOf(undefined)` + \\ - `@TypeOf(null)` + \\ - [Arrays](https://ziglang.org/documentation/master/#Arrays) + \\ - [Optionals](https://ziglang.org/documentation/master/#Optionals) + \\ - [Error Set Type](https://ziglang.org/documentation/master/#Error-Set-Type) + \\ - [Error Union Type](https://ziglang.org/documentation/master/#Error-Union-Type) + \\ - [Vectors](https://ziglang.org/documentation/master/#Vectors) + \\ - [opaque](https://ziglang.org/documentation/master/#opaque) + \\ - [@Frame](https://ziglang.org/documentation/master/#Frame) + \\ - `anyframe` + \\ - [struct](https://ziglang.org/documentation/master/#struct) + \\ - [enum](https://ziglang.org/documentation/master/#enum) + \\ - [Enum Literals](https://ziglang.org/documentation/master/#Enum-Literals) + \\ - [union](https://ziglang.org/documentation/master/#union) + \\ + \\For these types, `@Type` is not available: + \\ - [Functions](https://ziglang.org/documentation/master/#Functions) + \\ - BoundFn , .arguments = &.{ "comptime info: std.builtin.TypeInfo", @@ -1795,8 +1904,9 @@ pub const builtins = [_]Builtin{ .signature = "@typeInfo(comptime T: type) std.builtin.TypeInfo", .snippet = "@typeInfo(${1:comptime T: type})", .documentation = - \\ Provides type reflection. - \\ For structs, unions, enums, and error sets, the fields are guaranteed to be in the same order as declared. For declarations, the order is unspecified. + \\Provides type reflection. + \\ + \\For [structs](https://ziglang.org/documentation/master/#struct), [unions](https://ziglang.org/documentation/master/#union), [enums](https://ziglang.org/documentation/master/#enum), and [error sets](https://ziglang.org/documentation/master/#Error-Set-Type), the fields are guaranteed to be in the same order as declared. For declarations, the order is unspecified. , .arguments = &.{ "comptime T: type", @@ -1807,7 +1917,7 @@ pub const builtins = [_]Builtin{ .signature = "@typeName(T: type) *const [N:0]u8", .snippet = "@typeName(${1:T: type})", .documentation = - \\ This function returns the string representation of a type, as an array. It is equivalent to a string literal of the type name. + \\This function returns the string representation of a type, as an array. It is equivalent to a string literal of the type name. , .arguments = &.{ "T: type", @@ -1818,9 +1928,10 @@ pub const builtins = [_]Builtin{ .signature = "@TypeOf(...) type", .snippet = "@TypeOf(${1:...})", .documentation = - \\ `@TypeOf` is a special builtin function that takes any (nonzero) number of expressions as parameters and returns the type of the result, using Peer Type Resolution. - \\ The expressions are evaluated, however they are guaranteed to have no runtime side-effects: - \\test.zig + \\`@TypeOf` is a special builtin function that takes any (nonzero) number of expressions as parameters and returns the type of the result, using [Peer Type Resolution](https://ziglang.org/documentation/master/#Peer-Type-Resolution). + \\ + \\The expressions are evaluated, however they are guaranteed to have no *runtime* side-effects: + \\ \\```zig \\const std = @import("std"); \\const expect = std.testing.expect; @@ -1837,13 +1948,6 @@ pub const builtins = [_]Builtin{ \\ return ptr.*; \\} \\``` - \\```zig - \\$ zig test test.zig - \\Test [1/1] test "no runtime side effects"... - \\ - \\All 1 tests passed. - \\ - \\``` , .arguments = &.{ "...", @@ -1854,8 +1958,9 @@ pub const builtins = [_]Builtin{ .signature = "@unionInit(comptime Union: type, comptime active_field_name: []const u8, init_expr) Union", .snippet = "@unionInit(${1:comptime Union: type}, ${2:comptime active_field_name: []const u8}, ${3:init_expr})", .documentation = - \\ This is the same thing as union initialization syntax, except that the field name is a comptime-known value rather than an identifier token. - \\ `@unionInit` forwards its result location to `init_expr`. + \\This is the same thing as [union](https://ziglang.org/documentation/master/#union) initialization syntax, except that the field name is a [comptime](https://ziglang.org/documentation/master/#comptime)-known value rather than an identifier token. + \\ + \\`@unionInit` forwards its [result location](https://ziglang.org/documentation/master/#Result-Location-Semantics) to `init_expr`. , .arguments = &.{ "comptime Union: type",