Skip to content

Function Declarations

Overview

Function declarations provide a name and signature for logic units. A bare function name used in an expression context evaluates to a function pointer value.

Syntax

function someFunction(a: int, b: int): int {
    return a + b;
}

extern function externalFunction(a: int): int;

^ function regionFunction(a: int): int {
    return a;
}

extern ^ function externalRegionFunction(a: int): int;

Rules

Parameter Types

All function parameters MUST be explicitly typed. Function parameters MUST NOT use raw struct value types.

Return Types

If the function returns a value, the return type MUST be explicitly specified. If the return type annotation is omitted, the function MUST return no value. Function return types MUST NOT use raw struct value types.

Visibility

The export qualifier MUST be supported for function declarations to make them visible to other compilation units. Functions without the export qualifier MUST NOT be externally linkable.

Extern Functions

The extern qualifier MUST be supported for function declarations. Function declarations with the extern qualifier MUST provide a name and signature without a body; a function body on an extern declaration MUST NOT be permitted. Linkage for extern functions is implementation-defined. Functions with the extern qualifier combined with the export qualifier to make them visible to other compilation units MUST be permitted.

Region-Qualified Functions

The ^ qualifier MUST be supported on function declarations to mark a region-qualified function. The canonical declaration order for an external region-qualified function MUST be extern ^ function. A region-qualified function MUST only be called when an active region context exists at the call site.

Region-Qualified Return Lifetime

A non-region-qualified function MUST NOT return a value that transitively contains an owned handle. Region-qualified return lifetime constraints are defined in the Region Scopes section of this specifcation.

When a function returns a value, the returned expression MUST be implicitly convertible to the declared return type using the same conversion rules as assignment.

Function Locality

Top-level function declarations MUST only appear at the top level of a compilation unit. Nested function declarations MUST NOT be permitted. Member functions declared inside struct definitions are permitted.

Function Uniqueness

Duplicate function names within the same compilation unit MUST NOT be permitted. Name uniqueness across compilation units is implementation-defined.