Skip to content

Box wide constructor fields within runtime arity - #1044

Closed
oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/box-wide-constructor-fields
Closed

oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/box-wide-constructor-fields

Conversation

@oxura

@oxura oxura commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #991; replaces the closed #1015. That proposal widened CID_ARITY_T, but the native node walker also packs arity and field index into eight bits. This version keeps every constructor arity and CID_ARITY_T entry within 255 instead. Once multi-word fields have been boxed, a remaining run of one-word fields is represented by a boxed sub-node with its own bounded arity. Construction, pattern matches, layout conversions and pure-value display use the same source-field mapping.

tests/reg/record_256_fields.bend checks first/last fields at the boundary; tests/reg/wide_record_drop.bend drops a whole unopened list of six 256-field records before building six 300-field records and checks the last result. An existing 255-field case and the prior nested-wide constructor fixture still pass. Locally I also exercised a 512-field record, shared wide records containing strings, a multi-constructor wide datatype and native/JS agreement when printing a wide value.

Verification: interpreted JS, emitted JS and native C produced 501/501 on the drop regression; 256 and 512 fields and the existing nested-wide case compile and run natively; the new fixtures pass --checkup; bun gates/repo.ts reports PASS 46/46. The cluster gate and macOS build were unavailable. Segment arity remains independently bounded at 255 words.

@nicolas-abril

Copy link
Copy Markdown
Collaborator

Thank you @oxura for taking this on after #1015, and for the drop test we asked for. It was the most useful part of the review. We're closing this in favour of #1068, which fixes #991 closer to the root. Your record_256_fields and wide_record_drop tests are in it, credited as co-author on the commit.

Your branch works: every probe we ran agreed across the interpreter, JS and C, and the drop test prints 501/501. We went another way for two reasons:

  • Size: packing runs of fields into sub-nodes touches building, matching, layout conversion and show_val, and it put comp.ts at 63,848 of its 64,000-ttok cap.
  • Where the limit comes from: the 255-word limit is term_drop packing each node's child index and arity into 8 bits each. That walker already frees arrays of any size by keeping its index in the node's own slot 1.

So #1068 lets a constructor past 247 words take that array walk. Its u8 CID_ARITY_T entry holds 240 + its size class, and node_fill zeroes the rest of its block. That's +18 / −6 lines in comp.ts, and a program without such a node emits the same C apart from one line.

Two things came up while testing your branch that might be useful:

  • record_256_fields builds nothing at runtime. The compiler folds its literal record, so its C never builds a node. It still guards the old build refusal, which is why we kept it.
  • Segments have a separate limit. A continuation that keeps more than 255 one-word values live across a call still fails, for example a record of 300 Strings each built with ++. That's tracked in C backend: a segment with more than 247 live one-word values fails to compile #1069, if you'd like to look at it.

Note: this comment 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.

nicolas-abril added a commit that referenced this pull request Sep 25, 2026
…47 words as an array (#1068)

term_drop frees a tree without a stack, packing each node's position, child index and arity into one word, 8 bits each: that packing, not the language, capped a node at 255 words, so a record of 256 one-word fields was checked, interpreted and run on JS but refused by C (#991). The same walker already frees an array of any size, taking its cell count from the size class and keeping its index in the node's own slot 1.

A constructor past 247 words is padded to its size class, the pad written as zero like every unset word of a constructor, and keeps 240 plus log2 of its size in its u8 CID_ARITY_T entry; term_drop walks it as an array. WIDE drops to 247 for flat layouts and segments, so only a constructor's entry can pass it, and a value past WIDE words travels boxed. Datatypes no longer box multi-word fields to fit a node; a def's parameters still do (#944), inlined in sig_def. A program without such a node emits the same C but for one line in term_drop.

tests/reg/wide_record_drop comes from #1044; wide_record_stale drops padded 250-field nodes in blocks that still hold String pointers. The headers of arity_wall, record_wide_node and record_deep_boxed and SHADERS.md's segment limit say what the compiler does now.

Closes #991.

Co-authored-by: oxura <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C backend: a constructor with 256 single-word fields still exceeds CID_ARITY_T after #944

2 participants