Repository navigation
Description
What you did
I compiled this program to the interpreter, JS, and a native executable:
import Base
type R0 is Data:
R0{a: U32, b: U32, c: U32, d: U32, e: U32, f: U32, g: U32, h: U32}
type R1 is Data:
R1{a: R0, b: R0, c: R0, d: R0, e: R0, f: R0, g: R0, h: R0}
type R2 is Data:
R2{a: R1, b: R1, c: R1, d: R1, e: R1, f: R1, g: R1, h: R1}
def r0(+x: U32) -> R0:
R0{x, x, x, x, x, x, x, x}
def r1(+x: U32) -> R1:
R1{r0(x), r0(x), r0(x), r0(x), r0(x), r0(x), r0(x), r0(x)}
def r2(+x: U32) -> R2:
R2{r1(x), r1(x), r1(x), r1(x), r1(x), r1(x), r1(x), r1(x)}
def first0(x: R0) -> U32:
match x:
case R0{a, b, c, d, e, f, g, h}:
a
def first1(x: R1) -> U32:
match x:
case R1{a, b, c, d, e, f, g, h}:
first0(a)
def first2(x: R2) -> U32:
match x:
case R2{a, b, c, d, e, f, g, h}:
first1(a)
def main() -> U32:
first2(r2(7))bun bend2/main.ts repro.bend
bun bend2/main.ts repro.bend -o /tmp/repro.js
bun /tmp/repro.js
bun bend2/main.ts repro.bend -o /tmp/reproWhat happened
The interpreter and JS both print 7, but the native C build fails before invoking clang:
Error: an arity over 255
This reproduces on 2.0.23 as well, so it appears to be an uncovered case in the #843 fix rather than a 2.0.24 regression.
R0 is 8 words, R1 is 64 words, and R2 is 512 words. Since #843, a datatype past 256 words is supposed to become a heap node, so R2 should be boxed and compile.
The type layout does become BOX, but the constructor table is computed separately. compile_book stores lay_node(fl.book, c.k).ks.length in CID_ARITY_T; for a monomorphic R2, lay_node flattens the eight R1 fields again and produces 512. CID_ARITY_T is emitted as u8, so compile_tables rejects it.
The existing generic BoxK<BoxK<BoxK<U32>>> regression test does not expose this because lay_node sees the open type parameter of BoxK as a box, leaving the constructor arity at 8. Distinct monomorphic record types take the failing path.
There is also an exact-boundary variant: changing R2 to four R1 fields makes it exactly 256 words and still fails with the same error, while three fields (192 words) build and run as native C. lay_of boxes only layouts greater than WIDE = 256, but the u8 CID arity table can represent at most 255.
Expected
The C backend should box the 512-word R2 constructor consistently with its datatype layout and compile the program. The 256-word boundary should either be boxed as well or otherwise remain representable by the runtime metadata.
Environment
bend 2.0.24 (99f9c6cd)
Darwin arm64
Apple clang version 21.0.0 (clang-2100.0.123.102)
Activity
jasisz commentedon Sep 21, 2026
There is a second failure path through the same
u8table guard. Fixing onlyCID_ARITY_Tor the boxed constructor layout will not cover it.Starting from the report's
R0andR1definitions (R1is 64 words), removeR2and add:The interpreter and JS print
36; the native build fails withError: an arity over 255. The parallel lets makesum4non-flat, so it gets a runtime segment with 256 physical parameters (4 * 64) andFID_ARITY_Trejects it. Replacing the body with the equivalent single flat expression makes the native build succeed and print36, because that path emits a direct C helper instead of a segment-table entry.A wide record, a hidden cycle and a datatype named __proto__ all compile
VictorTaelin commentedon Sep 21, 2026
Fixed in 2.0.25. One rule now: any field list past 255 words (the u8 arity tables, which is where the boundary really comes from) has its multi-word fields boxed, and it applies to constructor layouts, constructor nodes and def signatures alike. So
R2is eight boxes ofR1, the exact-256 variant and yoursum4segment compile, and all three print 7 / 7 / 36 on every lane. Pinned astests/compile/record_wide_node.bend.One shape stays open, and I would rather say so than hide it: a fork whose join holds several wide results (
a b c d = r1(1) r1(2) r1(3) r1(4)with 64-word results) still dies "an arity over 255", because a join keeps its results flat. A layout rule cannot bound that; a wider arity table can. Open a new issue if it bites you and we will look at it. (A wide value held across a non-tail call is the same shape.)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.
A wide node is padded to its size class, and datatypes stop boxing fi…
sig_def boxes its wide parameters itself: lay_wide had one caller left
A constructor of any width builds on C: term_drop walks a node past 2…
A wide record, a hidden cycle and a datatype named __proto__ all compile