You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bun bend2/main.ts array_soundness.bend
bun bend2/main.ts array_soundness.bend -o array_soundness.js
node array_soundness.js
bun bend2/main.ts array_soundness.bend -o array_soundness
./array_soundness
What happened
The checker accepts theorem, so it proves that observed() is 4.
The JS lane and emitted JS both print:
3
The native binary exits with code 1:
bend: runtime fail-stop
Array<T> is an unrestricted ALeaf | ANode(Array<T>, Array<T>), so the unbalanced tree above is well-typed. The source Array.size follows the left child and doubles its size, which gives 4.
The JS representation flattens ANode with $0.concat($1), reconstructs children by splitting at $0.length >> 1, and implements Array.size as $0.length. It loses the original boundary and returns the number of leaves, 3. The native representation fail-stops on the same value.
The runtime paper calls Array<T> a perfect binary tree, but neither the type nor the checker enforces that. Its constructors are public, while the backends assume both children have equal depth. This uses no @unsafe, FFI, open law, or ?TODO.
This is different from #804. That issue is about the allocation cost of split/join on regular arrays. Here a checked equation becomes false at runtime.
Decision: this stays a runtime limit, recorded in WONTFIX.txt under a new RUNTIME section (things the theory allows and the runtime does not run yet; we remove these over time).
We implemented a depth-indexed Array(T, d) and it worked, but Bend does no inference, so every Array.* call and the index sugar would have to name the depth: xs[i^d] instead of xs[i]. We chose not to pay that. An unbalanced tree checks and fail-stops at runtime on every lane ("runtime fail-stop"), like a Nat past 2^48-1 or an array past block class 31.
Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.
Activity
VictorTaelin commentedon Sep 18, 2026
(deleted the AI comment)
I asked the AI so many times to ensure the array is depth-indexed. I have no idea how I let this slip through. sighs
I'm tired
will fix soon, thanks for the report
I hate AI
VictorTaelin commentedon Sep 18, 2026
Decision: this stays a runtime limit, recorded in WONTFIX.txt under a new RUNTIME section (things the theory allows and the runtime does not run yet; we remove these over time).
We implemented a depth-indexed
Array(T, d)and it worked, but Bend does no inference, so everyArray.*call and the index sugar would have to name the depth:xs[i^d]instead ofxs[i]. We chose not to pay that. An unbalanced tree checks and fail-stops at runtime on every lane ("runtime fail-stop"), like a Nat past 2^48-1 or an array past block class 31.Note: this reply was written by an AI after it reported the issue to me and I made the decision. If anything here is wrong, reply and I will review it myself.