Callable Types
A callable type holds a function value — anything from a bare static function pointer up to a stored target slot with a GC-tracked receiver. The full taxonomy uses one uniform spelling: R(P,...) plus a modifier and an optional this: parameter to control storage.
Type Variants
| Syntax | Storage | Description |
|---|---|---|
R(A,...) | 8 B | Bare function pointer to a statically alive function |
R(A,...)* | 8 B | Raw function pointer, nullable (e.g., FFI symbol) |
R(A,...)& | 8 B | Raw function pointer, non-null |
R(A,...)? | 8 B | GC reference to a heap closure, nullable |
R(A,...)! | 8 B | GC reference to a heap closure, non-null |
R(A,...)<N> | N B | Inline closure — thunk + env + (N − 16) bytes of captures |
R(ref T, A...) | 8 B | Unbound member fnptr — caller passes the receiver T explicitly |
R(this, A...) | 8 B | Type-body sugar — receiver auto-supplied via field access |
R(this: T*, A...) | 16 B | Stored target slot, raw pointer to T (nullable) |
R(this: T&, A...) | 16 B | Stored target slot, raw pointer to T (non-null) |
R(this: T?, A...) | 16 B | Stored target slot, GC ref to T (nullable) |
R(this: T!, A...) | 16 B | Stored target slot, GC ref to T (non-null) |
R(this: T, A...) | 8 B + sizeof(T) | Stored target slot, T inline |
R(this: */&/?/!, A...) | 16 B | Open target slot — any receiver type |
Function Pointers vs Closures
The trailing modifier is what picks the storage model:
- No modifier,
*,&are raw function pointer slots — no closure object, no GC. Just an 8-byte address.*is nullable,&is non-null, bareR(A,...)is for statically-known functions. ?and!are GC references to a heap closure. Assigning a lambda or a bound method allocates a closure on the GC heap and stores the reference.<N>is an inline closure — the closure thunk + env + captured bytes live directly inside the field, no allocation.Nis the total byte budget (16 bytes of header + the rest for captures).
type EventBus{ int(int, int) onStatic; // 8B, bare fnptr int(int)* handlerRaw; // 8B, raw fnptr nullable int(int)& handlerSafe; // 8B, raw fnptr non-null int(int)<32> onEventInline; // 32B inline closure int(int)? onEventGc; // 8B GC ref to closure}Free Functions and Static Methods
Assign by name. The function must be statically alive:
int DoubleIt(int x) x * 2;
int(int) op = DoubleIt;int r = op(21); // 42Bound Methods
A method reference without parentheses binds it to the receiver. Assigning to a ?/! slot allocates a heap closure that captures the receiver:
type Counter{ int value; int Get() this.value; int Add(int x) this.value + x;}
Counter? c = new Counter();c.value = 42;
int()? bound = c.Get; // GC closure capturing `c`int(int)? add = c.Add;int v = bound(); // 42int s = add(10); // 52Lambdas
Lambdas are valid for ? / ! (heap closure) and <N> (inline closure) slots:
int captured = 10;
// Inline closure — must declare the byte budgetint(int)<32> inlineAdd = (int x) => x + captured;
// GC closureint(int)? gcAdd = (int x) => x + captured;A <N> slot rejects lambdas / bound methods / new constructions today (no IL primitive yet to construct a closure body directly into inline storage); use a GC variant (? / !) when you need captures with no allocation guarantee.
Receiver / Target Slots
The this: form gives a callable field its own receiver. The modifier on T picks the storage shape — same ?/!/*/& semantics as any other field:
type Subscription{ void(this: Listener!, int code) handler; // 16B, GC ref to Listener}
void Wire(Subscription sub, Listener l){ sub.handler = l.OnEvent; // bound to `l` sub.handler(42); // dispatches as l.OnEvent(42)}The bare R(this, ...) form (no modifier, no : T) is type-body only. It declares “this field is a method-shaped fnptr; the receiver is the surrounding object”:
type Renderer{ int frameId; void(this, int dt) tick; // method-shaped, no stored target
void Render() { this.tick(16); } // lowers to tick(this, 16)}R(ref T, ...) is the general unbound-member fnptr form and is valid anywhere — the caller writes the receiver at every call.
No Auto-Stub Initialization
Callable fields start zero-initialized (null). Calling an unassigned non-null variant traps on null at dispatch — there is no auto-generated default stub. Assign in the constructor, or before first call.
Cross-Assembly
CallableKind (Static / RawFnPtr / RawFnPtrNonNull / GCClosureNullable / GCClosureNonNull / ThisAuto / ref-T / target-slot variants) and the receiver type both round-trip through the .asm FunctionTypeInfo blob, so callable-typed fields and parameters survive an export/import cycle with their dispatch shape intact.