feat(joinir): Phase 223-3 - LoopBodyCondPromoter implementation
Implements LoopBodyLocal condition promotion for Pattern4/continue patterns.
Previously, loops with LoopBodyLocal in conditions would Fail-Fast.
Now, safe Trim/skip_whitespace patterns (Category A-3) are promoted and lowering continues.
## Implementation
- **LoopBodyCondPromoter Box** (loop_body_cond_promoter.rs)
- extract_continue_condition(): Extract if-condition from continue branches
- try_promote_for_condition(): Thin wrapper delegating to LoopBodyCarrierPromoter
- ConditionPromotionRequest/Result API for Pattern2/4 integration
- **Pattern4 Integration** (pattern4_with_continue.rs)
- Analyze both header condition + continue condition
- On promotion success: merge carrier_info → continue lowering
- On promotion failure: Fail-Fast with clear error message
- **Unit Tests** (5 tests, all PASS)
- test_cond_promoter_skip_whitespace_pattern
- test_cond_promoter_break_condition
- test_cond_promoter_non_substring_pattern
- test_cond_promoter_no_scope_shape
- test_cond_promoter_no_body_locals
- **E2E Test** (phase223_p4_skip_whitespace_min.hako)
- Category A-3 pattern: local ch = s.substring(...); if ch == " " { continue }
- Verifies promotion succeeds and Pattern4 lowering proceeds
## Documentation
- joinir-architecture-overview.md: Updated LoopBodyCondPromoter section (Phase 223-3 完了)
- CURRENT_TASK.md: Added Phase 223-3 completion summary
- PHASE_223_SUMMARY.md: Phase overview and status tracking
- phase223-loopbodylocal-condition-*.md: Design docs and inventory
## Achievement
- **Before**: LoopBodyLocal in condition → Fail-Fast
- **Now**: Trim/skip_whitespace patterns promoted → Pattern4 lowering continues
- **Remaining**: Phase 172+ JoinIR Trim lowering for complete RC correctness
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -308,6 +308,27 @@ Local Region (1000+):
|
||||
- Phase 174 で `_parse_string` 最小化版(終端クォート検出)でも動作確認済み。
|
||||
- → 空白文字以外の文字比較ループにも対応可能(TrimLoopHelper の汎用性実証)。
|
||||
|
||||
- **LoopBodyCondPromoter(Phase 223-3 実装完了)**
|
||||
- ファイル: `src/mir/loop_pattern_detection/loop_body_cond_promoter.rs`
|
||||
- 責務:
|
||||
- ループ条件(header/break/continue)に出てくる LoopBodyLocal を carrier に昇格する統一 API。
|
||||
- P0(Category A-3: _skip_whitespace): 単一変数の Trim パターンのみ対応。
|
||||
- Pattern 2/Pattern 4 両対応の薄いコーディネーター箱(detection は LoopBodyCarrierPromoter に委譲)。
|
||||
- Phase 223-3 実装内容:
|
||||
- `extract_continue_condition()`: body 内の if 文から continue 条件を抽出。
|
||||
- `try_promote_for_condition()`: LoopBodyCarrierPromoter を使った昇格処理。
|
||||
- Pattern4 への統合完了: LoopBodyLocal 条件の昇格成功時に lowering を続行(以前は Fail-Fast)。
|
||||
- 設計原則:
|
||||
- **Thin coordinator**: LoopBodyCarrierPromoter に promotion ロジックを委譲し、metadata のみ返す。
|
||||
- **Pattern-agnostic**: Pattern2 (break) / Pattern4 (continue) の統一入口として機能。
|
||||
- **Fail-Fast**: 複雑パターン(Category B: 多段 if / method chain)は引き続き reject。
|
||||
- 入出力:
|
||||
- 入力: `ConditionPromotionRequest`(loop_param_name, cond_scope, break_cond/continue_cond, loop_body)
|
||||
- 出力: `ConditionPromotionResult::Promoted { carrier_info, promoted_var, carrier_name }` または `CannotPromote { reason, vars }`
|
||||
- 使用元(Phase 223-3 実装時):
|
||||
- Pattern4: promotion-first(昇格試行 → 成功なら CarrierInfo merge → 失敗なら Fail-Fast)
|
||||
- Pattern2: 既存 TrimLoopLowerer 経由で間接利用(将来的に統一可能)
|
||||
|
||||
- **ContinueBranchNormalizer / LoopUpdateAnalyzer**
|
||||
- ファイル:
|
||||
- `src/mir/join_ir/lowering/continue_branch_normalizer.rs`
|
||||
|
||||
Reference in New Issue
Block a user