Events (Zero-Cost Multicast)
Events provide multicast subscription with static, allocation-aware lowering.
16.1 Declaration form
Section titled “16.1 Declaration form”Events are declared as type fields with an optional inline capacity.
type Window { event{4} OnResize(i32 width, i32 height) event OnFocus()}Rules:
event{N}uses explicit compile-time positive capacity,eventwithout{N}uses the default event capacity,- event signature is declared as parameter list after the event name,
- event members are part of type layout via lowering expansion.
16.2 Subscription model
Section titled “16.2 Subscription model”+=adds a handler.-=removes a handler.- handlers must match event signature.
Invocation rule:
- only the owning type implementation may invoke the event (
this.EventName(...)).
16.3 Lowering contract
Section titled “16.3 Lowering contract”Events do not lower to a general-purpose runtime event object. They lower to structural fields in HIR/type layout:
__<EventName>_count__<EventName>_handlers: [FatPointer; N]
Invocation lowers to static conditional dispatch up to N.
16.4 Performance and safety goals
Section titled “16.4 Performance and safety goals”- predictable bounded dispatch,
- no hidden per-invocation heap allocation,
- closure/lambda handlers respect capture non-escape constraints.
16.5 Diagnostics
Section titled “16.5 Diagnostics”Compile-time diagnostics include:
- capacity errors,
- signature mismatch on subscription,
- illegal invocation from non-owner scope,
- unsupported escaping capture patterns.