master
   1//! Types and values provided by the Zig language.
   2
   3const builtin = @import("builtin");
   4const std = @import("std.zig");
   5const root = @import("root");
   6
   7pub const assembly = @import("builtin/assembly.zig");
   8
   9/// This data structure is used by the Zig language code generation and
  10/// therefore must be kept in sync with the compiler implementation.
  11pub const StackTrace = struct {
  12    index: usize,
  13    instruction_addresses: []usize,
  14};
  15
  16/// This data structure is used by the Zig language code generation and
  17/// therefore must be kept in sync with the compiler implementation.
  18pub const GlobalLinkage = enum(u2) {
  19    internal,
  20    strong,
  21    weak,
  22    link_once,
  23};
  24
  25/// This data structure is used by the Zig language code generation and
  26/// therefore must be kept in sync with the compiler implementation.
  27pub const SymbolVisibility = enum(u2) {
  28    default,
  29    hidden,
  30    protected,
  31};
  32
  33/// This data structure is used by the Zig language code generation and
  34/// therefore must be kept in sync with the compiler implementation.
  35pub const AtomicOrder = enum {
  36    unordered,
  37    monotonic,
  38    acquire,
  39    release,
  40    acq_rel,
  41    seq_cst,
  42};
  43
  44/// This data structure is used by the Zig language code generation and
  45/// therefore must be kept in sync with the compiler implementation.
  46pub const ReduceOp = enum {
  47    And,
  48    Or,
  49    Xor,
  50    Min,
  51    Max,
  52    Add,
  53    Mul,
  54};
  55
  56/// This data structure is used by the Zig language code generation and
  57/// therefore must be kept in sync with the compiler implementation.
  58pub const AtomicRmwOp = enum {
  59    /// Exchange - store the operand unmodified.
  60    /// Supports enums, integers, and floats.
  61    Xchg,
  62    /// Add operand to existing value.
  63    /// Supports integers and floats.
  64    /// For integers, two's complement wraparound applies.
  65    Add,
  66    /// Subtract operand from existing value.
  67    /// Supports integers and floats.
  68    /// For integers, two's complement wraparound applies.
  69    Sub,
  70    /// Perform bitwise AND on existing value with operand.
  71    /// Supports integers.
  72    And,
  73    /// Perform bitwise NAND on existing value with operand.
  74    /// Supports integers.
  75    Nand,
  76    /// Perform bitwise OR on existing value with operand.
  77    /// Supports integers.
  78    Or,
  79    /// Perform bitwise XOR on existing value with operand.
  80    /// Supports integers.
  81    Xor,
  82    /// Store operand if it is larger than the existing value.
  83    /// Supports integers and floats.
  84    Max,
  85    /// Store operand if it is smaller than the existing value.
  86    /// Supports integers and floats.
  87    Min,
  88};
  89
  90/// The code model puts constraints on the location of symbols and the size of code and data.
  91/// 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.
  92/// 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.
  93///
  94/// This data structure is used by the Zig language code generation and
  95/// therefore must be kept in sync with the compiler implementation.
  96pub const CodeModel = enum {
  97    default,
  98    extreme,
  99    kernel,
 100    large,
 101    medany,
 102    medium,
 103    medlow,
 104    medmid,
 105    normal,
 106    small,
 107    tiny,
 108};
 109
 110/// This data structure is used by the Zig language code generation and
 111/// therefore must be kept in sync with the compiler implementation.
 112pub const OptimizeMode = enum {
 113    Debug,
 114    ReleaseSafe,
 115    ReleaseFast,
 116    ReleaseSmall,
 117};
 118
 119/// The calling convention of a function defines how arguments and return values are passed, as well
 120/// as any other requirements which callers and callees must respect, such as register preservation
 121/// and stack alignment.
 122///
 123/// This data structure is used by the Zig language code generation and
 124/// therefore must be kept in sync with the compiler implementation.
 125pub const CallingConvention = union(enum(u8)) {
 126    pub const Tag = @typeInfo(CallingConvention).@"union".tag_type.?;
 127
 128    /// This is an alias for the default C calling convention for this target.
 129    /// Functions marked as `extern` or `export` are given this calling convention by default.
 130    pub const c = builtin.target.cCallingConvention().?;
 131
 132    pub const winapi: CallingConvention = switch (builtin.target.cpu.arch) {
 133        .x86_64 => .{ .x86_64_win = .{} },
 134        .x86 => .{ .x86_stdcall = .{} },
 135        .aarch64 => .{ .aarch64_aapcs_win = .{} },
 136        .thumb => .{ .arm_aapcs_vfp = .{} },
 137        else => unreachable,
 138    };
 139
 140    pub const kernel: CallingConvention = switch (builtin.target.cpu.arch) {
 141        .amdgcn => .amdgcn_kernel,
 142        .nvptx, .nvptx64 => .nvptx_kernel,
 143        .spirv32, .spirv64 => .spirv_kernel,
 144        else => unreachable,
 145    };
 146
 147    /// The default Zig calling convention when neither `export` nor `inline` is specified.
 148    /// This calling convention makes no guarantees about stack alignment, registers, etc.
 149    /// It can only be used within this Zig compilation unit.
 150    auto,
 151
 152    /// The calling convention of a function that can be called with `async` syntax. An `async` call
 153    /// of a runtime-known function must target a function with this calling convention.
 154    /// Comptime-known functions with other calling conventions may be coerced to this one.
 155    async,
 156
 157    /// Functions with this calling convention have no prologue or epilogue, making the function
 158    /// uncallable in regular Zig code. This can be useful when integrating with assembly.
 159    naked,
 160
 161    /// This calling convention is exactly equivalent to using the `inline` keyword on a function
 162    /// definition. This function will be semantically inlined by the Zig compiler at call sites.
 163    /// Pointers to inline functions are comptime-only.
 164    @"inline",
 165
 166    // Calling conventions for the `x86_64` architecture.
 167    x86_64_sysv: CommonOptions,
 168    x86_64_x32: CommonOptions,
 169    x86_64_win: CommonOptions,
 170    x86_64_regcall_v3_sysv: CommonOptions,
 171    x86_64_regcall_v4_win: CommonOptions,
 172    x86_64_vectorcall: CommonOptions,
 173    x86_64_interrupt: CommonOptions,
 174
 175    // Calling conventions for the `x86` architecture.
 176    x86_sysv: X86RegparmOptions,
 177    x86_win: X86RegparmOptions,
 178    x86_stdcall: X86RegparmOptions,
 179    x86_fastcall: CommonOptions,
 180    x86_thiscall: CommonOptions,
 181    x86_thiscall_mingw: CommonOptions,
 182    x86_regcall_v3: CommonOptions,
 183    x86_regcall_v4_win: CommonOptions,
 184    x86_vectorcall: CommonOptions,
 185    x86_interrupt: CommonOptions,
 186
 187    // Calling conventions for the `x86_16` architecture.
 188
 189    x86_16_cdecl: CommonOptions,
 190    x86_16_stdcall: CommonOptions,
 191    x86_16_regparmcall: CommonOptions,
 192    x86_16_interrupt: CommonOptions,
 193
 194    // Calling conventions for the `aarch64` and `aarch64_be` architectures.
 195    aarch64_aapcs: CommonOptions,
 196    aarch64_aapcs_darwin: CommonOptions,
 197    aarch64_aapcs_win: CommonOptions,
 198    aarch64_vfabi: CommonOptions,
 199    aarch64_vfabi_sve: CommonOptions,
 200
 201    /// The standard `alpha` calling convention.
 202    alpha_osf: CommonOptions,
 203
 204    // Calling convetions for the `arm`, `armeb`, `thumb`, and `thumbeb` architectures.
 205    /// ARM Architecture Procedure Call Standard
 206    arm_aapcs: CommonOptions,
 207    /// ARM Architecture Procedure Call Standard Vector Floating-Point
 208    arm_aapcs_vfp: CommonOptions,
 209    arm_interrupt: ArmInterruptOptions,
 210
 211    // Calling conventions for the `mips64` and `mips64el` architectures.
 212    mips64_n64: CommonOptions,
 213    mips64_n32: CommonOptions,
 214    mips64_interrupt: MipsInterruptOptions,
 215
 216    // Calling conventions for the `mips` and `mipsel` architectures.
 217    mips_o32: CommonOptions,
 218    mips_interrupt: MipsInterruptOptions,
 219
 220    // Calling conventions for the `riscv64` architecture.
 221    riscv64_lp64: CommonOptions,
 222    riscv64_lp64_v: CommonOptions,
 223    riscv64_interrupt: RiscvInterruptOptions,
 224
 225    // Calling conventions for the `riscv32` architecture.
 226    riscv32_ilp32: CommonOptions,
 227    riscv32_ilp32_v: CommonOptions,
 228    riscv32_interrupt: RiscvInterruptOptions,
 229
 230    // Calling conventions for the `sparc64` architecture.
 231    sparc64_sysv: CommonOptions,
 232
 233    // Calling conventions for the `sparc` architecture.
 234    sparc_sysv: CommonOptions,
 235
 236    // Calling conventions for the `powerpc64` and `powerpc64le` architectures.
 237    powerpc64_elf: CommonOptions,
 238    powerpc64_elf_altivec: CommonOptions,
 239    powerpc64_elf_v2: CommonOptions,
 240
 241    // Calling conventions for the `powerpc` and `powerpcle` architectures.
 242    powerpc_sysv: CommonOptions,
 243    powerpc_sysv_altivec: CommonOptions,
 244    powerpc_aix: CommonOptions,
 245    powerpc_aix_altivec: CommonOptions,
 246
 247    /// The standard `wasm32` and `wasm64` calling convention, as specified in the WebAssembly Tool Conventions.
 248    wasm_mvp: CommonOptions,
 249
 250    /// The standard `arc`/`arceb` calling convention.
 251    arc_sysv: CommonOptions,
 252    arc_interrupt: ArcInterruptOptions,
 253
 254    // Calling conventions for the `avr` architecture.
 255    avr_gnu,
 256    avr_builtin,
 257    avr_signal,
 258    avr_interrupt,
 259
 260    /// The standard `bpfel`/`bpfeb` calling convention.
 261    bpf_std: CommonOptions,
 262
 263    // Calling conventions for the `csky` architecture.
 264    csky_sysv: CommonOptions,
 265    csky_interrupt: CommonOptions,
 266
 267    // Calling conventions for the `hexagon` architecture.
 268    hexagon_sysv: CommonOptions,
 269    hexagon_sysv_hvx: CommonOptions,
 270
 271    /// The standard `hppa` calling convention.
 272    hppa_elf: CommonOptions,
 273
 274    /// The standard `hppa64` calling convention.
 275    hppa64_elf: CommonOptions,
 276
 277    kvx_lp64: CommonOptions,
 278    kvx_ilp32: CommonOptions,
 279
 280    /// The standard `lanai` calling convention.
 281    lanai_sysv: CommonOptions,
 282
 283    /// The standard `loongarch64` calling convention.
 284    loongarch64_lp64: CommonOptions,
 285
 286    /// The standard `loongarch32` calling convention.
 287    loongarch32_ilp32: CommonOptions,
 288
 289    // Calling conventions for the `m68k` architecture.
 290    m68k_sysv: CommonOptions,
 291    m68k_gnu: CommonOptions,
 292    m68k_rtd: CommonOptions,
 293    m68k_interrupt: CommonOptions,
 294
 295    /// The standard `microblaze`/`microblazeel` calling convention.
 296    microblaze_std: CommonOptions,
 297    microblaze_interrupt: MicroblazeInterruptOptions,
 298
 299    /// The standard `msp430` calling convention.
 300    msp430_eabi: CommonOptions,
 301    msp430_interrupt: CommonOptions,
 302
 303    /// The standard `or1k` calling convention.
 304    or1k_sysv: CommonOptions,
 305
 306    /// The standard `propeller` calling convention.
 307    propeller_sysv: CommonOptions,
 308
 309    // Calling conventions for the `s390x` architecture.
 310    s390x_sysv: CommonOptions,
 311    s390x_sysv_vx: CommonOptions,
 312
 313    // Calling conventions for the `sh`/`sheb` architecture.
 314    sh_gnu: CommonOptions,
 315    sh_renesas: CommonOptions,
 316    sh_interrupt: ShInterruptOptions,
 317
 318    /// The standard `ve` calling convention.
 319    ve_sysv: CommonOptions,
 320
 321    // Calling conventions for the `xcore` architecture.
 322    xcore_xs1: CommonOptions,
 323    xcore_xs2: CommonOptions,
 324
 325    // Calling conventions for the `xtensa`/`xtensaeb` architecture.
 326    xtensa_call0: CommonOptions,
 327    xtensa_windowed: CommonOptions,
 328
 329    // Calling conventions for the `amdgcn` architecture.
 330    amdgcn_device: CommonOptions,
 331    amdgcn_kernel,
 332    amdgcn_cs: CommonOptions,
 333
 334    // Calling conventions for the `nvptx` and `nvptx64` architectures.
 335    nvptx_device,
 336    nvptx_kernel,
 337
 338    // Calling conventions for kernels and shaders on the `spirv`, `spirv32`, and `spirv64` architectures.
 339    spirv_device,
 340    spirv_kernel,
 341    spirv_fragment,
 342    spirv_vertex,
 343
 344    /// Options shared across most calling conventions.
 345    pub const CommonOptions = struct {
 346        /// The boundary the stack is aligned to when the function is called.
 347        /// `null` means the default for this calling convention.
 348        incoming_stack_alignment: ?u64 = null,
 349    };
 350
 351    /// Options for x86 calling conventions which support the regparm attribute to pass some
 352    /// arguments in registers.
 353    pub const X86RegparmOptions = struct {
 354        /// The boundary the stack is aligned to when the function is called.
 355        /// `null` means the default for this calling convention.
 356        incoming_stack_alignment: ?u64 = null,
 357        /// The number of arguments to pass in registers before passing the remaining arguments
 358        /// according to the calling convention.
 359        /// Equivalent to `__attribute__((regparm(x)))` in Clang and GCC.
 360        register_params: u2 = 0,
 361    };
 362
 363    /// Options for the `arc_interrupt` calling convention.
 364    pub const ArcInterruptOptions = struct {
 365        /// The boundary the stack is aligned to when the function is called.
 366        /// `null` means the default for this calling convention.
 367        incoming_stack_alignment: ?u64 = null,
 368        /// The kind of interrupt being received.
 369        type: InterruptType,
 370
 371        pub const InterruptType = enum(u2) {
 372            ilink1,
 373            ilink2,
 374            ilink,
 375            firq,
 376        };
 377    };
 378
 379    /// Options for the `arm_interrupt` calling convention.
 380    pub const ArmInterruptOptions = struct {
 381        /// The boundary the stack is aligned to when the function is called.
 382        /// `null` means the default for this calling convention.
 383        incoming_stack_alignment: ?u64 = null,
 384        /// The kind of interrupt being received.
 385        type: InterruptType = .generic,
 386
 387        pub const InterruptType = enum(u3) {
 388            generic,
 389            irq,
 390            fiq,
 391            swi,
 392            abort,
 393            undef,
 394        };
 395    };
 396
 397    /// Options for the `microblaze_interrupt` calling convention.
 398    pub const MicroblazeInterruptOptions = struct {
 399        /// The boundary the stack is aligned to when the function is called.
 400        /// `null` means the default for this calling convention.
 401        incoming_stack_alignment: ?u64 = null,
 402        type: InterruptType = .regular,
 403
 404        pub const InterruptType = enum(u2) {
 405            /// User exception; return with `rtsd`.
 406            user,
 407            /// Regular interrupt; return with `rtid`.
 408            regular,
 409            /// Fast interrupt; return with `rtid`.
 410            fast,
 411            /// Software breakpoint; return with `rtbd`.
 412            breakpoint,
 413        };
 414    };
 415
 416    /// Options for the `mips_interrupt` and `mips64_interrupt` calling conventions.
 417    pub const MipsInterruptOptions = struct {
 418        /// The boundary the stack is aligned to when the function is called.
 419        /// `null` means the default for this calling convention.
 420        incoming_stack_alignment: ?u64 = null,
 421        /// The interrupt mode.
 422        mode: InterruptMode = .eic,
 423
 424        pub const InterruptMode = enum(u4) {
 425            eic,
 426            sw0,
 427            sw1,
 428            hw0,
 429            hw1,
 430            hw2,
 431            hw3,
 432            hw4,
 433            hw5,
 434        };
 435    };
 436
 437    /// Options for the `riscv32_interrupt` and `riscv64_interrupt` calling conventions.
 438    pub const RiscvInterruptOptions = struct {
 439        /// The boundary the stack is aligned to when the function is called.
 440        /// `null` means the default for this calling convention.
 441        incoming_stack_alignment: ?u64 = null,
 442        /// The privilege mode.
 443        mode: PrivilegeMode,
 444
 445        pub const PrivilegeMode = enum(u2) {
 446            supervisor,
 447            machine,
 448        };
 449    };
 450
 451    /// Options for the `sh_interrupt` calling convention.
 452    pub const ShInterruptOptions = struct {
 453        /// The boundary the stack is aligned to when the function is called.
 454        /// `null` means the default for this calling convention.
 455        incoming_stack_alignment: ?u64 = null,
 456        save: SaveBehavior = .full,
 457
 458        pub const SaveBehavior = enum(u3) {
 459            /// Save only fpscr (if applicable).
 460            fpscr,
 461            /// Save only high-numbered registers, i.e. r0 through r7 are *not* saved.
 462            high,
 463            /// Save all registers normally.
 464            full,
 465            /// Save all registers using the CPU's fast register bank.
 466            bank,
 467        };
 468    };
 469
 470    /// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.
 471    /// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
 472    pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {
 473        return std.Target.Cpu.Arch.fromCallingConvention(cc);
 474    }
 475
 476    pub fn eql(a: CallingConvention, b: CallingConvention) bool {
 477        return std.meta.eql(a, b);
 478    }
 479
 480    pub fn withStackAlign(cc: CallingConvention, incoming_stack_alignment: u64) CallingConvention {
 481        const tag: CallingConvention.Tag = cc;
 482        var result = cc;
 483        @field(result, @tagName(tag)).incoming_stack_alignment = incoming_stack_alignment;
 484        return result;
 485    }
 486};
 487
 488/// This data structure is used by the Zig language code generation and
 489/// therefore must be kept in sync with the compiler implementation.
 490pub const AddressSpace = enum(u5) {
 491    // CPU address spaces.
 492    generic,
 493    gs,
 494    fs,
 495    ss,
 496
 497    // x86_16 extra address spaces.
 498    /// Allows addressing the entire address space by storing both segment and offset.
 499    far,
 500
 501    // GPU address spaces.
 502    global,
 503    constant,
 504    param,
 505    shared,
 506    local,
 507    input,
 508    output,
 509    uniform,
 510    push_constant,
 511    storage_buffer,
 512    physical_storage_buffer,
 513
 514    // AVR address spaces.
 515    flash,
 516    flash1,
 517    flash2,
 518    flash3,
 519    flash4,
 520    flash5,
 521
 522    // Propeller address spaces.
 523
 524    /// This address space only addresses the cog-local ram.
 525    cog,
 526
 527    /// This address space only addresses shared hub ram.
 528    hub,
 529
 530    /// This address space only addresses the "lookup" ram
 531    lut,
 532};
 533
 534/// This data structure is used by the Zig language code generation and
 535/// therefore must be kept in sync with the compiler implementation.
 536pub const SourceLocation = struct {
 537    /// The name chosen when compiling. Not a file path.
 538    module: [:0]const u8,
 539    /// Relative to the root directory of its module.
 540    file: [:0]const u8,
 541    fn_name: [:0]const u8,
 542    line: u32,
 543    column: u32,
 544};
 545
 546pub const TypeId = std.meta.Tag(Type);
 547
 548/// This data structure is used by the Zig language code generation and
 549/// therefore must be kept in sync with the compiler implementation.
 550pub const Type = union(enum) {
 551    type,
 552    void,
 553    bool,
 554    noreturn,
 555    int: Int,
 556    float: Float,
 557    pointer: Pointer,
 558    array: Array,
 559    @"struct": Struct,
 560    comptime_float,
 561    comptime_int,
 562    undefined,
 563    null,
 564    optional: Optional,
 565    error_union: ErrorUnion,
 566    error_set: ErrorSet,
 567    @"enum": Enum,
 568    @"union": Union,
 569    @"fn": Fn,
 570    @"opaque": Opaque,
 571    frame: Frame,
 572    @"anyframe": AnyFrame,
 573    vector: Vector,
 574    enum_literal,
 575
 576    /// This data structure is used by the Zig language code generation and
 577    /// therefore must be kept in sync with the compiler implementation.
 578    pub const Int = struct {
 579        signedness: Signedness,
 580        bits: u16,
 581    };
 582
 583    /// This data structure is used by the Zig language code generation and
 584    /// therefore must be kept in sync with the compiler implementation.
 585    pub const Float = struct {
 586        bits: u16,
 587    };
 588
 589    /// This data structure is used by the Zig language code generation and
 590    /// therefore must be kept in sync with the compiler implementation.
 591    pub const Pointer = struct {
 592        size: Size,
 593        is_const: bool,
 594        is_volatile: bool,
 595        /// TODO make this u16 instead of comptime_int
 596        alignment: comptime_int,
 597        address_space: AddressSpace,
 598        child: type,
 599        is_allowzero: bool,
 600
 601        /// The type of the sentinel is the element type of the pointer, which is
 602        /// the value of the `child` field in this struct. However there is no way
 603        /// to refer to that type here, so we use `*const anyopaque`.
 604        /// See also: `sentinel`
 605        sentinel_ptr: ?*const anyopaque,
 606
 607        /// Loads the pointer type's sentinel value from `sentinel_ptr`.
 608        /// Returns `null` if the pointer type has no sentinel.
 609        pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child {
 610            const sp: *const ptr.child = @ptrCast(@alignCast(ptr.sentinel_ptr orelse return null));
 611            return sp.*;
 612        }
 613
 614        /// This data structure is used by the Zig language code generation and
 615        /// therefore must be kept in sync with the compiler implementation.
 616        pub const Size = enum(u2) {
 617            one,
 618            many,
 619            slice,
 620            c,
 621        };
 622
 623        /// This data structure is used by the Zig language code generation and
 624        /// therefore must be kept in sync with the compiler implementation.
 625        pub const Attributes = struct {
 626            @"const": bool = false,
 627            @"volatile": bool = false,
 628            @"allowzero": bool = false,
 629            @"addrspace": ?AddressSpace = null,
 630            @"align": ?usize = null,
 631        };
 632    };
 633
 634    /// This data structure is used by the Zig language code generation and
 635    /// therefore must be kept in sync with the compiler implementation.
 636    pub const Array = struct {
 637        len: comptime_int,
 638        child: type,
 639
 640        /// The type of the sentinel is the element type of the array, which is
 641        /// the value of the `child` field in this struct. However there is no way
 642        /// to refer to that type here, so we use `*const anyopaque`.
 643        /// See also: `sentinel`.
 644        sentinel_ptr: ?*const anyopaque,
 645
 646        /// Loads the array type's sentinel value from `sentinel_ptr`.
 647        /// Returns `null` if the array type has no sentinel.
 648        pub inline fn sentinel(comptime arr: Array) ?arr.child {
 649            const sp: *const arr.child = @ptrCast(@alignCast(arr.sentinel_ptr orelse return null));
 650            return sp.*;
 651        }
 652    };
 653
 654    /// This data structure is used by the Zig language code generation and
 655    /// therefore must be kept in sync with the compiler implementation.
 656    pub const ContainerLayout = enum(u2) {
 657        auto,
 658        @"extern",
 659        @"packed",
 660    };
 661
 662    /// This data structure is used by the Zig language code generation and
 663    /// therefore must be kept in sync with the compiler implementation.
 664    pub const StructField = struct {
 665        name: [:0]const u8,
 666        type: type,
 667        /// The type of the default value is the type of this struct field, which
 668        /// is the value of the `type` field in this struct. However there is no
 669        /// way to refer to that type here, so we use `*const anyopaque`.
 670        /// See also: `defaultValue`.
 671        default_value_ptr: ?*const anyopaque,
 672        is_comptime: bool,
 673        alignment: comptime_int,
 674
 675        /// Loads the field's default value from `default_value_ptr`.
 676        /// Returns `null` if the field has no default value.
 677        pub inline fn defaultValue(comptime sf: StructField) ?sf.type {
 678            const dp: *const sf.type = @ptrCast(@alignCast(sf.default_value_ptr orelse return null));
 679            return dp.*;
 680        }
 681
 682        /// This data structure is used by the Zig language code generation and
 683        /// therefore must be kept in sync with the compiler implementation.
 684        pub const Attributes = struct {
 685            @"comptime": bool = false,
 686            @"align": ?usize = null,
 687            default_value_ptr: ?*const anyopaque = null,
 688        };
 689    };
 690
 691    /// This data structure is used by the Zig language code generation and
 692    /// therefore must be kept in sync with the compiler implementation.
 693    pub const Struct = struct {
 694        layout: ContainerLayout,
 695        /// Only valid if layout is .@"packed"
 696        backing_integer: ?type = null,
 697        fields: []const StructField,
 698        decls: []const Declaration,
 699        is_tuple: bool,
 700    };
 701
 702    /// This data structure is used by the Zig language code generation and
 703    /// therefore must be kept in sync with the compiler implementation.
 704    pub const Optional = struct {
 705        child: type,
 706    };
 707
 708    /// This data structure is used by the Zig language code generation and
 709    /// therefore must be kept in sync with the compiler implementation.
 710    pub const ErrorUnion = struct {
 711        error_set: type,
 712        payload: type,
 713    };
 714
 715    /// This data structure is used by the Zig language code generation and
 716    /// therefore must be kept in sync with the compiler implementation.
 717    pub const Error = struct {
 718        name: [:0]const u8,
 719    };
 720
 721    /// This data structure is used by the Zig language code generation and
 722    /// therefore must be kept in sync with the compiler implementation.
 723    pub const ErrorSet = ?[]const Error;
 724
 725    /// This data structure is used by the Zig language code generation and
 726    /// therefore must be kept in sync with the compiler implementation.
 727    pub const EnumField = struct {
 728        name: [:0]const u8,
 729        value: comptime_int,
 730    };
 731
 732    /// This data structure is used by the Zig language code generation and
 733    /// therefore must be kept in sync with the compiler implementation.
 734    pub const Enum = struct {
 735        tag_type: type,
 736        fields: []const EnumField,
 737        decls: []const Declaration,
 738        is_exhaustive: bool,
 739
 740        /// This data structure is used by the Zig language code generation and
 741        /// therefore must be kept in sync with the compiler implementation.
 742        pub const Mode = enum { exhaustive, nonexhaustive };
 743    };
 744
 745    /// This data structure is used by the Zig language code generation and
 746    /// therefore must be kept in sync with the compiler implementation.
 747    pub const UnionField = struct {
 748        name: [:0]const u8,
 749        type: type,
 750        alignment: comptime_int,
 751
 752        /// This data structure is used by the Zig language code generation and
 753        /// therefore must be kept in sync with the compiler implementation.
 754        pub const Attributes = struct {
 755            @"align": ?usize = null,
 756        };
 757    };
 758
 759    /// This data structure is used by the Zig language code generation and
 760    /// therefore must be kept in sync with the compiler implementation.
 761    pub const Union = struct {
 762        layout: ContainerLayout,
 763        tag_type: ?type,
 764        fields: []const UnionField,
 765        decls: []const Declaration,
 766    };
 767
 768    /// This data structure is used by the Zig language code generation and
 769    /// therefore must be kept in sync with the compiler implementation.
 770    pub const Fn = struct {
 771        calling_convention: CallingConvention,
 772        is_generic: bool,
 773        is_var_args: bool,
 774        /// TODO change the language spec to make this not optional.
 775        return_type: ?type,
 776        params: []const Param,
 777
 778        /// This data structure is used by the Zig language code generation and
 779        /// therefore must be kept in sync with the compiler implementation.
 780        pub const Param = struct {
 781            is_generic: bool,
 782            is_noalias: bool,
 783            type: ?type,
 784
 785            /// This data structure is used by the Zig language code generation and
 786            /// therefore must be kept in sync with the compiler implementation.
 787            pub const Attributes = struct {
 788                @"noalias": bool = false,
 789            };
 790        };
 791
 792        /// This data structure is used by the Zig language code generation and
 793        /// therefore must be kept in sync with the compiler implementation.
 794        pub const Attributes = struct {
 795            @"callconv": CallingConvention = .auto,
 796            varargs: bool = false,
 797        };
 798    };
 799
 800    /// This data structure is used by the Zig language code generation and
 801    /// therefore must be kept in sync with the compiler implementation.
 802    pub const Opaque = struct {
 803        decls: []const Declaration,
 804    };
 805
 806    /// This data structure is used by the Zig language code generation and
 807    /// therefore must be kept in sync with the compiler implementation.
 808    pub const Frame = struct {
 809        function: *const anyopaque,
 810    };
 811
 812    /// This data structure is used by the Zig language code generation and
 813    /// therefore must be kept in sync with the compiler implementation.
 814    pub const AnyFrame = struct {
 815        child: ?type,
 816    };
 817
 818    /// This data structure is used by the Zig language code generation and
 819    /// therefore must be kept in sync with the compiler implementation.
 820    pub const Vector = struct {
 821        len: comptime_int,
 822        child: type,
 823    };
 824
 825    /// This data structure is used by the Zig language code generation and
 826    /// therefore must be kept in sync with the compiler implementation.
 827    pub const Declaration = struct {
 828        name: [:0]const u8,
 829    };
 830};
 831
 832/// This data structure is used by the Zig language code generation and
 833/// therefore must be kept in sync with the compiler implementation.
 834pub const FloatMode = enum {
 835    strict,
 836    optimized,
 837};
 838
 839/// This data structure is used by the Zig language code generation and
 840/// therefore must be kept in sync with the compiler implementation.
 841pub const Endian = enum {
 842    big,
 843    little,
 844};
 845
 846/// This data structure is used by the Zig language code generation and
 847/// therefore must be kept in sync with the compiler implementation.
 848pub const Signedness = enum(u1) {
 849    signed,
 850    unsigned,
 851};
 852
 853/// This data structure is used by the Zig language code generation and
 854/// therefore must be kept in sync with the compiler implementation.
 855pub const OutputMode = enum {
 856    Exe,
 857    Lib,
 858    Obj,
 859};
 860
 861/// This data structure is used by the Zig language code generation and
 862/// therefore must be kept in sync with the compiler implementation.
 863pub const LinkMode = enum {
 864    static,
 865    dynamic,
 866};
 867
 868/// This data structure is used by the Zig language code generation and
 869/// therefore must be kept in sync with the compiler implementation.
 870pub const UnwindTables = enum {
 871    none,
 872    sync,
 873    async,
 874};
 875
 876/// This data structure is used by the Zig language code generation and
 877/// therefore must be kept in sync with the compiler implementation.
 878pub const WasiExecModel = enum {
 879    command,
 880    reactor,
 881};
 882
 883/// This data structure is used by the Zig language code generation and
 884/// therefore must be kept in sync with the compiler implementation.
 885pub const CallModifier = enum {
 886    /// Equivalent to function call syntax.
 887    auto,
 888    /// Prevents tail call optimization. This guarantees that the return
 889    /// address will point to the callsite, as opposed to the callsite's
 890    /// callsite. If the call is otherwise required to be tail-called
 891    /// or inlined, a compile error is emitted instead.
 892    never_tail,
 893    /// Guarantees that the call will not be inlined. If the call is
 894    /// otherwise required to be inlined, a compile error is emitted instead.
 895    never_inline,
 896    /// Asserts that the function call will not suspend. This allows a
 897    /// non-async function to call an async function.
 898    no_suspend,
 899    /// Guarantees that the call will be generated with tail call optimization.
 900    /// If this is not possible, a compile error is emitted instead.
 901    always_tail,
 902    /// Guarantees that the call will be inlined at the callsite.
 903    /// If this is not possible, a compile error is emitted instead.
 904    always_inline,
 905    /// Evaluates the call at compile-time. If the call cannot be completed at
 906    /// compile-time, a compile error is emitted instead.
 907    compile_time,
 908};
 909
 910/// This data structure is used by the Zig language code generation and
 911/// therefore must be kept in sync with the compiler implementation.
 912pub const VaListAarch64 = extern struct {
 913    __stack: *anyopaque,
 914    __gr_top: *anyopaque,
 915    __vr_top: *anyopaque,
 916    __gr_offs: c_int,
 917    __vr_offs: c_int,
 918};
 919
 920/// This data structure is used by the Zig language code generation and
 921/// therefore must be kept in sync with the compiler implementation.
 922pub const VaListAlpha = extern struct {
 923    __base: *anyopaque,
 924    __offset: c_int,
 925};
 926
 927/// This data structure is used by the Zig language code generation and
 928/// therefore must be kept in sync with the compiler implementation.
 929pub const VaListArm = extern struct {
 930    __ap: *anyopaque,
 931};
 932
 933/// This data structure is used by the Zig language code generation and
 934/// therefore must be kept in sync with the compiler implementation.
 935pub const VaListHexagon = extern struct {
 936    __gpr: c_long,
 937    __fpr: c_long,
 938    __overflow_arg_area: *anyopaque,
 939    __reg_save_area: *anyopaque,
 940};
 941
 942/// This data structure is used by the Zig language code generation and
 943/// therefore must be kept in sync with the compiler implementation.
 944pub const VaListPowerPc = extern struct {
 945    gpr: u8,
 946    fpr: u8,
 947    reserved: c_ushort,
 948    overflow_arg_area: *anyopaque,
 949    reg_save_area: *anyopaque,
 950};
 951
 952/// This data structure is used by the Zig language code generation and
 953/// therefore must be kept in sync with the compiler implementation.
 954pub const VaListS390x = extern struct {
 955    __current_saved_reg_area_pointer: *anyopaque,
 956    __saved_reg_area_end_pointer: *anyopaque,
 957    __overflow_area_pointer: *anyopaque,
 958};
 959
 960/// This data structure is used by the Zig language code generation and
 961/// therefore must be kept in sync with the compiler implementation.
 962pub const VaListSh = extern struct {
 963    __va_next_o: *anyopaque,
 964    __va_next_o_limit: *anyopaque,
 965    __va_next_fp: *anyopaque,
 966    __va_next_fp_limit: *anyopaque,
 967    __va_next_stack: *anyopaque,
 968};
 969
 970/// This data structure is used by the Zig language code generation and
 971/// therefore must be kept in sync with the compiler implementation.
 972pub const VaListX86_64 = extern struct {
 973    gp_offset: c_uint,
 974    fp_offset: c_uint,
 975    overflow_arg_area: *anyopaque,
 976    reg_save_area: *anyopaque,
 977};
 978
 979/// This data structure is used by the Zig language code generation and
 980/// therefore must be kept in sync with the compiler implementation.
 981pub const VaListXtensa = extern struct {
 982    __va_stk: *c_int,
 983    __va_reg: *c_int,
 984    __va_ndx: c_int,
 985};
 986
 987/// This data structure is used by the Zig language code generation and
 988/// therefore must be kept in sync with the compiler implementation.
 989pub const VaList = switch (builtin.cpu.arch) {
 990    .amdgcn,
 991    .msp430,
 992    .nvptx,
 993    .nvptx64,
 994    .powerpc64,
 995    .powerpc64le,
 996    .x86,
 997    => *u8,
 998    .arc,
 999    .arceb,
1000    .avr,
1001    .bpfel,
1002    .bpfeb,
1003    .csky,
1004    .hppa,
1005    .hppa64,
1006    .kvx,
1007    .lanai,
1008    .loongarch32,
1009    .loongarch64,
1010    .m68k,
1011    .microblaze,
1012    .microblazeel,
1013    .mips,
1014    .mipsel,
1015    .mips64,
1016    .mips64el,
1017    .riscv32,
1018    .riscv32be,
1019    .riscv64,
1020    .riscv64be,
1021    .sparc,
1022    .sparc64,
1023    .spirv32,
1024    .spirv64,
1025    .ve,
1026    .wasm32,
1027    .wasm64,
1028    .xcore,
1029    => *anyopaque,
1030    .aarch64, .aarch64_be => switch (builtin.os.tag) {
1031        .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => *u8,
1032        else => switch (builtin.zig_backend) {
1033            else => VaListAarch64,
1034            .stage2_llvm => @compileError("disabled due to miscompilations"),
1035        },
1036    },
1037    .alpha => VaListAlpha,
1038    .arm, .armeb, .thumb, .thumbeb => VaListArm,
1039    .hexagon => if (builtin.target.abi.isMusl()) VaListHexagon else *u8,
1040    .powerpc, .powerpcle => VaListPowerPc,
1041    .s390x => VaListS390x,
1042    .sh, .sheb => VaListSh, // This is wrong for `sh_renesas`: https://github.com/ziglang/zig/issues/24692#issuecomment-3150779829
1043    .x86_64 => switch (builtin.os.tag) {
1044        .uefi, .windows => switch (builtin.zig_backend) {
1045            else => *u8,
1046            .stage2_llvm => @compileError("disabled due to miscompilations"),
1047        },
1048        else => VaListX86_64,
1049    },
1050    .xtensa, .xtensaeb => VaListXtensa,
1051    else => @compileError("VaList not supported for this target yet"),
1052};
1053
1054/// This data structure is used by the Zig language code generation and
1055/// therefore must be kept in sync with the compiler implementation.
1056pub const PrefetchOptions = struct {
1057    /// Whether the prefetch should prepare for a read or a write.
1058    rw: Rw = .read,
1059    /// The data's locality in an inclusive range from 0 to 3.
1060    ///
1061    /// 0 means no temporal locality. That is, the data can be immediately
1062    /// dropped from the cache after it is accessed.
1063    ///
1064    /// 3 means high temporal locality. That is, the data should be kept in
1065    /// the cache as it is likely to be accessed again soon.
1066    locality: u2 = 3,
1067    /// The cache that the prefetch should be performed on.
1068    cache: Cache = .data,
1069
1070    pub const Rw = enum(u1) {
1071        read,
1072        write,
1073    };
1074
1075    pub const Cache = enum(u1) {
1076        instruction,
1077        data,
1078    };
1079};
1080
1081/// This data structure is used by the Zig language code generation and
1082/// therefore must be kept in sync with the compiler implementation.
1083pub const ExportOptions = struct {
1084    name: []const u8,
1085    linkage: GlobalLinkage = .strong,
1086    section: ?[]const u8 = null,
1087    visibility: SymbolVisibility = .default,
1088};
1089
1090/// This data structure is used by the Zig language code generation and
1091/// therefore must be kept in sync with the compiler implementation.
1092pub const ExternOptions = struct {
1093    name: []const u8,
1094    library_name: ?[]const u8 = null,
1095    linkage: GlobalLinkage = .strong,
1096    visibility: SymbolVisibility = .default,
1097    /// Setting this to `true` makes the `@extern` a runtime value.
1098    is_thread_local: bool = false,
1099    is_dll_import: bool = false,
1100    relocation: Relocation = .any,
1101
1102    pub const Relocation = enum(u1) {
1103        /// Any type of relocation is allowed.
1104        any,
1105        /// A program-counter-relative relocation is required.
1106        /// Using this value makes the `@extern` a runtime value.
1107        pcrel,
1108    };
1109};
1110
1111/// This data structure is used by the Zig language code generation and
1112/// therefore must be kept in sync with the compiler implementation.
1113pub const BranchHint = enum(u3) {
1114    /// Equivalent to no hint given.
1115    none,
1116    /// This branch of control flow is more likely to be reached than its peers.
1117    /// The optimizer should optimize for reaching it.
1118    likely,
1119    /// This branch of control flow is less likely to be reached than its peers.
1120    /// The optimizer should optimize for not reaching it.
1121    unlikely,
1122    /// This branch of control flow is unlikely to *ever* be reached.
1123    /// The optimizer may place it in a different page of memory to optimize other branches.
1124    cold,
1125    /// It is difficult to predict whether this branch of control flow will be reached.
1126    /// The optimizer should avoid branching behavior with expensive mispredictions.
1127    unpredictable,
1128};
1129
1130/// This enum is set by the compiler and communicates which compiler backend is
1131/// used to produce machine code.
1132/// Think carefully before deciding to observe this value. Nearly all code should
1133/// be agnostic to the backend that implements the language. The use case
1134/// to use this value is to **work around problems with compiler implementations.**
1135///
1136/// Avoid failing the compilation if the compiler backend does not match a
1137/// whitelist of backends; rather one should detect that a known problem would
1138/// occur in a blacklist of backends.
1139///
1140/// The enum is nonexhaustive so that alternate Zig language implementations may
1141/// choose a number as their tag (please use a random number generator rather
1142/// than a "cute" number) and codebases can interact with these values even if
1143/// this upstream enum does not have a name for the number. Of course, upstream
1144/// is happy to accept pull requests to add Zig implementations to this enum.
1145///
1146/// This data structure is part of the Zig language specification.
1147pub const CompilerBackend = enum(u64) {
1148    /// It is allowed for a compiler implementation to not reveal its identity,
1149    /// in which case this value is appropriate. Be cool and make sure your
1150    /// code supports `other` Zig compilers!
1151    other = 0,
1152    /// The original Zig compiler created in 2015 by Andrew Kelley. Implemented
1153    /// in C++. Used LLVM. Deleted from the ZSF ziglang/zig codebase on
1154    /// December 6th, 2022.
1155    stage1 = 1,
1156    /// The reference implementation self-hosted compiler of Zig, using the
1157    /// LLVM backend.
1158    stage2_llvm = 2,
1159    /// The reference implementation self-hosted compiler of Zig, using the
1160    /// backend that generates C source code.
1161    /// Note that one can observe whether the compilation will output C code
1162    /// directly with `object_format` value rather than the `compiler_backend` value.
1163    stage2_c = 3,
1164    /// The reference implementation self-hosted compiler of Zig, using the
1165    /// WebAssembly backend.
1166    stage2_wasm = 4,
1167    /// The reference implementation self-hosted compiler of Zig, using the
1168    /// arm backend.
1169    stage2_arm = 5,
1170    /// The reference implementation self-hosted compiler of Zig, using the
1171    /// x86_64 backend.
1172    stage2_x86_64 = 6,
1173    /// The reference implementation self-hosted compiler of Zig, using the
1174    /// aarch64 backend.
1175    stage2_aarch64 = 7,
1176    /// The reference implementation self-hosted compiler of Zig, using the
1177    /// x86 backend.
1178    stage2_x86 = 8,
1179    /// The reference implementation self-hosted compiler of Zig, using the
1180    /// riscv64 backend.
1181    stage2_riscv64 = 9,
1182    /// The reference implementation self-hosted compiler of Zig, using the
1183    /// sparc64 backend.
1184    stage2_sparc64 = 10,
1185    /// The reference implementation self-hosted compiler of Zig, using the
1186    /// spirv backend.
1187    stage2_spirv = 11,
1188    /// The reference implementation self-hosted compiler of Zig, using the
1189    /// powerpc backend.
1190    stage2_powerpc = 12,
1191
1192    _,
1193};
1194
1195/// This function type is used by the Zig language code generation and
1196/// therefore must be kept in sync with the compiler implementation.
1197pub const TestFn = struct {
1198    name: []const u8,
1199    func: *const fn () anyerror!void,
1200};
1201
1202/// This namespace is used by the Zig compiler to emit various kinds of safety
1203/// panics. These can be overridden by making a public `panic` namespace in the
1204/// root source file.
1205pub const panic: type = p: {
1206    if (@hasDecl(root, "panic")) {
1207        if (@TypeOf(root.panic) != type) {
1208            // Deprecated; make `panic` a namespace instead.
1209            break :p std.debug.FullPanic(struct {
1210                fn panic(msg: []const u8, ra: ?usize) noreturn {
1211                    root.panic(msg, @errorReturnTrace(), ra);
1212                }
1213            }.panic);
1214        }
1215        break :p root.panic;
1216    }
1217    break :p switch (builtin.zig_backend) {
1218        .stage2_powerpc,
1219        .stage2_riscv64,
1220        => std.debug.simple_panic,
1221        else => std.debug.FullPanic(std.debug.defaultPanic),
1222    };
1223};
1224
1225pub noinline fn returnError() void {
1226    @branchHint(.unlikely);
1227    @setRuntimeSafety(false);
1228    const st = @errorReturnTrace().?;
1229    if (st.index < st.instruction_addresses.len)
1230        st.instruction_addresses[st.index] = @returnAddress();
1231    st.index += 1;
1232}