Skip to content

fix(array): the depth-wall error and Array.new say d is a depth - #1963

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
sebastianbreguel:fix/array-depth-error
Oct 30, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
sebastianbreguel:fix/array-depth-error

Conversation

@sebastianbreguel

@sebastianbreguel sebastianbreguel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1962 (the first two points; no new helper).

Array.new(T, d, v) takes a depth: it builds 2^d cells. Passing a length, as in Array.new(U32, 12288n, 0), hits the depth wall with "an array past the deepest block class 31", which names neither the argument nor that 31 is a depth. The fix is 14n (16384 cells).

Change

  • bend2/comp.ts: fail-stop 10 reads "an array past the deepest block class 31 (a depth d holds 2^d cells)". It is the one ERRS entry that changes; the others keep their text (checked by evaluating both tables). 65917 → 65927 ttok, cap 66000.
  • bend2/base.bend: a comment above Array.new: d is a depth, not a length (14n for 12288 cells), at most 31.
  • tests/io/array_depth_bound.bend: its #| line carries the new text.
Array.get(U32, Array.new(U32, d, 7), 5) Before After
d = 12288n, interp / JS / C "…block class 31", exit 1 "…block class 31 (a depth d holds 2^d cells)", exit 1
d = 14n, interp / JS / C 7 7

Verification (macOS arm64, Bun 1.4.2; Linux arm64 (Docker, Debian 13, Bun 1.4.2, clang 19))

  • Repro (Array.new(U32, 12288n, 7), and 14n) on interp, JS and C, macOS and Linux: the table above, the same on both
  • All 1796 tests under tests/, interpreter, before vs after, macOS and Linux: only array_depth_bound differs, in that line
  • gates/repo.ts: 54/54 (comp.ts 65,927 / 66,000 ttok)
  • gates/test.ts: runs on the minis
  • Metal build on macOS (Apple clang 21): cell!(12288n), built with its .gpu program, prints the new line, and cell!(14n) prints 7, before and after the change as on the other lanes
  • Whether that ! call ran on the GPU or on the runtime's CPU path: not confirmed (the Metal dispatch and commit counts under lldb are the same with +RTS --gpu off)
  • CUDA: no NVIDIA GPU here

Note: bend base Array.new prints the definition without its comment, so the new comment shows in base.bend only.

@Lorenzobattistela Lorenzobattistela self-assigned this Oct 30, 2026
The C wall is depth plus log2 of the cell's words (blk_new), so a two-word
record already stops at depth 31; a boxed v stops at depth 23 (its copies).
Same comp.ts ttok as before (65,927).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Lorenzobattistela
Lorenzobattistela merged commit 26628b1 into bendlang:main Oct 30, 2026
1 check passed
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.

Array.new: the depth argument is undocumented, and a length gives "an array past the deepest block class 31"

2 participants