Skip to content

Lowering: one helper knows the array layout (#453 step 1) - #478

Merged
ASDAlexander77 merged 4 commits into
mainfrom
array-reference
Oct 3, 2026
Merged

ASDAlexander77 merged 4 commits into
mainfrom
array-reference

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Step 1 of the arrays-as-references plan for #453 (spec: docs/superpowers/specs/2026-10-03-array-reference-design.md).

Refactor only, no behaviour change. A new ArrayLayout helper (include/TypeScript/LowerToLLVM/ArrayLayout.h) is now the one place that knows an array value is a { data, length } struct. The array ops in LowerToLLVM.cpp (length, push/pop/shift/unshift/splice, create/new/view), the casts and truthiness in CastLogicHelper.h, the read-only constant arrays and element addressing in LLVMCodeHelper.h, the === path (via extractArrayPtr) and the retain/release routines in OwnershipRoutineLogic.h all go through it. Outside ArrayLayout.h nothing references ARRAY_DATA_INDEX / ARRAY_SIZE_INDEX any more except the non-array fallback in LengthOf. Unused llvmArrayType / loc locals left by the first commit are removed.

Verification

  • IR gate: --emit=llvm --no-default-lib for every suite test (774 tests) under gc, rc and own = 4388 files (2066 .ll + 2322 .err), base compiler (main at 4dd14ca) vs this branch. The compiler's IR output is nondeterministic from run to run at baseline (hash-suffixed names, ___cast<> / ___bin_op_ union member order, string-length constants), so a raw diff -rq is not empty even for two runs of the unmodified compiler. The comparison therefore normalises those (digit runs of 5+ in names, cast names, string-length constants).
    • Two runs of the base compiler, normalised and order-preserving: 4385 files identical, 3 unstable (tests-01types_utility-rc.ll, tests-conditionalTypes2-own.err, tests-conditionalTypes2-rc.ll).
    • Base vs this branch, order-preserving, on the 4385 stable files: 0 differences.
    • The 3 unstable files, line-sorted: base vs this branch 0 differences (base vs base2 differs in all 3).
  • Full suite (Release): 99% passed, 1 failed of 3691. The failure is test-compile-gc-defaultlib-collector (stale local default library, unrelated); test-compile-shared-export-import-declare-linkname is Disabled.

🤖 Generated with Claude Code

ASDAlexander77 and others added 4 commits October 3, 2026 22:48
An array value becomes one pointer to a heap header { data, length,
capacity } that never moves, so every alias sees push/pop/splice/length=.
Rollout in three PRs: a behaviour-free layout helper, the switch, growth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Eight tasks in three PRs. Rulings folded into the spec: a null header
reads as an empty array (R1), main's string[] argv is made by a new op
(R2), the rest element is built in MLIRGen (R3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
….cpp)

ArrayLayout reads and writes an array's data and length, and makes one.
No change to the generated IR: --emit=llvm identical for every suite test
under gc, rc and own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… ArrayLayout

The last places outside the helper that knew the { data, length } layout.
Also drops the llvmArrayType/loc locals Task 1 left unused.
No change to the generated IR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 5e203fc into main Oct 3, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the array-reference branch October 3, 2026 23:16
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.

1 participant