Skip to content
Standard libraryZig 0.17.0Official documentation
Sourcestd/lang.zig

Source line 1

Types and values provided by the Zig language.

std.lang.AddressSpace

container

Source line 575

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

generic
gs
fs
ss
far

Allows addressing the entire address space by storing both segment and offset.

global
constant
param
shared
local
private
input
output
uniform
push_constant
storage_buffer
physical_storage_buffer
flash
flash1
flash2
flash3
flash4
flash5
cog

This address space only addresses the cog-local ram.

hub

This address space only addresses shared hub ram.

lut

This address space only addresses the "lookup" ram

externref
funcref

std.lang.assembly

alias

Source line 7

Alias of std.lang.assembly

std.lang.AtomicOrder

container

Source line 33

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

unordered
monotonic
acquire
release
acq_rel
seq_cst

std.lang.AtomicRmwOp

container

Source line 56

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

Xchg

Exchange - store the operand unmodified. Supports enums, integers, and floats.

Add

Add operand to existing value. Supports integers and floats. For integers, two's complement wraparound applies.

Sub

Subtract operand from existing value. Supports integers and floats. For integers, two's complement wraparound applies.

And

Perform bitwise AND on existing value with operand. Supports integers.

Nand

Perform bitwise NAND on existing value with operand. Supports integers.

Or

Perform bitwise OR on existing value with operand. Supports integers.

Xor

Perform bitwise XOR on existing value with operand. Supports integers.

Max

Store operand if it is larger than the existing value. Supports integers and floats.

Min

Store operand if it is smaller than the existing value. Supports integers and floats.

std.lang.BranchHint

container

Source line 1244

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

none

Equivalent to no hint given.

likely

This branch of control flow is more likely to be reached than its peers. The optimizer should optimize for reaching it.

unlikely

This branch of control flow is less likely to be reached than its peers. The optimizer should optimize for not reaching it.

cold

This branch of control flow is unlikely to ever be reached. The optimizer may place it in a different page of memory to optimize other branches.

unpredictable

It is difficult to predict whether this branch of control flow will be reached. The optimizer should avoid branching behavior with expensive mispredictions.

std.lang.builtin

constant

Source line 3

std.lang.CallingConvention

container

Source line 162

The calling convention of a function defines how arguments and return values are passed, as well as any other requirements which callers and callees must respect, such as register preservation and stack alignment.

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

auto

The default Zig calling convention when neither export nor inline is specified. This calling convention makes no guarantees about stack alignment, registers, etc. It can only be used within this Zig compilation unit.

async

The calling convention of a function that can be called with async syntax. An async call of a runtime-known function must target a function with this calling convention. Comptime-known functions with other calling conventions may be coerced to this one.

naked

Functions with this calling convention have no prologue or epilogue, making the function uncallable in regular Zig code. This can be useful when integrating with assembly.

@"inline"

This calling convention is exactly equivalent to using the inline keyword on a function definition. This function will be semantically inlined by the Zig compiler at call sites. Pointers to inline functions are comptime-only.

x86_64_sysv: CommonOptions
x86_64_x32: CommonOptions
x86_64_win: CommonOptions
x86_64_regcall_v3_sysv: CommonOptions
x86_64_regcall_v4_win: CommonOptions
x86_64_vectorcall: CommonOptions
x86_64_interrupt: CommonOptions
x86_64_preserve_none: CommonOptions
x86_sysv: X86RegparmOptions
x86_win: X86RegparmOptions
x86_mingw: X86RegparmOptions
x86_stdcall: X86RegparmOptions
x86_fastcall: CommonOptions
x86_thiscall: CommonOptions
x86_thiscall_mingw: CommonOptions
x86_regcall_v3: CommonOptions
x86_regcall_v4_win: CommonOptions
x86_vectorcall: CommonOptions
x86_interrupt: CommonOptions
x86_16_cdecl: CommonOptions
x86_16_stdcall: CommonOptions
x86_16_regparmcall: CommonOptions
x86_16_interrupt: CommonOptions
aarch64_aapcs: CommonOptions
aarch64_aapcs_darwin: CommonOptions
aarch64_aapcs_win: CommonOptions
aarch64_vfabi: CommonOptions
aarch64_vfabi_sve: CommonOptions
aarch64_preserve_none: CommonOptions
alpha_osf: CommonOptions

The standard alpha calling convention.

arm_aapcs: CommonOptions

ARM Architecture Procedure Call Standard

arm_aapcs_vfp: CommonOptions

ARM Architecture Procedure Call Standard Vector Floating-Point

arm_interrupt: ArmInterruptOptions
mips64_n64: CommonOptions
mips64_n32: CommonOptions
mips64_interrupt: MipsInterruptOptions
mips_o32: CommonOptions
mips_interrupt: MipsInterruptOptions
riscv64_lp64: CommonOptions
riscv64_lp64_v: CommonOptions
riscv64_interrupt: RiscvInterruptOptions
riscv32_ilp32: CommonOptions
riscv32_ilp32_v: CommonOptions
riscv32_interrupt: RiscvInterruptOptions
sparc64_sysv: CommonOptions
sparc_sysv: CommonOptions
powerpc64_elf: CommonOptions
powerpc64_elf_altivec: CommonOptions
powerpc64_elf_v2: CommonOptions
powerpc_sysv: CommonOptions
powerpc_sysv_altivec: CommonOptions
powerpc_aix: CommonOptions
powerpc_aix_altivec: CommonOptions
wasm_mvp: CommonOptions

The standard wasm32 and wasm64 calling convention, as specified in the WebAssembly Tool Conventions.

arc_sysv: CommonOptions

The standard arc/arceb calling convention.

arc_interrupt: ArcInterruptOptions
avr_gnu
avr_builtin
avr_signal
avr_interrupt
bpf_std: CommonOptions

The standard bpfel/bpfeb calling convention.

csky_sysv: CommonOptions
csky_interrupt: CommonOptions
hexagon_sysv: CommonOptions
hexagon_sysv_hvx: CommonOptions
hppa_elf: CommonOptions

The standard hppa calling convention.

hppa64_elf: CommonOptions

The standard hppa64 calling convention.

kvx_lp64: CommonOptions
kvx_ilp32: CommonOptions
lanai_sysv: CommonOptions

The standard lanai calling convention.

loongarch64_lp64: CommonOptions

The standard loongarch64 calling convention.

loongarch32_ilp32: CommonOptions

The standard loongarch32 calling convention.

m68k_sysv: CommonOptions
m68k_gnu: CommonOptions
m68k_rtd: CommonOptions
m68k_interrupt: CommonOptions
m88k_sysv: CommonOptions
microblaze_std: CommonOptions

The standard microblaze/microblazeel calling convention.

microblaze_interrupt: MicroblazeInterruptOptions
msp430_eabi: CommonOptions

The standard msp430 calling convention.

msp430_interrupt: CommonOptions
or1k_sysv: CommonOptions

The standard or1k calling convention.

propeller_sysv: CommonOptions

The standard propeller calling convention.

s390x_sysv: CommonOptions
s390x_sysv_vx: CommonOptions
sh_gnu: CommonOptions
sh_renesas: CommonOptions
sh_interrupt: ShInterruptOptions
ve_sysv: CommonOptions

The standard ve calling convention.

xcore_xs1: CommonOptions
xcore_xs2: CommonOptions
xtensa_call0: CommonOptions
xtensa_windowed: CommonOptions
amdgcn_device: CommonOptions
amdgcn_kernel
amdgcn_cs: CommonOptions
nvptx_device
nvptx_kernel
spirv_device
spirv_vertex
spirv_kernel: SpirvKernelOptions
spirv_fragment: SpirvFragmentOptions
spirv_task: SpirvKernelOptions
spirv_mesh: SpirvMeshOptions
ez80_cet
ez80_tiflags
spork8

std.lang.CallingConvention.archs

function

Source line 557

Returns the array of std.Target.Cpu.Arch to which this CallingConvention applies. Asserts that cc is not .auto, .@"async", .naked, or .@"inline".

pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch

Parameters

std.lang.CallingConvention.ArcInterruptOptions

container

Source line 416

Options for the arc_interrupt calling convention.

Fields

incoming_stack_alignment: ?u64 = null

The boundary the stack is aligned to when the function is called. null means the default for this calling convention.

type: InterruptType

The kind of interrupt being received.

std.lang.CallingConvention.ArcInterruptOptions.InterruptType

container

Source line 423

Fields

ilink1
ilink2
ilink
firq

std.lang.CallingConvention.ArmInterruptOptions

container

Source line 432

Options for the arm_interrupt calling convention.

Fields

incoming_stack_alignment: ?u64 = null

The boundary the stack is aligned to when the function is called. null means the default for this calling convention.

type: InterruptType = .generic

The kind of interrupt being received.

std.lang.CallingConvention.ArmInterruptOptions.InterruptType

container

Source line 439

Fields

generic
irq
fiq
swi
abort
undef

std.lang.CallingConvention.c

constant

Source line 167

This is an alias for the default C calling convention for this target. Functions marked as extern or export are given this calling convention by default.

std.lang.CallingConvention.CommonOptions

container

Source line 397

Options shared across most calling conventions.

Fields

incoming_stack_alignment: ?u64 = null

The boundary the stack is aligned to when the function is called. null means the default for this calling convention.

std.lang.CallingConvention.eql

function

Source line 561

pub fn eql(a: CallingConvention, b: CallingConvention) bool

Parameters

std.lang.CallingConvention.kernel

constant

Source line 177

CallingConvention

std.lang.CallingConvention.MicroblazeInterruptOptions

container

Source line 450

Options for the microblaze_interrupt calling convention.

Fields

incoming_stack_alignment: ?u64 = null

The boundary the stack is aligned to when the function is called. null means the default for this calling convention.

type: InterruptType = .regular

std.lang.CallingConvention.MicroblazeInterruptOptions.InterruptType

container

Source line 456

Fields

user

User exception; return with rtsd.

regular

Regular interrupt; return with rtid.

fast

Fast interrupt; return with rtid.

breakpoint

Software breakpoint; return with rtbd.

std.lang.CallingConvention.MipsInterruptOptions

container

Source line 469

Options for the mips_interrupt and mips64_interrupt calling conventions.

Fields

incoming_stack_alignment: ?u64 = null

The boundary the stack is aligned to when the function is called. null means the default for this calling convention.

mode: InterruptMode = .eic

The interrupt mode.

std.lang.CallingConvention.MipsInterruptOptions.InterruptMode

container

Source line 476

Fields

eic
sw0
sw1
hw0
hw1
hw2
hw3
hw4
hw5

std.lang.CallingConvention.RiscvInterruptOptions

container

Source line 490

Options for the riscv32_interrupt and riscv64_interrupt calling conventions.

Fields

incoming_stack_alignment: ?u64 = null

The boundary the stack is aligned to when the function is called. null means the default for this calling convention.

mode: PrivilegeMode

The privilege mode.

std.lang.CallingConvention.RiscvInterruptOptions.PrivilegeMode

container

Source line 497

Fields

supervisor
machine

std.lang.CallingConvention.ShInterruptOptions

container

Source line 504

Options for the sh_interrupt calling convention.

Fields

incoming_stack_alignment: ?u64 = null

The boundary the stack is aligned to when the function is called. null means the default for this calling convention.

save: SaveBehavior = .full

std.lang.CallingConvention.ShInterruptOptions.SaveBehavior

container

Source line 510

Fields

fpscr

Save only fpscr (if applicable).

high

Save only high-numbered registers, i.e. r0 through r7 are not saved.

full

Save all registers normally.

bank

Save all registers using the CPU's fast register bank.

std.lang.CallingConvention.SpirvFragmentOptions

container

Source line 528

Fields

pixel_centered_integer: bool = false
depth_assumption: DepthAssumption = .none

std.lang.CallingConvention.SpirvFragmentOptions.DepthAssumption

container

Source line 529

Fields

none = 0
greater = 1
less = 2
unchanged = 3

std.lang.CallingConvention.SpirvKernelOptions

container

Source line 522

Fields

x: u32
y: u32
z: u32

std.lang.CallingConvention.SpirvMeshOptions

container

Source line 540

Fields

stage_output: StageOutput = .output_triangles
max_primitives: u32 = 1
max_vertices: u32 = 3
x: u32
y: u32
z: u32

std.lang.CallingConvention.SpirvMeshOptions.StageOutput

container

Source line 541

Fields

output_points = 0
output_lines = 1
output_triangles = 2

std.lang.CallingConvention.Tag

constant

Source line 163

std.lang.CallingConvention.winapi

constant

Source line 169

CallingConvention

std.lang.CallingConvention.withStackAlign

function

Source line 565

pub fn withStackAlign(cc: CallingConvention, incoming_stack_alignment: u64) CallingConvention

Parameters

cc: CallingConvention
incoming_stack_alignment: u64

std.lang.CallingConvention.X86RegparmOptions

container

Source line 405

Options for x86 calling conventions which support the regparm attribute to pass some arguments in registers.

Fields

incoming_stack_alignment: ?u64 = null

The boundary the stack is aligned to when the function is called. null means the default for this calling convention.

register_params: u2 = 0

The number of arguments to pass in registers before passing the remaining arguments according to the calling convention. Equivalent to __attribute__((regparm(x))) in Clang and GCC.

std.lang.CallModifier

container

Source line 1004

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

auto

Equivalent to function call syntax.

never_tail

Prevents tail call optimization. This guarantees that the return address will point to the callsite, as opposed to the callsite's callsite. If the call is otherwise required to be tail-called or inlined, a compile error is emitted instead.

never_inline

Guarantees that the call will not be inlined. If the call is otherwise required to be inlined, a compile error is emitted instead.

no_suspend

Asserts that the function call will not suspend. This allows a non-async function to call an async function.

always_tail

Guarantees that the call will be generated with tail call optimization. If this is not possible, a compile error is emitted instead.

always_inline

Guarantees that the call will be inlined at the callsite. If this is not possible, a compile error is emitted instead.

compile_time

Evaluates the call at compile-time. If the call cannot be completed at compile-time, a compile error is emitted instead.

std.lang.CodeModel

container

Source line 94

The code model puts constraints on the location of symbols and the size of code and data. The selection of a code model is a trade off on speed and restrictions that needs to be selected on a per application basis to meet its requirements. A slightly more detailed explanation can be found in (for example) the System V Application Binary Interface (x86_64) 3.5.1.

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

default
extreme
kernel
large
medany
medium
medlow
medmid
normal
small
tiny

std.lang.CompilerBackend

container

Source line 1280

This enum is set by the compiler and communicates which compiler implementation is used to produce machine code.

In theory, Zig code should be agnostic to the backend that implements the language. The only reason to observe this value is to work around problems with compiler implementations.

A common pitful is failing the compilation if the compiler backend does not match a whitelist of backends; a more resilient strategy is to detect that a known problem would occur in a blacklist of backends.

The enum is nonexhaustive so that alternate Zig language implementations may choose a random number as their tag, thereby avoiding conflicts with other implementations, and codebases can interact with these values even if this upstream enum does not have a name for the number. Of course, upstream is happy to accept patches to add additional Zig implementations to this enum.

This data structure is part of the Zig language specification.

Fields

other = 0

It is allowed for a compiler implementation to not reveal its identity, in which case this value is appropriate. Be cool and make sure your code supports other Zig compilers!

stage1 = 1

The original Zig compiler created in 2015 by Andrew Kelley. Implemented in C++. Used LLVM. Deleted from the ZSF ziglang/zig codebase on December 6th, 2022.

stage2_llvm = 2

The reference implementation self-hosted compiler of Zig, using the LLVM backend.

stage2_c = 3

The reference implementation self-hosted compiler of Zig, using the backend that generates C source code.

Note that one can observe whether the compilation will output C code directly with object_format value rather than the compiler_backend value.

stage2_wasm = 4

The reference implementation self-hosted compiler of Zig, using the WebAssembly backend.

stage2_arm = 5

The reference implementation self-hosted compiler of Zig, using the arm backend.

stage2_x86_64 = 6

The reference implementation self-hosted compiler of Zig, using the x86_64 backend.

stage2_aarch64 = 7

The reference implementation self-hosted compiler of Zig, using the aarch64 backend.

stage2_x86 = 8

The reference implementation self-hosted compiler of Zig, using the x86 backend.

stage2_riscv64 = 9

The reference implementation self-hosted compiler of Zig, using the riscv64 backend.

stage2_sparc64 = 10

The reference implementation self-hosted compiler of Zig, using the sparc64 backend.

stage2_spirv = 11

The reference implementation self-hosted compiler of Zig, using the spirv backend.

stage2_powerpc = 12

The reference implementation self-hosted compiler of Zig, using the powerpc backend.

stage2_loongarch = 13

The reference implementation self-hosted compiler of Zig, using the loongarch backend.

zsf_spork8 = 14

The Zig Software Foundation self-hosted implementation of Zig. Backend originally contributed by Ben Anderman in 2026.

_

std.lang.Endian

container

Source line 957

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

big
little

std.lang.Endian.foreign

constant

Source line 962

Endian

std.lang.Endian.native

constant

Source line 961

std.lang.ExportOptions

container

Source line 1202

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

name: []const u8
linkage: GlobalLinkage = .strong
section: ?[]const u8 = null
visibility: SymbolVisibility = .default

std.lang.ExternOptions

container

Source line 1211

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

name: []const u8
library_name: ?[]const u8 = null
linkage: GlobalLinkage = .strong
visibility: SymbolVisibility = .default
is_thread_local: bool = false

Setting this to true makes the @extern a runtime value.

is_dll_import: bool = false
relocation: Relocation = .any
decoration: ?Decoration = null

std.lang.ExternOptions.Decoration

container

Source line 1222

Fields

location: u32
flat: u32
descriptor: Descriptor

std.lang.ExternOptions.Decoration.Descriptor

container

Source line 1227

Fields

set: u32
binding: u32

std.lang.ExternOptions.Relocation

container

Source line 1233

Fields

any

Any type of relocation is allowed.

pcrel

A program-counter-relative relocation is required. Using this value makes the @extern a runtime value.

std.lang.FloatMode

container

Source line 950

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

strict
optimized

std.lang.GlobalLinkage

container

Source line 18

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

strong
weak

std.lang.LinkMode

container

Source line 982

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

static
dynamic

std.lang.Optimize

container

Source line 113

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

debug

Safety checks enabled. Optimize for bug detection, accurate debug info, and compilation speed (in that order).

safe

Safety checks enabled. Optimize for runtime performance.

fast

Safety checks disabled. Optimize for runtime performance.

small

Safety checks disabled. Optimize for machine code size, then runtime performance.

std.lang.Optimize.Debug

constant

Source line 125

Deprecated, to be removed after 0.18.0

@This()

std.lang.Optimize.fromString

function

Source line 133

Deprecated, to be removed after 0.18.0

pub fn fromString(s: []const u8) ?@This()

Parameters

s: []const u8

std.lang.Optimize.ReleaseFast

constant

Source line 129

Deprecated, to be removed after 0.18.0

@This()

std.lang.Optimize.ReleaseSafe

constant

Source line 127

Deprecated, to be removed after 0.18.0

@This()

std.lang.Optimize.ReleaseSmall

constant

Source line 131

Deprecated, to be removed after 0.18.0

@This()

std.lang.Optimize.runtimeSafety

function

Source line 148

Returns whether illegal behavior safety checks are enabled based on the provided optimization mode.

pub fn runtimeSafety(o: @This()) bool

Parameters

o: @This()

std.lang.OptimizeMode

alias

Source line 109

Deprecated, to be removed after 0.18.0

Alias of std.lang.Optimize

std.lang.OutputMode

container

Source line 974

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

Exe
Lib
Obj

std.lang.panic

constant

Source line 1345

This namespace is used by the Zig compiler to emit various kinds of safety panics. These can be overridden by making a public panic namespace in the root source file.

type

std.lang.panic.panic

function

Source line 1350

fn panic(msg: []const u8, ra: ?usize) noreturn

Parameters

msg: []const u8
ra: ?usize

std.lang.PrefetchOptions

container

Source line 1175

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

rw: Rw = .read

Whether the prefetch should prepare for a read or a write.

locality: u2 = 3

The data's locality in an inclusive range from 0 to 3.

0 means no temporal locality. That is, the data can be immediately dropped from the cache after it is accessed.

3 means high temporal locality. That is, the data should be kept in the cache as it is likely to be accessed again soon.

cache: Cache = .data

The cache that the prefetch should be performed on.

std.lang.PrefetchOptions.Cache

container

Source line 1194

Fields

instruction
data

std.lang.PrefetchOptions.Rw

container

Source line 1189

Fields

read
write

std.lang.ReduceOp

container

Source line 44

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

And
Or
Xor
Min
Max
Add
Mul

std.lang.returnError

function

Source line 1366

pub noinline fn returnError() void

std.lang.root

constant

Source line 5

std.lang.Signedness

container

Source line 967

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

signed
unsigned

std.lang.SourceLocation

container

Source line 626

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

module: [:0]const u8

The name chosen when compiling. Not a file path.

file: [:0]const u8

Relative to the root directory of its module.

fn_name: [:0]const u8
line: u32
column: u32

std.lang.StackTrace

container

Source line 11

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

index: usize
instruction_addresses: []usize

std.lang.std

alias

Source line 4

Alias of std

std.lang.SymbolVisibility

container

Source line 25

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

default
hidden
protected

std.lang.TestFn

container

Source line 1337

This function type is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

name: []const u8
func: *const fn () anyerror!void

std.lang.Type

container

Source line 640

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

type
void
bool
noreturn
int: Int
float: Float
pointer: Pointer
array: Array
@"struct": Struct
comptime_float
comptime_int
undefined
null
optional: Optional
error_union: ErrorUnion
error_set: ErrorSet
@"enum": Enum
@"union": Union
@"fn": Fn
@"opaque": Opaque
frame: Frame
@"anyframe": AnyFrame
vector: Vector
enum_literal
spirv: Spirv

std.lang.Type.AnyFrame

container

Source line 936

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

child: ?type

std.lang.Type.Array

container

Source line 722

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

len: comptime_int
child: type
sentinel_ptr: ?*const anyopaque

The type of the sentinel is the element type of the array, which is the value of the child field in this struct. However there is no way to refer to that type here, so we use *const anyopaque. See also: sentinel.

std.lang.Type.Array.sentinel

function

Source line 734

Loads the array type's sentinel value from sentinel_ptr. Returns null if the array type has no sentinel.

pub inline fn sentinel(comptime arr: Array) ?arr.child

Parameters

arr: Array

std.lang.Type.ContainerLayout

container

Source line 742

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

auto
@"extern"
@"packed"

std.lang.Type.Enum

container

Source line 807

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

tag_type: type
mode: Mode
field_names: []const [:0]const u8
field_values: []const comptime_int

Guaranteed to have the same length as field_names.

decl_names: []const [:0]const u8

std.lang.Type.Enum.Mode

container

Source line 819

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

exhaustive
nonexhaustive

std.lang.Type.ErrorSet

container

Source line 801

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

error_names: ?[]const [:0]const u8

std.lang.Type.ErrorUnion

container

Source line 794

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

error_set: type
payload: type

std.lang.Type.Float

container

Source line 676

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

bits: u16

std.lang.Type.Fn

container

Source line 847

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

attrs: Attributes
is_generic: bool
return_type: ?type

null means the return type is generic, i.e. it depends on a function argument.

param_types: []const ?type

A null element represents either an anytype parameter, or a parameter with a generic type, i.e. where the type depends on a previous function argument.

param_attrs: []const ParamAttributes

Guaranteed to have the same length as param_types.

std.lang.Type.Fn.Attributes

container

Source line 863

Fields

@"callconv": CallingConvention = .auto
varargs: bool = false

std.lang.Type.Fn.ParamAttributes

container

Source line 859

Fields

@"noalias": bool = false

std.lang.Type.Frame

container

Source line 930

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

function: *const anyopaque

std.lang.Type.Int

container

Source line 669

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

signedness: Signedness
bits: u16

std.lang.Type.Opaque

container

Source line 924

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

decl_names: []const [:0]const u8

std.lang.Type.Optional

container

Source line 788

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

child: type

std.lang.Type.Pointer

container

Source line 682

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

size: Size
attrs: Attributes
child: type
sentinel_ptr: ?*const anyopaque

The type of the sentinel is the element type of the pointer, which is the value of the child field in this struct. However there is no way to refer to that type here, so we use *const anyopaque. See also: sentinel

std.lang.Type.Pointer.Attributes

container

Source line 711

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

@"const": bool = false
@"volatile": bool = false
@"allowzero": bool = false
@"addrspace": ?AddressSpace = null
@"align": ?usize = null

std.lang.Type.Pointer.sentinel

function

Source line 695

Loads the pointer type's sentinel value from sentinel_ptr. Returns null if the pointer type has no sentinel.

pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child

Parameters

ptr: Pointer

std.lang.Type.Pointer.Size

container

Source line 702

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

one
many
slice
c

std.lang.Type.Spirv

container

Source line 871

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

sampler
image: Image
sampled_image: type
runtime_array: type

std.lang.Type.Spirv.Image

container

Source line 877

Fields

usage: Usage
format: Format
dim: Dimensionality
depth: Depth
access: Access
arrayed: bool
multisampled: bool

std.lang.Type.Spirv.Image.Access

container

Source line 918

Fields

unknown
read_only
write_only
read_write

std.lang.Type.Spirv.Image.Depth

container

Source line 916

Fields

unknown
depth
not_depth

std.lang.Type.Spirv.Image.Dimensionality

container

Source line 909

Fields

@"1d"
@"2d"
@"3d"
cube

std.lang.Type.Spirv.Image.Format

container

Source line 892

Fields

unknown
rgba32f
rgba32i
rgba32u
rgba16f
rgba16i
rgba16u
rgba8unorm
rgba8snorm
rgba8i
rgba8u
r32f
r32i
r32u

std.lang.Type.Spirv.Image.Usage

container

Source line 886

Fields

unknown: type
sampled: type
storage: type

std.lang.Type.Struct

container

Source line 750

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

is_tuple: bool
layout: ContainerLayout
backing_integer: ?type

Always null if layout != .@"packed".

field_names: []const [:0]const u8
field_types: []const type

Guaranteed to have the same length as field_names.

field_attrs: []const FieldAttributes

Guaranteed to have the same length as field_names.

decl_names: []const [:0]const u8

std.lang.Type.Struct.FieldAttributes

container

Source line 764

Fields

@"comptime": bool = false
@"align": ?usize = null

null means the field alignment is not explicitly specified. The field will still be aligned to at least @alignOf the field type.

default_value_ptr: ?*const anyopaque = null

The type of the default value is the type of this struct field. However, that type is not known here, so we use a type-erased pointer instead, which must be cast to a pointer to the field type.

See also: defaultValue.

std.lang.Type.Struct.FieldAttributes.defaultValue

function

Source line 779

Loads the field's default value from default_value_ptr. FieldType must exactly match the corresponding element of Struct.field_types. Returns null if the field has no default value.

pub inline fn defaultValue(comptime attrs: FieldAttributes, comptime FieldType: type) ?FieldType

Parameters

attrs: FieldAttributes
FieldType: type

std.lang.Type.Union

container

Source line 824

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

layout: ContainerLayout
tag_type: ?type
backing_integer: ?type

Always null if layout != .@"packed".

field_names: []const [:0]const u8
field_types: []const type

Guaranteed to have the same length as field_names.

field_attrs: []const FieldAttributes

Guaranteed to have the same length as field_names.

decl_names: []const [:0]const u8

std.lang.Type.Union.FieldAttributes

container

Source line 838

Fields

@"align": ?usize = null

null means the field alignment is not explicitly specified. The field will still be aligned to at least @alignOf the field type.

std.lang.Type.Vector

container

Source line 942

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

len: comptime_int
child: type

std.lang.TypeId

type

Source line 636

std.lang.UnwindTables

container

Source line 989

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

none
sync
async

std.lang.VaList

type

Source line 1108

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

std.lang.VaListAarch64

container

Source line 1031

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

__stack: *anyopaque
__gr_top: *anyopaque
__vr_top: *anyopaque
__gr_offs: c_int
__vr_offs: c_int

std.lang.VaListAlpha

container

Source line 1041

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

__base: *anyopaque
__offset: c_int

std.lang.VaListArm

container

Source line 1048

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

__ap: *anyopaque

std.lang.VaListHexagon

container

Source line 1054

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

__current_saved_reg_area_pointer: *anyopaque
__saved_reg_area_end_pointer: *anyopaque
__overflow_area_pointer: *anyopaque

std.lang.VaListPowerPc

container

Source line 1062

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

gpr: u8
fpr: u8
reserved: c_ushort
overflow_arg_area: *anyopaque
reg_save_area: *anyopaque

std.lang.VaListS390x

container

Source line 1072

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

__gpr: c_long
__fpr: c_long
__overflow_arg_area: *anyopaque
__reg_save_area: *anyopaque

std.lang.VaListSh

container

Source line 1081

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

__va_next_o: *anyopaque
__va_next_o_limit: *anyopaque
__va_next_fp: *anyopaque
__va_next_fp_limit: *anyopaque
__va_next_stack: *anyopaque

std.lang.VaListX86_64

container

Source line 1091

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

gp_offset: c_uint
fp_offset: c_uint
overflow_arg_area: *anyopaque
reg_save_area: *anyopaque

std.lang.VaListXtensa

container

Source line 1100

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

__va_stk: *c_int
__va_reg: *c_int
__va_ndx: c_int

std.lang.WasiExecModel

container

Source line 997

This data structure is used by the Zig language code generation and therefore must be kept in sync with the compiler implementation.

Fields

command
reactor
Source code

std/lang.zig

//! Types and values provided by the Zig language.

const builtin = @import("builtin");
const std = @import("std.zig");
const root = @import("root");

pub const assembly = @import("lang/assembly.zig");

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const StackTrace = struct {
    index: usize,
    instruction_addresses: []usize,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const GlobalLinkage = enum(u1) {
    strong,
    weak,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const SymbolVisibility = enum(u2) {
    default,
    hidden,
    protected,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const AtomicOrder = enum {
    unordered,
    monotonic,
    acquire,
    release,
    acq_rel,
    seq_cst,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const ReduceOp = enum {
    And,
    Or,
    Xor,
    Min,
    Max,
    Add,
    Mul,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const AtomicRmwOp = enum {
    /// Exchange - store the operand unmodified.
    /// Supports enums, integers, and floats.
    Xchg,
    /// Add operand to existing value.
    /// Supports integers and floats.
    /// For integers, two's complement wraparound applies.
    Add,
    /// Subtract operand from existing value.
    /// Supports integers and floats.
    /// For integers, two's complement wraparound applies.
    Sub,
    /// Perform bitwise AND on existing value with operand.
    /// Supports integers.
    And,
    /// Perform bitwise NAND on existing value with operand.
    /// Supports integers.
    Nand,
    /// Perform bitwise OR on existing value with operand.
    /// Supports integers.
    Or,
    /// Perform bitwise XOR on existing value with operand.
    /// Supports integers.
    Xor,
    /// Store operand if it is larger than the existing value.
    /// Supports integers and floats.
    Max,
    /// Store operand if it is smaller than the existing value.
    /// Supports integers and floats.
    Min,
};

/// The code model puts constraints on the location of symbols and the size of code and data.
/// The selection of a code model is a trade off on speed and restrictions that needs to be selected on a per application basis to meet its requirements.
/// A slightly more detailed explanation can be found in (for example) the [System V Application Binary Interface (x86_64)](https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf) 3.5.1.
///
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const CodeModel = enum(u4) {
    default,
    extreme,
    kernel,
    large,
    medany,
    medium,
    medlow,
    medmid,
    normal,
    small,
    tiny,
};

/// Deprecated, to be removed after 0.18.0
pub const OptimizeMode = Optimize;

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Optimize = enum {
    /// Safety checks enabled. Optimize for bug detection, accurate debug info,
    /// and compilation speed (in that order).
    debug,
    /// Safety checks enabled. Optimize for runtime performance.
    safe,
    /// Safety checks disabled. Optimize for runtime performance.
    fast,
    /// Safety checks disabled. Optimize for machine code size, then runtime performance.
    small,

    /// Deprecated, to be removed after 0.18.0
    pub const Debug: @This() = .debug;
    /// Deprecated, to be removed after 0.18.0
    pub const ReleaseSafe: @This() = .safe;
    /// Deprecated, to be removed after 0.18.0
    pub const ReleaseFast: @This() = .fast;
    /// Deprecated, to be removed after 0.18.0
    pub const ReleaseSmall: @This() = .small;
    /// Deprecated, to be removed after 0.18.0
    pub fn fromString(s: []const u8) ?@This() {
        return std.StaticStringMap(@This()).initComptime(&.{
            .{ "Debug", .debug },
            .{ "ReleaseSafe", .safe },
            .{ "ReleaseFast", .fast },
            .{ "ReleaseSmall", .small },
            .{ "debug", .debug },
            .{ "safe", .safe },
            .{ "fast", .fast },
            .{ "small", .small },
        }).get(s);
    }

    /// Returns whether illegal behavior safety checks are enabled based on the
    /// provided optimization mode.
    pub fn runtimeSafety(o: @This()) bool {
        return switch (o) {
            .debug, .safe => true,
            .fast, .small => false,
        };
    }
};

/// The calling convention of a function defines how arguments and return values are passed, as well
/// as any other requirements which callers and callees must respect, such as register preservation
/// and stack alignment.
///
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const CallingConvention = union(enum(u8)) {
    pub const Tag = @typeInfo(CallingConvention).@"union".tag_type.?;

    /// This is an alias for the default C calling convention for this target.
    /// Functions marked as `extern` or `export` are given this calling convention by default.
    pub const c = builtin.target.cCallingConvention().?;

    pub const winapi: CallingConvention = switch (builtin.target.cpu.arch) {
        .x86_64 => .{ .x86_64_win = .{} },
        .x86 => .{ .x86_stdcall = .{} },
        .aarch64 => .{ .aarch64_aapcs_win = .{} },
        .thumb => .{ .arm_aapcs_vfp = .{} },
        else => unreachable,
    };

    pub const kernel: CallingConvention = switch (builtin.target.cpu.arch) {
        .amdgcn => .amdgcn_kernel,
        .nvptx, .nvptx64 => .nvptx_kernel,
        .spirv32, .spirv64 => .{ .spirv_kernel = .{ .x = 1, .y = 1, .z = 1 } },
        else => unreachable,
    };

    /// The default Zig calling convention when neither `export` nor `inline` is specified.
    /// This calling convention makes no guarantees about stack alignment, registers, etc.
    /// It can only be used within this Zig compilation unit.
    auto,

    /// The calling convention of a function that can be called with `async` syntax. An `async` call
    /// of a runtime-known function must target a function with this calling convention.
    /// Comptime-known functions with other calling conventions may be coerced to this one.
    async,

    /// Functions with this calling convention have no prologue or epilogue, making the function
    /// uncallable in regular Zig code. This can be useful when integrating with assembly.
    naked,

    /// This calling convention is exactly equivalent to using the `inline` keyword on a function
    /// definition. This function will be semantically inlined by the Zig compiler at call sites.
    /// Pointers to inline functions are comptime-only.
    @"inline",

    // Calling conventions for the `x86_64` architecture.
    x86_64_sysv: CommonOptions,
    x86_64_x32: CommonOptions,
    x86_64_win: CommonOptions,
    x86_64_regcall_v3_sysv: CommonOptions,
    x86_64_regcall_v4_win: CommonOptions,
    x86_64_vectorcall: CommonOptions,
    x86_64_interrupt: CommonOptions,
    x86_64_preserve_none: CommonOptions,

    // Calling conventions for the `x86` architecture.
    x86_sysv: X86RegparmOptions,
    x86_win: X86RegparmOptions,
    x86_mingw: X86RegparmOptions,
    x86_stdcall: X86RegparmOptions,
    x86_fastcall: CommonOptions,
    x86_thiscall: CommonOptions,
    x86_thiscall_mingw: CommonOptions,
    x86_regcall_v3: CommonOptions,
    x86_regcall_v4_win: CommonOptions,
    x86_vectorcall: CommonOptions,
    x86_interrupt: CommonOptions,

    // Calling conventions for the `x86_16` architecture.

    x86_16_cdecl: CommonOptions,
    x86_16_stdcall: CommonOptions,
    x86_16_regparmcall: CommonOptions,
    x86_16_interrupt: CommonOptions,

    // Calling conventions for the `aarch64` and `aarch64_be` architectures.
    aarch64_aapcs: CommonOptions,
    aarch64_aapcs_darwin: CommonOptions,
    aarch64_aapcs_win: CommonOptions,
    aarch64_vfabi: CommonOptions,
    aarch64_vfabi_sve: CommonOptions,
    aarch64_preserve_none: CommonOptions,

    /// The standard `alpha` calling convention.
    alpha_osf: CommonOptions,

    // Calling convetions for the `arm`, `armeb`, `thumb`, and `thumbeb` architectures.
    /// ARM Architecture Procedure Call Standard
    arm_aapcs: CommonOptions,
    /// ARM Architecture Procedure Call Standard Vector Floating-Point
    arm_aapcs_vfp: CommonOptions,
    arm_interrupt: ArmInterruptOptions,

    // Calling conventions for the `mips64` and `mips64el` architectures.
    mips64_n64: CommonOptions,
    mips64_n32: CommonOptions,
    mips64_interrupt: MipsInterruptOptions,

    // Calling conventions for the `mips` and `mipsel` architectures.
    mips_o32: CommonOptions,
    mips_interrupt: MipsInterruptOptions,

    // Calling conventions for the `riscv64` architecture.
    riscv64_lp64: CommonOptions,
    riscv64_lp64_v: CommonOptions,
    riscv64_interrupt: RiscvInterruptOptions,

    // Calling conventions for the `riscv32` architecture.
    riscv32_ilp32: CommonOptions,
    riscv32_ilp32_v: CommonOptions,
    riscv32_interrupt: RiscvInterruptOptions,

    // Calling conventions for the `sparc64` architecture.
    sparc64_sysv: CommonOptions,

    // Calling conventions for the `sparc` architecture.
    sparc_sysv: CommonOptions,

    // Calling conventions for the `powerpc64` and `powerpc64le` architectures.
    powerpc64_elf: CommonOptions,
    powerpc64_elf_altivec: CommonOptions,
    powerpc64_elf_v2: CommonOptions,

    // Calling conventions for the `powerpc` and `powerpcle` architectures.
    powerpc_sysv: CommonOptions,
    powerpc_sysv_altivec: CommonOptions,
    powerpc_aix: CommonOptions,
    powerpc_aix_altivec: CommonOptions,

    /// The standard `wasm32` and `wasm64` calling convention, as specified in the WebAssembly Tool Conventions.
    wasm_mvp: CommonOptions,

    /// The standard `arc`/`arceb` calling convention.
    arc_sysv: CommonOptions,
    arc_interrupt: ArcInterruptOptions,

    // Calling conventions for the `avr` architecture.
    avr_gnu,
    avr_builtin,
    avr_signal,
    avr_interrupt,

    /// The standard `bpfel`/`bpfeb` calling convention.
    bpf_std: CommonOptions,

    // Calling conventions for the `csky` architecture.
    csky_sysv: CommonOptions,
    csky_interrupt: CommonOptions,

    // Calling conventions for the `hexagon` architecture.
    hexagon_sysv: CommonOptions,
    hexagon_sysv_hvx: CommonOptions,

    /// The standard `hppa` calling convention.
    hppa_elf: CommonOptions,

    /// The standard `hppa64` calling convention.
    hppa64_elf: CommonOptions,

    kvx_lp64: CommonOptions,
    kvx_ilp32: CommonOptions,

    /// The standard `lanai` calling convention.
    lanai_sysv: CommonOptions,

    /// The standard `loongarch64` calling convention.
    loongarch64_lp64: CommonOptions,

    /// The standard `loongarch32` calling convention.
    loongarch32_ilp32: CommonOptions,

    // Calling conventions for the `m68k` architecture.
    m68k_sysv: CommonOptions,
    m68k_gnu: CommonOptions,
    m68k_rtd: CommonOptions,
    m68k_interrupt: CommonOptions,

    m88k_sysv: CommonOptions,

    /// The standard `microblaze`/`microblazeel` calling convention.
    microblaze_std: CommonOptions,
    microblaze_interrupt: MicroblazeInterruptOptions,

    /// The standard `msp430` calling convention.
    msp430_eabi: CommonOptions,
    msp430_interrupt: CommonOptions,

    /// The standard `or1k` calling convention.
    or1k_sysv: CommonOptions,

    /// The standard `propeller` calling convention.
    propeller_sysv: CommonOptions,

    // Calling conventions for the `s390x` architecture.
    s390x_sysv: CommonOptions,
    s390x_sysv_vx: CommonOptions,

    // Calling conventions for the `sh`/`sheb` architecture.
    sh_gnu: CommonOptions,
    sh_renesas: CommonOptions,
    sh_interrupt: ShInterruptOptions,

    /// The standard `ve` calling convention.
    ve_sysv: CommonOptions,

    // Calling conventions for the `xcore` architecture.
    xcore_xs1: CommonOptions,
    xcore_xs2: CommonOptions,

    // Calling conventions for the `xtensa`/`xtensaeb` architecture.
    xtensa_call0: CommonOptions,
    xtensa_windowed: CommonOptions,

    // Calling conventions for the `amdgcn` architecture.
    amdgcn_device: CommonOptions,
    amdgcn_kernel,
    amdgcn_cs: CommonOptions,

    // Calling conventions for the `nvptx` and `nvptx64` architectures.
    nvptx_device,
    nvptx_kernel,

    // Calling conventions for kernels and shaders on the `spirv32` and `spirv64` architectures.
    spirv_device,
    spirv_vertex,
    spirv_kernel: SpirvKernelOptions,
    spirv_fragment: SpirvFragmentOptions,
    spirv_task: SpirvKernelOptions,
    spirv_mesh: SpirvMeshOptions,

    // Calling conventions for the `ez80` architecture.
    ez80_cet,
    ez80_tiflags,

    // Calling convention used by
    // [snake2p example program](https://github.com/benanderman/spork-8/blob/1bce10a2c3a3888a3f4ca8208112afbc5973fda4/Code/programs/snake2p.asm)
    spork8,

    /// Options shared across most calling conventions.
    pub const CommonOptions = struct {
        /// The boundary the stack is aligned to when the function is called.
        /// `null` means the default for this calling convention.
        incoming_stack_alignment: ?u64 = null,
    };

    /// Options for x86 calling conventions which support the regparm attribute to pass some
    /// arguments in registers.
    pub const X86RegparmOptions = struct {
        /// The boundary the stack is aligned to when the function is called.
        /// `null` means the default for this calling convention.
        incoming_stack_alignment: ?u64 = null,
        /// The number of arguments to pass in registers before passing the remaining arguments
        /// according to the calling convention.
        /// Equivalent to `__attribute__((regparm(x)))` in Clang and GCC.
        register_params: u2 = 0,
    };

    /// Options for the `arc_interrupt` calling convention.
    pub const ArcInterruptOptions = struct {
        /// The boundary the stack is aligned to when the function is called.
        /// `null` means the default for this calling convention.
        incoming_stack_alignment: ?u64 = null,
        /// The kind of interrupt being received.
        type: InterruptType,

        pub const InterruptType = enum(u2) {
            ilink1,
            ilink2,
            ilink,
            firq,
        };
    };

    /// Options for the `arm_interrupt` calling convention.
    pub const ArmInterruptOptions = struct {
        /// The boundary the stack is aligned to when the function is called.
        /// `null` means the default for this calling convention.
        incoming_stack_alignment: ?u64 = null,
        /// The kind of interrupt being received.
        type: InterruptType = .generic,

        pub const InterruptType = enum(u3) {
            generic,
            irq,
            fiq,
            swi,
            abort,
            undef,
        };
    };

    /// Options for the `microblaze_interrupt` calling convention.
    pub const MicroblazeInterruptOptions = struct {
        /// The boundary the stack is aligned to when the function is called.
        /// `null` means the default for this calling convention.
        incoming_stack_alignment: ?u64 = null,
        type: InterruptType = .regular,

        pub const InterruptType = enum(u2) {
            /// User exception; return with `rtsd`.
            user,
            /// Regular interrupt; return with `rtid`.
            regular,
            /// Fast interrupt; return with `rtid`.
            fast,
            /// Software breakpoint; return with `rtbd`.
            breakpoint,
        };
    };

    /// Options for the `mips_interrupt` and `mips64_interrupt` calling conventions.
    pub const MipsInterruptOptions = struct {
        /// The boundary the stack is aligned to when the function is called.
        /// `null` means the default for this calling convention.
        incoming_stack_alignment: ?u64 = null,
        /// The interrupt mode.
        mode: InterruptMode = .eic,

        pub const InterruptMode = enum(u4) {
            eic,
            sw0,
            sw1,
            hw0,
            hw1,
            hw2,
            hw3,
            hw4,
            hw5,
        };
    };

    /// Options for the `riscv32_interrupt` and `riscv64_interrupt` calling conventions.
    pub const RiscvInterruptOptions = struct {
        /// The boundary the stack is aligned to when the function is called.
        /// `null` means the default for this calling convention.
        incoming_stack_alignment: ?u64 = null,
        /// The privilege mode.
        mode: PrivilegeMode,

        pub const PrivilegeMode = enum(u2) {
            supervisor,
            machine,
        };
    };

    /// Options for the `sh_interrupt` calling convention.
    pub const ShInterruptOptions = struct {
        /// The boundary the stack is aligned to when the function is called.
        /// `null` means the default for this calling convention.
        incoming_stack_alignment: ?u64 = null,
        save: SaveBehavior = .full,

        pub const SaveBehavior = enum(u3) {
            /// Save only fpscr (if applicable).
            fpscr,
            /// Save only high-numbered registers, i.e. r0 through r7 are *not* saved.
            high,
            /// Save all registers normally.
            full,
            /// Save all registers using the CPU's fast register bank.
            bank,
        };
    };

    pub const SpirvKernelOptions = struct {
        x: u32,
        y: u32,
        z: u32,
    };

    pub const SpirvFragmentOptions = struct {
        pub const DepthAssumption = enum(u2) {
            none = 0,
            greater = 1,
            less = 2,
            unchanged = 3,
        };

        pixel_centered_integer: bool = false,
        depth_assumption: DepthAssumption = .none,
    };

    pub const SpirvMeshOptions = struct {
        pub const StageOutput = enum(u2) {
            output_points = 0,
            output_lines = 1,
            output_triangles = 2,
        };

        stage_output: StageOutput = .output_triangles,
        max_primitives: u32 = 1,
        max_vertices: u32 = 3,
        x: u32,
        y: u32,
        z: u32,
    };

    /// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.
    /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
    pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {
        return std.Target.Cpu.Arch.fromCallingConvention(cc);
    }

    pub fn eql(a: CallingConvention, b: CallingConvention) bool {
        return std.meta.eql(a, b);
    }

    pub fn withStackAlign(cc: CallingConvention, incoming_stack_alignment: u64) CallingConvention {
        const tag: CallingConvention.Tag = cc;
        var result = cc;
        @field(result, @tagName(tag)).incoming_stack_alignment = incoming_stack_alignment;
        return result;
    }
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const AddressSpace = enum(u5) {
    // CPU address spaces.
    generic,
    gs,
    fs,
    ss,

    // x86_16 extra address spaces.
    /// Allows addressing the entire address space by storing both segment and offset.
    far,

    // GPU address spaces.
    global,
    constant,
    param,
    shared,
    local,
    private,
    input,
    output,
    uniform,
    push_constant,
    storage_buffer,
    physical_storage_buffer,

    // AVR address spaces.
    flash,
    flash1,
    flash2,
    flash3,
    flash4,
    flash5,

    // Propeller address spaces.

    /// This address space only addresses the cog-local ram.
    cog,

    /// This address space only addresses shared hub ram.
    hub,

    /// This address space only addresses the "lookup" ram
    lut,

    // Web Assembly
    externref,
    funcref,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const SourceLocation = struct {
    /// The name chosen when compiling. Not a file path.
    module: [:0]const u8,
    /// Relative to the root directory of its module.
    file: [:0]const u8,
    fn_name: [:0]const u8,
    line: u32,
    column: u32,
};

pub const TypeId = std.meta.Tag(Type);

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Type = union(enum) {
    type,
    void,
    bool,
    noreturn,
    int: Int,
    float: Float,
    pointer: Pointer,
    array: Array,
    @"struct": Struct,
    comptime_float,
    comptime_int,
    undefined,
    null,
    optional: Optional,
    error_union: ErrorUnion,
    error_set: ErrorSet,
    @"enum": Enum,
    @"union": Union,
    @"fn": Fn,
    @"opaque": Opaque,
    frame: Frame,
    @"anyframe": AnyFrame,
    vector: Vector,
    enum_literal,
    spirv: Spirv,

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Int = struct {
        signedness: Signedness,
        bits: u16,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Float = struct {
        bits: u16,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Pointer = struct {
        size: Size,
        attrs: Attributes,
        child: type,

        /// The type of the sentinel is the element type of the pointer, which is
        /// the value of the `child` field in this struct. However there is no way
        /// to refer to that type here, so we use `*const anyopaque`.
        /// See also: `sentinel`
        sentinel_ptr: ?*const anyopaque,

        /// Loads the pointer type's sentinel value from `sentinel_ptr`.
        /// Returns `null` if the pointer type has no sentinel.
        pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child {
            const sp: *const ptr.child = @ptrCast(@alignCast(ptr.sentinel_ptr orelse return null));
            return sp.*;
        }

        /// This data structure is used by the Zig language code generation and
        /// therefore must be kept in sync with the compiler implementation.
        pub const Size = enum(u2) {
            one,
            many,
            slice,
            c,
        };

        /// This data structure is used by the Zig language code generation and
        /// therefore must be kept in sync with the compiler implementation.
        pub const Attributes = struct {
            @"const": bool = false,
            @"volatile": bool = false,
            @"allowzero": bool = false,
            @"addrspace": ?AddressSpace = null,
            @"align": ?usize = null,
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Array = struct {
        len: comptime_int,
        child: type,

        /// The type of the sentinel is the element type of the array, which is
        /// the value of the `child` field in this struct. However there is no way
        /// to refer to that type here, so we use `*const anyopaque`.
        /// See also: `sentinel`.
        sentinel_ptr: ?*const anyopaque,

        /// Loads the array type's sentinel value from `sentinel_ptr`.
        /// Returns `null` if the array type has no sentinel.
        pub inline fn sentinel(comptime arr: Array) ?arr.child {
            const sp: *const arr.child = @ptrCast(@alignCast(arr.sentinel_ptr orelse return null));
            return sp.*;
        }
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const ContainerLayout = enum(u2) {
        auto,
        @"extern",
        @"packed",
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Struct = struct {
        is_tuple: bool,
        layout: ContainerLayout,
        /// Always `null` if `layout != .@"packed"`.
        backing_integer: ?type,

        field_names: []const [:0]const u8,
        /// Guaranteed to have the same length as `field_names`.
        field_types: []const type,
        /// Guaranteed to have the same length as `field_names`.
        field_attrs: []const FieldAttributes,

        decl_names: []const [:0]const u8,

        pub const FieldAttributes = struct {
            @"comptime": bool = false,
            /// `null` means the field alignment is not explicitly specified. The field will still
            /// be aligned to at least `@alignOf` the field type.
            @"align": ?usize = null,
            /// The type of the default value is the type of this struct field. However, that type
            /// is not known here, so we use a type-erased pointer instead, which must be cast to
            /// a pointer to the field type.
            ///
            /// See also: `defaultValue`.
            default_value_ptr: ?*const anyopaque = null,

            /// Loads the field's default value from `default_value_ptr`.
            /// `FieldType` must exactly match the corresponding element of `Struct.field_types`.
            /// Returns `null` if the field has no default value.
            pub inline fn defaultValue(comptime attrs: FieldAttributes, comptime FieldType: type) ?FieldType {
                const dp: *const FieldType = @ptrCast(@alignCast(attrs.default_value_ptr orelse return null));
                return dp.*;
            }
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Optional = struct {
        child: type,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const ErrorUnion = struct {
        error_set: type,
        payload: type,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const ErrorSet = struct {
        error_names: ?[]const [:0]const u8,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Enum = struct {
        tag_type: type,
        mode: Mode,

        field_names: []const [:0]const u8,
        /// Guaranteed to have the same length as `field_names`.
        field_values: []const comptime_int,

        decl_names: []const [:0]const u8,

        /// This data structure is used by the Zig language code generation and
        /// therefore must be kept in sync with the compiler implementation.
        pub const Mode = enum { exhaustive, nonexhaustive };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Union = struct {
        layout: ContainerLayout,
        tag_type: ?type,
        /// Always `null` if `layout != .@"packed"`.
        backing_integer: ?type,

        field_names: []const [:0]const u8,
        /// Guaranteed to have the same length as `field_names`.
        field_types: []const type,
        /// Guaranteed to have the same length as `field_names`.
        field_attrs: []const FieldAttributes,

        decl_names: []const [:0]const u8,

        pub const FieldAttributes = struct {
            /// `null` means the field alignment is not explicitly specified. The field will still
            /// be aligned to at least `@alignOf` the field type.
            @"align": ?usize = null,
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Fn = struct {
        attrs: Attributes,
        is_generic: bool,
        /// `null` means the return type is generic, i.e. it depends on a function argument.
        return_type: ?type,

        /// A `null` element represents either an `anytype` parameter, or a parameter with a generic
        /// type, i.e. where the type depends on a previous function argument.
        param_types: []const ?type,
        /// Guaranteed to have the same length as `param_types`.
        param_attrs: []const ParamAttributes,

        pub const ParamAttributes = struct {
            @"noalias": bool = false,
        };

        pub const Attributes = struct {
            @"callconv": CallingConvention = .auto,
            varargs: bool = false,
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Spirv = union(enum(u2)) {
        sampler,
        image: Image,
        sampled_image: type,
        runtime_array: type,

        pub const Image = struct {
            usage: Usage,
            format: Format,
            dim: Dimensionality,
            depth: Depth,
            access: Access,
            arrayed: bool,
            multisampled: bool,

            pub const Usage = union(enum(u2)) {
                unknown: type,
                sampled: type,
                storage: type,
            };

            pub const Format = enum(u4) {
                unknown,
                rgba32f,
                rgba32i,
                rgba32u,
                rgba16f,
                rgba16i,
                rgba16u,
                rgba8unorm,
                rgba8snorm,
                rgba8i,
                rgba8u,
                r32f,
                r32i,
                r32u,
            };

            pub const Dimensionality = enum(u2) {
                @"1d",
                @"2d",
                @"3d",
                cube,
            };

            pub const Depth = enum(u2) { unknown, depth, not_depth };

            pub const Access = enum(u2) { unknown, read_only, write_only, read_write };
        };
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Opaque = struct {
        decl_names: []const [:0]const u8,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Frame = struct {
        function: *const anyopaque,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const AnyFrame = struct {
        child: ?type,
    };

    /// This data structure is used by the Zig language code generation and
    /// therefore must be kept in sync with the compiler implementation.
    pub const Vector = struct {
        len: comptime_int,
        child: type,
    };
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const FloatMode = enum {
    strict,
    optimized,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Endian = enum {
    big,
    little,

    pub const native = builtin.target.cpu.arch.endian();
    pub const foreign: Endian = @fromBackingInt(@intCast(1 - @backingInt(native)));
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Signedness = enum(u1) {
    signed,
    unsigned,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const OutputMode = enum(u2) {
    Exe,
    Lib,
    Obj,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const LinkMode = enum(u1) {
    static,
    dynamic,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const UnwindTables = enum {
    none,
    sync,
    async,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const WasiExecModel = enum {
    command,
    reactor,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const CallModifier = enum {
    /// Equivalent to function call syntax.
    auto,
    /// Prevents tail call optimization. This guarantees that the return
    /// address will point to the callsite, as opposed to the callsite's
    /// callsite. If the call is otherwise required to be tail-called
    /// or inlined, a compile error is emitted instead.
    never_tail,
    /// Guarantees that the call will not be inlined. If the call is
    /// otherwise required to be inlined, a compile error is emitted instead.
    never_inline,
    /// Asserts that the function call will not suspend. This allows a
    /// non-async function to call an async function.
    no_suspend,
    /// Guarantees that the call will be generated with tail call optimization.
    /// If this is not possible, a compile error is emitted instead.
    always_tail,
    /// Guarantees that the call will be inlined at the callsite.
    /// If this is not possible, a compile error is emitted instead.
    always_inline,
    /// Evaluates the call at compile-time. If the call cannot be completed at
    /// compile-time, a compile error is emitted instead.
    compile_time,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListAarch64 = extern struct {
    __stack: *anyopaque,
    __gr_top: *anyopaque,
    __vr_top: *anyopaque,
    __gr_offs: c_int,
    __vr_offs: c_int,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListAlpha = extern struct {
    __base: *anyopaque,
    __offset: c_int,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListArm = extern struct {
    __ap: *anyopaque,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListHexagon = extern struct {
    __current_saved_reg_area_pointer: *anyopaque,
    __saved_reg_area_end_pointer: *anyopaque,
    __overflow_area_pointer: *anyopaque,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListPowerPc = extern struct {
    gpr: u8,
    fpr: u8,
    reserved: c_ushort,
    overflow_arg_area: *anyopaque,
    reg_save_area: *anyopaque,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListS390x = extern struct {
    __gpr: c_long,
    __fpr: c_long,
    __overflow_arg_area: *anyopaque,
    __reg_save_area: *anyopaque,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListSh = extern struct {
    __va_next_o: *anyopaque,
    __va_next_o_limit: *anyopaque,
    __va_next_fp: *anyopaque,
    __va_next_fp_limit: *anyopaque,
    __va_next_stack: *anyopaque,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListX86_64 = extern struct {
    gp_offset: c_uint,
    fp_offset: c_uint,
    overflow_arg_area: *anyopaque,
    reg_save_area: *anyopaque,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListXtensa = extern struct {
    __va_stk: *c_int,
    __va_reg: *c_int,
    __va_ndx: c_int,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaList = switch (builtin.cpu.arch) {
    .amdgcn,
    .msp430,
    .nvptx,
    .nvptx64,
    .powerpc64,
    .powerpc64le,
    .x86,
    => *u8,
    .arc,
    .arceb,
    .avr,
    .bpfel,
    .bpfeb,
    .csky,
    .hppa,
    .hppa64,
    .kvx,
    .lanai,
    .loongarch32,
    .loongarch64,
    .m68k,
    .microblaze,
    .microblazeel,
    .mips,
    .mipsel,
    .mips64,
    .mips64el,
    .riscv32,
    .riscv32be,
    .riscv64,
    .riscv64be,
    .sparc,
    .sparc64,
    .spirv32,
    .spirv64,
    .ve,
    .wasm32,
    .wasm64,
    .xcore,
    => *anyopaque,
    .aarch64, .aarch64_be => switch (builtin.os.tag) {
        .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => *u8,
        else => switch (builtin.zig_backend) {
            else => VaListAarch64,
            .stage2_llvm => @compileError("disabled due to miscompilations"),
        },
    },
    .alpha => VaListAlpha,
    .arm, .armeb, .thumb, .thumbeb => VaListArm,
    .hexagon => if (builtin.target.abi.isMusl()) VaListHexagon else *u8,
    .powerpc, .powerpcle => VaListPowerPc,
    .s390x => VaListS390x,
    .sh, .sheb => VaListSh, // This is wrong for `sh_renesas`: https://github.com/ziglang/zig/issues/24692#issuecomment-3150779829
    .x86_64 => switch (builtin.os.tag) {
        .uefi, .windows => switch (builtin.zig_backend) {
            else => *u8,
            .stage2_llvm => @compileError("disabled due to miscompilations"),
        },
        else => VaListX86_64,
    },
    .xtensa, .xtensaeb => VaListXtensa,
    else => @compileError("VaList not supported for this target yet"),
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const PrefetchOptions = struct {
    /// Whether the prefetch should prepare for a read or a write.
    rw: Rw = .read,
    /// The data's locality in an inclusive range from 0 to 3.
    ///
    /// 0 means no temporal locality. That is, the data can be immediately
    /// dropped from the cache after it is accessed.
    ///
    /// 3 means high temporal locality. That is, the data should be kept in
    /// the cache as it is likely to be accessed again soon.
    locality: u2 = 3,
    /// The cache that the prefetch should be performed on.
    cache: Cache = .data,

    pub const Rw = enum(u1) {
        read,
        write,
    };

    pub const Cache = enum(u1) {
        instruction,
        data,
    };
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const ExportOptions = struct {
    name: []const u8,
    linkage: GlobalLinkage = .strong,
    section: ?[]const u8 = null,
    visibility: SymbolVisibility = .default,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const ExternOptions = struct {
    name: []const u8,
    library_name: ?[]const u8 = null,
    linkage: GlobalLinkage = .strong,
    visibility: SymbolVisibility = .default,
    /// Setting this to `true` makes the `@extern` a runtime value.
    is_thread_local: bool = false,
    is_dll_import: bool = false,
    relocation: Relocation = .any,
    decoration: ?Decoration = null,

    pub const Decoration = union(enum) {
        location: u32,
        flat: u32,
        descriptor: Descriptor,

        pub const Descriptor = struct {
            set: u32,
            binding: u32,
        };
    };

    pub const Relocation = enum(u1) {
        /// Any type of relocation is allowed.
        any,
        /// A program-counter-relative relocation is required.
        /// Using this value makes the `@extern` a runtime value.
        pcrel,
    };
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const BranchHint = enum(u3) {
    /// Equivalent to no hint given.
    none,
    /// This branch of control flow is more likely to be reached than its peers.
    /// The optimizer should optimize for reaching it.
    likely,
    /// This branch of control flow is less likely to be reached than its peers.
    /// The optimizer should optimize for not reaching it.
    unlikely,
    /// This branch of control flow is unlikely to *ever* be reached.
    /// The optimizer may place it in a different page of memory to optimize other branches.
    cold,
    /// It is difficult to predict whether this branch of control flow will be reached.
    /// The optimizer should avoid branching behavior with expensive mispredictions.
    unpredictable,
};

/// This enum is set by the compiler and communicates which compiler
/// implementation is used to produce machine code.
///
/// In theory, Zig code should be agnostic to the backend that implements the
/// language. The only reason to observe this value is to **work around
/// problems with compiler implementations.**
///
/// A common pitful is failing the compilation if the compiler backend does not
/// match a whitelist of backends; a more resilient strategy is to detect that
/// a known problem would occur in a blacklist of backends.
///
/// The enum is nonexhaustive so that alternate Zig language implementations
/// may choose a random number as their tag, thereby avoiding conflicts with
/// other implementations, and codebases can interact with these values even if
/// this upstream enum does not have a name for the number. Of course, upstream
/// is happy to accept patches to add additional Zig implementations to this
/// enum.
///
/// This data structure is part of the Zig language specification.
pub const CompilerBackend = enum(u64) {
    /// It is allowed for a compiler implementation to not reveal its identity,
    /// in which case this value is appropriate. Be cool and make sure your
    /// code supports `other` Zig compilers!
    other = 0,
    /// The original Zig compiler created in 2015 by Andrew Kelley. Implemented
    /// in C++. Used LLVM. Deleted from the ZSF ziglang/zig codebase on
    /// December 6th, 2022.
    stage1 = 1,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// LLVM backend.
    stage2_llvm = 2,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// backend that generates C source code.
    ///
    /// Note that one can observe whether the compilation will output C code
    /// directly with `object_format` value rather than the `compiler_backend` value.
    stage2_c = 3,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// WebAssembly backend.
    stage2_wasm = 4,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// arm backend.
    stage2_arm = 5,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// x86_64 backend.
    stage2_x86_64 = 6,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// aarch64 backend.
    stage2_aarch64 = 7,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// x86 backend.
    stage2_x86 = 8,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// riscv64 backend.
    stage2_riscv64 = 9,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// sparc64 backend.
    stage2_sparc64 = 10,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// spirv backend.
    stage2_spirv = 11,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// powerpc backend.
    stage2_powerpc = 12,
    /// The reference implementation self-hosted compiler of Zig, using the
    /// loongarch backend.
    stage2_loongarch = 13,
    /// The Zig Software Foundation self-hosted implementation of Zig. Backend
    /// originally contributed by Ben Anderman in 2026.
    zsf_spork8 = 14,

    _,
};

/// This function type is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const TestFn = struct {
    name: []const u8,
    func: *const fn () anyerror!void,
};

/// This namespace is used by the Zig compiler to emit various kinds of safety
/// panics. These can be overridden by making a public `panic` namespace in the
/// root source file.
pub const panic: type = p: {
    if (@hasDecl(root, "panic")) {
        if (@TypeOf(root.panic) != type) {
            // Deprecated; make `panic` a namespace instead.
            break :p std.debug.FullPanic(struct {
                fn panic(msg: []const u8, ra: ?usize) noreturn {
                    root.panic(msg, @errorReturnTrace(), ra);
                }
            }.panic);
        }
        break :p root.panic;
    }
    break :p switch (builtin.zig_backend) {
        .stage2_loongarch,
        .stage2_powerpc,
        .stage2_riscv64,
        => std.debug.simple_panic,
        else => std.debug.FullPanic(std.debug.defaultPanic),
    };
};

pub noinline fn returnError() void {
    @branchHint(.unlikely);
    @setRuntimeSafety(false);
    const st = @errorReturnTrace().?;
    if (st.index < st.instruction_addresses.len)
        st.instruction_addresses[st.index] = @returnAddress();
    st.index += 1;
}