Builtins (v0.2.1)

Compiler-provided functions, low-level memory and ABI operations, and builtin types for type, target, host, and compile-time work.

Latest

Overview

Builtins are compiler-provided functions and reserved operations. Some return information about types, some return information about the target or host, and some help validate assumptions while compiling.

They are often used in constants and static checks. For example, sizeOf(u32) can define a constant, staticAssert can stop compilation if an assumption is wrong, and target builtins can select one branch over another before code generation.

Use builtins when the value belongs to the compiler, the ABI, the target machine, or low-level memory operations rather than to ordinary runtime program state.

Primary source: syntax/builtins/README.md

Syntax Signatures

const SIZE: usize = sizeOf(u32);
const ALIGN: u32 = alignOf(u32);

fn verifyTypes() void {
    staticAssert(isSameType(u32, u32), "type mismatch");
}

Behavior and Use

Compile-time builtins are evaluated while the compiler processes the program, and memory and ABI builtins lower directly to low-level memory operations, ABI queries, or compiler-managed variadic argument access.

When staticAssert or compileError fails, compilation stops immediately. Warnings produced by compileWarning continue compilation but still affect diagnostics output.

Best Practices

Type Layout Builtins

These builtins describe the size and layout of a type as the compiler sees it.

Type Information Builtins

These builtins answer structural questions about types.

Source Location Builtins

These builtins expose the source position currently being compiled.

Compile-Time Check Builtins

These builtins validate assumptions or emit diagnostics during compilation.

Compiler Information Builtins

These builtins report facts about the compiler itself.

String Builtins

These builtins operate on constant strings known to the compiler.

Type Predicate Builtins

These builtins return booleans about general type categories.

Target Information Builtins

These builtins report what kind of machine and ABI the compiler is targeting.

Host Information Builtins

These builtins report facts about the machine running the compiler, not the machine being targeted.

Memory and ABI Builtins

These builtins lower directly to low-level memory operations, ABI queries, or variadic argument access.

Builtin Type

The language also exposes one builtin alias that appears in many APIs.

Using Builtins in Declarations

Builtins are most useful when they keep declarations tied to target facts.

Example

const PTR_BITS: usize = pointerWidth();

fn verify() void @public {
    staticAssert(PTR_BITS == 64 or PTR_BITS == 32, "unsupported pointer width");
}

Back to language reference