Skip to content

refactor(interp): resolve typed array element layout from one table - #200

Merged
siyul-park merged 1 commit into
mainfrom
refactor/jit-element-shape
Aug 16, 2026
Merged

siyul-park merged 1 commit into
mainfrom
refactor/jit-element-shape

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Stage 3 (second half) of the JIT lowering rework. Stacked on #199.

Change

The element storage layout — which heap itab a container must carry, where its element data starts, how wide an element is, and whether a loaded element is an unboxed payload — was written out longhand in four places:

Site What it spelled out
arrayGet full kind → (itab, base, scale, raw) switch
arraySet the same switch again, minus raw
arrayLen the itab set, with base offsets
hoistable (planner) the itab set again, to mean "primitive typed array"

elemShapes is now the one place that layout is written down, with elemShapeOf resolving by element kind and elemShapeByItab by concrete container itab. A new element kind is one row instead of an edit to each site, and the four sites can no longer disagree about a kind's width or base offset.

hoistable's rule also reads directly now — it hoists only when the shape resolves and its elements are raw, because a ref array's elements carry ownership a cached slice header cannot account for. That was previously expressed by listing six itabs and omitting the seventh, leaving the reason implicit.

No behavior change: the table reproduces the same kind and itab sets, with the same base offsets and scales, that the four copies named.

The guard combinator was evaluated and rejected

The plan called for a second extraction here — one guarded-access combinator for arrayGet/arraySet and structGet/structSet. I looked at it and did not do it, deliberately:

  • arraySet queues three side exits (shape, bounds, value); arrayGet queues a different set
  • arraySet runs a hoisted fast path before the guards and returns early from inside it
  • the two differ in return arity — (bool, bool) vs bool
  • the orderings that differ are exactly the ones the refcount invariants depend on

A combinator covering all of that would take more parameters than it removes, in the code where a mistake is a use-after-free rather than a style problem. The repetition here is real but shallow; the abstraction would be deep and speculative.

arrayGetKnown and arrayKind are also left alone — both dispatch on the concrete Go type of a live heap value rather than on an itab, which is a different mechanism.

Test plan

  • go test -race ./...
  • make lint, make check-generated

Refs #164

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

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

Next review available in: 21 minutes

Limit details: You’ve used all 1 included review currently available under your plan.

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: e196d32b-eb53-4294-b742-ae41addfa522

📥 Commits

Reviewing files that changed from the base of the PR and between 81bc93a and 540c799.

📒 Files selected for processing (2)
  • interp/jit_arm64.go
  • interp/jit_plan.go

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 force-pushed the refactor/jit-heap-handlers branch from daa922c to 08bb211 Compare August 16, 2026 06:11
The element storage layout - which heap itab a container must carry, where its
element data starts, how wide an element is, and whether a loaded element is an
unboxed payload - was written out longhand in four places: arrayGet and
arraySet each carried the full kind switch, arrayLen carried the itab set with
its base offsets, and the planner's hoist eligibility carried the itab set
again to mean "primitive typed array".

elemShapes is now the one place that layout is written down, with elemShapeOf
resolving by element kind and elemShapeByItab by concrete container itab. A new
element kind is one row instead of an edit to each site, and the four sites can
no longer disagree about a kind's width or base offset.

hoistable's rule reads directly now: it hoists a container only when the shape
resolves and its elements are raw, because a ref array's elements carry
ownership that a cached slice header cannot account for. That was previously
expressed by listing six itabs and omitting the seventh.

No behavior change: the table reproduces the same kind and itab sets, with the
same base offsets and scales, that the four copies named.

The guard preamble shared by arrayGet/arraySet and structGet/structSet was
evaluated for the same treatment and left alone. The sequences look alike but
differ in the number and kind of side exits they queue, in whether a hoisted
fast path runs before the guards, and in return arity; a combinator covering
them would take more parameters than it removes, in the code where the refcount
invariants live.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@siyul-park
siyul-park force-pushed the refactor/jit-element-shape branch from f1f81b4 to 540c799 Compare August 16, 2026 06:11
@siyul-park
siyul-park changed the base branch from refactor/jit-heap-handlers to main August 16, 2026 06:11
@siyul-park
siyul-park merged commit 7a141fd into main Aug 16, 2026
1 of 2 checks passed
siyul-park added a commit that referenced this pull request Aug 16, 2026
* refactor(interp): reject a self callee instead of falling through

The BLR slot path cannot serve a call to the function currently being
emitted: it has published no slot yet. A self callee that selfCall turns
down was falling through to that path with the call marker pushed back
onto the operand stack, so ctx.sp() counted one slot too many and the
callee frame base landed one slot high.

Nothing reaches it - instrumenting the branch across the interp suite
and all 18 benchmark kernels recorded zero hits - so this removes an
untested path rather than fixing an observed failure. Rejecting matches
what the code did before the marker handling moved.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(interp): build the element shape table on every architecture

jit_plan.go resolves a container's element layout through elemShapeByItab,
but that table and the itabs it names lived in jit_arm64.go, whose name
constrains it to one GOARCH. The planner is portable and compiles for
architectures with no native backend at all, so every non-arm64 build
failed on an undefined symbol.

Move the heap itabs, the element shape table, and the ref-array element
offset the table names into the portable JIT core. Nothing changes for
arm64; the architecture file keeps only lowering detail.

Regression from #200, where the table was introduced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* build: baseline coverage against what CI can actually measure

The gate compares one number across two architectures with very
different compiled surfaces. CI runs on amd64, where the arm64 JIT
backend is not compiled but the portable planner, tracer, and JIT core
are - and every test that exercises them skips, so they count as
uncovered.

72.8 was recorded in #146, before the JIT grew. It has not been
measurable since: non-arm64 builds have failed outright, so the job
never reached the gate. With the build fixed, the honest amd64 number is
63.6.

Raising it again needs portable tests for the planner and tracer, not a
different threshold.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
@siyul-park
siyul-park deleted the refactor/jit-element-shape branch November 7, 2026 10:21
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