docs(joinir): Phase 218 JsonParser if-sum investigation complete

Completes Phase 218 investigation: Identifies root cause preventing
AST-based if-sum lowerer from activating.

## Investigation Summary

### Test Case Created
- File: apps/tests/phase218_json_if_sum_min.hako
- Pattern: JsonParser-style conditional accumulation (sum = sum + i)
- Expected: RC=10, Actual: RC=0 (blocked by phantom carrier)

### Root Cause Identified: Phantom Carrier Bug

**Problem**: AST-based if-sum lowerer (Phase 213) never activates

**Cause Chain**:
1. loop_update_summary.rs uses name-based heuristics
2. Detects phantom "count" variable (doesn't exist in code)
3. counter_count() returns 2 instead of 1 (i + phantom "count")
4. is_simple_if_sum_pattern() returns false
5. Dual-mode dispatch uses legacy fallback instead of AST lowerer

**Evidence**:
```
Debug output shows hardcoded template "i % 2 == 1" (legacy lowerer)
Not from AST extraction (AST-based lowerer never called)
```

### Critical Discovery

**Phase 216 claim "RC=2 " for phase212_if_sum_min.hako is false**
- Current execution: RC=0 (wrong)
- Expected: RC=2
- Indicates: Phase 213-217 "success" was actually legacy lowerer

### Documentation Gap

Phase 216/217 tests may not have been executed correctly, or regression
occurred. All "if-sum" patterns are currently broken due to phantom
carrier detection blocking AST lowerer activation.

## Files Created

1. apps/tests/phase218_json_if_sum_min.hako - Test case
2. docs/development/current/main/phase218-jsonparser-if-sum-min.md - Investigation report

## Files Updated

1. CURRENT_TASK.md - Phase 218 investigation results
2. joinir-architecture-overview.md - Phase 218 entry

## Next Steps: Phase 219

**Target**: Fix phantom carrier detection in loop_update_summary.rs
**Fix**: Remove name-based heuristics, use assignment-based detection only
**Expected Result**: Both phase212 and phase218 tests pass with correct RC

## Lessons Learned

1. Documentation can become stale - verify test results
2. Silent fallbacks hide bugs - dual-mode needs clear activation logging
3. Name heuristics are fragile - prefer structural analysis

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-10 02:07:28 +09:00
parent 803a603e69
commit 980965afc8
4 changed files with 329 additions and 0 deletions

View File

@ -0,0 +1,48 @@
// Phase 218: JsonParser-style if-sum pattern test (SIMPLIFIED)
// Tests: Loop with conditional accumulation using variable-based sum (JsonParser pattern)
// Target: selfhost JsonParser pattern (e.g., sum = sum + digit when digit > 0)
//
// Pattern:
// Simulate digits: 0, 1, 3, 0, 5
// Skip zero digits (i=0, i=3)
// Accumulate valid digits: sum = sum + digit
// Final sum: 0 + 1 + 3 + 5 = 9
//
// Expected result: 9 (sum of valid digits)
static box JsonIfSumTest {
sum_digits(data) {
local sum
sum = 0
local i
i = 0
local len
len = 5
loop(i < len) {
// Simulate digit extraction: [0, 1, 3, 0, 5]
// This is simpler than nested-if version
// For now, just use i itself as digit (JsonParser would do actual string parsing)
// JsonParser pattern: if digit > 0 { sum = sum + digit }
if i > 0 {
// Conditional update: sum = sum + i (simulating: sum = sum + digit)
sum = sum + i
print(sum) // Force if to stay in MIR
} else {
print(0) // Ensure else branch exists
}
i = i + 1
}
return sum
}
main() {
// Test: sum = 1 + 2 + 3 + 4 = 10
local result
result = JsonIfSumTest.sum_digits(0) // dummy arg
return result
}
}