Visibility
Two declaration modifiers control how a symbol is seen: pub decides what crosses a module boundary, and ext declares a body-less function resolved at link time.
The pub modifier
pub marks a declaration as part of its module's public surface. Other modules that use this module can reference pub-marked symbols by name. A declaration without pub is file-private: only code in the same file can see it.
pub fun add(a: i64, b: i64) i64 { ret a + b; }
fun helper() { ... } # private: only callable inside this file
pub rec Point { x: i64; y: i64; }
pub val MAX: i64 = 100;
The modifier applies to declarations: fun, rec, uni, def, val, var, and ext fun.
fwd always publishes and does not take an explicit pub modifier.
External functions with ext
ext declares a function with the C ABI as a forward reference: it has no body, and the linker resolves the symbol at link time. Only functions can be ext.
#[symbol("write")]
pub ext fun libc_write(fd: i64, buf: *u8, n: i64) i64;
ext fundeclarations have no body.- The C ABI is the contract: argument and return types must be representable in C.
Overriding the linker name
By default the linker looks up the declared name. The #[symbol("real_name")] decorator overrides it, binding the declaration to a different external symbol.
There are no body-less functions outside of ext fun. Regular forward declarations do not exist.
See also
- Functions - regular function declarations
- Modules - how
usereaches public symbols - Decorators -
#[symbol]and other attributes