Repository navigation
Conversation
Quest-Claim: 85f4f619dcf7bc25
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…gument holds after The writer marks each handle it encodes whose value the call takes, and abandons those once the call returns or unwinds, instead of walking the argument again: a callback that changed a list argument meanwhile no longer closes the wrong handles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound. The writer marks which handles it encoded as moved, so the cleanup closes exactly what Rust took. This fixes the cause, not a symptom, and adds no per-call copy.
Reviewed changes — the full diff of both commits: the runtime writer, the generator, the regression test, and the quest file removal.
__Writer.moved/abandon:movedencodes the handle throughhandle()and records its index in a lazily allocatedBooleanArraythat grows withslots.abandon()closes only the markedheldentries. The index bound holds becausehandle()always growsslotsbeyondheld.size - 1.Gen::encode:movespropagates throughList,Option,BoxandTuple, but not throughRef. Objects getw.moved(...)only whenmoved(abi, ty)is true, soCopyobjects inside moved tuples still usehandleand are never abandoned. This matches the oldclosefilter.- Cleanup placement:
{w}.abandon()goes intoafter, whichGen::movingruns inside the writer'suse {}on both the return and unwind paths. It runs beforerelease(), the same order as the deletedGen::close. - Regression test: a
Logcallback swapschanged[0]duringlogCounts. The test checks that the moved counter is closed and the replacement stays open, on both the success path and the unwind path (a lone-surrogatecharcheck).
ℹ️ Go's binding still finds moved handles by re-walking the argument
This PR does not touch Go, but Go has the same pattern. go.rs close builds for _, v := range more { v.Handle_.Moved() } and runs it after the call (moves.push(self.close(¶m.ty, &name, 0)) near ffi/src/go.rs:2992). A Go slice shares its backing array with the caller, so a callback that captured more and sets more[0] = placed would cause the same mismatch fixed here: placed gets marked moved and the taken object stays open. Swift's close also re-walks, but Swift arrays are value types, so a callback cannot change the caller's copy. This is mergeable as is; a follow-up quest for Go seems worthwhile.
Technical details
# Go: a call marks moved the handles its slice argument holds after the call, not those it encoded
## Affected sites
- ffi/src/go.rs:2792 — `close` re-walks `e` (slices, options, tuples) after the call
- ffi/src/go.rs:2992 — `moves.push(self.close(¶m.ty, &name, 0))`
## Required outcome
- A Go call that moves objects out of a slice argument marks moved (`Handle_.Moved()`) exactly the handles it encoded, even when a callback reassigns slice elements during the call; the replacement stays open.
- Regression test in the Go api test, mirroring `unwinds()` in ffi/tests/api.kt.
## Suggested approach
- Collect the moved handles while lowering (as Kotlin's `__Writer.moved` now does), then run `Moved()` on that list.claude-opus-5-5 | 𝕏

A Kotlin call that moves objects out of a collection argument, such as
logCounts'smore: List<Counter>, now closes exactly the handles it encoded, whether it returns or unwinds, even when a callback it reaches changes that collection meanwhile. Before, the cleanup walked the argument again after the call, so a callback that swapped A for B abandoned B, which Rust never took, and left A's wrapper open on a value Rust had already taken.Changes
ffi/runtime/rt.kt:__Writer.moved(handle)encodes a handle ashandledoes and marks it in aBooleanArraybesideheld.__Writer.abandon()abandons each marked handle. Nothing is copied per call: the array is allocated only once a moved handle is encoded, and grows withslots.ffi/src/kotlin.rs:Gen::encodeiswrite_valuewith amovesflag. A moved argument's writes emitw.moved(...)for each non-Copyobject reached by value, through a list,Option,Box, or tuple, never through a reference. Itsafterisw.abandon().Gen::close, which re-walked the argument, is gone.ffi/tests/api.kt: inunwinds(), aLogcallback replacesmore[0]duringlogCounts. The test checks that the moved counter is closed and the replacement stays open, once on the success path and once on the unwind path, where a callback's failedcharcheck unwinds the call.Decisions
held, so a parallelBooleanArrayis all the extra state needed. This is the Plan's second option.Copyobject inside a moved tuple, such as theentrytuple's second element, is still encoded withhandleand is never abandoned, as before.Validation
tests/api.kton the old generator,just ffi test --test fixtures api_kotlin -- --exactfails withfailed: what the call moved is closed. With the fix it passes.logCounts,counters,chain,items,entry, ...) writeswN.moved(...)and runswN.abandon()on both paths. TheCopyelement ofentry's tuple is still written withwN.handle(...).just cipasses locally.Public API
None. The generated Kotlin's public signatures and the C ABI are unchanged; only
_Native.__Writer's internal runtime gainsmovedandabandon.Caused by
Vec<T>argument's handles by walking the argument after the call, not by the handles encoded (found by reviewer: CodeRabbit on kixel-ai/rust2#922, which runs the same cleanup on the unwind path)Follow-ups
None.
Models
Size: S
Implementer: Claude Code, claude-opus-5-5, medium effort (arm A)
🤖 Generated with Claude Code
Review
Rewritten by
quest reviewafter each round.Head: 1c4f56a
Base: origin/main at b99b71f
Risk: medium,
the base has no RISK.md to name what is always high or customer-facing, so every change is mediumClassified: medium by default
Reviewer: Codex, gpt-6.1-sol, medium effort
Session:
01a1fcc4-5b63-7c10-8c9f-61571183b539, round 1Score: 9/10,
The writer preserves replacement handles across successful and unwinding callbacks, with regression coverage and no actionable defects found by inspection, though tests were not run as instructed.Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0
Findings: none
Summary by CodeRabbit