feat(llvm): Phase 131-11-H/12 - ループキャリアPHI型修正 & vmap snapshot SSOT
## Phase 131-11-H: ループキャリアPHI型修正 - PHI生成時に初期値(entry block)の型のみ使用 - backedge の値を型推論に使わない(循環依存回避) - NYASH_CARRIER_PHI_DEBUG=1 でトレース ## Phase 131-12-P0: def_blocks 登録 & STRICT エラー化 - safe_vmap_write() で PHI 上書き保護 - resolver miss を STRICT でエラー化(フォールバック 0 禁止) - def_blocks 自動登録 ## Phase 131-12-P1: vmap_cur スナップショット実装 - DeferredTerminator 構造体(block, term_ops, vmap_snapshot) - Pass A で vmap_cur をスナップショット - Pass C でスナップショット復元(try-finally) - STRICT モード assert ## 結果 - ✅ MIR PHI型: Integer(正しい) - ✅ VM: Result: 3 - ✅ vmap snapshot 機構: 動作確認 - ⚠️ LLVM: Result: 0(別のバグ、次Phase で調査) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
| A | `apps/tests/phase87_llvm_exe_min.hako` | ✅ | ✅ | ✅ | **PASS** - Simple return 42, no BoxCall, exit code verified |
|
||||
| B | `apps/tests/loop_min_while.hako` | ✅ | ✅ | ✅ | **PASS** - Loop/PHI path runs end-to-end (Phase 131-10): prints `0,1,2` and exits |
|
||||
| B2 | `/tmp/case_b_simple.hako` | ✅ | ✅ | ✅ | **PASS** - Simple print(42) without loop works |
|
||||
| C | `apps/tests/llvm_stage3_loop_only.hako` | ❌ | - | - | **TAG-EMIT** - Complex loop (break/continue) fails JoinIR pattern matching |
|
||||
| C | `apps/tests/llvm_stage3_loop_only.hako` | ✅ | ✅ | ⚠️ | **TAG-RUN** - Runs but result mismatch (VM ok / LLVM wrong) |
|
||||
|
||||
## Root Causes Identified
|
||||
|
||||
@ -175,7 +175,7 @@ RC: 0
|
||||
|
||||
---
|
||||
|
||||
### 4. TAG-EMIT: JoinIR Pattern Coverage Gap (Case C) - ✅ ROOT CAUSE IDENTIFIED
|
||||
### 4. Case C: loop(true) + break/continue - from TAG-EMIT to TAG-RUN
|
||||
|
||||
**File**: `apps/tests/llvm_stage3_loop_only.hako`
|
||||
|
||||
@ -195,29 +195,22 @@ static box Main {
|
||||
}
|
||||
```
|
||||
|
||||
**MIR Compilation**: FAILURE
|
||||
```
|
||||
❌ MIR compilation error: [joinir/freeze] Loop lowering failed:
|
||||
JoinIR does not support this pattern, and LoopBuilder has been removed.
|
||||
Function: main
|
||||
Hint: This loop pattern is not supported. All loops must use JoinIR lowering.
|
||||
```
|
||||
**MIR Compilation**: SUCCESS(Phase 131-11)
|
||||
|
||||
**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
|
||||
**What changed**:
|
||||
- Pattern gap was resolved by introducing a dedicated infinite-loop early-exit pattern (Phase 131-11 A–C).
|
||||
- A loop-carrier PHI type-cycle bug was fixed by seeding the PHI type from the entry(init) value (Phase 131-11 H).
|
||||
- Root cause report: `docs/development/current/main/phase-131-11-g-phi-type-bug-report.md`
|
||||
|
||||
**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
|
||||
```
|
||||
**Current issue**: **TAG-RUN (wrong result)**
|
||||
VM and MIR look correct, but LLVM output does not match expected result for Case C.
|
||||
|
||||
**Solution** (Phase 131-11 Recommended):
|
||||
**Next actions**:
|
||||
- Dump LLVM IR (`NYASH_LLVM_DUMP_IR=...`) and trace PHI/value resolution (`NYASH_LLVM_TRACE_PHI=1`, `NYASH_LLVM_TRACE_VALUES=1`).
|
||||
- Reduce Case C to isolate whether the bug is “loop value” or “string concat/print path”:
|
||||
- `return counter` (no string concat)
|
||||
- `print(counter)` (no `"Result: " + ...`)
|
||||
- Compare with VM and inspect the IR use-sites.
|
||||
- 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)**:
|
||||
|
||||
Reference in New Issue
Block a user