Skip to main content

Crate gruel_intrinsics

Crate gruel_intrinsics 

Source
Expand description

Declarative registry of Gruel’s @intrinsic set.

This crate is the single source of truth for every intrinsic the compiler recognizes. Each intrinsic is described by an IntrinsicDef value; the full list lives in INTRINSICS. Compiler stages (RIR astgen, Sema, codegen) consult the registry instead of carrying their own name lists, and the website’s intrinsic reference page is generated from the same data.

Behavior (semantic analyzers, codegen arms) still lives in the consumer crates — the registry owns metadata and identity, not per-intrinsic logic. Stages dispatch on the stable IntrinsicId enum rather than matching strings.

§What earns a place in this registry

ADR-0087 commits to the rule: intrinsics carry compiler magic, not transport. A row earns its place in IntrinsicId / INTRINSICS if it does at least one of:

  1. Codegen-emitted lowering of a language feature (e.g. @vec(...) constructs a Vec(T) aggregate; pointer ops emit a typed load / store; @spawn synthesises a @mark(c) thunk per (arg, ret, fn) triple).
  2. Compile-time type / kind dispatch on heterogeneous arguments (e.g. @dbg(42, true, "hi") routes per arg type; @type_info(T)).
  3. Compile-time evaluation with no runtime presence (e.g. @size_of, @align_of, @target_arch, @compile_error).
  4. A row is blocked on a missing language feature that would otherwise let it move to the prelude (ADR-0087 currently tracks four such rows — @panic family, @spawn / @thread_join, @cstr_to_vec, @dbg — each with a documented prerequisite).

Rows that exist only because “there is a libc function we want to call” and have an expressible Gruel signature today do NOT belong here. ADR-0087 migrated the original wave of those rows (@read_line, @parse_*, @random_*, @utf8_validate, @bytes_eq, @alloc / @free / @realloc) to prelude fns in prelude/runtime_wrappers.gruel; future additions of similar shape should land there first.

See ADR-0050 and ADR-0087.

Structs§

IntrinsicDef
Metadata for one intrinsic. Instances live as const entries in INTRINSICS; nothing in this type is runtime-mutable.
PointerMethod
One method or associated function on Ptr(T) / MutPtr(T) (ADR-0063).
SliceMethod
One method on Slice(T) / MutSlice(T) (ADR-0064).

Enums§

Category
High-level grouping used when rendering the documentation reference page.
IntrinsicId
Stable identity for every intrinsic. Stages dispatch on this rather than comparing strings, so adding an intrinsic requires updating a closed match in each consumer — the compiler enforces coverage.
IntrinsicKind
Whether an intrinsic takes an expression argument list (the common case) or a type argument (@size_of(T), @type_info(T), etc.).
PointerKind
Which builtin pointer constructor an entry is defined on.
PointerOpForm
Whether an entry is an instance method or an associated function.
SliceKind
Which builtin slice constructor an entry is defined on.

Constants§

INTRINSICS
The canonical list of every intrinsic the compiler recognizes.
POINTER_METHODS
Closed registry of every pointer method / associated function (ADR-0063).
SLICE_METHODS
Closed registry of every slice method (ADR-0064).

Functions§

by_category
Iterate over intrinsics in a single category.
is_type_intrinsic
Is this name a type intrinsic (takes a type arg, as @size_of(T) does)?
iter
Iterate over every registered intrinsic.
lookup_by_id
Look up an intrinsic by its stable IntrinsicId.
lookup_by_name
Look up an intrinsic by its source-level name (without the leading @).
lookup_pointer_method
Look up a pointer method/assoc fn by (kind, name, form).
lookup_slice_method
Look up a slice method by (kind, name).
render_reference_markdown
Render the full intrinsics reference page as markdown.