Skip to content

refactor: consolidate MAX_DEPTH RV handling into rv_clone_iterative#129

Merged
atoomic merged 1 commit into
garu:masterfrom
Koan-Bot:koan.atoomic/refactor-max-depth-rv-consolidation
Apr 25, 2026
Merged

refactor: consolidate MAX_DEPTH RV handling into rv_clone_iterative#129
atoomic merged 1 commit into
garu:masterfrom
Koan-Bot:koan.atoomic/refactor-max-depth-rv-consolidation

Conversation

@Koan-Bot

@Koan-Bot Koan-Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

What

Consolidates three separate RV cases in the rdepth > MAX_DEPTH block into a single rv_clone_iterative() call.

Why

The MAX_DEPTH handler had dedicated code paths for RV-to-AV and RV-to-HV that duplicated logic already in rv_clone_iterative(). These two paths were also missing SvWEAKREF handling — weak references to deeply nested arrays/hashes past MAX_DEPTH were silently converted to strong references during clone.

This is another instance of the recursive-to-iterative translation gap pattern (cf. GH #107, #113, #116, #119, #120, #127): when the iterative paths were added incrementally, each new one carried a subset of the safety invariants from the recursive path.

How

Removed the separate RV-to-AV and RV-to-HV blocks (lines 408–422), letting all RV types fall through to the existing rv_clone_iterative() call. This function already dispatches to av_clone_iterative()/hv_clone_iterative() for container referents and handles blessing + weakref propagation.

Net effect: −12 lines of code, +1 bug fix, same behavior for non-weakref cases.

Testing

  • All 23 tests in t/10-deep_recursion.t pass (added 5 new tests for weakref preservation past MAX_DEPTH)
  • Full test suite: 350 tests pass across 26 files

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 63 insertions(+), 22 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

The rdepth > MAX_DEPTH block had three separate RV cases (RV-to-AV,
RV-to-HV, RV-to-scalar) that duplicated logic already present in
rv_clone_iterative. The first two cases also lacked SvWEAKREF handling,
silently converting weak references into strong ones when cloning past
MAX_DEPTH.

Consolidate all three into a single rv_clone_iterative call, which
already handles AV/HV referent dispatch, blessing preservation, and
weakref propagation. This removes ~12 lines of duplicated code and
fixes the weakref loss bug.

Add tests verifying weakref preservation on deeply nested structures
past MAX_DEPTH.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@atoomic atoomic marked this pull request as ready for review April 25, 2026 11:56
@atoomic atoomic merged commit b828252 into garu:master Apr 25, 2026
28 checks passed
@Koan-Bot Koan-Bot deleted the koan.atoomic/refactor-max-depth-rv-consolidation branch April 25, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants