Skip to content

feat(interp): add array set fusion - #181

Merged
siyul-park merged 8 commits into
mainfrom
agent/array-set-fusion-jit-fix
Aug 9, 2026
Merged

siyul-park merged 8 commits into
mainfrom
agent/array-set-fusion-jit-fix

Conversation

@siyul-park

@siyul-park siyul-park commented Aug 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add ARRAY_SET fusion lowering for constant typed arrays
  • share generic array access through arrayGet / arraySet
  • keep generated handlers and runtime helpers on the same naming boundary
  • simplify related fusion pattern naming and document the specialization boundary
  • preserve the ARM64 deferred-ref ownership issue as a separate tracked issue (ARM64 JIT: deferred refcount imbalance through self tail call #179)

Validation

  • make check-generated
  • git diff --check
  • go test ./internal/cmd/geninterp ./instr ./types ./program ./interp

Known issue

ARM64 self-tail-call deferred-ref imbalance remains tracked separately in #179; this PR does not mask or weaken that ownership test.

Summary by CodeRabbit

  • New Features

    • Added support for updating constant-backed arrays during optimized execution.
    • Added type-aware value conversion for typed arrays, including bounds validation.
    • Added support for fused array update operations from constant values.
  • Bug Fixes

    • Improved execution recovery when array or struct updates cannot continue natively.
    • Improved reference handling when values and execution frames are released, helping prevent stale references and memory issues.

Keep the threaded array.set implementation shared by fused and standalone paths. Restrict native array.set lowering to proven constant containers and deopt other shapes to the threaded handler. This removes duplicate generated mutation logic and keeps the JIT fast path conservative.
Keep array.set fusion on compile-time constant containers so the generator and ARM64 backend share one specialization boundary. Remove the unused dynamic-container path and inline the single-use value producer selection.
@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@siyul-park, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f7d8ec74-4872-4dc8-a6d9-968e07ada6da

📥 Commits

Reviewing files that changed from the base of the PR and between 02ed48c and b558552.

📒 Files selected for processing (7)
  • docs/fusion.md
  • docs/jit-internals.md
  • internal/cmd/geninterp/lower.go
  • internal/cmd/geninterp/pattern.go
  • interp/interp.go
  • interp/jit_arm64.go
  • interp/threaded.go
📝 Walkthrough

Walkthrough

The PR adds constant-backed ARRAY_SET fusion for typed arrays, centralizes standalone array writes, and updates ARM64 JIT frame reference ownership. Heap mutation documentation now describes resumable mutation-specific state.

Changes

ARRAY_SET JIT support

Layer / File(s) Summary
ARRAY_SET fusion and mutation
internal/cmd/geninterp/pattern.go, internal/cmd/geninterp/lower.go, interp/interp.go
Constant typed-array patterns now fuse CONST_GET, index, value, and ARRAY_SET. Lowering validates operands, checks bounds, converts values, and stores elements. Standalone writes use Interpreter.setArrayElem.
Frame reference ownership and fallback
interp/jit_arm64.go, docs/jit-internals.md
Retiring JIT frames now release reference locals after returned values are retained. Non-constant ARRAY_SET containers exit to interpreter execution. Documentation describes the resumable mutation paths.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CONST_GET
  participant resolve
  participant element
  participant storeArray
  participant Interpreter.setArrayElem
  CONST_GET->>resolve: supply constant array, index, and value
  resolve->>element: build fused ARRAY_SET
  element->>storeArray: convert and store typed value
  element->>Interpreter.setArrayElem: handle standalone or fallback write
Loading

Possibly related issues

  • siyul-park/minivm issue 173: The PR adds the proposed ARRAY_SET fusion patterns and primitive typed-array lowering.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding ARRAY_SET fusion in the interpreter.
Description check ✅ Passed The description covers the changes, validation, and related issue, although it uses different headings from the repository template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/array-set-fusion-jit-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@siyul-park siyul-park self-assigned this Aug 9, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
interp/jit_arm64.go (1)

3318-3347: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject constant generic arrays from native ARRAY_SET.

backingConst proves only constant provenance. It does not prove a typed-array representation. The types.KindRef arm selects heapArrayRef, so a constant *types.Array can still reach native mutation.

Restrict the native path to heapArrayI1, heapArrayI8, heapArrayI32, heapArrayI64, heapArrayF32, and heapArrayF64. Deopt generic arrays to the threaded handler.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@interp/jit_arm64.go` around lines 3318 - 3347, Update the native ARRAY_SET
path around the kind switch to reject generic constant arrays: allow only the
six typed-array backing kinds heapArrayI1, heapArrayI8, heapArrayI32,
heapArrayI64, heapArrayF32, and heapArrayF64. Remove or bypass the
types.KindRef/heapArrayRef case so generic arrays deopt to the threaded handler
instead of reaching native mutation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cmd/geninterp/lower.go`:
- Around line 2333-2351: Restore caller-before-callee declaration order by
moving storeArray in internal/cmd/geninterp/lower.go below element, which calls
it; also move releaseFrameRefs in interp/jit_arm64.go below stitch and ret,
which call it. Make no other behavioral changes.

In `@interp/jit_arm64.go`:
- Around line 2689-2710: Refactor arm64Lowerer.releaseFrameRefs to preflight-box
all reference locals before emitting any instructions, returning false without
mutating IR if boxing fails; then perform full reference release using the
existing zero-count release or side-exit mechanism rather than an unconditional
decrement/store. Preserve the native frame cleanup and returned-reference retain
sequence, and document that JIT contract in docs/jit-internals.md.

---

Outside diff comments:
In `@interp/jit_arm64.go`:
- Around line 3318-3347: Update the native ARRAY_SET path around the kind switch
to reject generic constant arrays: allow only the six typed-array backing kinds
heapArrayI1, heapArrayI8, heapArrayI32, heapArrayI64, heapArrayF32, and
heapArrayF64. Remove or bypass the types.KindRef/heapArrayRef case so generic
arrays deopt to the threaded handler instead of reaching native mutation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e3949b2-9679-4f87-b643-e5fbfc2793d5

📥 Commits

Reviewing files that changed from the base of the PR and between d56f31b and 02ed48c.

📒 Files selected for processing (6)
  • docs/jit-internals.md
  • internal/cmd/geninterp/lower.go
  • internal/cmd/geninterp/pattern.go
  • interp/interp.go
  • interp/jit_arm64.go
  • interp/threaded.go

Comment thread internal/cmd/geninterp/lower.go Resolved
Comment thread interp/jit_arm64.go Resolved

@siyul-park siyul-park left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all current CodeRabbit findings against the updated branch.

  • Caller-before-callee ordering: fixed in b558552 by moving releaseFrameRefs below stitch/ret; the existing storeArray ordering already matches the guideline.
  • Frame ref cleanup: fixed in b558552. Ref locals are collected/boxed before the release sequence, and each release uses the normal guardRC path so a final owner deoptimizes instead of being unconditionally decremented. The contract is documented in docs/jit-internals.md.
  • Generic constant arrays in native ARRAY_SET: fixed by removing the KindRef/heapArrayRef native case; ref-element arrays now deopt to the threaded handler. The existing terminal-fallback parity test passes.

I also checked analogous ref-release sites (ARRAY_SET, STRUCT_SET, reads, releaseRef) for the same unconditional-final-owner pattern; existing mutation/read paths already use the guarded release contract.

Validation: focused ARM64 tests and all non-ARM64 packages pass. The known self-tail-call deferred-ref case remains the only expected failure and is tracked in #179.

@siyul-park
siyul-park merged commit 610d72b into main Aug 9, 2026
4 of 5 checks passed
@siyul-park
siyul-park deleted the agent/array-set-fusion-jit-fix branch August 9, 2026 07:59
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