Contents

The compiler identifies values that need tracing, emits root maps at collection points, and lets the runtime reclaim unreachable objects. There is no manual free, reference counting, or lifetime parameters.

Managed and Unmanaged Values#

Category Types Management
Managed List[T], bytes, records, sum types, Option, Result, closures, ptr Traced by the collector; ptr is traced as a root but its pointee is not
Runtime-owned text str Immutable; storage is owned by the runtime; not reclaimed by the collector
Unmanaged scalar Integers, f64, bool, rune, enums Copied by value
Foreign cstr, extern records C representation; not traced; lifetime is the program's responsibility

A managed record cannot be stored in an extern record or passed as an opaque pointer and expected to remain valid.

Reference Semantics#

A managed value is represented by a reference. Assignment copies the reference, not the object. Field and element mutation is visible through every binding referring to the same object.

type Point {
    x i32
    y i32
}

var first = Point { x = 1, y = 2 }
var second = first
second.x = 9
print(first.x)       // 9

Reassigning a binding does not affect another binding.

var values = [1, 2]
var alias = values
alias[0] = 9
print(values[0])     // 9

alias = [7, 8]
print(values[0])     // 9

Lists and byte buffers may reuse capacity when they grow. An append through one binding can be visible through another, or the bindings can diverge after reallocation. Treat a mutable collection as shared state unless only one binding reaches it.

Allocation#

A list literal allocates a list object with length and capacity equal to the number of elements. Record construction allocates a record object with fields initialized before publication. A sum constructor allocates a tagged object, and Option and Result constructors allocate small tagged objects. A closure allocates a closure object containing a function pointer and captured values.

Lists grow by allocating a larger buffer or using spare capacity. + always produces a new list; += may reuse existing storage. Element assignment mutates existing storage.

Roots#

The compiler emits a root frame for every function with managed locals, parameters, a managed return value, or captures. The frame contains a descriptor and the addresses of managed slots. The runtime walks the frames of every attached thread when marking.

A closure keeps captured managed values reachable through the closure object. A local variable keeps a managed value reachable until its scope ends. Managed module constants should be immutable and few.

Collection#

The runtime is a precise tracing collector. Collection is triggered by allocation pressure and by polls at function entry and loop back edges. A collection marks reachable objects from the roots, then sweeps unreachable storage. The repository's design specification describes the intended Immix mark-region collector; the current runtime implements a parallel mark-and-sweep subset. A managed value remains valid while reachable; the program does not control when reclamation happens.

There are no finalizers, weak references, or prompt reclamation. Do not use memory pressure or destructor timing as part of a program's semantics.

Cycles#

Reclamation is tracing, not reference counting. A cycle of managed values is reclaimed when no root reaches the cycle. The language does not expose a way to break a cycle manually and does not provide weak references.

FFI Boundary#

String concatenation and slicing create immutable runtime-owned storage that is not part of the traced heap.

A cstr points to unmanaged memory. A ptr is an opaque address. An extern record has C layout and is copied by value. None carries a Haze lifetime, and the collector does not trace through them.

A managed value should not be passed to C as an opaque pointer unless the runtime explicitly supports it. The supported bridge types are cstr, bytes::ptr, and extern records. Foreign code must not retain a pointer beyond the call unless the pointee is kept valid. See Extern and C FFI.

Errors and Unwinding#

A failed checked construction returns an Error from the enclosing function. Scopes between the construction and the return are exited, and their defers run. Values that were live in those scopes become unreachable according to ordinary scope rules.

A runtime contract failure or assertion failure aborts. The runtime does not run Haze defers during a panic.

Release Mode#

-release removes runtime contract and invariant checks. It does not remove index bounds checks, allocation, root tracking, or collection.

An out-of-range index aborts even in a release build.

Concurrency#

The runtime supports multiple mutators and parallel collection for embedding and runtime tests. The language has no thread, async, or synchronization syntax. A Haze program can use operating-system processes through the standard library but cannot spawn a Haze thread. Do not assume a managed value is safe to share across threads unless the embedding layer provides a synchronization protocol.

Rules#

Rule Reason
Prefer new values to shared mutation Contracts describe arguments and results, not hidden aliasing
Do not mutate a parameter unless it is the API's purpose A postcondition sees the final parameter value
Do not retain a cstr or raw ptr without a documented owner The collector does not know the foreign lifetime
Do not store managed values in extern records C layout cannot describe a traced reference
Avoid long-lived cycles unless the domain requires them Reclamation depends on tracing the graph
Do not depend on collection timing Reclamation is not prompt and has no finalizer guarantee
Keep release builds verified -release removes contract and invariant checks