intrinsics
import std::core::intrinsics; · source
Intrinsics
core::intrinsics declares the operations the compiler lowers directly to LLVM rather than to a call. Nothing here has a body, and the list below is abbreviated by width where a family repeats.
intrinsic function malloc(size: u64) -> void*;
intrinsic function realloc(ptr: void*, new_size: u64) -> void*;
intrinsic function free(ptr: void*) -> void;
intrinsic function ptr_diff(a: void*, b: void*) -> i64;
intrinsic function panic(message: string, loc: Location) -> never;
intrinsic function location() -> Location;
intrinsic function try_catch(body: void*, data: void*) -> boolean;
intrinsic function trap() -> never;
intrinsic function debugtrap() -> void;
intrinsic function frame_address(level: u32) -> void*;
intrinsic function return_address(level: u32) -> void*;
intrinsic function atomic_fence(order: u32) -> void;
intrinsic function atomic_load_u8(ptr: u8*, order: u32) -> u8; // ... _u32, _u64
intrinsic function atomic_store_u8(ptr: u8*, value: u8, order: u32) -> void; // ... _u32, _u64
intrinsic function atomic_add_u8(ptr: u8*, value: u8, order: u32) -> u8; // ... _u32, _u64
intrinsic function atomic_sub_u8(ptr: u8*, value: u8, order: u32) -> u8; // ... _u32, _u64
intrinsic function atomic_and_u8(ptr: u8*, value: u8, order: u32) -> u8; // ... _u32, _u64
intrinsic function atomic_or_u8(ptr: u8*, value: u8, order: u32) -> u8; // ... _u32, _u64
intrinsic function atomic_xor_u8(ptr: u8*, value: u8, order: u32) -> u8; // ... _u32, _u64
intrinsic function atomic_swap_u8(ptr: u8*, value: u8, order: u32) -> u8; // ... _u32, _u64
intrinsic function atomic_cmpxchg_u8(ptr: u8*, cmp: u8, new: u8,
succ: u32, fail: u32, out_ok: boolean*) -> u8; // ... _u32, _u64
intrinsic function fpclass(value: f64, test: i32) -> boolean;
intrinsic function fabs64(value: f64) -> f64;
intrinsic function fabs32(value: f32) -> f32;
intrinsic function floor64(value: f64) -> f64;
intrinsic function ceil64(value: f64) -> f64;
intrinsic function ftrunc64(value: f64) -> f64;
intrinsic function round64(value: f64) -> f64;
intrinsic function copysign64(magnitude: f64, sign: f64) -> f64;
intrinsic function sqrt64(value: f64) -> f64;
intrinsic function sqrt32(value: f32) -> f32;
intrinsic function fma64(x: f64, y: f64, z: f64) -> f64;
intrinsic function bswap16(value: u16) -> u16; // ... 32, 64
intrinsic function popcount32(value: u32) -> u32; // ... 64
intrinsic function clz32(value: u32) -> u32; // ... 64
intrinsic function ctz32(value: u32) -> u32; // ... 64
intrinsic function rotl32(value: u32, n: u32) -> u32; // ... 64
intrinsic function rotr32(value: u32, n: u32) -> u32; // ... 64
intrinsic function dirent_name(entry: void*) -> string;
intrinsic function dirent_type(entry: void*) -> i32;
intrinsic function va_arg_i32(args: void*) -> i32; // ... _u32, _i64, _u64, _f64, _ptr, _string
The memory intrinsics back alloc and core::mem; the atomics back sync::atomic; the float intrinsics back math; the bit intrinsics (byte swap, population count, leading and trailing zeros, rotates) lower to the LLVM intrinsics of the same names, count in u32 whatever the operand's width, and back the hash rounds in encoding; and the va_arg_* family backs VaArgs::next. memcpy, memset, sizeof, and alignof are keywords rather than intrinsics and need no declaration. You will rarely call any of these directly — the typed wrappers exist so you don't have to.
Unlike the rest of core, the module is not in the prelude. Its functions are exported, so bringing it in bare would make panic name both the intrinsic and core::panic; reach an intrinsic by path, intrinsics::malloc(64) after import std::core::intrinsics;, or import it by name.
Source locations
type struct Location {
file: string;
line: u32;
column: u32;
function: string;
}
A place in the source, made by the compiler. Each call of location() answers the place it is written: its line and column, and the qualified name of the function it is written in (App::Main::main, never a linker symbol). Inside a function marked ![caller_location] it is the place of the call to that function instead, so a check can report its caller's line; the standard library's index bounds check is marked this way, so an out-of-range xs[i] reports the xs[i]. core::panic(message, intrinsics::location()) names all of it: panicked at <file>:<line>:<column> in <function>: <message>. The full rules are in Intrinsic Functions.
Properties
| Property | Type |
|---|---|
file | string |
line | u32 |
column | u32 |
function | string |
intrinsic function location() -> Location;
intrinsic function location() -> Location;intrinsic function name(param: Type) -> Ret;Declares a function the compiler lowers directly to LLVM IR rather than calling. Intrinsics are the contract between the standard library and the compiler (malloc, memcpy, printf, ...); user code does not normally declare its own.
function name<T>(param: Type) -> Ret { ... }Declares a function. Parameters are written name: Type and are never inferred; the return type follows -> and defaults to void. Declaration order does not matter: every signature is collected before any body is checked, so functions may call each other freely and recurse.
intrinsic function malloc(size: u64) -> void*(parameter) size: u64intrinsic function realloc(ptr: void*, new_size: u64) -> void*(parameter) ptr: void*(parameter) new_size: u64intrinsic function free(ptr: void*) -> voidintrinsic function ptr_diff(a: void*, b: void*) -> i64(parameter) a: void*(parameter) b: void*intrinsic function panic(message: string, loc: Location) -> never(parameter) message: stringprimitive stringNUL-terminated raw string (u8*), matching the C ABI. Length-typed text is Str / String.
(parameter) loc: Locationtype struct Location {
file: string;
line: u32;
column: u32;
function: string;
}A place in the source: the file as the build was given it, the line and column (both from 1), and the readable qualified name of the function the place is in. Made by the compiler, for location() and for the caller of a ![caller_location] function.
primitive neverThe type of an expression that does not return. Only valid as a return type, written by functions that always panic, trap, or diverge. 0 bytes.
primitive typeintrinsic function location() -> Locationintrinsic function try_catch(body: void*, data: void*) -> boolean(parameter) body: void*(parameter) data: void*intrinsic function trap() -> neverintrinsic function debugtrap() -> voidintrinsic function frame_address(level: u32) -> void*(parameter) level: u32intrinsic function return_address(level: u32) -> void*intrinsic function atomic_fence(order: u32) -> void(parameter) order: u32intrinsic function atomic_load_u8(ptr: u8*, order: u32) -> u8(parameter) ptr: u8*intrinsic function atomic_store_u8(ptr: u8*, value: u8, order: u32) -> void(parameter) value: u8intrinsic function atomic_add_u8(ptr: u8*, value: u8, order: u32) -> u8intrinsic function atomic_sub_u8(ptr: u8*, value: u8, order: u32) -> u8intrinsic function atomic_and_u8(ptr: u8*, value: u8, order: u32) -> u8intrinsic function atomic_or_u8(ptr: u8*, value: u8, order: u32) -> u8intrinsic function atomic_xor_u8(ptr: u8*, value: u8, order: u32) -> u8intrinsic function atomic_swap_u8(ptr: u8*, value: u8, order: u32) -> u8intrinsic function atomic_cmpxchg_u8( ptr: u8*, cmp: u8, new: u8, succ: u32, fail: u32, out_ok: boolean* ) -> u8(parameter) cmp: u8(parameter) new: u8(parameter) succ: u32(parameter) fail: u32(parameter) out_ok: boolean*intrinsic function fpclass(value: f64, test: i32) -> boolean(parameter) value: f64(parameter) test: i32intrinsic function fabs64(value: f64) -> f64intrinsic function fabs32(value: f32) -> f32(parameter) value: f32intrinsic function floor64(value: f64) -> f64intrinsic function ceil64(value: f64) -> f64intrinsic function ftrunc64(value: f64) -> f64intrinsic function round64(value: f64) -> f64intrinsic function copysign64(magnitude: f64, sign: f64) -> f64(parameter) magnitude: f64(parameter) sign: f64intrinsic function sqrt64(value: f64) -> f64intrinsic function sqrt32(value: f32) -> f32intrinsic function fma64(x: f64, y: f64, z: f64) -> f64(parameter) x: f64(parameter) y: f64(parameter) z: f64intrinsic function bswap16(value: u16) -> u16(parameter) value: u16intrinsic function popcount32(value: u32) -> u32(parameter) value: u32intrinsic function clz32(value: u32) -> u32intrinsic function ctz32(value: u32) -> u32intrinsic function rotl32(value: u32, n: u32) -> u32(parameter) n: u32intrinsic function rotr32(value: u32, n: u32) -> u32intrinsic function dirent_name(entry: void*) -> string(parameter) entry: void*intrinsic function dirent_type(entry: void*) -> i32intrinsic function va_arg_i32(args: void*) -> i32(parameter) args: void*type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct Location {
file: string;
line: u32;
column: u32;
function: string;
}A place in the source: the file as the build was given it, the line and column (both from 1), and the readable qualified name of the function the place is in. Made by the compiler, for location() and for the caller of a ![caller_location] function.
Location.file: stringLocation.line: u32Location.column: u32import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
type struct VaArgs {
ptr: void*;
}Single-pointer wrapper over the active va_list. ptr is the raw va_list pointer - the args identifier the compiler binds in a variadic body.
VaArgs::next<T>(&this) -> T
where T: VaArgRead the next variadic argument as T (one of the promoted scalar types), advancing the list. ![implicit] lets the type be recovered from the call's expected type, so const n: i64 = va.next(); works; va.next<i64>() is the explicit form.
sizeof(T)The size of a type in bytes, as a compile-time constant - usable in static_assert. alignof(T) gives the alignment.
alignof(T)The alignment of a type in bytes, as a compile-time constant - usable in static_assert. sizeof(T) gives the size.
intrinsic function panic(message: string, loc: Location) -> neverfunction panic(message: string, loc: intrinsics::Location) -> neverPanic with message, reporting the place loc: intrinsics::location() written at the call, or in a ![caller_location] function its caller's. The helpers below do that automatically.
intrinsic function location() -> Locationfunction at(arr: &Array<i32>, index: u64) -> i32Array element read without the Option ceremony; callers stay in range.
Location.file: stringLocation.line: u32Location.column: u32for (item in iterable) { ... }Separates the loop variable from the sequence in a for loop. The sequence is evaluated once; the loop lowers to loop { match (it.next()) { Some(x) => .., None => break } }.