Attributes Reference
Declaration attributes currently recognized by analysis and tests.
Attributes are written with @name or @name(args...) before declarations.
The current language has a closed attribute table: unknown source attributes
are rejected, and user-defined decorators are not part of 0.0.0-dev.
@deprecated("use new_fn instead")
fn old_fn() {}
@discardable
fn side_effect() -> i32 {
return 42;
}
| Attribute | Allowed targets | Arguments | Effect |
|---|---|---|---|
@export / export | Top-level declarations and globals | none | Exports the declaration from the module interface. See Visibility and Privacy. |
@extern / extern | Top-level functions and globals | none | Declares a Zynx-linkage symbol whose body is provided by another object or module unit. |
foreign | Top-level functions and globals | ABI string; optional library block | Declares a non-Zynx ABI symbol. Only foreign "C" and foreign library "name" { abi "C"; ... } are accepted in 0.0.0-dev. |
@symbol | foreign declarations | one string literal | Uses the named foreign symbol while keeping the Zynx declaration name local. |
@intrinsic / intrinsic | Functions and methods | none | Marks a compiler/runtime intrinsic declaration. Normal source cannot define new intrinsic behavior. |
@inline | Functions and methods | none | Codegen inline hint. Rejected with external declarations. |
@discardable | Functions and methods | none | Suppresses ignored-result warnings for calls. |
@deprecated | Functions and methods | optional string literal | Emits a deprecation warning on calls. |
@weak | Functions and methods | none | Emits weak linkage for generated definitions. |
@section | Functions and methods | one string literal | Places the generated function in an object section. |
@noreturn | Functions and methods returning void | none | Marks the generated function as not returning. |
@unmangled | Functions, methods, and globals | none | Uses the source name as the emitted symbol name. |
@packed | Structs and unions | none | Uses packed source-order layout. Rejected with @strict. |
@strict | Structs and unions | none | Uses source-order layout with target ABI alignment and padding. Rejected with @packed. |
@native | Structs, unions, enums, and errors | none | Declares C-compatible aggregate or enum layout where supported by FFI rules. |
@c_name | Structs, unions, enums, errors, and globals | one string literal | Records the C spelling used by bindgen/header emission. |
@private | Struct fields and methods | none | Applies the private field and method rules from Visibility and Privacy. |
@readonly | Struct fields | none | Rejects assignment to the field after initialization. |
@bits | Fields of @native struct | one integer literal | Declares a native bitfield width. |
@derive(json) | Structs | json | Enables typed std.json.decode<T> support for the struct. |
@json_allow_unknown | Structs with @derive(json) | none | Allows typed JSON decoding to ignore object fields that do not map to struct fields. |
@json_key | Fields of structs with @derive(json) | one string literal | Uses the named JSON object key for the field. |
@json_optional | Fields of structs with @derive(json) | none | Allows the field to be absent and keeps the field default. |
@json_skip | Fields of structs with @derive(json) | none | Ignores the field during typed JSON decoding. |
@suppress | Locals and declarations | warning names | Suppresses supported warning kinds for that declaration. |
@unused | Local bindings | none | Marks the binding as intentionally unused. |
@abi | Top-level declarations and methods | one string literal | Includes a declaration only for a matching target ABI. |
@arch | Top-level declarations and methods | one string literal | Includes a declaration only for a matching target architecture. |
@platform | Top-level declarations and methods | one string literal | Includes a declaration only for a matching target platform. |
Attribute validity depends on declaration kind and modifier ordering. The
compiler reports duplicate or misplaced attributes. Duplicate attributes are
rejected except for repeated @suppress(...).
export, extern, and intrinsic can also be parsed as declaration modifiers;
the parser represents them internally as synthesized attributes. foreign is a
separate declaration form for non-Zynx ABI boundaries.
Methods without a first self parameter are static methods. The old @static
method attribute is not part of the current source surface.
Names beginning with __zynx_ are reserved for compiler-private generated code
and are not a stable user extension mechanism.
LLVM hooks such as @llvm.memcpy and @llvm.uadd.with.overflow are compiler
builtins used in expressions, not declaration attributes.