LEGACY DOCS · 12.0Stable is 13.2. This page stays because it still owns historical or unchanged contracts.CURRENT 13.2 →
RELEASE LINE13.2 STABLE13.1 PREDECESSOR13.0 PREVIOUS12.4 NATIVE MIRARCHIVE

V12.0 BASE CONTRACT

Defer

Structured defer runs LIFO on fallthrough, return, break, continue, and Result propagation.

DByte 12.0 · Language

Contract§

static mut CLEANED: u32

fn compute() -> int:
    let marker: u32 = 1 as u32
    defer [borrow marker]:
        CLEANED = marker
    return 42

pub fn kernel_main() -> int:
    if compute() != 42:
        return 1
    if CLEANED != (1 as u32):
        return 1
    return 0

Source: source-examples/v12.0.0/defer.dby

static mut CLEANED: u32

fn compute() -> int:
    let marker: u32 = 1 as u32
    defer [borrow marker]:
        CLEANED = marker
    return 42

pub fn kernel_main() -> int:
    if compute() != 42:
        return 1
    if CLEANED != (1 as u32):
        return 1
    return 0
DBY · 274 BSHA-256 b0ad207646ea6e5b69443ea335b295a62f1ee45d14f30e551904c77b22dbbd7f

Mechanics§

defer is a structured lexical block whose captures are established at registration. Canonical HIR emits cleanup blocks in reverse registration order for fallthrough, return, break, continue and Result propagation.

Validation and failure§

Move captures move immediately and borrow captures remain live until execution. There is no runtime defer stack, unwinder or exception path.

Evidence and boundary§

Tests assert LIFO order for every exit class and native proof observes cleanup on success and propagated error.

Executable example§

static mut CLEANED: u32

fn compute() -> int:
    let marker: u32 = 1 as u32
    defer [borrow marker]:
        CLEANED = marker
    return 42

pub fn kernel_main() -> int:
    if compute() != 42:
        return 1
    if CLEANED != (1 as u32):
        return 1
    return 0

WEBSITE V12 FIXTURE