Repository navigation
Description
Bend 2.0.38, Linux x86-64.
Array<T> is a binary tree whose type admits an ANode whose two children have different depths. The compiled runtime cannot represent one: it keeps an array as one flat block of 2^c cells and checks the halves' lengths. So a value the type accepts and the plain run produces is refused by -o, and the same value inside an IO block is refused by the JS lane too.
The program
import Base
def sz(r: Array<F32> & U32) -> U32:
(a, n) = r
n
def main() -> U32:
sz(Array.size(F32, ANode{ALeaf{0.0}, ANode{ALeaf{1.0}, ALeaf{2.0}}}))
Three leaves, the right child one level deeper than the left.
What happens
| lane | result |
|---|---|
bend mixed.bend (JS, no -o) |
prints 2 |
bend mixed.bend -o mixed && ./mixed (C) |
bend: runtime fail-stop, exit 1 |
the same size printed with IO.print(String.append(..., U32.show(...))) on the JS lane |
bend: runtime fail-stop |
bend --check-only accepts all three. A balanced ANode{ALeaf{0.0}, ALeaf{1.0}} works everywhere.
So the value is reachable three ways: accepted by the checker, produced by the JS lane when nothing else touches it, and refused by the C lane and by the JS lane once it crosses the IO boundary.
Why it is not simply "a crash"
array_node in bend2/comp.ts checks a.length !== b.length and raises the fail-stop, so the C runtime is refusing on purpose. The bug is the mismatch between that invariant and the type: ANode{xs, ys} takes two Array<T> and cannot tell a leaf from a node, so there is no way to write the invariant in the type as it stands.
This is the same question as #1934 asks from the other side (whether Base should state Array's own facts). It also matters for the value law in bend-ml: the counterexample that makes get_other_set need ASet.Apart is exactly this tree, ANode{ANode{ALeaf{0.0}, ALeaf{1.0}}, ALeaf{2.0}} (bend-ml#26), which means the counterexample itself can only be run on the JS lane.
What I would ask for
One of:
- a type that cannot express a mixed-depth
ANode(a depth index, orArray<T>as a perfect tree only, with a separate type for the general binary tree the laws want); or - a runtime that represents it (the JS lane already does when the value stays pure); or
- a diagnostic at check time that says an
ANodeof two different depths is not representable, rather than a fail-stop after the program has been accepted and run.
The first is a language decision and above my call; the third would at least make the failure arrive before the run.
Reported here because the message is a runtime fail-stop with no detail, so the failing program is not obvious from the error. I have not changed anything in bend2/ (AGENTS.md keeps it human-written).
Activity
Lorenzobattistela commentedon Nov 5, 2026
Closed as in #808