Conversation
fglock
added a commit
that referenced
this pull request
Apr 24, 2026
… build Restores TT chomp.t / directive.t / text.t "Can't call method clone on undef" that the earlier commit "drop asymmetric incref in RuntimeScalar.addToArray" exposed — without reintroducing the DBIC TxnScopeGuard #18 refcount leak. ## Root cause During `my $arr = [ Foo->new(1), Foo->new(2) ]`: 1. Foo->new(1) returns a RuntimeScalar referencing a blessed hash. It's added to the literal's RuntimeArray. 2. Foo->new(2) constructs its value. Somewhere inside, `setLarge*` triggers MortalList.flush() to process pending deferred decrefs. 3. If the Foo(1) element is marked as mortal pending and hasn't yet been tied down by createReferenceWithTrackedElements (which runs only at literal-end), the mid-build flush decrements its refCount to 0 and fires DESTROY on Foo(1). 4. The anon-array-literal ends up with a DESTROYed Foo(1) — later accesses fail with "Can't call method X on undefined". ## Previous (incorrect) approach c8f669b solved this by adding a refcount-incref to every RuntimeScalar.addToArray call. The incref PINS each element so the mid-build flush can't drop refCount to 0. Unfortunately the incref also applies to paths that are NOT anon-array-literal construction — e.g. RuntimeList iteration used by some arg-flattening paths — and no matching decref exists, leaking +1 refCount per blessed value. That phantom refCount broke DBIC's zombie-ref double-DESTROY detection (t/storage/txn_scope_guard.t test 18). ## New approach: narrow envelope at the emit site Wrap the *entire* anon-array-literal construction in MortalList.suppressFlush(true) ... suppressFlush(prev); if (prev) flush(). Keeps the window of "mid-build flush cannot fire" as short as possible, and affects *only* the anon-array-literal call site (EmitLiteral), not every addToArray caller. Refcount accounting in every other path stays symmetric — DBIC's zombie-refs test keeps passing. Bytecode emitted (prolog): ICONST_1 INVOKESTATIC MortalList.suppressFlush(Z)Z ISTORE wasFlushingSlot <... existing element-add loop + createReferenceWithTrackedElements ...> Bytecode emitted (epilog, keeping the reference on TOS): ILOAD wasFlushingSlot INVOKESTATIC MortalList.suppressFlush(Z)Z POP ILOAD wasFlushingSlot IFNE skipFlush INVOKESTATIC MortalList.flush()V skipFlush: The IFNE ensures we don't flush when flushing was previously suppressed by an OUTER context — in that case the outer unwinder will handle it. ## Test plan - make dev — PASS - DBIC 15-test indicator set — **15/15 PASS (0 real failures)** - Template t/chomp.t — 78/78 PASS (was "Can't call method clone on undef" after the revert) - DBIC t/storage/txn_scope_guard.t — 18/18 PASS Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.