Repository navigation
fix(compiler): lay_el accepts datatypes and type formers only - #1426
Lorenzobattistela merged 2 commits into
Conversation
lay_el kept an allow-list of non-datatype element types (equality, now functions). It now refuses only a type variable, or an application or match stuck on one, and gives every other non-datatype element one box, which is what lay_of gave them. The guide change is dropped: arrays of functions are built leaf by leaf, which is not the usual way to use arrays. The regression adds a generic domain, erased-argument functions, and Array.set on a function array built by depth. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
10da3bb to
b93d46d
Compare
|
Thanks @nicolas-abril. Dropping the allow-list is the right direction, and the change is sound: every element type that now reaches the box path gets BOX from Checked on main 000de96 + this PR:
Two things before merging:
|
From the review of bendlang#1426. lay_el refused a short list of stuck tags, so a stuck Ref (a law or family with no body) was laid out as a box, and an undefined type crashed on t.$. It now accepts a datatype or one of the type formers (function, equality, Type, Quant), which form a closed set, returns lay_of for a former so the two stay in step, and refuses everything else, undefined included. Tests: Array.swap and Array.set under a generic domain, and a refusal for an element type that applies a type variable (Array<F(U32)>). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Follow-up to #1410 (already merged), from its review.
lay_elkept an allow-list of element types that aren't datatypes: equality types for #1130, and function types since #1410. Every new kind of element type would hitan open Array element typeagain in the JS and C builds.lay_el: accepts a datatype or one of the type formers: function (All), equality (Eql),Type(Typ) andQuant(Qnt). Those formers are a closed set. A former getslay_of's layout, so the two stay in step. Everything else is refused as open: a type variable, a hole, a stuck application, or a law or family with no body. A missing (undefined) type is refused too, instead of crashing.tests/reg/array_function_element.bendcovers a genericArray<(T -> U32)>used withU32and withBool,Array.swapandArray.setunder that generic domain, anArray<(@-m: Nat -> U32)>of erased-argument functions, andArray.seton a function array built recursively on a depth.tests/reg/array_open_element_family.bend: an element type that applies a type variable (Array<F(U32)>with-F: Type -> Type) still refuses.A law or family with no body as an element type is refused by
lay_elnow. It can't be put in a test, because the checker stops a book with a TODO before the compiler runs.About #1404: its
Array.new(U32 -> U32, …)call stays rejected on purpose.Array.newcopies its value into every leaf, so it needsData, and closures can't be copied. Function arrays are built fromALeaf/ANode, and both halves of eachANodemust have the same depth for the JS and C builds.Validation
array_function_element.bendgives49 19 a!b! 16 22 43 9 16in the interpreter, JS and C.array_open_element.bendandarray_open_element_family.bendfail withan open Array element typeon all three paths.bun gates/repo.ts: PASS 54/54.🤖 Generated with Claude Code