Skip to content

Intrinsics

Reference compiler-lowered memory, layout, numeric, SIMD, and runtime primitives.

Updated View as Markdown

The intrinsics namespace declares operations recognized directly by the compiler or runtime. Most exist to implement the prelude and should not appear in ordinary application code.

Memory

Unsafe allocation operations include:

pointer := unsafe { intrinsics.alloc(size, alignment) }
resized := unsafe { intrinsics.realloc(pointer, old_size, new_size, alignment) }
unsafe { intrinsics.dealloc(resized, new_size, alignment) }

Typed load, store, and drop_in_place operate on ptr[T]. Retain and release helpers expose managed representation details and must not be used to guess ownership.

Allocation sizes and alignments are usize. The caller must pass the same layout contract to reallocation and deallocation that was used for allocation. Typed loads and stores still require an initialized, aligned range large enough for T.

mem_copy requires non-overlapping ranges. Use mem_move when source and destination can overlap. mem_fill writes a repeated byte pattern, not a typed default value.

Pointers

ptr_cast[F, T] changes an arena pointer’s pointee type. transmute[F, T] reinterprets bits between compiler-approved layouts. to_raw, raw_load, raw_store, raw_add, and raw_cast operate on absolute linear-memory pointers under stricter suspension rules.

Bulk raw memory uses mem_copy, mem_move, and mem_fill.

Arena-relative ptr[T] values participate in the compiler’s guest-memory model. rawptr[T] values are absolute WebAssembly addresses and have stricter escape and suspension restrictions. Conversion between the two is not an ownership transfer.

Layout

These queries fold after generic specialization:

size: usize = intrinsics.size_of[Packet]()
alignment: usize = intrinsics.align_of[Packet]()
offset: usize = intrinsics.offset_of[Packet]("payload")

row_fingerprint[T] supports typed dataframe result registration. is_rc_managed[T] exposes compiler representation classification to prelude implementations.

offset_of requires a real field of the specialized type. Layout results are backend ABI facts, not portable serialization formats. Do not persist a raw struct image and assume a later compiler version or another target will use the same layout.

Ownership

Low-level retain, release, clone, and drop operations exist for compiler and prelude implementations. They operate on representation-level ownership:

  • retaining creates another managed ownership claim;
  • releasing removes one claim and can recursively destroy children;
  • drop_in_place[T] drops a value at a known initialized location;
  • raw stores do not automatically express high-level replacement semantics.

Application code should rely on ordinary assignment, arguments, return values, and scoped cleanup. Manually mixing these intrinsics with compiler-generated ownership can leak, double-release, or use freed storage.

Numeric and SIMD

The namespace includes scalar numeric primitives and the WebAssembly v128 surface: lane splats, extraction/replacement, arithmetic, comparisons, shifts, bitwise operations, floating operations, and selected conversions.

These names mirror backend instructions rather than portable high-level algorithms. Wrap them behind a feature-appropriate API and provide a scalar path if the target contract requires one.

SIMD loads and stores use raw pointers and therefore require an unsafe region. Lane types, wrapping behavior, signedness, and conversion semantics follow the named WebAssembly instruction rather than the higher-level Numeric trait.

Runtime plumbing

Scheduler, task, stream, reference-count, and host-ABI intrinsics support standard-library implementation. Their handle encodings and frame offsets are not stable application interfaces.

Several runtime intrinsics are marked private in the prelude. Others remain name-resolvable because standard-library bodies need them, but that visibility does not make their ABI a supported user contract.

Portability

Before exposing an intrinsic through application code, decide which layer owns the dependency:

Need Preferred layer
Safe reusable operation Standard-library or project wrapper
Target-specific optimization Small tested unsafe module
Compiler representation query Compiler/prelude implementation
Host capability Typed @host adapter

Keep a scalar or typed fallback where possible. Tests should cover both the wrapper’s safe preconditions and the backend behavior it relies on.

Read Unsafe before calling any unsafe intrinsic. Passing the type checker is not proof that a low-level invariant is valid.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close