0007. Observational immutability with scoped arenas
- Status: Accepted
- Date: 2026-10-29
- Plan: M4.2, M5.1–M5.8
- Review: Memory and representation
Context
Immutable values make programs easier for models and tools to reason about, and make replay and parallelism safe. Naive immutability copies too much; a tracing garbage collector costs latency, memory and startup time.
Decision
- Values are immutable as far as programs can observe. The implementation may mutate storage it can prove unshared: builders sealed into values, in-place reuse of unique values, destination passing.
- Memory comes from arenas with scopes: a scratch arena per loop iteration and per agent transition, request and persistent lifetimes, and promotion of values that survive into carry state.
- Guarantees, not best efforts: destination passing for returned records and vectors, and amortized O(1) appends to a uniquely owned carry accumulator.
- No tracing GC. Reference counting with reuse is allowed only
for large persistent values, and only if the
perceus-rcexperiment shows it pays. - Checked
i64is the default integer; wrapping arithmetic is explicit.
Alternatives considered
- Tracing GC — simplest for users; startup, pauses and memory overhead conflict with the CLI and agent-density goals.
- Ownership and borrowing in the source language — fast, but a large concept models handle less reliably.
- Persistent data structures everywhere — pays for sharing most values never need.
Consequences
Escape analysis and promotion reports become compiler features (M5.2). Patterns that rely on long-lived shared mutable state use tables and typed IDs instead.