Expand description
Single source of truth for builtin function signatures used by the parser
and runtime VM: identifier resolution, typo suggestions, return-type
inference, static arity & per-arg type checks, runtime arity & type
enforcement, and lint awareness all consult the registry through the
lookup / is_builtin helpers.
§Architecture
Historically every builtin lived in two places — its implementation +
runtime registration in harn-vm/src/stdlib/*.rs, and a hand-written
BuiltinSignature literal under signatures/*.rs here in the parser.
Drift between the two was caught at test time but cost a 2-file tax per
new builtin.
That two-sided system has been replaced by the #[harn_builtin]
proc-macro (see harn-builtin-macros), which emits both the runtime
handler registration AND the parser BuiltinSignature from a single
annotated function. The vm crate aggregates them and installs them here
at driver startup via harn_builtin_registry::install_builtin_signatures.
During migration the legacy static signatures::groups() tables remain
as a fallback so unmigrated builtins still type-check. Lookups always
consult installed entries first and fall through to the static tables;
installed wins on name collisions. As modules port to #[harn_builtin]
their entries move out of the static tables into the macro-emitted
MODULE_BUILTINS slices. Once all signatures have migrated the static
tables are deleted.
Structs§
- Builtin
Metadata - Public view of one builtin used by
harn-lintand other crates that need just identifier + return-type hints (no parameter types). - Builtin
Signature - A complete, static description of one builtin: identifier, arity range, per-parameter types, generic type parameters, return type, and any where-clause bounds the type checker should enforce on call.
- Param
- One parameter slot inside a
BuiltinSignature. - Shape
Field Descriptor
Enums§
- Ty
const-friendly type IR used in builtin descriptors. Mirrors the runtimeTypeExprfromharn-parserbut is constructable inconstposition with no allocation. Convert toTypeExprat the boundary via the parser-sideTy::to_type_exprhelper.
Constants§
- TY_ANY
- TY_BOOL
- TY_
BYTES - TY_
BYTES_ OR_ NIL bytes | nil.- TY_
CLOSURE - TY_DICT
- TY_
DICT_ OR_ NIL dict | nil.- TY_
DURATION - TY_
FLOAT - TY_INT
- TY_
INT_ OR_ NIL int | nil.- TY_LIST
- TY_
NEVER - TY_NIL
- TY_
NUMBER int | float.- TY_
STRING - TY_
STRING_ OR_ NIL string | nil.
Traits§
- Builtin
Signature Ext - TyExt
- Parser-side extension methods on
TyandBuiltinSignaturethat depend on the parser’s owned AST types (kept out ofharn-builtin-metaso that crate stays dep-free).
Functions§
- builtin_
return_ type - Statically-known return type for
name, materialized as aTypeExpr. ReturnsNonefor unknown names AND for builtins whose return type is genuinely dynamic (Ty::Any). - install_
builtin_ signatures - Install the process-global signature registry. Called once by the driver
(CLI, LSP, lint, serve, dap) at startup. Test harnesses that build a Vm
via
harn_vm::stdlib::stdlib_probe_vm()inherit the install through that helper. - is_
builtin - Is
namea builtin known to the parser? - is_
untyped_ boundary_ source - Returns true if this builtin produces an untyped/opaque value that should be validated before field access in strict types mode.
- iter_
builtin_ metadata - Iterate over every builtin’s name and statically-known return-type
strings. Used by
harn-lintand other consumers that want a lightweight “what does this builtin return” view without bringing in the full type IR. - iter_
builtin_ names - Every builtin name. Installed names come first, then any static-only names that aren’t shadowed by installed entries. Output is NOT alphabetically sorted (callers that need that re-sort themselves).
- lookup
- Linear scan of the installed slice plus the static groups for a given
name. Installed entries win when both sides carry the same name (the
#[harn_builtin]-emitted signature shadows any legacy static duplicate). O(N+M) per call where N+M ≈ 600 — well below any typecheck hot path, and explicitly NOT cached so installs after the first call are picked up without leaking an old merged slice. - static_
signature_ names - Names that come only from the hand-written static fallback tables
(
signatures::groups()), independent of whatever the driver installed. - ty_
to_ type_ expr - Convert a const-IR
Tyinto the parser’s ownedTypeExpr. Generic references stay asNamed(name)so the checker’s existing scope-based generic-param resolution applies.