Repository navigation
fix(runtime): caller() must not zero out invocant when @_ is shifted (GH-1682) - #1698
Merged
Merged
Conversation
) When a method accesses $_[0] (e.g. `$_[0]->isa(...)`) before calling `shift @_`, RuntimeArray.get() was calling recordLocalArrayOwner(@_, 0) on the caller's scalar. This overwrote the element's localArrayOwner to point at @_. Later, when Carp::croak called caller() which called clearStaleLocalArrayAliases() on the pristine args snapshot, the element was detected as stale (no longer at index 0 of @_ after the shift) and clearForArraySlotRemoval() was called on it — zeroing out the caller's original variable. The fix: in RuntimeArray.get(), only call recordLocalArrayOwner() when the array owns its elements (elementsOwned == true). Aliased arrays like @_ borrow scalars from the caller without owning them; recording @_ as the owner here corrupts the stale-alias detection for the caller's variable. This preserves the existing behaviour of caller_db_args_freed.t, which relies on clearStaleLocalArrayAliases() correctly clearing an element whose owner (@values) was emptied after the call. Adds regression test: unit/method_custom_isa_caller_preservation.t Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.
Summary
Fixes #1682 — Math::BigInt
mbimbf.tandtrap.tfailures forMath::BigFloat.Root cause:
RuntimeArray.get()was callingrecordLocalArrayOwner(@_, index)on aliased arrays like@_. When a method called$_[0]->some_method()beforeshift @_, this overwrote the element'slocalArrayOwnerto point at@_. Later,Carp::croak→caller()→clearStaleLocalArrayAliases()detected the element as stale (no longer in@_after the shift) and calledclearForArraySlotRemoval()on it — which zeroed out the original caller's variable (e.g.$x).Fix: In
RuntimeArray.get(), only callrecordLocalArrayOwner()whenelementsOwned == true. Aliased arrays like@_setelementsOwned = false(viasetFromListAliased), so their elements' canonical array-slot tracking is never overwritten.Regression test:
unit/method_custom_isa_caller_preservation.t— directly reproduces the pattern (method call on$_[0]beforeshift+Carp::croak).Test plan
unit/method_custom_isa_caller_preservation.tpasses (all 5 functional tests ok)unit/caller_db_args_freed.tstill passes (verifiedclearStaleLocalArrayAliasesstill works correctly for the@valuesaliasing case)src/test/resources/module/Math-BigInt/t/trap.t— tests 37, 41, 43, 45 (previouslynot okforMath::BigFloat) now passmakepasses (shard failures are pre-existing:apostrophe_package_separator_feature.tisolation issue andPerlOnJavaHomeIntegrationTestJAR packaging issue, both unrelated to this change)🤖 Generated with Claude Code