builtin namespace contains types and values that are automatically provided by the Zig compiler. These types are used by the language code generation and must be kept in sync with the compiler implementation.
Overview
Import the builtin namespace:Core Types
Type System
Represents type information at runtime. Used by
@typeInfo() to inspect types.Variants:type- The typetypevoid- The typevoidbool- Boolean typenoreturn- Thenoreturntypeint: Int- Integer typefloat: Float- Floating-point typepointer: Pointer- Pointer typearray: Array- Array type@"struct": Struct- Struct typeoptional: Optional- Optional typeerror_union: ErrorUnion- Error union typeerror_set: ErrorSet- Error set type@"enum": Enum- Enum type@"union": Union- Union type@"fn": Fn- Function type@"opaque": Opaque- Opaque typevector: Vector- Vector type- And more…
Tag type for
Type union, equivalent to std.meta.Tag(Type).Stack Traces
Data structure used by Zig language code generation for stack traces.
Represents a location in source code.
Enumerations
Compilation Modes
Optimization level for compilation.Values:
Debug- No optimizations, safety checks enabledReleaseSafe- Optimizations enabled, safety checks enabledReleaseFast- Optimizations enabled, safety checks disabledReleaseSmall- Optimize for small binary size
Output type of compilation.Values:
Exe- ExecutableLib- LibraryObj- Object file
Library linkage mode.Values:
static- Static linkingdynamic- Dynamic linking
Code Model
The code model puts constraints on the location of symbols and the size of code and data.Values:
defaulttinysmallkernelmediumlargeextreme- And more architecture-specific models…
Calling Conventions
Defines how arguments and return values are passed in function calls.Common variants:
auto- Default Zig calling conventionasync- Async function calling conventionnaked- No prologue or epilogue@"inline"- Semantically inlinedc- Default C calling convention (alias)- Platform-specific conventions (x86_64_sysv, aarch64_aapcs, etc.)
Atomic Operations
Memory ordering for atomic operations.Values:
unordered- No ordering constraintsmonotonic- Single total order existsacquire- Acquire semanticsrelease- Release semanticsacq_rel- Acquire and releaseseq_cst- Sequentially consistent
Atomic read-modify-write operations.Values:
Xchg- Exchange (store operand unmodified)Add- Add operand to existing valueSub- Subtract operand from existing valueAnd- Bitwise ANDNand- Bitwise NANDOr- Bitwise ORXor- Bitwise XORMax- Store maximumMin- Store minimum
Memory and Linking
Memory address spaces for pointers.CPU address spaces:
genericgs,fs,ss(x86-specific)
global,constant,shared,localuniform,push_constant,storage_buffer
flash,flash1, … (AVR)cog,hub,lut(Propeller)
Symbol linkage type.Values:
internal- Internal linkagestrong- Strong symbolweak- Weak symbollink_once- Link once
Symbol visibility.Values:
default- Default visibilityhidden- Hidden symbolprotected- Protected symbol
Other Enumerations
Integer signedness.Values:
signedunsigned
Byte order.Values:
big- Big-endianlittle- Little-endian
Floating-point optimization mode.Values:
strict- Strict IEEE 754 complianceoptimized- Allow optimizations
Vector reduction operations.Values:
And,Or,XorMin,MaxAdd,Mul
Compiler Information
Identifies which compiler backend is being used.Values:
other(0) - Unknown/unidentified compilerstage1(1) - Original C++ compiler (deleted 2022)stage2_llvm(2) - Self-hosted with LLVM backendstage2_c(3) - Self-hosted with C backendstage2_wasm(4) - Self-hosted with WebAssembly backendstage2_arm(5) - Self-hosted with ARM backendstage2_x86_64(6) - Self-hosted with x86_64 backendstage2_aarch64(7) - Self-hosted with AArch64 backendstage2_x86(8) - Self-hosted with x86 backendstage2_riscv64(9) - Self-hosted with RISC-V 64 backend- And more…
Options and Configuration
Modifiers for function calls.Values:
auto- Equivalent to normal call syntaxnever_tail- Prevent tail call optimizationnever_inline- Prevent inliningno_suspend- Assert function will not suspendalways_tail- Require tail call optimizationalways_inline- Require inliningcompile_time- Evaluate at compile-time
Hints for branch prediction.Values:
none- No hintlikely- Branch likely to be takenunlikely- Branch unlikely to be takencold- Branch very unlikely (can be placed in different memory page)unpredictable- Difficult to predict (avoid expensive mispredictions)
Options for
@prefetch builtin.Options for
@export builtin.Options for
@extern builtin.Platform-Specific Types
Variable Argument Lists
Platform-specific va_list type for variable arguments. The actual type varies by architecture:
- On x86_64 (non-Windows):
VaListX86_64 - On AArch64:
VaListAarch64 - On ARM:
VaListArm - On many architectures:
*u8or*anyopaque
VaListX86_64VaListAarch64VaListArmVaListPowerPcVaListS390x- And more…
WASI
WASI execution model.Values:
command- Command-line programreactor- Library/service
Unwind table generation mode.Values:
none- No unwind tablessync- Synchronous unwind tablesasync- Asynchronous unwind tables
Testing
Represents a test function. Used by the Zig test runner.
Panic Handling
Namespace used by the Zig compiler to emit various kinds of safety panics.Can be overridden by making a public
panic namespace in the root source file:Assembly
Architecture-specific assembly utilities and register definitions.Location:
lib/std/builtin/assembly.zigSee Also
- std namespace - Standard library exports
- std.Build API - Build system API
- Language Reference - Complete language specification