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: the depth argument is undocumented, and a length gives "an array past the deepest block class 31" #1962
import Base
def main() -> IO(Unit):
do IO<Unit>:
a = Array.new(U32, 12288n, 0)
return Unit{}
SOME PROOFS FAIL
bend: an array past the deepest block class 31
Changing only 12288n to 14n builds and runs. The intent was a 12,288-element array; d is a binary-tree depth, so the correct value is 14 (2^14 = 16,384 leaves), or T.depth(n) where that helper is available.
Observed
bend base Array.new shows the definition but nothing says d is a depth:
def Array.new(-T: Data, +d: Nat, +v: T) -> Array<T>:
match d:
case 0n:
ALeaf{v}
case 1n+p:
ANode{[v : T^p], [v : T^p]}
The error names the block class but not the argument, and a reader who passes a length has no way to know that 31 is a depth bound rather than a size bound.
Relation to existing issues
This is not #1267 (the closed depth-24 boxed-value split between JS and native), and not tests/io/array_depth_bound.bend (depth 31). It is the public signature and its diagnostic.
Proposed
Document d as the tree depth, 2^d leaves, and that the largest legal depth is 31.
Make the error say so, for example: depth 12288 exceeds the deepest block class (31); pass the depth, for example 14 for 12288 elements.
If useful, add Array.of_length(n, v) or point at T.depth(n), so the common case does not require knowing the representation.
The workaround is proven: depth 23 loads a 6.3 MB byte array in 45 ms.
Activity