Commit Graph

3 Commits

Author SHA1 Message Date
d4f90976da refactor(joinir): Phase 244 - ConditionLoweringBox trait unification
Unify condition lowering logic across Pattern 2/4 with trait-based API.

New infrastructure:
- condition_lowering_box.rs: ConditionLoweringBox trait + ConditionContext (293 lines)
- ExprLowerer implements ConditionLoweringBox trait (+51 lines)

Pattern migrations:
- Pattern 2 (loop_with_break_minimal.rs): Use trait API
- Pattern 4 (loop_with_continue_minimal.rs): Use trait API

Benefits:
- Unified condition lowering interface
- Extensible for future lowering strategies
- Clean API boundary between patterns and lowering logic
- Zero code duplication

Test results: 911/911 PASS (+2 new tests)

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-11 02:35:31 +09:00
577b5b01d5 docs: Update Phase 212.5 completion status and add Phase 213 plan
Phase 212.5 完了を記録し、Phase 213 への継続を明記。

- phase212-5-implementation-complete.md: Phase 213 への継続を追記
- CURRENT_TASK.md: Phase 212.5 完了エントリ + Phase 213 計画を追加

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 23:37:18 +09:00
aeb6282c2d feat(joinir): Phase 212.5 Structural if detection for Pattern 3 routing
Phase 212.5 で発見した「ループ内 if が Pattern 1 に誤ルーティング」問題を修正。
構造ベース if 検出により、単一キャリアの if-update パターンも Pattern 3 へ正しくルーティング可能に。

## Changes

### 1. AST Feature Extractor (ast_feature_extractor.rs)
- **Added**: `detect_if_in_body()` function
  - Detects ANY if statement in loop body (not just if-else)
  - Enables structural if detection vs carrier-count heuristic
- **Modified**: `extract_features()`
  - Uses `detect_if_in_body()` for `has_if` detection
  - Removes dependency on carrier count for if detection

### 2. Loop Pattern Classification (loop_pattern_detection/mod.rs)
- **Modified**: `classify()` function
  - Pattern 3: `carrier_count > 1` → `has_if && carrier_count >= 1`
  - Pattern 1: `!has_if_else_phi` → `!has_if`
  - Now routes single-carrier if-update patterns to Pattern 3

## Verification

Test case: `apps/tests/phase212_if_sum_min.hako`

### Before (Phase 212):
-  Routed to Pattern 1 (wrong)
-  if statement disappeared in MIR
-  Carriers: only `i` (sum missing)

### After (Phase 212.5):
-  Routed to Pattern 3 (correct!)
-  MIR contains PHI nodes: `%31 = phi [%25, bb9], [%29, bb10]`
-  Carriers: `i`, `sum`, `count` detected

Pattern routing log:
```
[joinir/pattern3] Generated JoinIR for Loop with If-Else PHI
[joinir/pattern3] Carriers: i (counter), sum (accumulator), count (counter)
```

## Known Limitation

Pattern 3 lowerer (`lower_loop_with_if_phi_pattern`) is currently a
test-only hardcoded implementation:
- Loop condition: `i <= 5` (hardcoded)
- If condition: `i % 2 == 1` (hardcoded)
- Update logic: `sum + i` (hardcoded)

This is why `phase212_if_sum_min.hako` produces RC=0 instead of RC=2.
Pattern routing is complete; AST-based lowerer generalization is Phase 213.

## Documentation

- `docs/development/current/main/phase212-5-implementation-complete.md`
  - Complete implementation report with verification details

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-09 23:35:57 +09:00