Scope Lifetimes and Affine Use
Every execution of a function, block, or callable body is a lifetime unit. This is the development implementation following v0.1.0; installing v0.1.0 alone does not provide these new guarantees.
Temporary Data and Returned Data
Temporary allocations end with the execution that created them. A returned value survives in the enclosing execution, including its nested strings, records, lists, arrays, variants, and closure captures. Data passed in from an outer execution retains its existing storage lifetime.
fun make_message: () -> String = {
val temporary = [1, 2, 3];
temporary |> list_count;
"scope" + " result"
}
fun main: () -> Boolean = {
val message = () make_message;
message == "scope result"
}
The temporary list ends with make_message; the returned text remains valid
in main. Ordinary blocks and with Arena use the same rule:
fun make_values: () -> List<Int32> = {
with Arena { [1, 2, 3] }
}
No explicit arena or lifetime annotation is needed for ordinary values. The compiler shares physical storage between scopes and reclaims temporary data at exit. A fixed arena is not reserved for every pair of braces.
Invocation, Definition, and Repetition
Defining a lambda stores its captures; it does not execute its body. Each call
has its own lifetime, including recursive calls and repeated map callbacks.
A returned closure preserves its captured data until the enclosing execution
ends. Scope chaining passes a valid result to the next scope.
Each while iteration and fold reduction reclaims obsolete replacement
state. Assigning a new heap value to an enclosing mut val preserves the new
value; repeated replacements do not retain every previous allocation.
The same preservation applies to a new heap-backed element stored in an outer
array, including arrays reached through enclosing records.
A growing live value still uses growing storage and can exhaust the arena.
Affine Use Is A Separate Rule
Affine checking controls how often a binding may be used. It does not determine which executing scope retains storage. Primitive Copy bindings can be read again; ordinary immutable affine bindings can be referenced at most once. Mutable bindings keep their existing reassignment rules.
This change does not introduce Rust ownership, borrowing rules, or user-written
lifetime annotations. Component Model own and borrow remain host ABI
contracts, with their existing synchronous resource cleanup rules.
Runtime Limits
The current backend compacts reachable new data at scope exit using bounded, reusable scratch storage. It conservatively keeps active enclosing bindings until their containing scope ends; it does not promise reclamation after the last expression that uses a binding. Internal addresses may change and must not be retained by hosts. Use the explicit Component ABI for composite values.
An uncaught Wasm trap skips normal epilogues. Inspect diagnostics and discard
the instance. Result::Err is an ordinary value and receives normal cleanup.
return, break, continue, and ?? return/?? break/?? continue reclaim
the scope they leave before they branch: return keeps only its value, and
continue and break keep only what outlives the loop. Postfix ?, async
suspension, and cancellation are future features.
Experimental TAT constraints remain separate. Ordinary values in a temporal block use the same lifetime rule, but the old experimental File/Database/ Transaction cleanup stubs fail closed: they are not validated host resource destruction. Synchronous B1 resources continue through their Component adapters.