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
{{ message }}
Repository navigation
C backend: a constructor with 256 single-word fields still exceeds CID_ARITY_T after #944 #991
python3 gen.py
bun bend2/main.ts repro.bend --check-only
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/repro
What happened
The checker accepts the file, and the interpreter and JS both print 42. The native build fails before invoking clang:
Error: an arity over 255
Changing n from 256 to 255 makes the native build succeed and print 42.
This is a remaining direct-constructor case after #944. lay_wide handles a layout past WIDE by replacing each multi-word field layout with BOX, which fixes a small number of wide nested fields. Here every field is already one word, so the mapping leaves all 256 fields unchanged. lay_node(...).ks.length reaches CID_ARITY_T as 256, and compile_tables rejects it because the table is u8.
This is separate from the wide fork-join shape noted in the closing comment on #944: no fork or wide intermediate result is involved.
Expected
The C backend should represent or box a checker-accepted constructor with 256 single-word fields instead of failing on an internal runtime-table limit. If 255 source fields is intended to be a language limit, the checker should diagnose it consistently rather than leaving the file accepted by the checker, interpreter, and JS backend.
Environment
bend 2.0.25 (a49524265bdfa5753a4bf38e25f0574a705dd868)
Darwin arm64
Apple clang version 21.0.0 (clang-2100.0.123.102)
Different trigger for what looks like the same ceiling, plus a misleading
diagnostic worth noting.
Two-parameter function, a local is Type former beside an imported Df:
import Base
import ./df.bend as D
type Box<-T: Type> is Type:
Box { a: T, b: T }
def mk(x: U32, y: U32) -> Box<U32>:
Box{x, y}
def take1(b: Box<U32>) -> U32:
match b:
case Box{a, _}:
a
def take2(b: Box<U32>, df: D.Df<Array<U32>>) -> U32:
match b:
case Box{a, _}:
a
def main() -> IO(Unit):
d1 = D.df_new(1)
do IO<Unit>:
IO.print(U32.show(take1(mk(7, 9))))
IO.print(U32.show(take2(mk(7, 9), d1)))
take1 alone compiles and runs, printing 7. Add take2 and the compiler
prints:
All terms check, but 1 def relies on unsafe or foreign code:
- main
Error: an arity over 255
So it type-checks cleanly and fails at link with the same an arity over 255
message, with no 256-field constructor anywhere in sight - take2 has two
parameters and Box has two fields. I suspect Df being boxed (it holds g: T, nns: List<&2, NormalNoise>, bn: BlendedNoise) is what pushes the
term over CID_ARITY_T once inlined.
The part that cost me the most time: the compiler does not always report this
as an arity error. In a larger file the same condition surfaced as
- expected : Data
- observed : Type
with no arity mentioned, so I spent several rounds trying to fix a type error
that was not there. If the arity check runs before or instead of the type
error in some paths, a clearer diagnostic would have saved that.
The case that actually blocks a port, in case it is useful alongside the
two-parameter one: the limit behaves like a per-call-site inlining budget,
not just constructor width.
Porting a noise implementation (ImprovedNoise / Perlin / Normal) section by
section, with each section generating its own program:
section
result
a
compiles
d
compiles
d2
compiles
i (xoroshiro high-rejection)
compiles
the other 9
refused
The nine that fail are exactly the ones that need more than one call into
the noise module. Sections that need a single call site per program compile
fine. So the same helper that is fine once is refused twice, which points at
inlining/replication at the call site rather than at any one function's arity.
I also checked whether splitting on the port side can dodge it. It cannot: with
the two largest evaluator families stubbed out (172 lines of interpolation and
flat cache), the evaluator is still refused, because the core arithmetic
dispatch alone fills the frame.
So port-side restructuring is not a workaround here, and the ceiling looks like
it scales with total expanded call-site size rather than with any single
constructor. If that matches what you see in #991, it may be one limit with
several triggers.
Activity
nataxcan commentedon Sep 24, 2026
Different trigger for what looks like the same ceiling, plus a misleading
diagnostic worth noting.
Two-parameter function, a local
is Typeformer beside an importedDf:take1alone compiles and runs, printing7. Addtake2and the compilerprints:
So it type-checks cleanly and fails at link with the same
an arity over 255message, with no 256-field constructor anywhere in sight -
take2has twoparameters and
Boxhas two fields. I suspectDfbeing boxed (it holdsg: T,nns: List<&2, NormalNoise>,bn: BlendedNoise) is what pushes theterm over
CID_ARITY_Tonce inlined.The part that cost me the most time: the compiler does not always report this
as an arity error. In a larger file the same condition surfaced as
with no arity mentioned, so I spent several rounds trying to fix a type error
that was not there. If the arity check runs before or instead of the type
error in some paths, a clearer diagnostic would have saved that.
nataxcan commentedon Sep 24, 2026
The case that actually blocks a port, in case it is useful alongside the
two-parameter one: the limit behaves like a per-call-site inlining budget,
not just constructor width.
Porting a noise implementation (ImprovedNoise / Perlin / Normal) section by
section, with each section generating its own program:
The nine that fail are exactly the ones that need more than one call into
the noise module. Sections that need a single call site per program compile
fine. So the same helper that is fine once is refused twice, which points at
inlining/replication at the call site rather than at any one function's arity.
I also checked whether splitting on the port side can dodge it. It cannot: with
the two largest evaluator families stubbed out (172 lines of interpolation and
flat cache), the evaluator is still refused, because the core arithmetic
dispatch alone fills the frame.
So port-side restructuring is not a workaround here, and the ceiling looks like
it scales with total expanded call-site size rather than with any single
constructor. If that matches what you see in #991, it may be one limit with
several triggers.
A constructor of any width builds on C: term_drop walks a node past 2…