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:
nyash-codex
2025-12-14 21:28:41 +09:00
parent 413504d6de
commit 7dfd6ff1d9
21 changed files with 1391 additions and 133 deletions

View File

@ -6,6 +6,7 @@ Critical for SSA form - handles value merging from different control flow paths
import llvmlite.ir as ir
from phi_wiring import phi_at_block_head
from typing import Dict, List, Tuple, Optional
from utils.values import safe_vmap_write
def lower_phi(
builder: ir.IRBuilder,
@ -131,6 +132,18 @@ def lower_phi(
# Store PHI result
vmap[dst_vid] = phi
# Register PHI definition in def_blocks (critical for resolver dominance tracking)
if resolver is not None and hasattr(resolver, 'def_blocks') and cur_bid is not None:
resolver.def_blocks.setdefault(dst_vid, set()).add(cur_bid)
import os
if os.environ.get('NYASH_LLVM_PHI_DEBUG') == '1':
try:
from trace import phi as trace_phi_debug
trace_phi_debug(f"[PHI_DEBUG] Registered dst_vid={dst_vid} in def_blocks for block={cur_bid}")
except Exception:
pass
# Strict mode: fail fast on synthesized zeros (indicates incomplete incoming or dominance issue)
import os
if used_default_zero and os.environ.get('NYASH_LLVM_PHI_STRICT') == '1':