## 概要 LLVM backend のCall処理、PHI wiring、Plugin loader を強化。 次のリファクタリング(箱化モジュール化)のための準備も含む。 ## 変更内容 ### LLVM Call処理強化 - `mir_call/__init__.py`: Call ルーティングロジック改善 - `mir_call/global_call.py`: print処理の marshal強化 - `mir_call/method_call.py`: メソッド呼び出し処理改善 - `boxcall.py`: BoxCall処理改善 ### PHI処理強化 - `phi_manager.py`: PHI管理改善 - `phi_wiring/wiring.py`: PHI配線ロジック強化(+17行) - `phi_wiring/tagging.py`: Type tagging改善 - `resolver.py`: Value解決ロジック強化(+34行) ### Copy伝播 - `copy.py`: Copy命令のType tag伝播追加(+10行) ### Plugin loader強化 - `library.rs`: エラー出力改善、[plugin/missing]ログ追加(+34行) - fail-fast強化 ### テスト - `phase97_json_loader_escape_llvm_exe.sh`: Phase 97 E2Eテスト追加 - `phase97_next_non_ws_llvm_exe.sh`: Phase 97 E2Eテスト追加 ### その他 - `nyash_kernel/lib.rs`: Kernel側の改善(+23行) ## 統計 - 14ファイル変更 - +256行 / -53行 = +203 net ## 次のリファクタリング準備 以下の箇所がリファクタリング対象として識別済み: 1. Call ルーティング箱の明文化 2. print の marshal 箱 3. TypeFacts/Tagging 箱の一本化 4. PHI Snapshot 契約のSSOT 5. Plugin loader のエラー出力統合 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""
|
|
Phase 132-Post: PHI Management Box
|
|
|
|
Box-First principle: Encapsulate PHI lifecycle management
|
|
- Track PHI ownership (which block created which PHI)
|
|
- Protect PHIs from overwrites (SSOT principle)
|
|
- Filter vmap to preserve PHI values
|
|
"""
|
|
|
|
class PhiManager:
|
|
"""PHI value lifecycle manager (Box pattern)"""
|
|
|
|
def __init__(self):
|
|
self.predeclared = {} # (bid, vid) -> phi_value
|
|
|
|
def register_phi(self, bid: int, vid: int, phi_value):
|
|
"""Register a PHI as owned by specific block"""
|
|
self.predeclared[(bid, vid)] = phi_value
|
|
|
|
def is_phi_owned(self, bid: int, vid: int) -> bool:
|
|
"""Check if PHI is owned by block"""
|
|
return (bid, vid) in self.predeclared
|
|
|
|
def filter_vmap_preserve_phis(self, vmap: dict, target_bid: int) -> dict:
|
|
"""Filter vmap while preserving owned PHIs
|
|
|
|
SSOT: PHIs in vmap are the single source of truth
|
|
Phase 132-P0: Also add PHIs from predeclared registry
|
|
"""
|
|
result = {}
|
|
for vid, val in vmap.items():
|
|
# PHIs are valid SSA values across dominated blocks; keep them in the per-block view.
|
|
result[vid] = val
|
|
|
|
# Phase 132-P0: Add PHIs from predeclared that aren't in vmap yet
|
|
for (bid, vid), phi_val in self.predeclared.items():
|
|
if bid == target_bid and vid not in result:
|
|
result[vid] = phi_val
|
|
|
|
return result
|
|
|
|
def sync_protect_phis(self, target_vmap: dict, source_vmap: dict):
|
|
"""Sync values but protect existing PHIs (Fail-Fast)
|
|
|
|
Never overwrite PHIs - they are SSOT
|
|
"""
|
|
for vid, val in source_vmap.items():
|
|
existing = target_vmap.get(vid)
|
|
if existing and hasattr(existing, 'add_incoming'):
|
|
continue # SSOT: Don't overwrite PHIs
|
|
target_vmap[vid] = val
|