docs(phase131): Case C 調査完了 - InfiniteEarlyExit パターン追加方針
## 根本原因解明 - loop(true) が Pattern4 に誤ルーティング - Pattern4 は BinaryOp 比較を期待、boolean literal で失敗 ## 解決方針 - 新パターン InfiniteEarlyExit 追加(Pattern 2 拡張ではなく) - classify() の優先度修正 - Shape guard で最小受理(break+continue 各1箇所) ## 作成ドキュメント - case-c-infinite-loop-analysis.md (13KB詳細分析) - phase131-11-case-c-summary.md (4KBサマリー) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -175,7 +175,7 @@ RC: 0
|
||||
|
||||
---
|
||||
|
||||
### 4. TAG-EMIT: JoinIR Pattern Mismatch (Case C)
|
||||
### 4. TAG-EMIT: JoinIR Pattern Coverage Gap (Case C) - ✅ ROOT CAUSE IDENTIFIED
|
||||
|
||||
**File**: `apps/tests/llvm_stage3_loop_only.hako`
|
||||
|
||||
@ -203,10 +203,36 @@ Function: main
|
||||
Hint: This loop pattern is not supported. All loops must use JoinIR lowering.
|
||||
```
|
||||
|
||||
**Diagnosis**:
|
||||
- `loop(true)` with `break`/`continue` doesn't match Pattern 1-4
|
||||
- LoopBuilder fallback was removed (Phase 33 cleanup)
|
||||
- JoinIR Pattern coverage gap: needs Pattern 5 or Pattern variant for infinite loops with early exit
|
||||
**Root Cause** (Phase 131-11 Analysis):
|
||||
1. **Pattern Gap**: `loop(true)` (infinite loop) not recognized by Patterns 1-4
|
||||
2. **Loop Variable Extraction Fails**: `extract_loop_variable_from_condition()` expects binary comparison (`i < 3`), not boolean literal (`true`)
|
||||
3. **Classification Priority Bug**: `has_continue = true` routes to Pattern 4, but Pattern 4 expects a loop variable
|
||||
|
||||
**Failure Flow**:
|
||||
```
|
||||
1. LoopPatternContext::new() detects has_continue=true, has_break=true
|
||||
2. classify() returns Pattern4Continue (because has_continue)
|
||||
3. Pattern4::can_lower() tries extract_loop_variable_from_condition(BoolLiteral(true))
|
||||
4. ❌ Fails: "Unsupported loop condition pattern"
|
||||
5. No pattern matches → freeze() error
|
||||
```
|
||||
|
||||
**Solution** (Phase 131-11 Recommended):
|
||||
- Add `is_infinite_loop: bool` feature to `LoopFeatures` (detect `loop(true)`).
|
||||
- Fix classification so `has_break && has_continue` does not route to Pattern 4.
|
||||
- Introduce a dedicated pattern kind + lowerer for **infinite loop + early-exit (+ optional continue)**:
|
||||
- Example name: `InfiniteEarlyExit` (avoid “Pattern5” naming collision with existing Trim/P5).
|
||||
- Scope (minimum): `loop(true)` with exactly one `break` site and one `continue` site (Fail-Fast outside this).
|
||||
|
||||
**Files to Modify**:
|
||||
1. `src/mir/loop_pattern_detection/mod.rs` - Add `is_infinite_loop` field, update classify()
|
||||
2. `src/mir/builder/control_flow/joinir/patterns/ast_feature_extractor.rs` - Detect `loop(true)` in condition
|
||||
3. `src/mir/builder/control_flow/joinir/patterns/router.rs` - Pass condition to extract_features()
|
||||
4. `src/mir/builder/control_flow/joinir/patterns/pattern2_with_break.rs` - Add infinite loop lowering path
|
||||
|
||||
**Docs (Phase 131-11)**:
|
||||
- Detailed analysis: `docs/development/current/main/case-c-infinite-loop-analysis.md`
|
||||
- Implementation summary: `docs/development/current/main/phase131-11-case-c-summary.md`
|
||||
|
||||
**Location**: `src/mir/builder/control_flow/joinir/router.rs` - pattern matching logic
|
||||
|
||||
|
||||
Reference in New Issue
Block a user