Files
hakorune/docs/development/current/main
nyash-codex 803a603e69 feat(joinir): Phase 217 Multi-carrier if-sum complete (zero impl!)
Completes Phase 217: Validates Pattern 3 multi-carrier if-sum support
with **ZERO additional code** - Phase 195/214/215 boxes compose perfectly.

## The Surprise

Expected: Modify lowerers for multi-carrier support
Actual: Everything just works out-of-the-box! 🎉

## Test Results (All Passing)

### Primary Target
- phase217_if_sum_multi_min.hako: RC=2 
  - Carriers: sum + count (2 accumulators)
  - Loop: i=0..2, both increment when i>0
  - Returns sum=2

### Regression Tests
- loop_if_phi.hako (P3, 1 carrier): RC=2 
- phase212_if_sum_min.hako (P3, 1 carrier): RC=2 
- loop_min_while.hako (P1): RC=2 

## Why It Just Worked

Box composition from previous phases:

**Phase 195 (Multi-Carrier PHI Box)**:
- CarrierInfo tracks N carriers automatically
- Exit PHI generation handles arbitrary count
- ExitLineReconnector updates variable_map for all

**Phase 214 (Dynamic Inputs Box)**:
- Removed hardcoded 3-input assumption
- `join_inputs = (0..total_inputs).map(ValueId)`
- Auto-scales: 1 loop_var + N carriers = N+1 inputs

**Phase 215 (ExprResult Contract Box)**:
- Marks first carrier as expr_result
- Propagates through Boundary → ExitLine → Return
- Works regardless of carrier count

Result: Boxes A + B + C = Multi-carrier support (no glue code!)

## Architecture Verification

Dynamic scaling confirmed:
```rust
// Automatic for 2 carriers (sum, count)
total_inputs = 1 + 2 = 3
join_inputs = [ValueId(0), ValueId(1), ValueId(2)]
host_inputs = [loop_var_id, sum_binding, count_binding]
```

Exit PHI generation:
```
Loop Header:
  %i_phi = phi [0, entry], [%i_next, back]
  %sum_phi = phi [0, entry], [%sum_exit, back]    ← Carrier 1
  %count_phi = phi [0, entry], [%count_exit, back] ← Carrier 2
```

## Box Theory Validation

**「箱理論」の勝利!**

Well-designed boxes compose without modification:
- Each box has single responsibility
- Clear contracts between boxes
- No tight coupling
- New capabilities emerge from composition

Phase 217 proves this philosophy works in practice.

## Documentation

- Added: docs/development/current/main/phase217-if-sum-multi.md
- Added: apps/tests/phase217_if_sum_multi_min.hako (test case)
- Updated: CURRENT_TASK.md (Phase 217 complete status)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-10 01:53:06 +09:00
..