fix: count nesting depth, not call count, in rdepth#139
Draft
Koan-Bot wants to merge 3 commits into
Draft
Conversation
rdepth previously incremented on every sv_clone() call, including sibling elements within arrays and hashes. A flat array of N>MAX_DEPTH elements would falsely trigger the iterative fallback even though the actual nesting depth was only 2 (one RV + one AV). Move rdepth increment from the top of sv_clone() to the single point that increases nesting: the RV dereference (rdepth+1 when cloning the referent). Sibling elements in av_clone/hv_clone loops now keep the same rdepth as their parent container. Halve MAX_DEPTH (4000→2000 Linux/macOS, 2000→1000 Windows) since rdepth now counts nesting levels directly rather than call pairs. The effective stack usage and safety margins remain identical. Add tests for wide structures (arrays/hashes with 3×MAX_DEPTH elements) to verify they never trigger the iterative path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
install-with-cpm@v1 regressed on Perl 5.8-5.22 after a recent cpm update requiring Perl 5.24+. Bump to @v2 for action-based jobs and use direct `cpm install` in the Docker-based Linux matrix (where cpm is pre-installed). Matches the approach approved by @atoomic in PR garu#120. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The cycle back-edge at chain_len/2 landed exactly at the recursive/iterative boundary on Windows (MAX_DEPTH=1000), causing rv_clone_iterative to loop on the cycle before hseen had registered the target. Move the target to chain_len*3/4 so it falls in the recursive range on all platforms — hseen catches the back-edge during the iterative walk. Co-Authored-By: Claude Opus 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.
What
Make
rdepthtrack actual nesting depth (RV dereferences) instead of totalsv_clone()call count.Why
rdepthincremented on everysv_clone()call, including sibling elements within flat arrays and hashes. A flat array of N > MAX_DEPTH elements falsely triggered the iterative fallback even though the actual nesting depth was only 2. The iterative path historically had more bugs than the recursive path, so entering it unnecessarily was both a correctness risk and a performance penalty.How
rdepth++from the top ofsv_clone().rdepth + 1at the only point that increases nesting: the RV dereference (SvRV(clone) = sv_clone(SvRV(ref), ..., rdepth + 1, ...)).av_clone/hv_cloneloops keep the samerdepthas their parent.rdepthnow counts nesting levels directly. Effective stack usage unchanged.Testing
Quality Report
Changes: 7 files changed, 97 insertions(+), 37 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline