#804·Bend

Array structural split/join allocates and copies (blk_half/blk_node); the paper says both halves come in place and joining is free

Author: phenomenon0Created Sep 18, 2026Updated Sep 18, 2026

What you did

Compared the runtime paper's array cost model with the emitter and runtime routines in the current tree (source reading only; no timing was measured).

What happened

The paper (bend2/docs/BendRT/main.typ, § Arrays): "A match on the tree takes both halves in place, and joining two adjacent halves back is free."

The emitter (bend2/comp.ts at 0b7e2b11): an Array ANode{l, r} constructor emits blk_node(e, l, r) (line 2228), and a match on ANode emits two blk_half(e, sw, hi) calls (line 2647). Those routines allocate and copy: blk_node (line 4068) allocates the merged block, copies both halves word by word, then frees both inputs; blk_half (line 4093) allocates and copies each half, then frees the source on the high call. The compiler's own comment (lines 4007-4016) states it: "A match on ANode is blk_half twice: each half allocated in its class and copied... ANode{l, r} is blk_node: the merged class, l and r copied and freed shallow... A match to the leaves copies O(n log n) words where a view copied none; get, set, swap, size and new open no half."

So for materialized structural split/join (indexed get/set opens no half), the paper's cost model does not match the implementation. Either the paper should say allocate-and-copy, or the views should be implemented.

bend --version

bend 2.0.5

uname -sm

Linux x86_64