Repository navigation
fix(interp): two native frame defects on the self-call and return paths - #193
Conversation
ret took the retain on a returned ref after guardFrame had already read the backing local's refcount. guardFrame deopts whenever rc <= pending, and the most ordinary ref-returning shape - allocate a node into a local, return it - sits exactly at that boundary, because the local is the only holder and so rc == pending == 1. Every such RETURN therefore left native code. The regression test's program measures 512 guard-value exits against 1024 native entries before this change and none after, so half of all native calls were deopting at their return. Execution stayed correct throughout, since the interpreter completes the RETURN either way, which is why neither a value nor a refcount oracle catches this: the test asserts the guard-value exit count directly. Taking the retain first raises rc above pending, the guard passes, and the following releaseFrame decrement leaves exactly the one live reference the caller now owns - the same net transfer threaded retire performs. stitch is deliberately left alone. Its callee returns cannot reach the same boundary: call()'s inline path rejects any callee holding a ref local, so an inlined return is backed by a parameter or an upvalue, whose refcount exceeds the frame's pending count. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 46 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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
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. Comment |
selfCall lowers recursion as a BL back to ctx.head, re-entering the plan's entry prologue. That is only the callee's real entry when the live frame is the plan's own, but selfCall checked neither ctx.kind nor len(ctx.frames), and the trace frontend reaches it with a foreign frame live. Any CALL inside a function-entry-anchored trace whose callee ref matches the anchor is recorded as an ordinary self CALL, including one nested inside an already-inlined callee's body. So a trace that inlines A -> B and then sees B call back into A arrives at selfCall with two frames, and the BL lays A's parameter prologue over B's activation. When the two frame shapes differ the result is not a wrong answer but a fault inside the Go runtime: the added test segfaults deterministically without this change, at three distinct wild addresses across runs, inside asm/arm64.invoke. Of the two conditions only the frame count is load-bearing today - a loop plan cannot currently carry a self CALL, because the tracer cuts one anchored at a loop header - but ctx.head is equally not an entry prologue in that case, so both are checked together where the BL is emitted. The static frontend never reached this: directCall rejects a self callee outright, and it is the only path that sets step.known. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Split out of #191. Two independent defects, both present on
maintoday, unrelated to the performance work that PR carries.1. A native self-call could branch into a foreign frame — SIGSEGV
selfCalllowers recursion as aBLback toctx.head, re-entering the plan's entry prologue. That is only the callee's real entry when the live frame is the plan's own — butselfCallchecked neitherctx.kindnorlen(ctx.frames).The trace frontend reaches it with a foreign frame live. Any
CALLinside a function-entry-anchored trace whose callee ref matches the anchor is recorded as an ordinary selfCALL, including one nested inside an already-inlined callee's body. So a trace that inlinesA → Band then seesBcall back intoAarrives atselfCallwith two frames, and theBLlaysA's parameter prologue overB's activation.When the two frame shapes differ, the result is not a wrong answer — it is a fault inside the Go runtime:
Reproduced deterministically on
main, at three distinct wild addresses across runs, faulting insideasm/arm64.invoke.TestARM64_SelfCallFromInlinedFramesegfaults without the fix and passes with it.Of the two conditions only the frame count is load-bearing today — verified by isolating them:
ctx.kind != entryFunctionalone does not stop the crash,len(ctx.frames) != 1alone does. A loop plan cannot currently carry a selfCALL, because the tracer cuts one anchored at a loop header. Butctx.headis equally not an entry prologue in that case, so both are checked together where theBLis emitted.The static frontend never reached this:
directCallrejects a self callee outright, and it is the only path that setsstep.known.2.
retdeopted on every ref returnrettook the retain on a returned ref afterguardFramehad already read the backing local's refcount.guardFramedeopts wheneverrc <= pending, and the most ordinary ref-returning shape — allocate a node into a local, return it — sits exactly at that boundary, because the local is the only holder, sorc == pending == 1.Measured on
mainwith the program the test uses: 512guard-valueexits against 1024 native entries — half of all native calls deopted at their return. After the fix: 0.Execution stayed correct throughout, since the interpreter completes the
RETURNeither way, so a spurious deopt is invisible to both a value oracle and a refcount oracle.TestARM64_RefReturnasserts theguard-valueexit count directly, alongside threaded-twin parity checks that rule out the retain leaking or freeing.Taking the retain first raises
rcabovepending, the guard passes, and the followingreleaseFramedecrement leaves exactly the one live reference the caller now owns — the same net transfer threadedretireperforms.stitchis deliberately left alone: its callee returns cannot reach the same boundary, becausecall()'s inline path rejects any callee holding a ref local, so an inlined return is backed by a parameter or an upvalue whose refcount exceeds the frame's pending count.docs/jit-internals.mdrecords that asymmetry.Test plan
TestARM64_SelfCallFromInlinedFrame— mutual recursion through ref-parameter callees at depths 1–16; SIGSEGVs onmain, passes with the fixTestARM64_RefReturn— fails onmainwithguardFrame spuriously deopted a RETURN of a singly-owned frame localgo test -race ./...,make check-generated,go vet ./...Refs #164
🤖 Generated with Claude Code