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
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