Skip to content

Events (Zero-Cost Multicast)

Events provide multicast subscription with static, allocation-aware lowering.

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,
  • event without {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.
  • += adds a handler.
  • -= removes a handler.
  • handlers must match event signature.

Invocation rule:

  • only the owning type implementation may invoke the event (this.EventName(...)).

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.

  • predictable bounded dispatch,
  • no hidden per-invocation heap allocation,
  • closure/lambda handlers respect capture non-escape constraints.

Compile-time diagnostics include:

  • capacity errors,
  • signature mismatch on subscription,
  • illegal invocation from non-owner scope,
  • unsupported escaping capture patterns.