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
Array.new of a boxed value works in JS but native fail-stops at depth 24 #1267
Both --check-only and --verdict print ALL PROOFS CHECK. Emitted JS exits 0 and prints 1n. The native C binary exits 1 with bend: runtime fail-stop.
Changing only 24n to 23n makes both backends exit 0 and print 1n.
F32.show(1.0) matters only because it creates a dynamic heap-allocated String. In native blk_new, a boxed array shares its default term across 2^d cells. The redirect reference count has 24 bits (RFC_CNT = (1 << 24) - 1), so blk_new explicitly posts ERR_RFCS when d >= 24 and a default word is nontrivial. The JS implementation is Array(2 ** d).fill(v) and has no corresponding restriction.
The 24-bit count itself is a documented BendRT limitation, and #975 mentions that refcount overflow is rejected with ERR_RFCS. The observable issue here is the resulting backend acceptance split in the public Array.new operation: the same checked source completes on JS and fail-stops on native C. I found no issue or WONTFIX entry covering that depth-24 boxed-array split.
This is below the documented/common array-depth wall. tests/io/array_depth_bound.bend makes both lanes reject only a depth past 31 and describes depth 31 itself as legal subject to host memory. Native C therefore has a hidden lower acceptance wall based on the runtime representation of the element: a static or flat value can work at depth 24, while a dynamic boxed value fail-stops.
The lanes should either share an explicit boxed-array limit or represent the repeated native default without requiring a 2²⁴ reference count. The current source type and Array.new API do not expose the native-only restriction.
bend --version
Reproduced on v2.0.34 (7d8a3eb036042c6549461054d25a10f26d361c5c) and current main (57b6c150f63704f53d533776deb3859578d4b09e).
Closing as not planned. On the C lane, copies of a shared value are tracked by a 24-bit count, so one value can have at most 2^24-1 live copies. Array.new(T, 24n, x) makes 2^24 copies of x, which goes past that. JS keeps no count, so it runs on, and that is why the two lanes differ. Removing the cap would make every reference count wider, which costs memory and speed everywhere, so we're keeping it.
#1366 gives this case its own error message instead of the generic 'runtime fail-stop', and adds a WONTFIX entry with the workaround: build the value again for each group, so each build has its own count. For example, two depth-23 arrays joined by ANode:
Activity
Lorenzobattistela commentedon Oct 6, 2026
Closing as not planned. On the C lane, copies of a shared value are tracked by a 24-bit count, so one value can have at most 2^24-1 live copies. Array.new(T, 24n, x) makes 2^24 copies of x, which goes past that. JS keeps no count, so it runs on, and that is why the two lanes differ. Removing the cap would make every reference count wider, which costs memory and speed everywhere, so we're keeping it.
#1366 gives this case its own error message instead of the generic 'runtime fail-stop', and adds a WONTFIX entry with the workaround: build the value again for each group, so each build has its own count. For example, two depth-23 arrays joined by ANode:
This gives 2^24 elements and prints 1n on both C and JS. Sharing one +x between the two halves still stops on C, because it is the same value.