Stories: Memory Model
See also:
spec/memory.md— the rules this story explains.
Safety without a collector and without lifetimes
The starting commitment was a subtraction, not an addition: no tracing garbage collector, and no lifetime annotations. Those are the two roads the rest of the industry took to memory safety, and Zane wanted neither. A collector buys safety by handing the mechanism to a runtime — the managed-altitude cost the foundations story argues against — and pays for it with pauses, headroom, and a non-deterministic moment of death that makes destruction unpredictable. Lifetime annotations, the Rust road, keep determinism but make the programmer carry the proof: a borrow checker that forbids whole patterns and a 'a vocabulary the source has to speak fluently to compile. We turned both down at once, which sounds like wanting the impossible — safety with neither a runtime watching nor a proof obligation on the author.
The position stays coherent because it keeps the half of Rust’s model that costs nothing in annotations — single ownership and deterministic, scope-driven destruction — and we refused only the half that does. Every class instance has one owner (§2.1); when its scope drains it dies, with no collector consulted. That gets determinism for free. The hard part is the other kind of storage — the non-owning reference, & — because that is exactly where Rust spends its annotation budget and its borrow checker. The bet was that a reference’s safety could be made to fall out of the shape of storage and ordinary lexical scope, rather than out of a separate analysis the author feeds. “Safety from shape” was never the goal in itself; it is what is left over once you refuse both a collector and a lifetime vocabulary. Some mechanism still has to make refs safe, and if it is not a runtime and not an annotation, it has to be the structure of the storage forms themselves. The cost of that stance is real, and the rest of this story is mostly the working-out of it: to refuse the borrow checker is to refuse the mechanism that, in Rust, makes the move problem go away by fiat — and so the move problem becomes ours to solve.
The move problem, and the anchor that never moves
That problem surfaces the instant the two halves meet. Single ownership needs to move values — transfer ownership into a return slot, an outer scope, a container — and needs owners to be overwritable in place (§2.2). A non-owning ref, naively, is the value’s address. Put those together and you have the classic dangling reference: the ref records an address, the value moves, the address is now stale. This is precisely the situation a borrow checker exists to outlaw — it forbids the move while a borrow is live — and forbidding the move is the ergonomic price we had just refused to pay. So the requirement stated itself plainly: a ref has to keep pointing at the same value even when that value moves.
The move forces the question, but the move also hands over the answer, because the compiler itself does the moving — at the moment a value relocates, the compiler knows both where it was and where it now is. The trick is to interpose one level of indirection that itself never moves: a small fixed cell, reachable with confidence at all times, that holds the value’s current location. A ref points at that cell; the cell points at the value. Now a move is a one-line update — the compiler writes the value’s new location into the cell it was always going to touch anyway — and every ref, reading through the cell on its next use, sees the new home with no fixup of its own. The cell earned its name: it is the fixed point a drifting value is tethered to, the anchor. The same single mechanism dissolves three superficially different hazards at once — a move, an in-place owner overwrite, and the readability of a moved-from symbol (which simply downgrades to a ref through the same cell) — because all three are just “the value is somewhere else now,” and the anchor is the one place that fact has to be recorded.
The road not taken here is the obvious road: instead of indirecting through a cell, fix up the refs directly — on a move, walk every ref that points at the value and rewrite it. That keeps the deref one hop shorter, but it forces the owner to enumerate its refs, which requires carrying a list of them and paying O(number of refs) on every move and every overwrite. The anchor inverts that cost: the owner records one link (to its anchor), the move touches one cell, and the count of refs never enters the arithmetic — moves and overwrites are O(1) in the number of refs by construction (§4.5). The honest cost lands on the read side, and it is permanent: every dereference through a ref pays one extra dependent load — the cell read sitting between the ref and the value — that a raw pointer would not. We judged a fixed one-load tax on reads a better trade than an unbounded fixup cost on moves, especially since the common case is a value read through a ref far more often than it is moved. That single dependent load, multiplied across the layered dereferencing the design invites, is the pressure that later forces every link to be small (the indexed table).
Finding the anchor, and not paying when there are no refs
The anchor solves the move, but it raises two of its own. When a value moves, the compiler has to find that value’s anchor in order to update it — so the value needs a path back to its cell. And if every value carried an anchor whether or not anything ever referenced it, we would be charging the whole program for a feature most values never use. Both are answered by giving each value a backpointer: a single small field that records where its anchor lives (§4.2). A move reads the backpointer, finds the cell, updates it — done. And because the backpointer can hold a sentinel for “no anchor exists yet,” the anchor need not exist until the first ref is actually taken: an unreferenced value keeps its backpointer at the sentinel and consumes no cell at all, while the first & lazily mints the anchor and records it (§4.3). The vast majority of values, which are never referenced, pay only for the one backpointer field they carry and nothing more.
It matters that the backpointer is a single link and not a list. The temptation, once a value points back at its anchor, is to let it point back at all its refs — but that is the O(n)-move design from the previous chapter wearing a different hat. One backpointer is exactly enough: it lets a move locate the cell, and it lets the owner mint fresh refs by copying its anchor’s identity, without the owner ever once enumerating who points at it. The asymmetry is deliberate — an owner knows about its anchor, never about its refs — and it is the whole reason the move stays O(1).
From a reserved pool to an indexed heap table
Anchors need a home, and the first home was the lazy choice: a fixed region of memory set aside at startup just for anchor cells. It worked, and it bothered us for two reasons that turned out to be the same reason. A fixed region imposes a fixed cap — why should a program be allowed only so many simultaneously-referenced values? — and in the common case where few values are referenced, that reserved space sits mostly empty, paid for and unused. Both are the symptom of pinning anchor storage to a size guessed ahead of time. The fix was to stop treating anchors as special and store them the way any dynamically-sized data is stored: in a growable structure on the heap. That collapses the cap (it grows on demand) and the waste (it is only as big as the live anchors need) together. What remains fixed shrinks to a single master anchor — one word at a known location that records where the anchor table currently lives (§3.1) — so that when the table relocates to grow, exactly one word is rewritten and no ref or backpointer is disturbed.
Putting the table on the heap forces the last move, and it shapes the whole layout: once the table can relocate, a backpointer or a ref can no longer be a raw address into it — it has to be an index, a position in the table that survives the table moving underneath it. So refs and backpointers stop being pointers and become indices (§4.2). That sounds like a concession, but it is where the design pays itself back, because an index can be small. The reason to care is cache locality, and cache locality is unusually load-bearing here: the anchor scheme already committed us to layered dereferencing — ref to cell, cell to owner, owner to field, often several such hops per logical access — and the cost of all that indirection is dominated by whether the links it walks are sitting in cache. So the design generalizes the index into a single discipline: the runtime owns one contiguous region, and every location inside it is a u32 offset from one register-held base rather than a native pointer. A ref, a backpointer, an anchor cell, and the master anchor are all u32 — half the width of a 64-bit pointer — so twice as many of them fit in a cache line, and the hot anchor table stays resident. The extra dependent load the anchor scheme imposed is made cheap precisely by making the loaded cell small. The cost is a ceiling: a u32 caps the program at roughly four billion live anchors and the region at a few gigabytes (stretched by alignment-scaled offsets). We took the ceiling without much hesitation — it sits far past any realistic working set — in exchange for halving the size of the most-walked links in the language.
Where a new ref may come from
A ref that always resolves through an anchor is only safe if it never gets created pointing at an object that has no stable anchor to begin with. So the other half of the model is a restriction on where a new & may be born: only from storage that denotes a real, stable, owner-rooted place — a named symbol, a field of a place, or an & parameter (§2.8). A temporary — the result of Engine() or makeEngine() — is rejected as a source, because it has no home for an anchor to track; it exists only for the instant of the expression, and a ref to it would be a ref to nothing the moment the statement ends. The owner form materializes such a temporary into stable storage; the ref form cannot, because there is nothing to make stable.
The subtlest case, and the case that looks arbitrary until you see what forces it, is that a subscript [] may never create a new &, even though it can read one that is already stored. The reason is dynamic size. Take a ref to the last element of a list and then pop that element: the element is gone, but the ref would remain, now pointing at a slot the container has reclaimed — a dangling ref minted entirely within the safe language. The container’s own operations move and drop elements as it grows and shrinks, and an & carved out of an owned element would have no anchor relationship strong enough to survive that. So the language forbids minting an & from an owned element in the first place; what weapons[1] may yield is an & only when an & was already stored there, a value the container holds rather than an interior pointer the container hands out. That keeps element references stable by never letting them come into existence on unstable ground, rather than by trying to track and invalidate them after the fact — the tracking road is exactly the per-element bookkeeping the whole model is built to avoid.
The same rooted-source idea runs through parameters, but with a twist that protects the call site. A parameter declared &T demands that the caller hand over a real place; a plain T parameter does not, and therefore must not be re-exported as a new & from inside the callee (§2.9). The point of splitting the two is to keep the call uniform: consume(e) and inspect(e) read identically, and it is the signature, not the syntax at the call, that determines whether an &-rootable source is required. We considered letting the caller’s punctuation carry that distinction and rejected it for the same reason the rest of the language pushes such facts into declarations — the obligation belongs to the function’s contract, not to a decoration the caller has to remember. A related small rule rounds this out: every symbol must be initialized at its declaration (§2.11). Once owners are freely overwritable later, a bare uninitialized declaration would reintroduce the maybe-uninitialized storage path the model otherwise never has, so it is simply disallowed — you may reassign all you like, but you may not start from nothing. The cost of this whole cluster is borne by the library author: a function that needs to retain or return a ref must say so with & in its signature, and a caller who holds only a temporary or a plain value cannot conjure a ref from it. Expressiveness the C programmer takes for granted — pointer to anything, anywhere — is deliberately not on offer; in return a ref, once it exists, is known to rest on stable ground.
The value world stays closed, and placement stays the compiler’s
Two last pressures pull in opposite directions — one locks a door, the other opens one — and they are worth telling together because both are about how far the value layer can be trusted to behave. The locked door is the struct. Structs are plain inline values: copied by overwriting bytes, with no anchor and no destruction tracking. That is only sound if a struct can never smuggle in a value that needs tracking — so a struct field may hold primitives and other structs and nothing else, checked transitively through the whole nested graph (§2.10). Let a struct contain a class and a byte-copy would silently duplicate ownership; let it contain an & and a byte-copy would silently duplicate ref-tracking state without ever going through the anchor system that makes that state correct. Both break the single invariant that lets struct copies be mechanical, so the closed value world is enforced rather than hoped for — the strictness-buys-speed bargain of the foundations story in miniature.
The opened door is placement. Because the anchor model makes a ref resolve identically no matter where its owner physically lives — the ref walks to a cell, and the cell can hold a stack address as easily as a heap one — the compiler is free to put a class instance wherever is cheapest, stack or heap, with no language-visible consequence (§3.5). It uses the stack whenever the instance is statically sized and does not escape beyond what a move can satisfy, and is forced to the heap only by genuine dynamic size or escape. This freedom is broad rather than rare because dynamic size is kept from leaking upward: the core dynamically-sized types — List, String — are represented as fixed-size handles whose backing store lives on the heap, so a type containing one stays statically sized and stack-eligible, with only the backing store forced onto the heap (§3.6). Placement, like the boolean-packing latitude beside it, is a freedom the language hands to the compiler precisely because it has been arranged to be unobservable — and it is unobservable only because the anchor indirection, the mechanism this whole story is built around, already decoupled a ref from any fixed address. The cost is the cost the chapter cannot remove: this only holds for as long as the model keeps placement semantically invisible, and every feature that might let a program observe where a value physically sits — raw addresses, layout introspection — is a feature this freedom quietly forbids.
Struct and class collapse into one axis, and this becomes a borrow
The previous chapter drew its line between struct and class, but that pair was later recognized as one axis wearing two names — the foundations story explains why the split collapsed into a single # modifier. Seen from the memory model, the collapse barely moves anything, which is the tell that the old two-kind framing was carrying more than its weight: the machinery this document is built on — the backpointer, the anchor cell, lazy allocation, move updates — was never about “class” as a keyword. It was about identity. So the rule became “a reference type — a #-marked type — carries an anchor,” and every statement the old text made about a “class instance” now applies to a reference-type instance, unchanged in substance. The struct-downstream restriction generalized the same way: it was always enforcing “no identity-bearing or ref-bearing field inside a copied value,” so it is now value-downstream enforcement (§2.10) — a value type may contain no reference or & field, transitively — which reads as a slightly broader rule but forbids exactly the fields it always forbade.
The one genuinely new fact the axis exposed is that & and # are the same fact from two sides. A stored, move-surviving & needs an anchor to point at, and only a reference type has one, so an & references a reference type and nothing else (§2.4): a persistent handle over a value is written &#T, and a bare &Int over a value is simply ill-formed. This was implicit in the old model — you could only & a class — but naming the value/reference axis made it explicit and, better, composable: #Int is a reference cell and &#Int a handle to it, which is how a value that a program wants several observers to share becomes shareable at all.
That leaves the question the old model answered by forbidding it: if a value has no anchor, how is one mutated in place? The answer, for a value receiver, is that this is a borrow of the caller’s storage, not a copy — the method is handed the caller’s slot for the duration of the call. This is what let value types become mutable at all: the previous design made a struct method return a replacement value precisely because a by-value receiver was a copy whose writes the caller would never see, and a scoped borrow of the caller’s slot removes that reason. A reference receiver needs no such device — it is an implicit &, since a reference type already carries an anchor to point at (functions.md §2.4); the borrow is strictly the value world’s device. The borrow is deliberately non-escaping — it cannot be stored as an & or returned as one, because a value is not &-rootable — so a value stays alias-free even while it is being mutated through, which is the property the concurrency safety rule (concurrency.md §4.2) then leans its whole weight on. The cost is a subtlety a reader must hold: a borrow is a reference in the machine, but it is one the type system refuses to let outlive the call, and that refusal — not the absence of a pointer — is what keeps the value world closed.
Naming the tether
Every chapter before this one has called the non-owning & by the plainest word to hand — a “ref”, short for reference — and for a long time nothing depended on the word. The type system caught up, and the word stopped being fine. Once the value/reference type axis settled into its own vocabulary — a value type, a reference type, and the # that separates them (the foundations story records that collapse) — the language had two different concepts both leaning on the root “reference”: the # kind of a type, and the & handle to one. They are orthogonal — the kind of type is a property of the owner, the handle is a separate non-owning cell that points at it — and yet “reference type” and “ref” are the same word twice, so a bare “reference” in a sentence could mean either. “ref” felt like it separated them, but it never did: it is only “reference” with the end bitten off, carrying the exact collision it appeared to resolve.
So we went looking for a word that belonged to the value side alone and shared no root with the type axis. Keeping “ref” was the first option and the first rejected, for the reason just given — it does not actually pull the two apart. The next was link: plain, short, and honest about the semantics, since a link is a non-owning connection with no suggestion of ownership or lifetime. It was the safe choice, and its flaw was that it was only safe — “link” says nothing about the shape of this particular relationship, and it walks straight into “linked list” and “linker” the moment a data-structures chapter needs those words.
The better lead came from a word already in the model. An & resolves through an anchor — a name chosen chapters ago — and an anchor is a nautical image, so the question was obvious: on the value side, what do you make fast to an anchor? The precise answers are all real and all unusable. A boat is joined to its anchor by the rode, which is exactly the relationship — held fast but not owned, and slippable — but “rode” reads as road on the page and looks like a typo. A mooring pennant and a warp are the same idea under other names, and they lose to “flag” and to “warp speed”. The one member of that family that survives ordinary prose is tether.
We nearly rejected it too. A tether, we worried, sounds like it keeps the far end attached — as if a live & might hold its owner alive, which is the opposite of the rule that a tether can never extend a lifetime. But that reading is backwards, and seeing why settled the name. The point a boat is tethered to is the fixed point; the tether binds and bounds the boat on its end, not the anchor. A boat on a tether is held within reach of the anchor; the anchor is not held by the boat. Map that onto the model and it is not a hazard, it is the scope rule stated as an image: an owner is the fixed point, and every & taken on it is bound to stay within the owner’s reach — a tether may not outlive what it is tied to (lifetimes.md §1.1). The word we thought fought the semantics turned out to encode them.
So the value-side handle is a tether (memory.md §2.4), and the type axis keeps “reference type” to itself. The name pays a small resonance back on a second look, the kind of resonance the naming guide recommends: a tether is slack — it does not pull the owner anywhere, it keeps station beside it, which is exactly how a non-owning handle sits next to the value it watches. And it joins a set already speaking the same dialect — a verb acts, a mould shapes, a value is borrowed and given back, an anchor holds fast — so now a tether ties to the anchor without owning it.
The cost is the ordinary cost of any coined term: a reader meets “tether” and must be given its definition once, where “ref” would have passed without comment — at the price of the collision that started this. And the rename reaches sideways into ordinary words: an owner with a tether on it is now “tethered”, one with none “untethered”, which quietly retires “referenced” from the value side to keep the split clean. The earlier chapters of this very story still use “ref”, because they were written when that was the word, and the history is left standing rather than back-dated; this chapter is where the name changed, not a pretence that it was always so.
When the free stacks fragment, and the arena takes the scope
By this point the model’s names had settled, but the machinery underneath them had not. Allocation, all along, had been served by size-indexed free stacks: round every request up to an 8-byte boundary, give each rounded size its own stack of freed slots, and satisfy a request by popping the matching stack or bumping a frontier when it was empty. It was O(1) and it avoided coalescing, and for a long time that was enough. What it could not avoid was the failure mode built into its own shape. Each size class hoards its freed memory and lends it to no other, so exhausting the 32-byte stack is out-of-memory for 32-byte objects — even with the 16-byte and 64-byte stacks sitting on abundant free space they will never surrender. A size-classed allocator fragments along its own class boundaries, and under a churny workload that fragmentation is not a tail risk; it is the steady state.
The first fix we tried was the cheap fix, and we rejected it for making the cure worse than the disease. If the 32-byte class is empty, why not serve the request from the 64-byte class — hand out a larger block and waste the difference? It removes the spurious out-of-memory, but it does so by pouring internal fragmentation into every oversized allocation, and internal fragmentation is precisely what size classes existed to prevent: the whole reason to bucket by size is cache density, and a 64-byte slot holding a 32-byte object is a cache line half full of nothing. We would have traded a fragmentation we could see for one smeared invisibly across the whole heap.
The move that actually dissolved the problem was to stop treating allocation as a global pool at all. Zane already has a strong notion of when memory should die: the water-tower scope (concurrency.md §4.1), the lexical region whose owned objects live exactly until the scope drains. Scopes nest last-in-first-out, and that is exactly the discipline a bump allocator wants: if every scope owns its own arena — a region it bump-allocates into and releases whole — then allocation is a single pointer advance and deallocation is a single pointer rewind, because nothing inside a scope outlives the scope. There are no size classes to fragment along, because there are no size classes; a bump arena hands out the next N bytes regardless of N. The fragmentation problem is not so much solved as made inexpressible (memory.md §3.2).
The honest cost is the cost every arena pays, and we took it with eyes open. A bump arena does not reclaim individual objects: an owner overwritten or logically destroyed partway through a scope leaves its bytes stranded as dead space until the whole arena is released. A workload that churns heavily within one long-lived scope holds more peak memory than the free stacks would have — handing a reclaimed slot straight back was the free stacks’ one real virtue. We judged that a good trade, because the pattern arenas punish (unbounded intra-scope churn) is rarer than the pattern they reward (a scope that allocates, works, and drains), and because bulk release buys a benefit the free stacks never could: teardown with no per-object work at all. When a scope drains its whole arena goes back to the OS in one unmap — no walk over the objects, no drop-glue threaded through the exit, the memory simply gone.
The last table problem, and the segmented offset
Bump arenas paid for themselves everywhere but one place, and it was the place the whole model is built around: the anchor. An anchor has to stay reachable and fixed for as long as any tether points at it, and until now the anchors had lived in one growable heap-resident table that a tether indexed. Put arenas underneath that table and its old flaw turns fatal. A monolithic contiguous table, when it fills, has to realloc — allocate a larger block and copy every cell across — and that is an O(N) step that also invalidates any native pointer into the array. We had spent the whole design making moves and overwrites O(1); reintroducing an O(N) resize on the anchor path, the hottest indirection in the language, would have handed all of it back.
The obvious escape was to scatter the cells: stop keeping anchors in one array, allocate each on its own, and let a tether hold the cell’s address directly. That kills the resize — there is no array to grow — but it resurrects the cost the indexed table was invented to kill. A raw address is 64 bits. Inflate every tether and every backpointer back to eight bytes and the cache density we bought by making them u32s is gone, and every resolution is back on 64-bit pointer math. We would have solved the resize by un-solving the size.
The two dead ends pointed at the same missing idea: we needed cells that could be scattered — so no table ever resizes — yet addressed narrowly — so a reference stays 32 bits. The arenas already supplied the first half: a cell is just another bump allocation, dropped in beside the owner that mints it, with no table in sight. The second half is to keep addressing everything with a u32 but to read that u32 as a segmented offset rather than a flat index — the high bits name a 1 MiB chunk and the low bits a word within it (memory.md §3.1). An arena is a chain of such chunks; when one fills, the runtime maps another from the OS and gives it the next chunk id, and nothing already placed ever moves. A small chunk directory turns a chunk id into a native base, so a reference resolves in a shift, a mask, and one hot directory load. The cell stays four bytes, the tether stays four bytes, and there is no table left to resize (memory.md §4.1, §4.2).
What falls out is a memory model that is uniformly 32-bit and, per tethered object, exactly twelve bytes of machinery: the four-byte tether wherever it is stored, the four-byte anchor cell, and the four-byte backpointer the payload carries home to that cell. The double indirection a tether walks — tether to cell, cell to payload — looks like it should cost two cache misses, and the arena brings that cost closer to zero: the cell read is a load into arena memory that is almost always already warm. Our first attempt at that warmth was to drop each cell right beside the payload that mints it, so the two share a cache line and the second hop is paid for by the first. It worked for the deref, and it opened a loose end the next chapter has to pull on — a cell sitting in the payload stream is a cell a payload-only scan has to step over, and a payload’s position starts to depend on how many of its neighbours were tethered before it.
The one motion this has to survive is escape. A value that outlives its scope is moved into a parent, and under arenas its payload is therefore copied into the parent’s arena — the child arena is about to be unmapped and cannot keep it. The backpointer makes that copy invisible: the runtime follows it to the payload’s one anchor cell and rewrites the cell with the payload’s new location. Every tether still points at that same cell and never registers that the payload moved (memory.md §4.5) — the same one-cell-update that made an in-place move O(1) makes a cross-arena promotion O(1) too. When the scope finally drains, its chunks are unmapped and its cells vanish with the objects they served, and the scope rules that governed tethers all along guarantee nothing still pointing could point into them.
The cost is a ceiling, and a lower one than the flat region carried its own version of. Splitting a u32 into a chunk id and an offset spends bits on structure that a flat offset spent on range: with 1 MiB chunks and 8-byte-aligned slots the arithmetic lands at 32 GiB of live arena across up to 32768 chunks — roomy, but a hard cap, and a program that genuinely needs more cannot have it without widening the reference and paying back the cache density we just secured. The chunk directory is a hop the flat “region base plus offset” did without, too: one more small, hot table on the resolve path. We were content to trade a fixed horizon and a register-resident directory for an allocator that never fragments, never resizes an anchor table, and vaporizes an entire scope’s memory in a single unmap.
Where the cells live, and the scan that pays for them
The previous chapter left a cell sitting beside every payload and called the shared cache line a win. It is a win — for the deref. What we had not yet measured was the other side of the same coin, and when we built the layout and ran it on real hardware the coin landed. Two workloads slid backwards. A sweep that reads only payloads — the common case of walking a collection and touching each object’s fields — slowed by around a fifth, because the interleaved cells sit between the payloads and a scan that reads only payloads drags the cells through cache anyway; the same objects packed tight would have touched fewer lines. And a write-heavy growth buffer regressed harder still, because once cells share the payload stream the stream’s alignment stops being the compiler’s to control — a buffer’s base now depends on how many cells were minted ahead of it, and a run of entities that should have sat one-per-line ended up straddling two. The shared-line trick had quietly made the arena’s geometry a function of tether history, and iteration paid for it.
The tempting repair was to go backwards: put the anchors back in one compact heap table, the way the pre-arena model had. That table was never slow to read — it stayed small and hot, and it kept payloads perfectly contiguous because nothing lived between them. But the reason it read so well is exactly the reason it could not stay. A single global table has no scope to be unmapped with; every cell in it has to be handed back one at a time as its owner dies, or the table leaks and grows without bound. That is the per-object teardown the arenas had just abolished — the “free is a no-op” and one-unmap-per-scope wins are wins because nothing walks the objects to reclaim them. A global table would have bought back the payload density by selling the teardown, and the teardown was the larger prize. The compactness that made the table attractive was the very property that forced the per-object free; the two could not be separated.
So the fix was not to leave the arena but to stop mixing two streams inside it. Cells get their own region — a separate chunk chain in the same scope arena, addressed by the same segmented offsets, bump-allocated and bulk-unmapped exactly like the payload region, just not braided through it (memory.md §4.1). Payload scans go back to full density because the payload stream holds only payloads, and a payload’s position no longer depends on the tethers minted before it, so the alignment the compiler wants is the compiler’s again. The cells, gathered into their own region, are still compact and still hot — a tether resolution reads a cell from a dense, cache-resident run, just not from the same line as the payload it will then visit. It is arenas the whole way down: two streams, one drain.
The cost is real and we name it plainly. We gave up the shared-cache-line bonus on the deref itself — the cell and its payload no longer ride into cache together, so a single tether resolution can pay two loads where the interleaved layout often paid one. We judged that the right trade because the payload sweep is the hotter path in the workloads we cared about: densifying the scan that runs over every object beats shaving a load off the deref that runs only when a tether is actually followed. It is the mirror image of the choice the last chapter made, now that we have measured which side of the coin comes up more often.
Separating the region also forced us to finish a sentence the last chapter had left dangling. It had described promotion as “rewrite the one cell and every tether follows,” which quietly skipped the question of which arena that cell is in. Now the answer is unambiguous: the cell lives in the region of the scope that minted it, and on escape that scope is precisely the scope about to drain. Every tether already pointing at the cell was taken in that scope or deeper, so none of them outlives it — the lifetime rule that has fenced tethers all along (lifetimes.md §1.1) does the fencing here too. So promotion updates the old cell to the payload’s new home, keeping those doomed-but-still-live tethers reading the promoted copy until their scope ends, and then resets the payload’s backpointer to zero so the value re-anchors from scratch in its new scope: the next tether taken on it there mints a fresh cell in the destination region, one that finally lives as long as the value does (memory.md §4.5). The old cell and its tethers expire together when the source scope drains, and nothing ever reads a cell that has been unmapped. That reset is the honest tax of keeping cells scope-local rather than in one immortal table — a second, cheaper re-anchoring the immortal table would not have needed, paid so that anchors can vanish in the same unmap as everything else.
A free zero sentinel, and cache-line-aligned buffers
The separate cell region closed the placement question, but it quietly loosened a constraint we had been treating as fixed, and it took a benchmark regression to notice. Growing an owned buffer — appending a hundred thousand small records to a list — ran markedly slower under the arena than under the free-stack allocator it replaced. Nothing about a pure bump-and-fill should have been slower; the frontier just advances. The cause turned out to be one byte of history.
A CPU moves memory in fixed sixty-four-byte cache lines: a value wholly inside one line costs one line to touch, a value spanning a boundary costs two. Our growth buffer was based at arena offset 8 — not on a line boundary — and a run of 32-byte records laid down from offset 8 puts every other record across a boundary. The write-heavy fill was paying for nearly twice the necessary lines. The old free-stack build had, by luck, handed back a line-aligned block; the arena had not.
The eight-byte skew was not arbitrary, and finding out why turned a one-line fix into a small piece of design. The arena reserves the value zero as the untethered sentinel: a backpointer or tether of 0 marks “no anchor.” In the earliest arena layout cells were bump-allocated from the same frontier as payloads, so the very first cell could land at offset 0 and collide with the sentinel — we prevented that by starting the frontier at 8, one slot in. But the previous chapter had since moved cells into their own region. Once no cell is ever drawn from the payload frontier, no cell can sit at offset 0 — and the only words that carry the sentinel value are backpointers and tethers, which name cells. The reservation was guarding a collision that could no longer happen. It was vestigial.
That reframed the sentinel entirely. Zero is safe not because we hold the slot empty, but because cells live at offsets that are never zero. So the payload frontier can start at offset 0 — a chunk base, which is line-aligned — and the sentinel costs no reserved memory at all: a real payload sits at offset 0, still unambiguous, because 0 is only ever read as null through a backpointer or tether, and those name cells (memory.md §3.1). The buffer that started all this, being the first allocation in its scope, now lands line-aligned for free.
Starting at zero only aligns the first allocation, though; a buffer created after other objects still lands wherever the frontier happens to be. So the durable rule aligns the structure whose alignment actually matters: a dynamically-sized backing store is allocated cache-line-aligned, the frontier bumped to the next line before it is placed (memory.md §3.6). Only backing stores earn it — they are what gets streamed and grown; a small inline object stays 8-byte aligned, since padding every little allocation up to a line would waste most of a line each for locality it will never use. Payloads from zero and backing stores aligned, together, put the fill back on the old model’s number.
There was a larger temptation in the same corner, and we turned it down. If a tether and a backpointer only ever name cells, why address them with a full segmented offset — why not a dense ordinal index into the cells, a smaller field? The appeal is real but the arithmetic isn’t: the width of a reference is the log of the number of objects it must name, index or offset alike, so an ordinal cell index is only smaller than the u32 we already use if we also cap the number of simultaneously-tethered objects — a u16 buys two bytes and a 65,536-cell ceiling. And a dense global index needs one packed anchor array to index into, which is exactly the structure per-scope bulk teardown cannot provide: draining a scope frees a block wholesale and promotion inserts a cell into a parent region, so the cells never form one contiguous array without a free-list — the per-object teardown we spent the arena to escape. A per-scope index that keeps the bulk free has to carry its scope’s chunk id, at which point it is the segmented offset again. The real bit-efficiency — half a native pointer, and eight-byte words rather than bytes — is already banked in the u32 segmented offset; the further notch pays out only in a bounded profile that guarantees the cap, so we left it there.
The cost of what we kept is a rounding: up to a cache line of padding before each backing store, unmeasurable against the store it precedes, and the standing discipline that the payload frontier and the cell region stay separate so that zero keeps its meaning for free. Cheap insurance, for a sentinel that now costs nothing and a fill that no longer straddles.
Two vocabularies: host and guest above anchor and tether
With the arena layout settled, one vocabulary problem remained. Calling &T a tether had solved the collision with “reference type,” but it left the source language and the runtime sharing one word. The problem is that those are different layers. Source code needs names for the lifetime relationship a programmer reasons about; the memory model needs names for the indirection that keeps that relationship working when an object moves. Using tether for both made an implementation choice sound like the meaning of &T itself.
The source pair is now host and guest. A host is the symbol, field, or container slot that stores a reference-type object — or its hosting handle — and governs the object’s lifetime. A guest is an &T: it may access the hosted object, but it neither stores that object nor controls how long it lives. When the object moves, it is rehosted, and its guests continue reaching it. The ordinary relationship does useful work here: a host provides both accommodation and the duration of a guest’s stay, while a guest may use what is provided but cannot outlast the host.
The runtime keeps anchor and tether. Each guest is represented by a tether that resolves through an anchor; moving or rehosting the object updates the anchor, so existing tethers keep working. That vocabulary remains a natural mechanical picture, but it no longer leaks upward into source semantics. The concise model is: an object lives in a host; a guest may access it; internally, the guest’s tether follows the object through its anchor.
The alternatives each blurred a distinction we wanted to keep sharp. Owner/tether named the two halves accurately in isolation but paired source semantics with implementation. Owner/guest worked, though “owner” stressed rights and destruction more than residence. Owner/view was technically reasonable without being a convincing lived relationship. Proxy, keyholder, delegate, and licensee were variously technical, overloaded, or indirect; “key” also collided with dictionary keys. CC/email language suggested secondary participation, but a CC recipient receives an independent copy rather than live access to one moving object. And keeping tether as the name of &T remained expressive, but preserved the very overload this split was meant to remove.
Two payload streams, and the anchor that leaves the scope
With the vocabulary settled, the allocator came back open. The scope arena survived, but the pure-bump conclusion did not survive unchanged. Fixed-size values, reference-type hosts, and dynamic handles still fit the original rule: append them densely and reclaim their chunks when the scope drains. Resizable backing stores do not. A list can abandon several buffers while its scope remains alive, so treating those buffers like ordinary fixed-size payloads strands exactly the kind of reusable holes that matter. The arena therefore split into two lazy chunk chains per scope: one fixed-size region that remains a pure bump allocator, and one dynamic region that may reuse backing-store blocks. A chunk belongs to exactly one region, and a scope that never allocates a backing store never maps a dynamic chunk.
The dynamic region brings back free stacks in the one place where their fragmentation is controlled rather than global. Blocks use shared power-of-two byte classes beginning at 128 bytes, independent of element type. Allocation checks the exact-size LIFO stack first and bumps the frontier only when that stack is empty. A full list requests exactly twice its current byte size; it grows in place only when it is the frontier allocation and the added bytes fit before the chunk boundary. Otherwise its elements relocate into a reusable doubled block or a newly bumped one, and the old block enters its exact-size stack. Blocks above 1 MiB become dedicated contiguous oversized spans, addressed by one base segmented offset and reused through the same exact-size rule. The cost is dead space between size classes and until scope teardown, but reuse is confined to the buffers whose repeated growth creates it.
The scope-local anchor region turned out to have a deeper problem than teardown, and it retires a claim two chapters back. The segmented-offset chapter had promotion follow the backpointer to the one anchor cell and rewrite it, so no tether ever registers that the payload moved. That holds only while a payload has exactly one cell to rewrite. It stops the moment both sides of a move are already anchored: promotion could leave source guests naming the old cell while destination guests named a new one, and a later move had only one payload backpointer and could update only one path. Moving either cell would merely force every existing guest on that side to be repointed — the work anchors exist to avoid. The final design therefore takes anchors out of scopes entirely. One runtime-global pool grows through anchor-only pages, and an anchor cell may target either a payload or another anchor.
That second kind of target makes identity merging mechanical. A move into an already-anchored destination destroys its old occupant but preserves the destination host identity, so the destination anchor remains the terminal payload anchor. A distinct source anchor changes into a forwarding cell that targets it. Old source guests walk source anchor to destination anchor to payload; destination guests and newly created guests go directly to the destination anchor. Nothing in the source language exposes the chain, and no guest is enumerated or rewritten.
The same rule applies inside dynamic values. Rehosting copies the inline payload or handle into the destination host and relocates every owned backing store into an equal-size block or oversized span in the destination scope’s dynamic region. Contained reference-type hosts merge their anchor identities in the same way. The old source payload bytes cease to be live, and its host-capable slot stores the terminal tether as a guest. Anchor work remains O(1) per merged host, while the physical move is proportional to the bytes, elements, and contained hosts relocated.
Each anchor occupies an 8-byte-aligned physical slot: four bytes hold a target segmented offset and four identify whether that target is a payload or another anchor. The pool uses one free-address stack because all slots have the same size; allocation pops it before bumping the global frontier. Anchor pages remain mapped until runtime shutdown, even when wholly free, so an offset retained by the stack can never name an unmapped or repurposed page. The minimum physical machinery for one directly tethered identity remains sixteen bytes: a four-byte tether, an eight-byte anchor slot, and a four-byte payload backpointer.
The chain has a natural direction. A superseded source identity always forwards toward the destination identity, and moves only target the same or a higher scope, so a forwarding edge never points toward a shorter-lived host. Resolution may compress the path. Copying or rebinding an old guest stores the terminal identity rather than propagating the obsolete identity, so a forwarding anchor cannot newly escape the lexical scope that originally contained its source host.
That gives the two kinds of cell different retirement events. A terminal payload anchor returns when its final hosting identity ends. A forwarding anchor is pushed onto its former source scope’s retirement stack and remains only until that scope drains, when every old guest that could still contain the identity is dead. Neither case requires reference counting or guest enumeration, and both permit immediate free-stack reuse. The earlier restriction on moves with guests on both sides disappears entirely: the two identities simply become a runtime chain. An explicit &T remains guest-only and holds only a tether, while a slot declared T keeps its full storage after rehosting and may later host another T.
The sentinel changes by one small accounting detail. Segmented offset zero remains a valid payload location, but the global pool never issues anchor identity zero. The sentinel therefore costs one unusable anchor-slot identity rather than forcing either payload region away from its naturally aligned chunk base. Dynamic blocks begin at 128 bytes and preserve cache-line alignment through doubling, reuse, and oversized spans.
Removing the bare symbol as a guest source
The whole of the preceding machinery — hosts, guests, anchors, forwarding cells, retirement stacks — was built to keep a guest pointing at its object when the object moves. This five-line program asks a question that machinery does not settle:
main Player()
second Player()
guest &Player = main
second = main
Line 4 moves the object out of main’s slot and into second’s. Line 3 had already handed out a guest. So what does guest denote afterwards? The anchor system gives an answer — it follows the object, because that is exactly what anchors are for — and the answer is defensible. But it is not obviously right. A reader who wrote &Player = main may well have meant “watch that variable,” in which case following the object is wrong; a reader who meant “watch that player” is served correctly. The spelling does not distinguish them, and the model had quietly picked one reading and made the other unsayable. Worse, the reader who wanted the other reading had no way to find out except by discovering that their program behaved unexpectedly. That is the shape of a design flaw, not a documentation gap.
The first instinct was to make the machinery smarter. If a guest tracked the name rather than the object, guest would keep denoting main’s slot; but main’s slot is now empty in every sense that matters, so a guest to it is a guest to nothing and we are back to needing a null state we had spent the whole model avoiding. If it tracked the object, we had the existing design. So we tried a third layer: name → location → object, with the location as a stable middle that either end could be re-pointed at independently. That is a genuine idea and it is also, on inspection, the anchor system with an extra name — it moves the ambiguity from “which does a guest follow” to “which does a location follow,” and it charges another indirection for the privilege. We dropped it.
Then we tried the direction that looks decisive: make the object immovable. If nothing relocates, the question cannot be asked. We built that model out in full and it failed twice over, in ways worth recording because they are not obvious from the outside. It could not express a move whose destination is decided at runtime — if someIO() { boat.bottom!append(car) } else { boat.top!append(car) } — and its answer was to forbid the program rather than to place the car. And append moves into a list’s backing store, which relocates when the list grows; the model was claiming immovability in one section and admitting relocation in another. Anchors exist precisely so that objects can move. Removing them to buy an invariant the design cannot actually hold was the wrong turn, and we took it far enough to be sure.
The opposite extreme — no guests at all, so nothing can be left pointing anywhere — fails for a duller reason: a function that only wants to read an object would have to swallow it, and a language where reading costs you ownership is not one anyone would enjoy writing.
What finally resolved it was narrowing the question instead of answering it. The trouble is not that guests exist, and not that objects move; it is that a bare symbol’s own hosting slot is both the slot you may most freely overwrite and, until now, a slot you could point at. Those two properties are what generate the ambiguity, and only one of them is load-bearing. So memory.md §2.8.1 removes the other: a bare symbol stays a place expression — you may read it, mutate it, move from it, borrow it — but it is no longer a guest source. A new & is minted from a field access or from an &T parameter, and from nothing else. Line 3 of the program above is now a compile error, and it is an error at the line that creates the problem rather than a puzzle at the line that reveals it.
The reason this costs so little is worth stating plainly, because that argument settled the question for us: a guest to a bare symbol never buys any reach. A guest exists to let storage that does not own an object nevertheless get at it — a field in another object, an element of a container, a callee’s parameter. But a bare symbol is, by construction, already in scope everywhere a guest to it could be declared; you can simply use the symbol. The removed source was genuinely doing only one job, carrying an object into a call, and that job now belongs to the borrow mode.
Fields are a different matter, and they stay. A field belongs to an object whose lifetime the host system already tracks, so a guest to car.engine has a meaningful target to follow when the field is overwritten or the containing object is rehosted — and follow it does, through the unchanged anchor path. That asymmetry is the whole content of the rule: it constrains where a guest may come from, and changes nothing about what a guest can survive. The anchor system is untouched.
The cost is real and lands in one place: a structure that needs guests must be rooted in a field rather than in a bare local. A recursive #variant boxes its recursive case through &, so building one now starts from a node hosted in a field — Expr.flip(tree.root) rather than Expr.flip(leaf) — as adt.md §4.1 spells out. For a while we debated whether that was a defect. It is not, quite: the root of a recursive structure is what keeps the whole shape alive, and a field of the type that owns the structure is where such a root belongs anyway. But it is a constraint the previous design did not impose, and the programmer who reaches for a bare local to hold their first node will meet it as a surprise before they meet it as a principle. That is the honest ledger: one surprising rejection at the root of a tree, bought with the disappearance of an entire class of question about a guest’s meaning after a move.
Three ways to hand over an object
Taking away the bare-symbol guest source left a hole immediately, and it is the most ordinary hole imaginable: topSpeed(engine), where engine is a local and the function only wants to read it. Under the old model that parameter was &Engine and the argument was a bare symbol — the exact pairing now forbidden. Swallowing it instead is absurd for a read. So the rule as stated made a common program unwritable, and needed a companion.
We considered giving &T parameters a special exemption: a bare symbol may not initialize & storage, but may still feed an &T parameter. That is nearly right, and it is where the thinking sat for a while. It sank because an &T parameter is not merely an entry point — it is a guest, and a callee may store it in a field or return it. Exempting the argument would mean a bare symbol’s slot could still end up with a guest pointing at it, arriving by the one route the rule did not check. The exemption would have to be conditional on the callee’s use of the parameter, which is interprocedural inference — the analysis lifetimes.md §1.8 was written specifically to retire.
So the passing mode had to split. A parameter that merely reads or mutates the caller’s object for the duration of the call is a genuinely different contract from one that keeps a guest past the call, and the old &T was carrying both. Separating them gives the three modes in memory.md §2.9: T swallows, taking hosting access and downgrading the caller; &T takes a guest, which the callee may store or return and which only a guest source can supply; 'T borrows, accepting any place at all — bare symbols included — and granting read and mut access that expires with the call. The borrow was not a new concept: value types had always been passed exactly this way, and the reference world had simply never been given the same option.
That third mode turned out to pay for itself immediately in a place we had not been aiming at. A reference-type subject had been an implicit guest, which under the new source rule would have made node!setScale(...) illegal on a bare local — an absurdity. But a subject almost never needs to be kept; it needs to be read and written for the duration of the call. So a bare this T on a reference type is now an implicit 'T borrow (functions.md §2.4), and this &T is what a method writes in the rarer case where it stores or returns the subject. The pleasing part is that this makes the two type worlds consistent: a mut subject is a mutable borrow of the caller’s slot whether the type is a value or a reference, and the special-casing that used to sit in that sentence is gone.
Naming the mode took longer than designing it. The tempting move was to hand the constrained meaning to the bare & and mark the escaping form, on the general principle that the marked form should be the restricted form. That principle does not apply here, and noticing why was the turn: both forms are marked. The unmarked form is T, the swallow. Between & and a new sigil there is no asymmetry of markedness to appeal to, so the argument has to be made on continuity instead — and there & has a large incumbent claim. It denotes guest in a field type, in a storage declaration, in a return type, in the glossary, and across every chapter above this one. Redefining it in the parameter position alone would give the same character two meanings depending on where it sits, which is precisely the kind of context-dependence the two-vocabulary chapter had just finished removing from tether. So & keeps meaning guest everywhere, and the new concept takes the new mark.
' won it on two counts. The character was unused in Zane’s lexis — no character literals, no operator, no identifier start — so it cost nothing to reserve (lexical.md §4.3). And its existing association in the reader’s mind is with Rust’s lifetimes, which is closer to right than to wrong: a Rust lifetime annotates precisely the property a Zane borrow has — access valid for a bounded duration and no longer. The difference is that Zane’s version has nothing to name, because the duration is always the call. Borrowing the character while dropping the parameter it usually carries is, if anything, a decent summary of the language’s treatment of lifetimes generally. We weighed a keyword — borrow Engine — and rejected it as too heavy for a mark that appears on most parameters; and we weighed reusing #, which is taken by the reference mould and would have been genuinely confusing.
The cost of three modes is that there are three of them. A programmer now chooses a passing mode per parameter, and the choice is not always forced: a parameter that only reads could be written 'T or &T, and only the question “does the callee keep it?” separates them. We do not think this is a real burden — the modes correspond to three contracts people already distinguish when they think about a function’s contract, and the signature now states which one applies rather than leaving it to the body — but it is one more axis in every signature, and it is fair to count it. Against that, one rule genuinely got simpler: an overload set may not differ only by the passing mode (functions.md §4.1), because the mode changes what the caller must supply and what state the call leaves them in, with nothing at the call site to distinguish two such overloads. That rule already existed for T versus &T; widening it to all three modes cost nothing and closed the door before anyone tried it.
The region takes the boxes, and a box requests its own size
A decision taken in one document arrives in another as a bill. Recursion stopped going through & and became hosting — that was settled on the ADT side, in the bindings chapter — and it left this document holding the part nobody had costed. A recursive member is now a fixed-size handle whose payload lives elsewhere, and that elsewhere had to be given an address, a size, and a price before the design was real. That is what forced the questions below: where such a payload goes, what block it requests, and which invariant it disturbs on the way. The pleasant part is that most of the answer was already written. A List is a handle inline with its backing store in the scope’s dynamic region, and a boxed node needs exactly that shape — statically sized where it is embedded, separately allocated where it lives. So a boxed payload is a dynamic block like any other (memory.md §3.3, §3.6), and the whole of the anchor system carries over untouched: a boxed instance keeps its own backpointer, is reached through its host’s field, and may be guested from that field access like any other field.
We did look at the other two places it could have gone. The fixed-size region is the obvious first guess — a boxed node is statically sized, after all — and it is wrong for a reason that is easy to miss: that region is a pure bump allocator with no reuse at all, deliberately, because a host’s slot is overwritten in place and nothing there is ever individually reclaimed. Tree nodes are the opposite case. They are created and destroyed one at a time, in numbers, throughout a scope’s life, and putting them in a region that reclaims nothing until drain would make every discarded subtree permanent dead space. The dynamic region already has precisely the machinery that case needs: one LIFO stack per size class, popped before the frontier is bumped, shared across every dynamic payload in the scope (memory.md §3.2). A freed node’s block comes straight back for the next node, or for a string, or for a list — which is the behaviour a parser needs when it builds and discards subtrees. The third option was a third region, dedicated to small fixed-size boxes. We costed it and dropped it: a region is a chunk chain, a frontier, a directory presence, and a set of free stacks, and all of that would have been duplicated to buy one feature — a different ladder of block sizes. If the ladder is the only difference, change the ladder.
Which left the question of what size a boxed block should be, and the first answer we reached for was instructively wrong. The dynamic region’s blocks are powers of two beginning at 128 bytes, so the obvious move was to extend that ladder downward — add 16, 32 and 64 so a small node is not handed a 128-byte block. We wrote it that way, and then noticed we had misread our own machinery. The size classes were never a property of the region. Look at the actual text of §3.2: there is one LIFO stack per exact byte size, created when a block of that size first becomes reusable. Powers of two appear because a list doubles — they are a consequence of growth, not a classification the region imposes on what it holds.
A boxed payload never grows. It is one instance of one type, allocated once and freed once, so there is nothing for a class to absorb and no reason to round up at all. It requests exactly the size of the type it holds, aligned as that type is aligned anywhere else: a twelve-byte node occupies twelve bytes. The ladder question — where the floor goes, how many classes belong under 128 — evaporates, because a fixed-size payload was never on a ladder. That the rival fix, sub-allocating a 128-byte block into node slots, is a second allocator with its own occupancy bookkeeping sitting on stacks that already do that job, stopped mattering: there is no block to sub-allocate.
Exact sizes buy nothing across different sizes — a freed twelve-byte block will never serve a thirteen-byte request, where a class would have pooled them. That trade lands the right way here, because boxed payloads are the homogeneous case. A #variant is laid out at its widest case plus a tag, so every node of one type is the same size, and the block a discarded subtree returns is precisely the shape the next node wants. Classes pool heterogeneous churn; a tree is not that.
This does disturb a single invariant, and we had written a chapter to earn it. The cache-line-aligned buffer got its alignment cheaply because the minimum block was 128 bytes and every larger block doubled, so alignment fell out with nothing to enforce. Blocks that are neither 128 bytes nor a doubling of it break that. The rule now names the two kinds of block separately rather than deriving alignment from size: a growable backing store is cache-line aligned as before, and a boxed payload takes its own type’s alignment requirement — which is the alignment that type would have in any other position, so nothing new is being invented. The frontier is rounded up before it is bumped. The price is a little padding where a small block precedes a large one, and we would rather pay that than either waste most of every node’s block or teach the region a second allocator.
What a copy is for, and the ban that survived it
A rule can look finished and still be resting on nothing, and the way you find out is that somebody asks why. This chapter is about one, that a value variant cannot contain itself, which turned out to be resting on two mistakes of ours, and about what was left standing after both were withdrawn.
The previous chapter handed recursion to reference types and gave a reason for the half it withheld. A box is owned storage, we said; some owner has to free it, relocate it, and define its copy; that owner is a host, and having one makes a type a reference type. So a value type gets no box, and a value variant cannot contain itself.
Review asked the obvious question — would recursive variants not also work with value types? — and the first casualty was not the rule but the evidence for it. The spec had been using Expr to demonstrate the ban, and Expr demonstrates nothing: its # is already forced by intLit String, because a value sum may not carry a reference type. Anyone checking the example against the rule finds a type that would be a #variant regardless. Isolating the rule properly took a pair whose payloads are all value types, Countdown against Chain, and once it was isolated there was nothing behind it.
We defended it twice, and both defences were wrong in the same shape: each imagined machinery that this runtime already has.
The first was that a box-owning value would need a teardown obligation — destruction tracking that value types deliberately do not carry. That conflated two different mechanisms wearing one word. The tracking a reference type needs is anchors, and anchors exist so that a guest can detect whether its host has died. A value cannot be guested and needs none of it. Knowing when a value dies is a separate question with a boring answer: its slot is overwritten, or its host, container, or scope dies — every one of those a point the compiler can name from the program text. And the walk to run there was already specified, for reference hosts, in the paragraph about overwriting a host: return the occupant’s dynamic blocks, backing stores and boxed payloads alike, recursively. Extending it to values is the same sentence with a different subject.
The second was worse, because it sounded like systems expertise. A snap of such a value, we argued, walks a structure while a writer mutates it, so the reader may follow a handle to a block the writer has freed — use-after-free, needing hazard pointers or epoch reclamation. That reasoning presupposes that freeing can unmap. This arena never does that while a reader could be running: the water tower keeps a scope alive until its spawned work finishes, and chunks are unmapped only at drain, in bulk. A block freed mid-walk is recycled inside a live mapping. A stale handle therefore resolves into readable memory holding somebody else’s bytes — garbage data, not an invalid access, which is precisely the failure class the flat case already has and already discards on the version check.
After both withdrawals, the remainder was not a rule. It was a price list: copying an existing recursive value allocates and costs O(structure), and a concurrent snapshot pays for a validated walk and possible retry. We had been reading a cost as an impossibility, which is the specific mistake that keeps a language smaller than it should be.
So the copy became deep (memory.md §2.3). Copying an existing value copies the whole value: its inline bytes, and a fresh allocation and recursive copy of every boxed payload it owns. It is worth being precise about how little that changes for existing code — a value with no boxed member is copied by copying its bytes, exactly as before, which is every value type anyone has written so far. Depth is not a feature added on top of copying; it is what “copy” already meant, applied honestly to a value that owns storage out of line. A value’s whole promise is that nothing reachable from it is reachable from anywhere else, and a shallow copy would break exactly that promise, in exactly the way that would matter.
That does not imply that every value-producing expression first creates a temporary and then copies it. A place expression denotes an existing value and is copied when bound elsewhere; a fresh non-place result constructs directly in its eventual destination, recursively through product members, value-variant payloads, function results, and match arms. Without that distinction, Countdown.more(Countdown.more(...)) would repeatedly copy every completed prefix and ordinary construction would become quadratic. The same destination rule makes Vector2(Int(3), Int(4)) construct the vector and both integers once, where they finally live. Overwrite carries the matching order rule: if the right-hand side reads the destination or anything reached through it, the replacement is completed before the old occupant and its blocks are destroyed. x = x and x = x.child therefore cannot erase their own source.
The residuals we do accept, and they are stated where they land rather than buried. Copying an existing boxed value allocates and walks its structure. A spawn reader taking a snapshot of one must treat every byte read before the final version check as untrusted: it validates a sum discriminant before dispatch, validates any count or length that directs traversal, validates every complete payload span, and stops at a depth bound. That bound is worth one sentence of its own, because an arbitrary one would have been a trap: a legal value deeper than it would fail every attempt, and “retry” would never converge. So the bound is derived — a correct walk descends through a distinct live block each step, so the scope’s live block count is a depth no real structure can reach. Exceeding it therefore always means recycled bytes, never an honest value that is merely deep, and discarding the attempt stays the right answer. An invalid value aborts the attempt; a valid-but-stale combination remains memory-safe and is discarded by the final version check. The snapshot is an ordinary deep copy into its fresh binding, so its blocks come from that destination scope’s stacks, not generally from the writer’s; the two contend on one allocator only when they actually share an arena. Those allocations stay provisional until the final version check accepts the attempt. If validation or that final check rejects it, every block allocated by the attempt is returned to the destination scope’s corresponding exact-size stacks before the reader retries, so failed walks cannot accumulate dead snapshot storage. A retry still redoes the whole walk, so a fast writer can starve a reader, which it cannot do for a flat value (concurrency.md §4.4). That cleanup is ordinary allocator rollback, not a reclamation scheme for writer memory; the concurrency rule is still validating an optimistic walk.
The interesting part is the line that did not move. Deep copy dissolves the stated reason for banning a reference-type field in a value type — “copying would silently duplicate hosting” — and for a while it looked as though List inside a struct should follow value recursion through the same door. It should not, and the reason is sharper than the reason it replaces: a reference type exists in order not to be copied. That is not a side effect of hosting; it is the whole point of the mark. A reference type has one host at a time, a stable identity that guests resolve through, and it reaches a new place by being moved. A copy of a value holding one could only duplicate the object — minting a second identity, so guests tethered to the original quietly fail to follow — or share it, so two values reach one host and “exactly one host” stops describing anything. Both outcomes destroy the purpose of the #. List and String are reference types, so they are covered by the same sentence, and they stay out (memory.md §2.10).
A boxed member never had that problem, which is why it walks through while a List field does not. A box holds an instance of the member’s own type — it is placement, not a change of type, and placement was already unobservable. Nothing about it signals “copy me by sharing.” So the # axis comes out of this with a tighter meaning than before: identity, aliasing, and copy-versus-move. Not “may contain itself.” That question turned out to belong to layout, and layout answered it the same way for both kinds.
Bare symbols become guest sources again
Two chapters up, we removed a guest source and then immediately built a passing mode to replace what removing it broke. That is a shape worth being suspicious of at the time, and we were not suspicious enough. This chapter reverts the ban.
The ban’s own ledger, written when it landed, put the cost at “one surprising rejection at the root of a tree” — you could no longer write Expr.flip(leaf) and had to root your structure in a field. That accounting was honest about the cost in view and blind to everything else, because the rest of the cost had already been spent one chapter later and was not being counted as cost. The borrow mode exists for exactly one reason: the ban made topSpeed(engine) unwritable, and some construct had to make it writable again. So the true bill was a new sigil, a third passing mode on every signature, a this whose meaning depended on which kind of type it named, and an &-return rule that had to explain separately why each of the two rejected modes was not a root. None of that appears in the chapter that took the credit for the ban being cheap.
Then the one item that was counted disappeared on its own. Making a recursive member an owned child took & out of recursive spines entirely: a recursive case is boxed through a handle, so a tree is built from owning edges and needs no guest source anywhere. The rule that a recursive structure must be rooted in a field went with it. The single cost the ban’s ledger had named was gone, and what remained on the page was the machinery built to pay a bill nobody was charging any more.
That is the pressure that reopened it, and the judgment that settled it was blunt: the ' semantic was not worth having as a separate concept to learn. Not “the borrow is wrong” — the borrow is exactly right for value types, where it has always been the nature of a parameter. The objection is to a second sigil whose whole job is to route around a restriction we chose. Delete the restriction and the sigil has no work left.
There is a harder version of that objection, and it makes the revert obvious rather than merely defensible. The ban did not remove the situation the machinery exists for. Not “removed it at a cost we later judged too high” — did not remove it at all.
The situation is two live anchor identities resolving to one payload. A payload carries a single backpointer, so it can be found from one cell; a second cell naming it cannot be updated on the next relocation. That is what forwarding anchors, the retirement stacks, and the target-kind discriminator are all for. It arises when a move has anchored objects on both sides. And here it is, reached without a bare symbol anywhere:
package Demo
type Engine = #struct { power Int; }
type Car = #struct { engine Engine; }
type Garage = #struct { car Car; }
Engine(power Int) => init{power}
Car(engine Engine) => init{engine}
Garage(car Car) => init{car}
Unit demo() {
garage Garage(Car(Engine(Int(1)))) // garage.car hosts parkedCar
// parkedCar.engine hosts parkedEngine
guestToParked &Engine = garage.car.engine // mints parkedAnchor, naming parkedEngine
{
arriving Car(Engine(Int(2))) // arriving hosts a Car
// its .engine hosts arrivingEngine
guestToArriving &Engine = arriving.engine // mints arrivingAnchor,
// naming arrivingEngine
garage.car = arriving // ← the move
}
return Unit()
}
Both guests are minted from field accesses. Fields were never banned — the ban’s own chapter is emphatic that “a field is a different matter and stays a legal source”, and treats that as the reason the restriction is narrow. So every line here was legal on the day the ban shipped, and the last line still puts parkedAnchor and arrivingAnchor on one payload: guestToParked follows the slot and observes arrivingEngine after the overwrite; guestToArriving follows the object and observes it too. arrivingAnchor becomes a forwarding cell targeting parkedAnchor, exactly as in the ban’s design.
So the ban was never buying the merge machinery’s removal. It bought one question — what a guest to a bare symbol’s own slot denotes after that slot is moved from — and left the underlying mechanism fully reachable by the ordinary route. We had been carrying it as though it were load-bearing on the runtime, and it was load-bearing on nothing but a documentation problem.
That reframes the whole ledger. It is not that we paid a sigil and a passing mode for a smaller runtime; the runtime is identical either way. We paid them for a narrower explanation, and then discovered the explanation has a perfectly good answer that fits in two bullets of the spec, given below.
Reverting means the five-liner comes back, and this time it has to be answered rather than made illegal:
main Player()
second Player()
guest &Player = main
second = main
The old chapter stated that the anchor system gives an answer — the guest follows the object — and that the answer is “defensible but not obviously right”, because a reader who wrote &Player = main might have meant watch that variable. The flaw in that worry is sitting in the same chapter, three paragraphs down, in the argument that was supposed to make the ban cheap: a guest to a bare symbol never buys any reach. A bare symbol is already in scope everywhere a guest to it could be declared. If you wanted to watch the variable, you can watch the variable — write main. The only reason to mint a guest at all is to carry the reference to places the symbol does not go: into a field, into a container, into a callee that keeps it. Every one of those is the object reading. The ambiguity we were protecting against was between one intention that needs a guest and one that has a shorter spelling, and we had removed the wrong intention.
So memory.md §2.8.1 now states it as a rule with two branches, matching the runtime’s behaviour all along. A guest names the object hosted at its source when it was minted. If that object is moved, the guest goes with it. If that object is destroyed by an overwrite of the slot it lived in, the slot’s hosting identity continues and the guest carries forward to the replacement. The two never compete, because an object cannot both leave and die in one step, and the program text shows which happened: a move is one statement and an overwrite is another. A reader has to carry only a single question — did it leave, or did it die — and the answer is legible at the line.
The case that looks like a puzzle and is not is re-hosting an emptied slot. After second = main, both guest and main denote the moved object; main downgraded to a guest to it, so the two agree and there is nothing to choose. Write main = Player() afterwards and they part: main names the new object, guest still names the old object, which is alive in second. That is not an ambiguity, it is two names for two objects — the move carried the old identity away, so the slot begins a fresh one rather than inheriting the guests of the object that left.
This is where we declined the rest of the package that was on the table. The proposal that accompanied the revert also made a moved-from symbol spent — unreadable after the move — on the grounds that a readable moved-from symbol keeps the “watch that variable” reading alive to compete with the object reading. We do not think it does. At the moment of the move the two readings coincide, which is the opposite of competing; they only diverge after a subsequent re-host, and by then the divergence is the ordinary fact that two different names denote two different objects. Making the symbol spent to prevent that would cost downgrade, not poison, a rule we like for its own sake and that has nothing to do with guest sources. So the downgrade stays and the revert is narrower than the proposal that prompted it.
With bare symbols pointable again, 'T has nothing left to do and goes. A reference-type parameter is T or &T (memory.md §2.9) — swallow it, or take a guest — and topSpeed(engine) works by declaring engine &Engine and passing the local as it stands. The ' character returns to being unused, its state before we borrowed it from Rust to name a concept for which Rust uses it differently.
The subject goes back to being an implicit guest. this now takes no marker at all, for either kind of type (functions.md §2.4), and this &T is gone rather than merely redundant — a guest subject may already be read, mutated, stored, or returned, so a marker selecting it would select the only option. This is the one place where we are giving up a property we said we liked. The borrow-mode chapter called it “the pleasing part”: a mut subject was a mutable borrow of the caller’s slot whether the type was a value or a reference, and the two worlds matched. They no longer do. A value subject is a borrow, a reference subject is a guest, and they are written identically because in both cases the subject is simply the object you called the method on and neither kind has a choice to express. The unification was real and it is lost; what it was bought with was a sigil on every non-consuming reference parameter in the language, and that is the wrong exchange rate.
One rule got shorter rather than longer, and we did not expect that rule to. Returning an & used to require a root in an &T parameter specifically, with the other two modes excluded for two different reasons — a borrow expires with the call, a swallowed parameter is a bare symbol and therefore not a source at all. Both exclusions are gone, and the rule underneath them turns out to be simpler than either: any parameter is a root, because a parameter belongs to the call-site scope (lifetimes.md §1.7). A guest rooted in one therefore names an object hosted in the very scope the return value lands in, so the scope comparison settles it at the call site with no special case. A local is still not a root, and now for the honest reason — its host is the body scope, which drains at the return — rather than for a reason about where guests may come from.
One cost is real and we are choosing it with our eyes open, and one apparent cost is not.
The apparent cost: merging stays reachable — but it was reachable before, through the field route above, so the revert does not spend it. Forwarding anchors, the retirement stacks, and the target-kind discriminator are permanent, and they were already permanent. What the revert does close off is a different set of proposals, the proposals that would have deleted the machinery by restricting the source language further — declaring which locals may be pointed at, or inferring it from where a guest is minted. Those are now off the table, and that is a real decision, just not the decision it is easy to mistake it for. It goes the way Zane leans: the merge machinery is written once, by the person implementing the compiler, and a source restriction is paid by every program that builds a structure and hands out a reference to it.
The real cost: a signature no longer guarantees non-escape. With three modes, 'T showed a caller that the callee could not keep the reference; &T showed that the callee might keep it. With two, &T covers both and the caller cannot tell them apart by reading the header. Nothing about this is unsafe — the scope rule keeps a guest from outliving its host, whatever the callee’s author intended — but it is a genuine loss of legibility, and it is the one argument for keeping 'T that survives the ban being lifted. We are not keeping it, because a mode that exists purely to document intent is a heavy means of documenting intent. If that turns out to be the wrong call, the tool to reach for is a non-escaping annotation on an &T parameter, not a third mode of passing an argument.
Contingent hosts float to their owner
The guest-source rule had always aimed to buy stability, but we had stated the boundary one expression too late. A subscript itself could not mint a guest, because a container may remove or replace an element while the container stays alive. We treated that as enough. It was not: players[100].weapon ended in an ordinary-looking field access, so it passed the rule even though the field existed only as long as element 100 did. The lexical owner comparison could not catch that. The container’s block may outlive the guest perfectly well while one storage position inside the container disappears underneath it.
Variants exposed the same mistake from the other direction. Their declaration deliberately shares a body grammar with structs, so a live case payload looks field-shaped when projected. But a struct field is a stable slot for as long as the struct that contains it, while a variant payload exists only while its tag is live. Treating both projections as guest sources because both use member syntax confused a syntactic symmetry with a lifetime guarantee.
Our first answer was the obvious answer: forbid the unstable source. memory.md §2.8 makes the whole path that originates a new & matter. A subscript anywhere in it disqualifies the mint, and so does a variant-case projection. A caller that wants a durable view keeps the guest one level higher — at the container or reference variant — and performs the subscript or abortable case read when it needs the interior value. Reading an &T already stored behind one of those accesses remains legal, because that copies a guest minted elsewhere rather than creating one from the unstable slot.
Review found the hole that answer did not close. A guest can predate the unstable storage:
node Node();
watch &Node = node;
holder Holder.some(node); // node moves; watch and node both remain guests
holder = Holder.none(Unit()); // the payload place disappears
Nothing in the source rule reaches the last line. The guest was minted while node was a perfectly stable symbol, and moving the object into the variant carried its anchor with it. In fact the move manufactures another guest automatically: the moved-from node symbol downgrades rather than becoming poison. The same shape exists for a container element. So merely refusing &players[i]-shaped origins was never enough; an object can acquire aliases first and contingent hosting second.
The static escape routes all cost a property more central than the problem. Forbidding an existing host from moving into contingent storage would make ordinary forms such as appending a named object or writing Expr.flip(inner) illegal while fresh nested construction stayed legal for an unrelated reason. Making the moved-from symbol spent would remove only one alias and leave any guest minted before the move untouched. Pinning an object once it had ever been guested would turn a read-only &T call into a restriction on where the object may later be stored unless we grew escape analysis around signatures. Runtime invalidation or guest counting would put per-reference machinery into the model precisely where anchors were meant to avoid it.
The answer that fits the owner model is to make the disappearing place stop being the object’s lifetime. memory.md §2.8.1 now gives a contingent host a third fate. If an element or variant payload disappears before its owner scope drains and its reference object is not explicitly moved elsewhere, the object floats into an anonymous host owned by that same scope. Existing guests follow the ordinary anchor path. The owner does not become longer, so a guest has not extended a lexical lifetime; the named contingent slot vanished and an anonymous host with the same owner took over.
That distinction reaches the anchor machinery too. A stable destination may own an anchor identity that survives replacement, so two anchored stable hosts can merge and leave a forwarding cell behind. A contingent destination never acquires that kind of slot identity: an incoming anchor remains the object’s identity, and if the place disappears the same terminal cell follows the anonymous float instead of being handed to the replacement (memory.md §4.5). That keeps the runtime rule aligned with the surface one — changing storage does not secretly become a stable name merely because an already-aliased object passed through it.
That is deliberately unconditional on whether a guest happens to be live. We could have looked at the anchor and floated only when one existed, but then whether an object dies would depend on whether somebody had referenced it, contradicting the rule that guests do not control hosting lifetime and quietly turning the anchor into liveness metadata. The price of the unconditional rule is conservative retention: a reference object removed from contingent storage without being relayed elsewhere can remain alive until the owner scope drains even when nobody can reach it. The arena model bounds that cost lexically, and an API whose author means to hand the object out may still move it explicitly instead of taking the float.
The source restriction still earns its keep even after floating makes the old alias safe. It stops a container index or live tag from becoming a durable identity of its own. Code that starts from changing storage must keep the stable container visible and re-project at use, rather than capture an element or case and silently detach its meaning from the operation that made it contingent. That is the surface rule we wanted in the first place; same-owner floating is the backstop that keeps aliases created before contingent hosting safe.
Per-field anchors when a struct moves
Floating settled an object’s fate when its place disappears. It left a plainer question standing, one the anchor machinery had answered only by implication: what happens when a reference struct moves while guests point at several of its fields? A field reached by a stable path is a legitimate guest source, so guests to s.a, s.b, and s.c may all exist at once. The spec stated that the merge rules applied “recursively” to contained hosts, and the payload-streams chapter stated the same in a sentence. Neither stated which hosts the recursion visits, whose anchor a field guest names, or the fate of the destination’s own field anchors when a move lands on an occupied stable host.
The answer was already fixed by the layout. Every reference-type instance carries its own backpointer (memory.md §3.3), and a field of reference type is an instance like any other, so a guest minted from s.a tethers the anchor of a, not the anchor of s. A move therefore owes each anchored field the same treatment it owes the outer host: re-target the cell when the destination position has no identity of its own, and merge into the destination field’s anchor when it does. The set of fields to visit is not discovered at runtime. A type’s reference-typed fields sit at offsets its declaration fixes, value-typed fields cannot contain any, and boxed payloads and backing stores extend the walk through the blocks rehosting already touches. The compiler can emit one backpointer check per contained host. memory.md §4.5 now states that walk and its three cases, and it states the piece that only followed from the stable-overwrite rule before: destroying an occupant keeps the anchors of its stable fields, because each of those fields is itself a stable slot of the host that survives.
Spelling it out made the cost visible, and the cost suggested another design. A struct with a hundred guested fields does a hundred anchor updates when it moves. We considered making the anchors relative instead. The outer host’s anchor would hold its absolute location, each field’s anchor would hold the parent’s anchor and an offset within it, and a guest would sum the offsets up the chain. A move would then update a single cell, however many fields beneath it were guested. It was also neat on the merging side, because a source root that becomes a forwarder carries every child anchor under it along for free.
We kept flat anchors, for three reasons. The first is where the cost lands. In the anchor chapter we chose one dependent load on every read over unbounded work on every move, because objects are read through guests far more often than they move. A chain puts a load per nesting level onto every read to save work on the move, which is the trade that chapter declined, now in the other direction (memory.md §4.4). The second is that the saving is smaller than it looks. A move already copies every byte of the struct, including each field’s backpointer word, so checking those words adds a constant factor to work that is proportional to the struct’s size anyway. Relative anchors would lower a constant factor on moves while raising one on every access. The third is that the chain has no offset to hold once it crosses a block. A boxed member’s payload and a list’s backing store live in separate dynamic blocks that relocate on their own, and list growth moves elements while their host stays put. A chain across a box has to dereference the handle, and through a recursive type its length is the depth of the structure, so a guest into the thousandth node of a boxed list would cost a thousand loads per access. The repair is to make every block boundary an absolute root, and the anchors inside relocated blocks are exactly the anchors rehosting already updates one at a time. The hybrid would have saved work only on inline fields, and paid for it with a third anchor kind, ancestor anchors forced into existence by any deep guest, parents that could not retire while children named them, and a re-parenting step whenever a field moved out of its struct.
The cost we accepted is that anchor work on a move scales with the number of guested hosts the moved type contains. It is bounded by the type, never by the number of guests, and it is paid only by values that are moved, not by every value that is read.
Dynamic bytes without reference identity
The string decision retired one example in the deep-copy chapter: String no longer belongs beside List as a reference type forbidden inside a value. We kept the prohibition on reference fields, and changed which side strings occupy. Their dynamic size did not require identity; the existing ownership and deep-copy model already had the machinery their bytes need.
That extends the accounting from boxes to backing stores. A string’s handle stays inline, its bytes occupy the dynamic region, and a value copy allocates independent bytes in the destination’s region (memory.md §2.3). No anchor follows those bytes, and a stored guest cannot name the string. Passing it to an ordinary parameter still borrows. We accepted copying where a value is stored, while keeping allocation, replacement ordering, and destruction under the rules already used for other owned value payloads.
Settled and roaming: the host that stopped moving
Everything above treats a moving host as the normal case and a guest as the party that has to keep up. The anchor was built so a guest could follow its object through a move, the float so it could follow the object out of a disappearing place, the forwarder so two moving identities could merge. Each of those was a sound answer to a question the previous design had just raised, and each made the next question harder. The compiler’s memory test suite made that visible all at once, because it ran the spec’s own examples instead of reading them. It found a callee that moved a swallowed value into a local and left the caller’s guest dangling once the local drained, a constructor whose guest outlived the value it named, and a refill that silently destroyed an object a guest still watched. The last of these broke the pattern. g &Engine = lend(e); e = Engine(2); left g naming the new engine, because lend had swallowed e’s object without moving it anywhere, so it still sat in the spent slot the refill overwrote. We could make g keep the old engine, by floating the old occupant out of the slot first, or make it follow the slot, by changing the meaning of a refill. Both were defensible. Neither was nice, and we judged the scenario itself — a host moved out of its symbol while a guest watches it — uncanny rather than merely unfinished.
The first idea was a third kind of type beside value and reference: a single-owner type that moves into anything but can never be guested, while reference types lose the ability to move out of a symbol at all. An owner would be built and bound to a symbol, single-owner values would be fed into it, and the owner would sit still for the rest of its life. We had been close to this once. The slot that could not be pointed at records making every object immovable and why it failed: a move whose destination was chosen at runtime could not be written, and a list’s backing store relocates whatever the model claimed. The new idea survives both, because it splits the two jobs. An object that has to travel travels in a state nobody can watch; only a watchable object stays put.
The question why the movers could not simply be value types settled their nature. A single-owner value moved into an owner’s hosting field becomes that field’s host, and hosts are exactly what guests point at, so the mover has to have the reference type’s shape, fields and all. It cannot be a separate kind of type. It is the same reference type in a different state. So the third kind of type became a modifier, written where a host is declared, the way & is: a reference-type host is either settled — guestable, and never moving again — or roaming — free to move anywhere, and guested by nothing. A roaming host settles by moving into a settled place, and nothing settled ever roams again.
The state is the place’s, not the type’s, and one rule settled how it propagates. A host’s insides travel with it, so a field inherits its root’s state: everything inside a settled host is settled, and everything inside a roaming host is roaming. That made the default an easy choice. We considered flipping it, so that a bare declaration roamed and a marker settled it, but a field already carries “whatever my root is”, so only a root needs a marker at all, and marking the rarer state at the root gives one marker with one meaning in every position. Bare stayed settled. Roaming is written ^Car. We weighed the sigils that were free and rejected each for a meaning it would drag in: * reads as a C pointer, % already introduces string interpolation, > after a lowercase name is a comparison, ~ is the flip operator, and #, which we tried first, already marks has identity where a type is declared, the opposite of a roaming host’s nature. ^ was the only character left with no meaning to fight. We took it without much love, and provisionally.
The names were argued the same way. Loose was the first word for the moving state and the right image, but the spec already calls '* the loose form of an operator, and a second loose would fight the first on every page that used both. Pinned imports Rust’s Pin along with its wrapper type and its unsafe, and fixed also means repaired and fixed-size. Settled reads in the hospitality register host and guest already live in — a guest can only visit a host that has settled — and roaming is its opposite in the same register, with no claim on it in programming worth defending.
Storage split along a line the containers drew for us. Fixed storage inherits: a struct’s fields are all there from construction and never come or go, so they share their root’s state. An array is the same shape, fixed in size and filled at construction, but it is a value type and holds no host to begin with. Dynamic storage does not inherit: a list’s elements and a variant’s payload are roaming even under a settled root, because they are places that appear and disappear while their owner lives. We considered settled lists, whose elements could be guested because they would never be moved out. That is a dynamic container that may grow but never shrink, and a container with that asymmetry has surprising semantics wherever it is used; a dynamic container should be strictly dynamic. So a settled list may itself be guested, and its elements never are. The float, which existed only so that a guested object could survive its place disappearing, has nothing left to rescue: nothing in a disappearing place is guested.
Fields were the last question. We considered letting a field be declared roaming, so a settled object could hand a child off, and found it could not be checked where it is written — a struct’s declaration cannot show whether a given instance will settle — so a roaming field was dropped. What falls out instead needs no syntax: a field of a roaming host may be moved out, because the host is roaming, nothing can be watching it, and the gap is tracked in the host’s declaration block exactly as a spent symbol is. A field of a settled host is never moved out, only overwritten. A swap that takes a settled object’s child out while putting a replacement in would let a settled object hand children off; we left it for when a program needs it.
One consequence we only noticed by following a constructor through. A roaming value cannot hold a guest into its own insides, because nothing inside a roaming host is guestable. That retires the shape we had just made legal, where a constructor mints a guest to its own field and the guest travels with the object — and it should, because a guest that points inside a value that is still moving is a guest whose meaning depends on where the value lands. Wiring an object to its own parts happens after it settles, from outside: kit.mount!attach(kit.engine).
The cost lands at every move boundary. A factory returns ^Car, a verb that takes ownership declares ^Car, and a symbol that will be returned is declared ^ from the start, because a settled host cannot leave the block it settled in. A program that wants a guest to one object among many keeps the objects in settled fields or an array, never a list. What we bought with that is the subject of the next two chapters: most of the machinery this story has built so far turns out to have existed for the one combination the split removes.
The borrow comes back, without a sigil
The split reached the subject first. A method’s this on a reference type had been an implicit guest (the ban chapter put it back there), and a roaming host cannot be guested. So this became a borrow in every method: access to the caller’s host for the duration of the call, never stored and never returned. this already worked that way for a value type, so the subject stopped being a special case on either side of the # axis, and a method never moves its subject on either side either. The cost is a shape we had used as an example for a long time: &Weapon getWeapon(this Player) => this.weapon cannot return a guest rooted in a borrow. It becomes a function, &Weapon weaponOf(player &Player) => player.weapon, called with a settled player.
That exposed the parameters. A read-only helper peek(car &Car) could not take a roaming car, and our first answer was to let an &T parameter accept a roaming argument whenever the callee neither stored nor returned it, decided by the summary that already records where parameters come to rest. The better question was the meaning of a bare Car parameter at all. It had denoted swallow — the callee takes the host, but the value stays hosted at the call site — and that middle state was the source of the dangling local, the lent-value rescue and the refill that destroyed a watched object. With a real move available as ^Car, swallowing had no job left. So a bare reference parameter became a borrow, exactly as a bare value parameter already is, and a reference type’s parameters became three plain modes: bare borrows, ^ takes the host, & takes a guest. The helper is peek(car Car) and takes either kind of host.
We had owned a borrow mode for reference types once, as 'T, and retired it (the ban chapter) because a second sigil whose only job was routing around a restriction was not worth learning. This borrow has no sigil. It is the bare spelling, it carries the meaning the bare spelling already had for values, and the restriction it once routed around is gone.
We asked whether value types should get ^ too, for symmetry, and the honest answer was that taking ownership of a value means almost nothing. A value has no identity, so a value moved into a callee is indistinguishable from one copied there and never used again. The only visible effect would be a restriction — the caller’s symbol spent — and the only benefit, skipping a deep copy, is one the compiler can take on its own wherever a stored argument is the caller’s last use of it. So value types stay bare-only, and the compiler moves on last use as an optimization the spec need not mention. The asymmetry is the identity axis itself: ^ and & exist because a reference object has a host and can be watched, and a value has neither. A type parameter written ^T therefore means a move only when T is a reference type; instantiated with a value type it reads as the bare form, so a generic push(value ^T) serves both kinds.
Guests without anchors
An anchor exists so that a guest survives its object moving. The anchor chapter built it for moves out of symbols, the payload-streams chapter carried it across scopes, the float carried it out of disappearing places, and forwarders merged identities when one anchored host landed on another. Going through the reasons an object moves, one at a time, against settled and roaming: a move out of a symbol or field happens only to a roaming host, which has no guests; a list’s storage relocating moves only roaming elements; a disappearing place holds only roaming values; a value relayed through a parameter and back moves as ^T, roaming the whole way; and a spawned call’s result comes home roaming until it is bound. Spawned work never mutates a reference-typed object, and the water tower keeps a scope’s hosts where they are until every spawn in it is done. No reason is left. A settled host does not move from the moment it settles until its scope drains.
So a guest is the settled host’s own segmented offset (memory.md §4), the same 32 bits a tether was, now naming the host directly instead of a cell that names it. The global anchor pool, the backpointer in every reference-type instance, forwarding cells, retirement stacks and lazy anchor creation all go. Reading through a guest loses one dependent load. A stable overwrite already guaranteed that a guest sees the replacement (memory.md §2.2), and it now does so for the plainest reason there is: the replacement is written at the same address. One rule was needed to keep that true below the surface. A boxed member’s payload had been returned and reallocated when the member was overwritten; under a settled host it is now overwritten in its own block, so a guest into it keeps its address.
The slot that could not be pointed at ended by saying anchors exist precisely so that objects can move. That was right, and it is why they go: the objects that can move are now the objects nothing points at. The cost of losing them is not in this chapter. It is the cost the first of these three chapters already counted — ^ at every move boundary, and no guest to anything a list holds.
Settled overwrites stay in place, and only an escape relocates
Bringing the C bench harness up to settled and roaming hosts meant deleting the anchor pool, the backpointer and the forwarders, and then reading every remaining layout rule for its role in serving a guest. Two of them were still doing it for an anchor. The first was the rule for moving into a host that already held an object: destroy the occupant, then relocate each of the incoming host’s dynamic blocks into a freshly allocated block. Under anchors that was harmless, because the anchor was retargeted to wherever the new blocks landed. Under plain offsets it dangles. The previous chapter had already kept a boxed member in its own block when it is overwritten, but only the member itself. A guest to car.engine.turbo, with both members boxed, still named a block that the overwrite of car.engine handed back to its size stack.
We could have made a guest’s legality depend on boxing and rejected any guest that crosses a boxed member. We rejected that at once: boxing is the compiler’s choice, permitted off a cycle and invisible in the source, so the same path would be a legal guest under one compiler and not under another. Instead we followed the struct’s shape. Occupant and replacement are the same type, so every boxed member the occupant holds has a block of exactly the size the replacement’s member needs, and overwriting a settled host now writes into those blocks at every depth a guest can reach (memory.md §2.2). The recursion stops at a variant payload, which nothing guests into and whose cases need not match. A fresh replacement is built directly in that storage; a moved-in one is copied into it and its own boxed blocks are returned.
Asking why the move-into rule existed at all, the history answered plainly. Its section had two jobs: retargeting anchors, and promoting an object that escapes a draining scope. The first is gone, and the second was already stated in the section beside it, so the section folded into that one.
The second rule was relocation itself. Every roaming move reallocated every block the host owned in the destination scope’s dynamic region and copied the contents across, recursively. That was cheap to accept while each move was retargeting anchors anyway, and it bought nothing a guest could see. With nothing inside a roaming host guested, the only question left is memory: the blocks must never outlive the arena they sit in. A move within the scope that holds them, or into a callee, leaves that scope alive for as long as the destination, so copying the handles is enough. Only an escape — a return out of the scope that allocated the blocks, or a store into a host declared above it — needs every block to sit in a scope that lives as long as the destination by the time the source drains. The spec now requires exactly that and leaves the means to the implementation, which may relocate on escape or allocate the blocks in the outer scope from the start (memory.md §3.5).
The cost is that escape still costs what relocation always cost unless the compiler places the blocks ahead of time, and ^ at every move boundary makes escapes common: a factory that returns a large tree pays O(tree) at its return. What it no longer pays is the same price again at every hand-off inside the scope that receives it.
ArrayRef: a fixed reference container whose elements can be guested
The settled-and-roaming chapter advised a program that needs a guest to one object among many to keep the objects in settled fields or an array, never a list. Half of that advice did not work. Array is a value type, and a value type may hold no reference type, so an array of objects with identity could not be written; the only settled storage for many objects was a set of named fields, and a program cannot have a thousand field names. Lists were never the problem. A settled list may be guested as a whole, and its elements reached through that guest by subscript, so nothing a list holds needs a guest of its own. The missing piece was fixed storage for many reference objects, the one shape whose elements cannot come or go.
The obvious repair was to let Array’s side of the # axis follow its element type: a value type over values, a reference type over references. We rejected it because it fuses two constructs under one name. Array is the value world’s fixed container, copied whole like everything else in that world, and making the same name denote a moved, guestable, identity-carrying host whenever its element happens to be # would make every reader of Array<T, n> ask which of the two it is. So Array stays a value type that holds only values, and a second primitive, @primitives$ArrayRef<T, n>, carries the reference form (generics.md §8.4). It has the same layout and is generic over any T, exactly as a generic #struct may hold either kind: a reference type may contain values, so nothing forbids ArrayRef<Int, 8>, though only a reference element can be guested. The name describes the type: an array on the reference side of the axis.
Its elements needed no new rule. They are fixed storage, all present from construction and never removed, which is the property that let a struct’s fields inherit their root’s state, so an ArrayRef’s elements inherit it the same way: settled under a settled root and guestable, roaming under a roaming one. One field rule did not carry over. A field of a roaming root may be moved out because the compiler tracks which field is spent, and an element’s index is a runtime value that no such tracking can follow, so an element is only ever overwritten in place. A reference type has no zero value to fill the elements with either, so an ArrayRef is built from an array literal or by the named constructor ArrayRef.fill, which calls a lambda once per index.
The guest-source rule had excluded any path through [], and ArrayRef needed a subscript that qualifies. Rather than mark subscripts, we let them follow the place they project (functions.md §2.9). A subscript’s body is itself a place expression, so whether squad[2] may mint a guest is whatever is true of the place the body names, followed through every subscript and field until it reaches an intrinsic projection. That is the same reasoning a verb returning &T already uses: whether return someCall(guest) type-checks depends on what someCall returns, not on the verb that forwards it. Exactly one intrinsic origin can be guested, the ArrayRef element under a settled root (memory.md §2.8).
The cost is a second fixed-size container that shares Array’s layout and differs in kind, so generic code over “a fixed run of T” chooses one, and an element can be replaced but never handed off.
Owner and reference replace host and guest, and the store rule compares scopes
The settled-and-roaming chapters left the spec stating one rule over and over: nothing may point at a roaming host. Every time it was written, the vocabulary got in the way. “Guest” is a noun with no verb, and a rule about what may stand in a relationship needs the verb as often as the noun. So the spec had been forcing one, about forty times: a settled host “may be guested”, a roaming one is “guested by nothing”, “nothing guests it”. “Nothing may reference roaming owners” states the same rule, and the version in our own vocabulary came out as “there may not be any guests to roaming hosts”. A term that fights every sentence about its own central rule is costing more than a style complaint, because writers route around it with passives and generic words, and a generic word drifts away from the term it stands in for.
Our first repair kept the noun and borrowed a verb. A guest visits a host, and the glossary was already reaching for that word (“a guest can only visit a host that has settled”). We rejected it quickly. “Visit” names the act of going to the object and using it, which is a dereference, while what the rules need is the standing relationship of holding an & at all. Every other verb of access (use, reach, touch) failed for the same reason.
So we dropped “guest” and looked for a word that bends into both forms on its own. link came back first: plain, a noun and a verb, a relationship with no suggestion of ownership. Naming the tether had set it aside once for colliding with linked lists and the linker. This time the objection was weight. A link reads as information, a pointer you may follow or ignore, and an & is the opposite: an obligation the compiler holds the program to. The other candidates each lost on one count. pointer is the most accurate word for a repointable, storable address, and it arrives with null and pointer arithmetic attached. pin has the best image, since only an object that holds still can be pinned, but the dependency spec already pins every version. address is literally true, but as a verb it mostly carries the sense speak to, and it is the machine-level word the source vocabulary had been split off to avoid. tie, bookmark, mention and attach were each workable, and each was lighter than the rule. That last failure named the requirement. The word should already carry the danger, so that a reader who meets the word already expects a handle that can dangle and must not outlive its target. Programmers learned exactly that about one word, and it was the word we had renamed away from.
reference had been given up because of reference type. Naming the tether left “ref” so the # axis could keep “reference” to itself, and our first instinct now was to rename the axis instead. Identity type and object type were the candidates, and we liked neither. What changed our mind was reading the two words together as a rule rather than a collision. An &T requires T to be a reference type, because only a reference type has an owner to point at (memory.md §2.4). A reference type is precisely the kind of type a reference may name, and the reason reference types need safety rules at all is that they can be referenced, which a value type cannot be. “A reference to a reference type” stopped reading as an echo and started reading as the definition. The one real hazard was smaller. A reference-type field owns its object, and a “reference field” would not, so one hyphen would carry the difference between owning and not owning. We closed that by naming an & slot by its sigil, an & field or an &T parameter, never a reference field (the spec guide §6.6).
With the guest gone, host had nothing to pair with, and the reasons it had won were gone too. In the two-vocabulary chapter we preferred it because “owner” stressed rights and destruction more than residence. Under settled and roaming, the role is ordinary ownership: one per object, governing its lifetime, handed on by a move. The plain word fits, and it gives the verb back for free (“car owns the engine”, “nothing owns the result”).
Owner was already taken, though. The lifetimes story had used it for the lifetime the store rule compares: a symbol’s declaring block, or a field’s root symbol’s. With hosts renamed, “the owner’s owner” would have been a real phrase, naming two different links of one chain, the slot that holds an object and the block at the root of that slot. We tried “owning scope” first and rejected it for making a block an owner by implication. A block is not an owner of anything: nobody had ever called a block a host, and the new vocabulary should not start. What the store rule compares is always a block, so we called it by its plain name, a place’s scope (lifetimes.md §1.1). The spec’s own prose had been calling the check “the scope comparison” all along. Now every sentence names one link: car owns the Car, and car’s scope is the block that declared it. Owning edges and owning steps, which describe the slot-to-object link, now match “owner” instead of competing with it.
The runtime pair went too. Anchor and tether had lived on in the contributing guides as an internal register, though anchors were removed and nothing in the memory model carries either name. They are now history in this story and nowhere else.
The cost is that the language now uses “reference” for two connected concepts, and a writing rule keeps them apart where the words alone would not. Readers also arrive with expectations from other languages. A C++ reference cannot be repointed, and a Zane reference can be repointed and stored. In Java a variable of reference type is a reference, while here the same declaration is an owner. Settled also loses the hospitality register it was chosen in, where a guest could only visit a host that had settled. It keeps its own image of a settler who has stopped travelling, which is the half of the argument that never depended on guests.
A call may not write what it borrows
With the vocabulary settled, we turned the compiler loose on the model it describes and wrote small programs to break it. The rules held where the spec stated them. Where it fell through was a place the spec had never looked: the inside of a single call. A borrow lends a place for the whole call, and we had treated that as a promise about the callee, which may not store, return or move the lent place. Nobody had asked about the rest of the call’s behaviour while the loan stands.
The answer is that it can destroy the borrowed storage. A mut method on a list, handed one of that list’s own elements as a borrow, may grow the list, and a growing list moves its elements to a new block; the borrow then reads freed memory. A variant subject that changes case destroys the payload a borrow argument names. A block argument captures the caller’s frame, so readAfter(engines[Int(1)], { engines = freshEngines(); }) frees the element before readAfter reads it, with no subject involved at all. An argument written after the borrow can do the same while it is evaluated, before the call even starts. A match binder is the same shape spread over an arm instead of a call: the binder is the payload’s own place, and an arm that overwrites the scrutinee destroys it. Every one of these was accepted, and every one read garbage once the freed block was reused.
A sixth case destroyed nothing, and that case settled the rule’s shape. v!setFrom(v), with V a value type, borrows v twice, once as the mut subject and once as other. The spec states that a value parameter is a borrow of the caller’s slot and lets the compiler pass a copy only where nobody could tell. Here somebody can: after this.x = Int(100), a borrow of v reads 100 and a copy reads the old value. The compiler passed a copy, and a #struct written the same way, passed by address, gave the other answer.
We weighed two narrow fixes first. The memory-safety cases could be closed by a rule aimed only at storage that can be freed: no borrow into a list element or a variant payload while another argument or block of the same call could grow the list or change the case. And the copy could be fixed in the compiler alone, passing a value by address whenever the subject might reach it, which the spec already required. Both would have worked. Together they make a rule with a list of exceptions — a borrowed field of a settled subject is fine, because a field is overwritten in place and the borrow sees the replacement; a borrowed element is not; a value aliased with its subject is fine but observes writes mid-call — and every caller would have to know which side of each line their argument fell on. We also looked at making the runtime safe instead, by copying or pinning a borrowed element for the duration of the call, and turned it down for the reason the model has always turned down tracking: it pays at every call for a case almost no call has.
So we took the stricter rule and stated it once (memory.md §2.9.1). Nothing else in a call writes a place the call borrows: not the mut subject, not a block argument, not a later argument. Overlap is judged by place paths, and any two elements of one container overlap, since an index is a runtime value. The match binder gets the same rule from the arm’s side (adt.md §5.1): while it names the payload, the arm may write through it but not around it. The copy question then disappears instead of being answered, because the program that could observe the difference no longer compiles. The compiler already reasoned this way for spawned calls, refusing a write to a list whose element a spawn had been lent; a synchronous call lends for a shorter time, but to a callee that may write its subject, so the same reasoning applies inside it.
An &T argument stays outside the rule, and that is not an exception but the difference between the two modes. A reference names a settled owner, which an overwrite replaces in place, so a reference that sees a write elsewhere in the call is doing exactly what references are for. A borrow is the caller’s slot lent for a moment, and the moment is only safe if it is quiet.
The cost lands on programs that were never in danger. car!tune(car.engine) borrowed a settled field of its own subject, which an overwrite would have replaced in place, and it is now refused. names!push(names[Int(1)]) — append a copy of one of my own elements — is a natural line to write, and it now takes two: copy the element into a local, then push the local. car!swapFrom(car) worked and is refused. We judged a rule with no exceptions worth those extra lines, because the callee is the other party: a method written against this rule never has to wonder whether a parameter changes under it while it runs.
The rule’s widest reach is into code that is not about memory at all. if is an ordinary declaration whose condition is a value parameter, so if(dirty) { dirty = Bool(false); } borrows dirty and hands the call a block that writes it, and the rule rejects it. We considered one exception here: pass a value argument as a snapshot whenever a block or a later argument of the same call writes it, which would let the flag be cleared and leave if reporting the value it was called with. We turned it down because it gets the model backwards. A value parameter is a borrow; that is the design, and the compiler may substitute a copy only where no program can tell. An exception that copies precisely where a program can tell would make copying a semantic rule for one shape of call, and a reader would have to identify that shape to learn the meaning of a parameter. So the condition is copied by its author instead, into a local the call can borrow without conflict, and the one extra line spells out exactly the copy the snapshot exception would have made silently.
A destination is located after its value
The same probing found a second order question, one level smaller. ints[Int(1)] = ints!growBy(Int(1000)) stores into an element of a list that its own right-hand side grows. The compiler worked out the element’s address first, then evaluated the right-hand side, which moved the list to a new block and returned the old block, and then wrote into the block it had already given back. A ! call on an element whose argument grows the same list did the same: the subject’s address was taken, the argument moved the list, and the method wrote into freed memory.
The spec had fixed half of this already. An overwrite reads its right-hand side against the destination’s pre-overwrite state, so x = x.child is safe, but it stated no rule for when the destination is found. We could have refused the shape outright — no ! call on a list inside a store into, or a call on, one of its elements — and the borrow rule of the previous chapter is exactly that kind of rule. But there is nothing here for a rule to protect. Nothing is borrowed across the gap; the write simply needs to land where the element is when the write happens. So the destination is located last (memory.md §2.12): a store evaluates its destination’s operands, then its right-hand side, and only then finds the place, and a ! call does the same with its subject after its arguments.
This leaves the two rules dividing the work along a line worth naming. A subject is located after the arguments, so an argument that grows the subject’s list is harmless and the borrow rule need not mention it. A borrow argument is taken when it is evaluated, in written order, so a later argument that writes it is a conflict the borrow rule does reject. We could have located every borrow late too, but a borrow argument may itself be a computation that selected its place — a fallback that picks a payload, a match — and re-locating it after other arguments had run would answer a question its own evaluation had already settled. The asymmetry is the cost: two arguments to one call are treated differently depending on whether one of them is the subject.
No growable list of references
The last gap the probes found was a list that could be declared and never filled. List<&Port> was legal, and the spec’s own examples read references out of one, but push takes its element as ^T, and with T an &Port the parameter became ^&Port — take the owner of a reference — which the spec gave no meaning. The compiler refused every push.
The obvious repair was to give it one: let ^T filled with an & behave as an &T parameter does, minting a reference from a settled argument and recording that it comes to rest in the list. We decided against it, because the more we looked at the list it would enable, the less it made sense. A reference names a settled owner, and the store rule requires that owner’s scope to outlive wherever the reference lands. A list that grows over its lifetime would be collecting references whose owners all have to outlive the list, one push at a time, and nothing in the shape of a growable collection fits that constraint naturally: what a program usually wants from “a list of things I point at” is either a fixed set of them, or a collection that owns them. The first is an ArrayRef of references, which stays legal, and the second is a list of owners. Giving ^ a second meaning to keep the third shape alive would have made ^ mean “hand over the owner” except when there is none.
So ^T is never filled with an & type (memory.md §2.9), and a list’s element type is never one either (generics.md §8.3). A list may still hold objects that carry references in their & fields, and reading one of those copies a reference that was already stored. The bare list of references is gone, and with it the one container whose contents could grow without anything owning them.
Overlap through a reference is checked where the reference is known
The borrow rule judged overlap by place paths, and review found the case paths cannot see. Two & paths can name one object: a type holding left &List<Int> and right &List<Int>, both pointed at the same list, makes this.left!push(this.right[Int(1)]) exactly names!push(names[Int(1)]), with every path in it diverging at the first field. Two & symbols initialized from one list do the same in two lines of a body. The compiler had already declined to follow either, but the spec stated no rule for them, and by its words both were legal.
The first answer we wrote down follows the object where it is visible and presumes the worst where it is not. An & symbol in the body stands for the place it was initialized from, so r[Int(1)] with r from names is names[Int(1)]. Everything else reached through a reference, a field or a parameter, may be any object of its type. We weighed a stricter version that judged every path through a reference by type, symbols included. That answer was simpler to state, but it rejected names!push(r[Int(1)]) with r taken from a different list two lines up, which the body can plainly see is safe.
Then we looked again at what “everything else” cost. Under it, this!push(from[Int(1)]) with from &List<Int> is refused in the body of append, for every caller, though nearly every caller passes two different lists. The body cannot see the target of from, but each caller can. So the question moves to where the answer is (memory.md §2.9.1). The body takes an &T parameter to be apart from its subject and its block parameters, and where it relies on that, the signature records the pair, the way it records where a parameter comes to rest (lifetimes.md §1.11). Each call checks the pair against what it passes: names!append(spares) is legal and names!append(names) is not. A caller that passes its own &T parameter on cannot answer either, so it records the pair in its own signature. The question climbs from the leaves of the call tree until it reaches the first frame that can see both places, and it is answered there.
Fields do not get the same treatment, because no frame is in that position. An & field was set wherever its object was built or last repointed, possibly in another package and long before the call, so no caller can see both places either. The compiler still rejects grow. Neither does a call through a function value, whose type records no pairs, so it keeps every &T argument apart from its mut subject and its block arguments, just as the resting-place check already presumes the worst of such a call.
Following the object instead of the path also exposed two writes the rule had not been counting. A ! call can write through the references its subject holds, in & fields or in the elements of an ArrayRef of references, as well as into the subject, so a borrowed element of a list one of them names is as much at risk as one of the subject’s own. And a block parameter passed on to a call runs the caller’s code, so peek(names, { names!push(Int(1)); }), where peek borrows an element through its &T parameter and runs the block while the borrow stands, reads freed memory without any write in sight in peek’s body. Both are now writes: the first of whatever the subject reaches, by type, and the second of whatever the block writes, which becomes another recorded pair. A repointing counts wherever it is written, too. A symbol pointed at one list and repointed to another at the bottom of a loop body names the second list on the next run of the statements above, so the body counts every place the symbol is ever pointed at, in any order.
The fixed-size region gets a bound the root manifest sets
The bound came out of a measurement, not a principle. The compiler placed every fixed-size slot with a runtime call of its own, and a profile of a loop that declared four small owners per iteration found about 600 of its 646 instructions spent in that bookkeeping (compiler#220). Each slot took a lock, rounded the frontier to its alignment, checked whether the current 1 MiB chunk still had room, and zeroed itself. Every one of those sizes was known when the program was compiled. Only the position was decided at run time, one slot at a time, and the check against the chunk’s end was there because the chunks of memory.md §3.1 are separate mappings at unrelated addresses.
The fix is the fix every machine stack already uses: lay each scope out as one frame when it is compiled, and place the whole frame with one pointer bump when the scope opens. That only works if the frames of one thread of execution sit in one contiguous range, and a contiguous range has an end. A chain of chunks never had one, since another chunk could always be mapped at another address. A range cannot grow past its reservation without moving, and a settled owner never moves. So the change that made a scope cheap to open also made the fixed-size region finite, and the question became the behaviour at its edge and who decides where the edge is.
We weighed two other answers before the answer we kept. A chunk per scope, sized at compile time, keeps the region unbounded, but every scope entry then maps memory or searches a pool of drained chunks. That costs about what the per-slot calls cost, and loses the locality of reusing the same pages. A check at every scope entry, comparing the new frontier against the range’s end on a branch marked unlikely, keeps the edge safe for a compare per scope, and it was our first plan. Then we looked at the size we meant to reserve: 256 MiB, thirty-two times a Linux main thread’s stack, holding only fixed-size slots, since lists and strings keep their data in the dynamic region. A program that fills that much with nested scopes is almost certainly recursing without end, and for that program a clear error is the right answer, not more room. So the range ends in a guard of unmapped addresses, and running into it is the check. Only a frame larger than the guard, which could jump over it, is compared before it is placed.
A fixed answer would still be wrong for the program that really does nest deeply, so the size is configurable, and the manifest is where a project’s build decisions already live (dependencies.md §2.1). Only the manifest of the project being built counts. A library cannot know how deeply the program that uses it nests, and it should not be able to make every program that depends on it reserve more, so a fetched manifest’s fields are ignored, as its from column is. We named the fields after the region they bound, fixed-region and spawned-fixed-region, rather than after a nesting depth, because the bound is in bytes: a scope holding a large array counts for more than one holding a counter.
Spawned calls get a field of their own, and a much smaller default, because of where their frames go. Each spawned call runs with its own nest of scopes, kept until the call’s result comes home (concurrency.md §3). The pool runs those calls on one thread per processor, but a program that spawns ten thousand calls before joining any has ten thousand ranges reserved at once, the way a server holds one lightweight thread per connection. At 256 MiB each, the compiler’s limit of 65,535 contexts would come to 16 TiB of address space. That fits in a 64-bit process, but it trips ulimit -v wherever that is set. We gave a spawned call 8 MiB, a Linux thread’s stack, which spawned-fixed-region raises (memory.md §3.7).
The cost showed up as soon as the range was built. The bound rarely binds. Calls nest on the machine stack too, a few MiB that the system sizes, and an ordinary recursion fills that long before it fills 256 MiB of frames. Before the range, the compiler’s runtime kept its scopes in a table of 32,768 and stopped a deeper program with an error. With the table gone, the machine stack was the next limit, and a full machine stack is a crash. So the bound came with a second rule: a program that fills the machine stack stops with an error too, and the spec states that rule beside the bound. The manifest sets only one of the two limits, though. The machine stack’s size is the system’s, so the field the error names matters for programs with large frames, and a deeply recursive program with small frames has nothing to raise. The reservation itself costs no memory, since a page takes RAM only when it is first touched, but it shows: a tool that reports a process’s virtual size counts the whole range, so a program that prints one line appears to use 256 MiB.
Review then found that the fields had no top. A manifest could request 64 GiB of frames, but the specification still described a u32 segmented offset reaching 32 GiB across all live chunks. We first capped both fields at 32GiB to make the new rule match that description. Looking back, the description was already outdated: the compiler used native addresses, and preserving the old representation was the only reason to impose the cap. The correction belonged in the addressing model, which the next chapter records.
Native addresses replace segmented offsets
The region fields exposed a mismatch we had carried forward from the segmented-offset design. We had accepted its 32 GiB ceiling in exchange for four-byte links, and the specification still described the chunk-directory lookup on every dereference. The compiler already stored native pointers instead. Capping a manifest field to preserve the earlier wording made the mismatch into a new restriction rather than correcting it.
So we replaced the segmented representation with native addresses (memory.md §3.1). A reference stores the address of its settled owner, a dynamic handle stores its payload’s address, and an exact-size stack stores the address of each returned block. Settled ownership still does the work that removed anchors: the object a reference names stays where it is, so reaching it needs neither a forwarding cell nor a chunk-directory load. Dynamic allocation can still use chunks without making the chunks part of every stored address.
With that representation, neither region field has a language-defined maximum (dependencies.md §2.1). The fixed-size frames share their reserved contiguous range, and dynamic payloads live outside it. What the system lets a process reserve determines whether a requested range can be made; a toolchain still checks that the byte count is representable, and a failed reservation stops the program. Reserving addresses does not allocate RAM for the whole range. This retires both the shared 32 GiB reach and the claim that the configured bound sets no addresses aside.
The cost is the space we had saved: a reference now occupies one native pointer, eight bytes on a 64-bit target, and boxed child handles and free-stack links have the same width. We give up the compressed representation’s cache density and remove its address decoding and artificial ceiling. The benchmark harness follows the native representation too. Its allocation tests now include four-owner scope frames placed with one bump and fixed slot offsets, alongside the per-owner allocator baseline. Published timings remain labelled as measurements of the earlier model, with the scope-frame rows unmeasured until a new full-suite run is made.
Passing stays implicit, and an ArrayRef takes its element type
The compiler had accepted & written before an expression, which the spec never had: a reference is minted where a settled place is stored into an & slot (memory.md §2.8), and nothing is written at the place itself. Taking the prefix out showed what it had been holding up. An ArrayRef of references had been built as ArrayRef([&p, &q]), and without the prefix there was no way to write it from the owners. A literal reads its element type off its elements (syntax.md §2.9), so [p, q] is a literal of Port, and the declared ArrayRef<&Port, 2> of the local it lands in cannot reach back into the call. For the compiler to build it anyway, it would have to work out from where the array is going that its elements were meant to be passed as references, reasoning backwards from the destination to the argument.
That made us question implicit minting itself, since every &T parameter and & field already works that way: the call site writes inspect(e), setSpare(e), or setEngine(e) identically, and the signature determines the mode (memory.md §2.9). So we tried putting the passing mode at the call site. The first version marked every argument with its mode, &g even where g was already a reference, which repeats at every use the mode the declaration states once. The second marked only a change of mode: an expression passes in its own mode, and an operator is legal only where it requests another mode. That left & on a settled place, to mint, and nothing for borrowing a roaming owner, so we added a borrow operator and let it share its character with the settled state, on the reading that a borrow holds its object still for the length of the call. The table that came out was clean. Every argument had exactly one mode, so overloads could have differed by mode without the tiebreak that functions.md §4.1 bans them to avoid. But a reference read by a borrowing helper needed the operator, age(%g) with % standing in for a character we never settled on, and so did a temporary handed to one, topSpeed(%makeEngine()), which are among the commonest calls a program makes.
We looked at the defaults instead of the operators. Making roaming the bare state would have retired ^ from the language, and we declined it for the reason the settled-and-roaming chapter gave: a field takes whatever state its root has, so only a root needs a marker, and the rarer state is the state to mark. We tried writing the mode on the name, player.mainWeapon& against a bare player.mainWeapon, which settled one point worth keeping, that a mode only matters where a value lands and never along the path to it: display(player.mainWeapon.dps) reads through the reference and passes a number. Last we kept ^ as an operator to take, so that a bare roaming owner would borrow and a spent one would always show it. Every move of a named owner then carried the mark, in stores and returns as well as calls (engine Engine = ^spare;, this.spare = ^engine;), and the code it produced was worse to read than the inference it removed.
That was the pattern across all of them: each design made ordinary code heavier everywhere, to fix the one place where the mode had to be inferred. So passing stays implicit, decided by the parameter as before, and that place gets an explicit type instead. Generics already had the mechanism. A type that inference cannot reach is passed as an argument to a T Type parameter (generics.md §5.3), the choice the generics story made in place of a type list at calls. ArrayRef([p, q], &Port) names its element type after the literal, the element type is fixed by that argument before the literal is matched, and each element is passed into an &Port slot exactly as an argument is passed to an &Port parameter (generics.md §8.4). The element type stays an argument because the literal comes first, which is how the form reads aloud. A type argument may now carry its & (syntax.md §3.3). With no & left in expressions, the marked form has nothing to be confused with. A ^ type is never an argument, since a type’s arguments never carry one.
The cost is what the operator designs would have bought. The call site still does not show whether a roaming owner is spent or a reference minted, so a reader learns either from the signature, and overloads still cannot differ by passing mode. The literal form alone still cannot build an array of references from owners, so a program has to know to name the element type. And a literal’s elements still share one type, so a settled owner and an existing reference cannot sit in one literal even when the element type would take both.
An ArrayRef constructor names the mode of its elements
The chapter before left one gap open: a literal’s elements share one type, so a settled owner and an existing reference could not sit in one ArrayRef literal, even with the element type named. The & prefix had covered it, since [&p, r] made both elements &Port before the literal saw them. We first closed it at the type argument, letting ArrayRef([p, r], &Port) take a literal that mixed the two and checking each element against the named type on its own.
That raised the question of what the named type was for. A store into an element never borrows, since the element outlives the call, so the only other modes are taking and copying, and the literal alone already did those with the type it read off its elements: ArrayRef([a, b], Enemy) built exactly what ArrayRef([a, b]) built. The named form only did work when the type was &T, so the parameter could declare that itself, @concepts$Array<&T Type, n @concepts$Int>, and the call would need no type at all. That is the chapter before’s own conclusion carried one step further: the signature determines the passing mode, here for each element of a literal as for any parameter (memory.md §2.9).
One constructor could not hold both meanings. An owning ArrayRef and a referencing ArrayRef would be two overloads that differ only by passing mode, which functions.md §4.1 bans, so the referencing constructor took a name, ArrayRef.refs, the way fill already had one. Writing the mode on the element type then showed that the plain constructor had been read loosely all along. Its parameter writes a bare T, and a bare parameter of a reference type borrows, so its elements were borrowed, and a borrowed owner cannot be stored. The compiler had been moving owners in anyway, which is exactly the meaning of ^T. So owners got their own constructor, ArrayRef.roaming, and the plain constructor kept the elements a borrow can store: a value, which a store through a borrow copies, and an existing reference, which is copied the same way. Each literal constructor now states in its signature how its elements arrive (generics.md §8.4).
The typed form had nothing left to do, and neither had the &-marked type argument we had added for it, so both went. The mixed literal survived the move: it carries no element type of its own and is taken only as &T elements (syntax.md §2.9), so ArrayRef.refs([p, r]) mints from p and copies r, and nothing else accepts it.
Writing those signatures down showed that the language could not spell them. ^ was legal on a parameter but never inside another type’s arguments, and an introduction nested in one carried no mode, so @concepts$Array<^T Type, n @concepts$Int> was not a type anyone could write; the compiler built the two signatures for itself. We could have kept them a privilege of the primitives and stated their modes in prose, but then those modes would be read off prose rather than a signature after all. So the element of a parameter’s own @concepts$Array may carry a marker, and no other nested introduction may: it is the one type argument whose contents are passed, each element as an argument of its own (generics.md §3.2). A constructor declared in Zane writes the same three signatures and gets the same three behaviours, and the same ban on overloads that differ only by mode, which now reaches the element as well (functions.md §4.1).
The cost falls on the commonest owning case. ArrayRef([Enemy(Int(1)), Enemy(Int(2))]) no longer builds, and every owning literal writes .roaming, a word that reads oddly over temporaries that were never named. There are three literal constructors to learn where there was one, and they overlap on values, since ^T over a value type is a borrow too (generics.md §3.6) and ArrayRef.roaming([Int(1)]) copies just as ArrayRef does. What they buy is that no construction reads its mode off anything but the signature it calls, which is the rule the chapter before settled on.
A list’s oversized span grows in place within a reservation
The allocator came back open when a released compiler could finally be timed against other languages. In the listgrowth test of langbench/, which appends two million small entities to an empty list twenty times over, Zane took 2.22 times as long as C. The list’s own work was not the problem. Most of the time went to the kernel, supplying fresh pages: past 1 MiB, every doubling allocated a new oversized span, copied the elements into it, and returned the old span to its size stack, where no allocation ever requested it again before the scope drained. Each round touched nearly twice the memory the finished list needed, and copied all of it. C’s realloc on a block that size touches each page once, because the C library moves the page tables rather than the bytes.
The first question we asked was why the list did not simply bump the frontier, the way it already grew below 1 MiB. The answer was that the frontier lives inside one chunk. A region’s chunks come from wherever the system puts them, so the addresses after the last chunk belong to other mappings, and an oversized span was never at a frontier at all: it was a mapping of its own with nothing to bump. Growing in place needed addresses past the end of the block that nothing else could take.
We considered two ways to have them. The first gave each region one long reserved range of addresses and carved its chunks from it in order, so that a list at the frontier could keep bumping past chunk boundaries. It extended the rule that already existed, and it would have fixed the benchmark, because that loop allocates nothing but the list. But it holds only while the list is the newest block in its region. A loop that builds a string or a boxed member per element puts that block after the list, and the next doubling is back to relocating, so the speed of growing a list would have depended on what else the loop allocated. The second gave the list’s span a reservation of its own. Nothing else is ever placed there, so the list grows in place whatever the scope allocates meanwhile. We chose that. Linux’s mremap would have given the same effect without a reservation, but macOS and Windows have no equivalent, and a reservation works the same way on all three.
So a list’s backing store that grows past 1 MiB now moves, once, into a span at the start of a larger reservation, and each later doubling makes more of the reservation usable instead of moving the elements (memory.md §3.1, §3.6). Reserving costs addresses, not memory: only what the span covers is backed, and only what is touched takes RAM. How large a reservation to take is the implementation’s choice, and a list that outgrows its reservation relocates into a fresh one. Measured before and after on one machine, the test’s time fell by more than half, to within a few percent of C’s.
The cost is in addresses and in reuse. A reservation counts against any limit a process has on its address space, so where one cannot be made the span is reserved alone, and growth relocates as it used to. A list whose oversized block was made by a copy or an escape has no reservation, so its next doubling relocates once. And growth past 1 MiB no longer takes a span from the size stack, so a returned span of exactly the right size can sit unused while a growing list maps new pages beside it. We judged that a fair trade: the stack’s reuse saves a mapping, but the reservation saves the copy at every doubling after the first.
Timing Zane against Goose starts a close comparison
The allocator chapters before this one were each driven by one benchmark at a time. What reopened the memory model as a whole was a language we came across with a very different idea of memory. Goose has no heap. Its dynamic data lives on a handful of data stacks that its compiler counts and reserves once, a scope’s exit resets a stack’s watermark instead of walking anything, and its trees are pools the program declares, linked by four-byte references. That is close to the region model Zane already had, pushed further: cheaper in memory and in time, and paid for in restrictions on the programs a programmer may write.
So we made benchmarks. We ported the langbench/ programs to Goose and ran the three languages side by side, and Zane was behind on exactly the tests its memory model was meant to be good at. On one machine, Zane v0.20 took 2.3 times Goose’s time on binarytrees, 2.8 times on listgrowth, 2.3 times on ntree, and 1.7 times on treecopy and on allocfree, and entities and concscan peaked at 158 MB where C and Goose used 94. The compute-bound tests were level everywhere, so the gap was in how the two languages held memory, not in their compilers’ arithmetic code.
We could have treated the numbers as a list of bugs and fixed them one at a time. We thought Goose had more to teach than that, so we decided to compare the two languages closely. We ran the same programs in Zane, Goose and C and profiled each function’s own instructions, so that a lead in one part of a program could not hide a loss in another. We read Goose’s specification and its compiler’s implementation notes against what the profiles showed. And because Goose compiles to C, we edited its output and Zane’s side by side and rebuilt both, to find which difference cost what. Each idea that came out of this was built behind a switch, measured against the others and against Goose, and kept, changed or dropped on the numbers. The whole process is recorded in the compiler repository: the experiment’s log has every idea we tried, each measurement and the dead ends, and its findings summarize what we learned and the model we ended with. The chapters that follow are what survived, in the order we found them, and the first was the plainest: memory a list had already finished with.
An outgrown span gives its memory back as the list leaves it
The comparison’s first finding was the reservation’s last cost. entities, which pushes three million 32-byte entities onto one list, peaked at 158 MB in Zane against 94 MB in C and in Goose. Below two million entities the three were level. The jump came where the list passed 64 MiB, the most its first reservation held: there it relocated into a fresh span, and the 64 MiB it left went onto its size stack, as the rule for a returned block required. Nothing took it from there. A list growing past 1 MiB never pops the stack, and nothing else in the scope requested a block of exactly that size, so the old span stayed in memory, every page still touched, until the scope drained. The list held its old elements’ bytes beside its new ones from the copy to the end of the scope.
The first fix we tried was a larger reservation, and measuring it showed why it was no fix. One more chunk of addresses let the list grow in place past 64 MiB, and entities dropped to 93 MB. But at 4.2 million entities the relocation came one doubling later, with twice as much left behind, and the peak rose from 194 MB to 258 MB. However large the reservation, some list outgrows it, and that list paid the larger stranded span. Moving the pages instead of copying them would have avoided the doubled peak at any size, but it was the same Linux-only mremap we had turned down for the reservation itself, for the same reason.
So the span a list leaves now gives its memory back as the elements are copied out of it, a chunk at a time, and is never pushed onto its stack (memory.md §3.1, §3.6). Its addresses stay with the scope until it drains, because the region gives back its mappings whole then, so only the memory goes early. Every platform can give pages back while keeping their addresses, so the rule is the same on all three. entities then peaked at 94 MB at three million entities, 130 MB at 4.2 million and 185 MB at six million, level with C at all three, and its time did not change.
The cost is a system call for every MiB the relocation copies, which is small beside the copy itself, and a span that can no longer be reused. That was no loss, since nothing had reused one: the stack held it for a request of exactly its size, and a list growing past 1 MiB was the only allocator of that size, and it never consulted the stack.
One box per cycle, and a first block of four elements
With the stranded memory gone, what remained on the tree tests was not how Zane allocated but how much it allocated, and Goose made that easy to see, because a Goose node is exactly as large as its links. ntree’s node is a list of its children. Each round grows a four-way tree and counts it, and each node’s list held four 24-byte children, 96 bytes, in a 128-byte block: a new list started with 128 bytes whatever its element type (memory.md §3.6), and every block below a chunk was aligned to a cache line, as the cache-line-aligned buffer chapter had settled. Goose’s node holds its children inline, with room for four. So a list’s first block now has room for four elements, rounded up to whole words and kept between 32 and 128 bytes, and a block below a chunk is aligned to its contents rather than to a line (memory.md §3.6). A small first block then comes from the same exact-size stacks as a boxed node of its size. ntree’s peak fell from 44.9 MB to 34.3 MB, its instructions from 2.25 billion to 1.41 billion, and no other test moved by more than a tenth of a percent.
binarytrees showed the same effect more starkly. Zane allocated three blocks a node, 48 bytes in all, where Goose allocated one of 8. Its Tree is a variant whose node case holds a Pair of two Trees, and the rule we had chosen in the adt story boxed every member whose edge lies on a cycle, so the Pair was boxed under node, and each Tree in the Pair was boxed again. That chapter had named the cost, two indirections where a hand-tuned scheme would charge one, and judged predictable layout worth it. Measured against Goose, the extra hops and blocks were most of the gap.
The first road we took went the whole way to Goose’s representation. A recursive variant’s whole tree went into one pool, its nodes linked by 32-bit offsets, and on top of that the base case was built inline, nodes were packed to Goose’s size, and pushes into the pool took Goose’s shape. It worked: treecopy came to 0.6 times Goose’s time. But it was a second representation for every recursive variant, with roots, pools per value and their relocations, and a much simpler change turned out to reach further. A cycle needs only one box to have a finite layout. So a variant’s payload that leads back to the variant is boxed, a field is boxed only when its cycle passes through no such payload, and every other member on the cycle is inline (adt.md §4). The rule still reads only the declarations and the kind of each member, so it keeps the properties the old rule was chosen for: no order to depend on and no search for a minimal cut. A Pair is then two inline Trees, each a tag and a box, and plain binarytrees came level with Goose without any pooling. treecopy, whose copy now copies a third of the blocks, came to 2.7 times faster than Goose. The pooling switches stayed in the compiler and out of the model.
Boxing off a cycle narrowed with it. The rule had let an implementation box any member at its discretion; it may now box a variant’s payload off a cycle, the case the permission was written for, and a field off a cycle is always inline. That keeps every field of a settled owner beside it, which the next chapter relies on. Review then found one cycle that broke it: A holding a B that holds an ArrayRef<A, 0>. The rule boxed A’s field, though the array holds no A at all. An array of no elements now stores nothing of its element type, so it is no edge of a cycle, and a cycle left with no payload on it runs through fields alone, whose types have no finite value to box.
The costs are small and specific. A small first block costs more doublings before a list reaches 128 bytes, each one a relocation, and a block below a chunk gives up the cache-line alignment that an earlier chapter had earned for streamed buffers. Neither showed in any test. A variant whose payload is large now keeps it behind one box where a field on the same cycle used to have its own, so a cycle of structs and variants is laid out by a slightly longer rule. And the reach of a box became the next question: with nodes this small, the eight bytes of each box were most of a node.
References and boxes become 32-bit offsets from the program image
With every node down to one block, the gap that remained was width. A Goose link is four bytes. A Zane reference, a box and a list handle’s items were each an eight-byte native pointer, the cost the native-addresses chapter had named and accepted when it retired the segmented offsets and their ceiling. A binarytrees node was two eight-byte boxes where Goose’s was two four-byte links, and an ntree node was a 24-byte list handle, its items a pointer and its count and room 64 bits each.
The first road brought the ceiling back on purpose. One range of addresses, from 4 GiB to 32 GiB, was reserved at start-up, every reservation was carved from it, and a reference, a box and a list’s items were stored as their address shifted right by three, in 32 bits. We called it the cage. It worked: binarytrees was ahead of Goose at depth 20, and ntree, with 12-byte handles, peaked at 18 MB against Goose’s 25. But it capped everything a program holds, lists included, at 28 GiB, it needed that one range free in every process, and a reference to a package constant needed the program’s own image below 4 GiB, so a program could no longer be loaded anywhere.
What let us do better was looking at what a reference can name. A reference names a settled owner (memory.md §2.8): a local, a package constant, or a field or ArrayRef element reached from one. It never names a list’s element or a variant’s payload, because those are roaming. So a reference never points into the dynamic region at all, only into a frame or into the program’s image. Our first idea was a scope’s level and an offset within its frame, since every frame’s size is known when the program is compiled. Levels are not fixed across calls, though: a function may recurse, or be handed a reference by its caller, so decoding a level would need a table of frame starts per thread and a load on every dereference. But a thread’s frames already sat back to back in one range (memory.md §3.7), so a slot’s distance from the range’s start was the level and the offset in one number. One step further, every thread’s frames went into the 2 GiB right below the program’s image, and a reference became its owner’s distance from the image’s first byte (memory.md §4.1). Package constants live in the image, so they fit too. Decoding is an addition to an address the linker provides, with no load, and the program can be loaded anywhere, because its image and its frames move together.
The same step gave lists a 16-byte handle: a native pointer to the elements, and a 32-bit count and capacity (memory.md §3.6). We counted the capacity in bytes first, which capped a list at 4 GiB, and then in elements, which caps it at 232 − 1 elements of any size. The items stayed a native pointer, for the reason that will close this chapter.
Boxes were still eight bytes, since their blocks live in dynamic chunks at whatever addresses the system gives. We asked why a box could not be an offset from its region, and the answer was that a region is a chain of chunks at unrelated addresses, so there is nothing to measure from. Goose’s answer is a stack per growable value, contiguous by construction, and we weighed giving every dynamic value a stack of its own. Goose’s own design notes argued against it: its stacks are one per growable slot in the program, not one per value at run time, and it rejects a stack per container itself, because a document with thousands of containers would need thousands of reservations. Its stacks also rest on a promise its compiler proves, that at most one growable value lives on each, always on top, and that promise is bought with restrictions Zane does not have: an array element may not be resizable, a type may not contain itself, and a tree has to be a pool the program declares. We wanted Goose’s link width without Goose’s language.
The way through was that a box does not need its block in a contiguous region, only within reach. So the runtime takes every dynamic chunk from a window of addresses it reserves within 16 GiB of the image, and a box is its block’s distance from the image in 8-byte units (memory.md §3.1). Chunks inside the window are taken and given back in any order; only their distance from the image is bounded. We also tried a different encoding with no window at all: a box as the number of the MiB its block is in and its offset within that MiB, with a table from numbers to addresses, so that chunks could be anywhere. It used the same memory, but it put a load from the table between loading a box and loading the node it names, and binarytrees ran about five percent slower. The freedom it bought, placing chunks wherever the system likes, was never needed by any run, so we kept the window.
Two more pieces finished the node. A variant of two cases, one carrying nothing and one a box or a reference, is now that word alone, with zero for the empty case, since nothing a box or reference names starts at the image itself (memory.md §3.3). A binarytrees node is then 8 bytes, as Goose’s is, and at depth 18 the test peaked at 10 MB where it had taken 34. The other piece was a field off a cycle staying inline (the chapter before), which keeps every settled owner, fields included, in a frame or the image, where a reference reaches it.
That left the cage with one lead, ntree’s 18 MB against 23, and it came from storing a list’s items in 32 bits. We declined it. A list growing past a chunk reserves room to double many times in place (the reservation chapter), and no 16 GiB window holds those reservations, so items in the window would have capped large lists or made them copy again. The cage was removed.
Several of the ideas we ended with are Goose’s in another form. Links are four bytes, as Goose’s are, though Goose measures a link from the link itself and we measure it from the image, which stays valid when a move copies the bytes that hold it (memory.md §3.5). A binarytrees node is one 8-byte block, as Goose’s is. A list’s first block has room for four elements, the room Goose gives a node’s children inline. And the compiler now makes a loop’s pushes the way Goose makes every push, with the room made once before the loop and no check inside it. What we did not take is the stacks: Zane keeps its regions, and with them recursive types and resizable values nested anywhere. Measured on one machine at the end, Zane took 0.71 times Goose’s time on binarytrees, 0.49 on treecopy, 0.42 on allocfree, 1.06 on listgrowth and 1.34 on ntree, which still uses less memory than Goose’s.
The costs are limits. Every thread’s fixed-size region shares the 2 GiB below the image, so the fixed-size bound can no longer reach 64 GiB, and at the default 8 MiB per spawned call, a program can hold about two hundred spawned calls at once, not the ten thousand that chapter imagined. The dynamic chunks a program holds at once share the window, and a list holds at most 232 − 1 elements. The model needs a runtime that can place memory near the program’s image, and a program whose system will not give it those addresses stops with an error. Each box and reference costs an addition to decode, which raised binarytrees’ instruction count by 8% and its time by nothing we could measure.
The compiler orders a struct’s fields, and C receives a copy in its own order
One placement freedom had stayed with the programmer. memory.md §3.3 laid a type’s fields out in declaration order, as C does, so a struct of a Bool, an Int and an I32, written in that order, took 24 bytes: seven bytes of padding after the Bool to align the Int, and four more after the I32 to round the whole up to eight. The same three fields written largest first take 16. In C that order is a contract, because C code may take a struct’s address, hand it to another translation unit, or overlay it on a buffer, and every reader must find each field where the source put it. Zane had promised the opposite: the placement chapter handed physical layout to the compiler on the condition that no program could observe it. A fixed field order kept a cost that only made sense in a language where layout is observable, and required the programmer to sort fields by hand to avoid it, which every C style guide teaches and few programs do.
So the compiler now chooses the order, once for each type (memory.md §3.3). It has to be once per type rather than per instance or per use, for the reason boxing is: every value of a type must be the same size with its fields in the same places, or an array of it loses uniform stride. The rule the compiler follows is its own business, and the spec does not state it. Today the compiler places fields in decreasing order of alignment, keeping declaration order among fields of one alignment. Since every Zane layout’s size is a multiple of its alignment, that leaves no padding between fields at all, only at the tail.
The one place we had to look hard was the C interface, because it was the one place a program’s layout met code that could see it. A C-compatible value type is any value struct of scalars, arrays of scalars and such structs, and it crosses into C by value, matched field by field against a C struct (ffi.md §3.3). The first road was to leave those types in declaration order and reorder only the rest. That road would have cost the compiler nothing, but a type’s fields determine its C-compatibility, which no declaration states, so every all-numeric struct qualifies, and those are exactly the structs where mixing 32- and 64-bit fields leaves padding. That road would have excluded most of the cases the change was for.
What settled it was a question about the other direction, which was really a question about the value world. If C could ever hand Zane a pointer to a struct it owned, and Zane read it in place as a value, then C’s layout would be fixed for that type everywhere, and worse, a value would be sitting in memory that C could still write. That would break the closure the placement chapter rests on, in which a value holds only values and is reached by nothing but its owner. Reading the C interface for such a path found none. A foreign verb’s struct result is copied into fresh storage when C returns it. A callback C calls receives its struct arguments by value. A handle’s object is never read by Zane at all, since a handle has no fields and is reached only through foreign verbs. And the only values Zane lends C in place are strings, and arrays and lists of scalars (ffi.md §3.4), whose elements lie the same way in both languages. No struct lies in memory that both languages read. C’s layout belongs to the copy made at the boundary, never to a Zane value, so the copy can put each field where C expects it while the value keeps its own order (ffi.md §3.3). The copy was already made field by field, with its padding zeroed, so writing the fields in another order costs nothing a crossing did not already pay.
The rest followed. A field order chosen from the field types alone is the same in every package that lays the type out, so separately compiled objects match on it. Rust reorders a struct’s fields by default too, and a struct that crosses into C needs #[repr(C)], because a Rust struct crosses as itself, by value or behind a pointer, rather than as a copy laid out for C. Zane needs no such mark, because its structs cross only as such copies.
The cost is control. A programmer who wants two fields side by side, because they are read together, cannot ask for it: the order is the compiler’s, and the spec offers no way to name one. Memory as a debugger shows it no longer reads in source order. A struct crossing into C whose order differs from C’s is rebuilt field by field each time, which the copy already was. In return, every value type is as small as its fields allow, and that shrinks every list element, array element, owner slot and box of the type with it: in the compiler, a list of two million {Bool, Int, I32} values went from 24 bytes an element to 16, and its peak memory from 49.8 MB to 34.1.
Growth past 1 MiB takes a span an overwrite returned
A benchmark port showed what that trade had left behind. LangArena’s Binarytrees::Arena, as first ported, held a list in a field of its state and replaced it with a fresh one each round, as a program keeping a working set across iterations does, and each round grew the new list again; a reduced program that grows it to 24 MiB held 919 MB after 40 rounds. The overwrite followed memory.md §2.2: it destroyed the old list and returned its span to the stack for its size. The new list then grew from its first block, moved once into a fresh span at 1 MiB, and grew in place from there, so no allocation ever requested a block from that stack. Every round left another 32 MiB span on it, its pages all still touched, until the scope drained at the end of the program.
We first looked at making the overwrite hand the old block to the replacement, as it writes a boxed member’s replacement into the block the occupant already holds. But a fresh list arrives empty, with a first block of a few dozen bytes, and the block it would need belongs to an occupant that dies only once the replacement exists. The pairing would have served one overwrite of one list, while the same pile builds whenever a scope ends one big list and grows another, whatever ended the first. We then considered giving the returned span’s memory back at once, as an outgrown span does. That would have fixed the peak, but the next list would fault every one of those pages in again, which is the cost we wrote the reservation chapter to remove. C’s malloc keeps a freed block of that size for the next request instead.
So growth reads the stacks above 1 MiB after all, and so does any other oversized block. A block past 1 MiB takes a returned span whose reservation holds as many addresses as a fresh one’s would: one of its own size first, else the smallest such span the scope holds, and only then maps a fresh span (memory.md §3.2, §3.6). An exact match would not have been enough: the new list requests 2 MiB, then 4, each size one the returned span is not, and it has a reservation of its own long before it reaches 32 MiB. A span taken by its reservation keeps it, so the new list grows in place within the old list’s addresses, over pages already resident. In the compiler, the reduced program’s 919 MB fell to 26 MB, and its page faults from 234,762 to 6,214. A span a list moves out of as it grows still gives its memory back and goes onto no stack, so what the outgrown-span chapter settled stands: a list never holds its old elements’ bytes beside its new ones.
The cost is that reuse past 1 MiB is no longer exact. A list that takes a 32 MiB span and grows only to 2 MiB keeps all 32 MiB resident until its scope drains, so memory after a peak falls more slowly than it would. It can raise the peak too: a later request for 32 MiB then maps a span of its own beside it, where the returned span would have served it. Taking a span of the block’s own size first, and else the smallest that fits, keeps that case to scopes that return only larger spans than they next ask for. Each oversized block its own size cannot supply also looks through the scope’s stacks, a short walk beside the mapping it saves.