Skip to content

Support equality-proof arrays in JS and C (#1130) - #1219

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:fix/array-equality-elements
Oct 2, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:fix/array-equality-elements

Conversation

@oxura

@oxura oxura commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1130.

lay_el now recognizes equality as a layout-stable primitive Data type, in addition to datatypes. It reuses the existing BOX/zero proof representation; no proof ABI change, heap wrapper, guessed generic layout or unchecked fallback. Equality endpoints may contain erased variables without making the proof representation open. Truly unknown element types still fail loudly.

Permanent regression uses a polymorphic equality-proof factory, clone, wrapped get, swap, set and a structural half-array match. It checks that the half has size 2 while the original clone retains size 4 (204).

Verification:

  • Before: reported example fails JS emission with an open Array element type.
  • After: reported example prints 4 on interpreter, emitted JS and native C.
  • New regression prints 204 on all three paths.
  • Both native C programs run with Clang AddressSanitizer and UndefinedBehaviorSanitizer enabled, with no diagnostics.
  • Existing open-element regression still rejects the unsupported generic representation; nodeless-default and size/wrapping controls retain their expected results (7, 16081).
  • bun gates/repo.ts: PASS 49/49.

No changes to bend2/bend.ts; no caps changed.

@oxura

oxura commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Joint verification of #1215, #1216, #1218, #1219 and #1220 against main commit 0187512:

  • All five independent PR branches merge cleanly in one octopus merge. Documentation hunks were separated and shared wording shortened so the combined guide stays within the original cap.
  • Combined bun gates/repo.ts: PASS 49/49; no caps changed.
  • Real Lean 4.34.0-built BendTT kernel accepts all three new positive proof regressions, unchanged vec_safe_lookup, and the five reported grouping/label/model-search witnesses.
  • Four runtime regressions produce 5n, 6n, 7n, 204 on interpreter, emitted JS and native C. All four C programs were exercised with AddressSanitizer and UndefinedBehaviorSanitizer; no diagnostics.
  • The merged emitted fb3 value passes an added {main == (.False, ()) : Bool} oracle. The corresponding .True oracle fails in the actual kernel, so successful type-checking is not the only evidence of value preservation.
  • Kind-only and empty-datatype unsafe dependencies still reject with exit 1 and the expected dependency sets.
  • The genuinely required unavailable model rejects promptly; -o explicitly reports no model for reflexive~n as out of scope. Search-limit exhaustion remains fail-closed, not an unchecked placeholder.

The cluster-wide corpus gates were not run; this evidence is the local repository gate, actual CLI/compiler runs and actual kernel checks.

@Lorenzobattistela

Lorenzobattistela commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks for this, the fix looks right. Equality elements get BOX, which is the layout they already have outside arrays, and datatype elements are unchanged. I checked it on the cluster: repo, ping and test (1527/1527) pass. Perf fails only on benches that fail on main too. A few requests before merging:

  1. Remove the GUIDE.md change. This doesn't belong in the guide. Please drop the hunk.
  2. Update the Lay header comment (comp.ts, above lay_of). It still says "lay_el refuses an open element type". Please add that an equality element is accepted even when its sides mention type variables, because its layout doesn't depend on them.
  3. Keep the equality layout in one place. The new branch returns BOX directly, which repeats what lay_of already returns for any type that isn't a datatype. Please return lay_of(book, A) there, so plain proofs and proof arrays can't drift apart if the proof representation ever changes.
  4. Cover the print path. A main that returns a proof array now reaches the printer's array branch, which used to die in lay_el. Please add a small test like this, which should print [{==}, {==}]:
import Base

def main() -> Array<{0n == 0n : Nat}>:
  Array.new({0n == 0n : Nat}, 1n, {==})

#|[{==}, {==}]

@Lorenzobattistela
Lorenzobattistela merged commit fddefd4 into bendlang:main Oct 2, 2026
@oxura

oxura commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed the merged corrections: no GUIDE hunk, the Lay header documents open equality endpoints, and lay_el delegates equality to lay_of(A) rather than duplicating BOX. The permanent array_equality_print fixture printed [{==}, {==}] in the actual source CLI, emitted JS under Bun and Node, and native CPU output (4 threads) on fa4ba634. Removed the stale GUIDE sentence from the PR description. Thanks for the cluster checks; these fresh checks are local CPU runs only.

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.

An Array of an equality type stops both emitters with "an open Array element type"

2 participants