fix(llvm): Phase 131-7 - Multi-pass vmap sync 修正(Branch bug 解消)

Phase 131-7: Multi-pass block lowering の vmap sync バグ修正

問題:
- Pass A (body instructions) が vmap_cur に値を保存
- Pass C (deferred terminators) が builder.vmap を参照
- → Pass A の値が Pass C に届かない
- → Branch condition が 0 に fallback → 無限ループ

修正:
- src/llvm_py/builders/block_lower.py (lines 237-248):
  - PHI-only フィルタを削除
  - 全ての値を global vmap に sync

変更ファイル:
- src/llvm_py/builders/block_lower.py: vmap sync 修正
- src/llvm_py/instructions/controlflow/branch.py: trace logging 追加
- src/llvm_py/instructions/unop.py: trace logging 追加
- src/llvm_py/llvm_builder.py: debug helpers 追加
- src/llvm_py/phi_wiring/wiring.py: trace logging 追加
- src/runner/modes/common_util/exec.rs: Python stdout 転送

結果:
-  Branch bug 修正: ループが正しく終了
-  出力: 無限ループ → 3回で停止
-  新 bug 発見: ExternCall が null を受け取る(PHI 値の代わりに)

Next: Phase 131-8 (ExternCall argument handling 修正)

🤖 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 07:38:21 +09:00
parent 35db1f8d78
commit 22753f8cc3
6 changed files with 122 additions and 7 deletions

View File

@ -189,17 +189,25 @@ def wire_incomings(builder, block_id: int, dst_vid: int, incoming: List[Tuple[in
vs = int(v_src)
except Exception:
continue
trace({"phi": "wire_process", "dst": int(dst_vid), "decl_b": bd, "v_src": vs, "init_src_vid": init_src_vid})
pred_match = nearest_pred_on_path(succs, preds_list, bd, block_id)
trace({"phi": "wire_pred_match", "decl_b": bd, "pred_match": pred_match})
if pred_match is None:
trace({"phi": "wire_skip_no_path", "decl_b": bd, "target": int(block_id), "src": vs})
continue
original_vs = vs
if vs == int(dst_vid) and init_src_vid is not None:
trace({"phi": "wire_self_carry", "dst": int(dst_vid), "vs": vs, "init_src_vid": init_src_vid})
vs = int(init_src_vid)
if original_vs != vs:
trace({"phi": "wire_replaced_src", "original": original_vs, "replaced": vs})
try:
val = builder.resolver._value_at_end_i64(
vs, pred_match, builder.preds, builder.block_end_values, builder.vmap, builder.bb_map
)
except Exception:
trace({"phi": "wire_resolved", "vs": vs, "pred": pred_match, "val_type": type(val).__name__})
except Exception as e:
trace({"phi": "wire_resolve_fail", "vs": vs, "pred": pred_match, "error": str(e)})
val = None
# Normalize to a well-typed LLVM value (i64)
if val is None: