5.1.25. Annotations and Options
This tutorial covers function and struct annotations, and compiler options that control lint, safety, and optimization.
5.1.25.1. Function annotations
Annotations are placed in [ ] before the function definition:
[export]
def main { ... }
[sideeffects]
def log(msg : string) { print(msg) }
[unused_argument(y)]
def use_only_x(x, y : int) : int { return x * 2 }
Common function annotations:
[export]— callable from host application[sideeffects]— has side effects, won’t be eliminated[init]— runs at context initialization[finalize]— runs at context shutdown[deprecated(message="...")]— produces warning on use[unused_argument(x)]— suppress unused arg lint[unsafe_operation]— calling requiresunsafeblock[no_aot]— disable AOT for this function[jit]— request JIT compilation
5.1.25.2. Combining annotations
Separate multiple annotations with commas:
[export, sideeffects]
def annotated_func() { ... }
5.1.25.3. Struct annotations
[safe_when_uninitialized]— zero-filled memory is valid[cpp_layout]— C++ struct alignment[persistent]— survives context reset
5.1.25.4. Private functions
Use the private keyword:
def private helper() : string {
return "module-private"
}
5.1.25.5. Compiler options
Set at the top of a file:
options gen2
options no_unused_function_arguments
options stack = 32768
Key options:
Option |
Description |
|---|---|
|
Enable gen2 syntax |
|
Unused args become errors |
|
Strict smart pointer checks (default: on) |
|
Disallow module-level globals |
|
|
|
Stack size in bytes |
|
Disable AOT for module |
|
Enable/disable all lint checks |
|
Deprecated usage becomes error |
See also
Annotations, Options in the language reference.
Full source: tutorials/language/25_annotations_and_options.das
Next tutorial: Contracts