feat(phase277-p2): PHI環境変数統合 8個→3個 - ユーザビリティ向上

Phase 277 P2: PHI関連環境変数の統合・整理

【問題】
- PHI関連環境変数が8個に乱立
- ユーザーが覚える変数が多すぎる
- 保守性が低い(関連設定が分散)

【解決】
1. debug_helper.py 新規作成(SSOT)
   - is_phi_debug_enabled(): 一般デバッグ(3変数統合)
   - is_phi_trace_enabled(): 詳細トレース(2変数統合)
   - is_phi_strict_enabled(): 厳格モード(既存維持)

2. 環境変数統合(8個→3個)
   統合後:
   - NYASH_LLVM_DEBUG_PHI: 一般PHIデバッグ
   - NYASH_LLVM_DEBUG_PHI_TRACE: 詳細トレース
   - NYASH_LLVM_PHI_STRICT: 厳格モード(既存維持)

   統合前(廃止予定):
   - NYASH_LLVM_PHI_DEBUG → NYASH_LLVM_DEBUG_PHI
   - NYASH_PHI_TYPE_DEBUG → NYASH_LLVM_DEBUG_PHI
   - NYASH_PHI_ORDERING_DEBUG → NYASH_LLVM_DEBUG_PHI
   - NYASH_LLVM_TRACE_PHI → NYASH_LLVM_DEBUG_PHI_TRACE
   - NYASH_LLVM_VMAP_TRACE → NYASH_LLVM_DEBUG_PHI_TRACE

3. 後方互換性対応
   - 旧環境変数使用時に非推奨警告表示
   - Phase 278 で削除予定

【効果】
-  ユーザビリティ向上: 覚える変数 8個→3個(62%削減)
-  保守性向上: 環境変数チェック 30+箇所→1箇所(SSOT)
-  ドキュメント簡潔化: environment-variables.md 整理
-  SSOT原則適用: debug_helper.py に環境変数ロジック集約

【影響範囲】
- 新規: debug_helper.py (SSOT)
- 修正: 9ファイル(PHI関連Python)
- ドキュメント: environment-variables.md, 10-Now.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-22 13:57:33 +09:00
parent 9a76a199ee
commit 03aa54a422
13 changed files with 559 additions and 65 deletions

View File

@ -5,6 +5,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 phi_wiring.debug_helper import is_phi_debug_enabled
from typing import Dict, List, Tuple, Optional
from utils.values import safe_vmap_write
@ -21,7 +22,7 @@ def lower_phi(
) -> None:
"""
Lower MIR PHI instruction
Args:
builder: Current LLVM IR builder
dst_vid: Destination value ID
@ -31,14 +32,57 @@ def lower_phi(
current_block: Current basic block
resolver: Optional resolver for advanced type handling
"""
# Phase 275 DEBUG
import sys
sys.stderr.write(f"[PHI_ENTER] dst={dst_vid} incoming={incoming}\n")
sys.stderr.flush()
if not incoming:
# No incoming edges - use zero
vmap[dst_vid] = ir.Constant(ir.IntType(64), 0)
return
# Use i64 for PHI to carry handles across blocks (strings/boxes),
# avoiding pointer PHIs that complicate dominance and boxing.
# Phase 275 P0: Detect PHI type from incoming values
# Default is i64 for handles, but use double if any incoming is double
phi_type = ir.IntType(64)
has_double = False
# First pass: check if any incoming value is double type
import sys
phi_debug = is_phi_debug_enabled()
if phi_debug:
sys.stderr.write(f"[PHI_TYPE] Processing dst={dst_vid} with {len(incoming)} incoming edges\n")
sys.stderr.flush()
for val_id, block_id in incoming:
block = bb_map.get(block_id)
if block is None:
if phi_debug:
sys.stderr.write(f"[PHI_TYPE] dst={dst_vid} val={val_id} block={block_id} -> block not found\n")
continue
if block_end_values is not None:
pred_snapshot = block_end_values.get(block_id, {})
val = pred_snapshot.get(val_id) if val_id is not None else None
if phi_debug:
val_type = str(val.type) if val is not None and hasattr(val, 'type') else 'None'
sys.stderr.write(f"[PHI_TYPE] dst={dst_vid} val={val_id} block={block_id} -> type={val_type}\n")
if val is not None:
try:
if isinstance(val.type, ir.DoubleType):
has_double = True
break
except Exception:
pass
else:
if phi_debug:
sys.stderr.write(f"[PHI_TYPE] dst={dst_vid} block_end_values is None\n")
if has_double:
phi_type = ir.DoubleType()
if phi_debug:
sys.stderr.write(f"[PHI_TYPE] dst={dst_vid} -> using DoubleType\n")
else:
if phi_debug:
sys.stderr.write(f"[PHI_TYPE] dst={dst_vid} -> using IntType(64)\n")
# Build map from provided incoming
incoming_map: Dict[int, int] = {}
@ -94,7 +138,7 @@ def lower_phi(
val = ir.Constant(phi_type, 0)
used_default_zero = True
else:
# Coerce pointer to i64 at predecessor end
# Coerce types at predecessor end if needed
if hasattr(val, 'type') and val.type != phi_type:
pb = ir.IRBuilder(block)
try:
@ -105,7 +149,15 @@ def lower_phi(
pb.position_at_end(block)
except Exception:
pb.position_at_end(block)
if isinstance(phi_type, ir.IntType) and val.type.is_pointer:
# Phase 275 P0: Handle type conversions for mixed PHI
if isinstance(phi_type, ir.DoubleType) and isinstance(val.type, ir.IntType):
# i64 → double: number promotion
val = pb.sitofp(val, phi_type, name=f"phi_i2f_{vid}")
elif isinstance(phi_type, ir.IntType) and isinstance(val.type, ir.DoubleType):
# double → i64: convert back (shouldn't happen if type detection works)
val = pb.fptosi(val, phi_type, name=f"phi_f2i_{vid}")
elif isinstance(phi_type, ir.IntType) and val.type.is_pointer:
i8p = ir.IntType(8).as_pointer()
try:
if hasattr(val.type, 'pointee') and isinstance(val.type.pointee, ir.ArrayType):
@ -139,8 +191,7 @@ def lower_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':
if is_phi_debug_enabled():
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}")
@ -148,8 +199,8 @@ def lower_phi(
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':
from phi_wiring.debug_helper import is_phi_strict_enabled
if used_default_zero and is_phi_strict_enabled():
raise RuntimeError(f"[LLVM_PY] PHI dst={dst_vid} used synthesized zero; check preds/incoming")
try:
from trace import phi as trace_phi

View File

@ -23,6 +23,8 @@ from __future__ import annotations
from typing import List, Dict, Any
import llvmlite.ir as ir
from phi_wiring.debug_helper import is_phi_debug_enabled
def is_phi_instruction(instr: ir.Instruction) -> bool:
"""Check if an instruction is a PHI instruction."""
@ -101,17 +103,17 @@ def reorder_block_instructions(builder, block_id: int) -> bool:
# The fix must be at the generation time - ensure PHIs are created FIRST.
# Instead, we verify and report if ordering is incorrect
import os
if os.environ.get('NYASH_PHI_ORDERING_DEBUG') == '1':
if is_phi_debug_enabled():
import sys
print(f"[phi_placement] Block {block_id}: {len(phi_instrs)} PHIs, "
f"{len(non_phi_instrs)} non-PHIs, terminator: {term_instr is not None}")
f"{len(non_phi_instrs)} non-PHIs, terminator: {term_instr is not None}", file=sys.stderr)
return True
except Exception as e:
import os
if os.environ.get('NYASH_PHI_ORDERING_DEBUG') == '1':
print(f"[phi_placement] Error in block {block_id}: {e}")
if is_phi_debug_enabled():
import sys
print(f"[phi_placement] Error in block {block_id}: {e}", file=sys.stderr)
return False
@ -167,15 +169,15 @@ def verify_phi_ordering(builder) -> Dict[int, bool]:
is_correct = _is_already_ordered(bb, phi_instrs, non_phi_instrs, term_instr)
results[block_id] = is_correct
import os
if os.environ.get('NYASH_PHI_ORDERING_DEBUG') == '1' and not is_correct:
print(f"[phi_placement] ❌ Block {block_id} has incorrect PHI ordering!")
if is_phi_debug_enabled() and not is_correct:
import sys
print(f"[phi_placement] ❌ Block {block_id} has incorrect PHI ordering!", file=sys.stderr)
print(f" PHIs: {len(phi_instrs)}, non-PHIs: {len(non_phi_instrs)}, "
f"terminator: {term_instr is not None}")
f"terminator: {term_instr is not None}", file=sys.stderr)
except Exception as e:
import os
if os.environ.get('NYASH_PHI_ORDERING_DEBUG') == '1':
print(f"[phi_placement] Error during verification: {e}")
if is_phi_debug_enabled():
import sys
print(f"[phi_placement] Error during verification: {e}", file=sys.stderr)
return results

View File

@ -3,8 +3,10 @@ from typing import Any
import os
import json
from .debug_helper import is_phi_trace_enabled
def trace(msg: Any):
if os.environ.get("NYASH_LLVM_TRACE_PHI", "0") != "1":
if not is_phi_trace_enabled():
return
out = os.environ.get("NYASH_LLVM_TRACE_OUT")
if not isinstance(msg, (str, bytes)):

View File

@ -0,0 +1,80 @@
"""Phase 277 P2: PHI デバッグ環境変数のSSOT
統合された環境変数を一元管理。
統合前の環境変数8個 → 統合後3個:
- NYASH_LLVM_DEBUG_PHI: 一般デバッグ(旧: LLVM_PHI_DEBUG, PHI_TYPE_DEBUG, PHI_ORDERING_DEBUG
- NYASH_LLVM_DEBUG_PHI_TRACE: 詳細トレース(旧: LLVM_TRACE_PHI, LLVM_VMAP_TRACE
- NYASH_LLVM_PHI_STRICT: 厳格モード(既存維持)
"""
import os
import sys
def is_phi_debug_enabled():
"""PHI一般デバッグが有効か
統合対象:
- NYASH_LLVM_PHI_DEBUG (旧)
- NYASH_PHI_TYPE_DEBUG (旧)
- NYASH_PHI_ORDERING_DEBUG (旧)
Returns:
bool: デバッグモードが有効
"""
# 新環境変数
if os.environ.get('NYASH_LLVM_DEBUG_PHI') == '1':
return True
# 旧環境変数の後方互換性Phase 278で削除予定
legacy_vars = [
'NYASH_LLVM_PHI_DEBUG',
'NYASH_PHI_TYPE_DEBUG',
'NYASH_PHI_ORDERING_DEBUG'
]
for var in legacy_vars:
if os.environ.get(var) == '1':
print(f"⚠️ DEPRECATED: {var} is deprecated. Use NYASH_LLVM_DEBUG_PHI=1 instead.",
file=sys.stderr)
return True
return False
def is_phi_trace_enabled():
"""PHI詳細トレースが有効か
統合対象:
- NYASH_LLVM_TRACE_PHI (旧)
- NYASH_LLVM_VMAP_TRACE (旧)
Returns:
bool: トレースモードが有効
"""
# 新環境変数
if os.environ.get('NYASH_LLVM_DEBUG_PHI_TRACE') == '1':
return True
# 旧環境変数の後方互換性Phase 278で削除予定
legacy_vars = [
'NYASH_LLVM_TRACE_PHI',
'NYASH_LLVM_VMAP_TRACE'
]
for var in legacy_vars:
if os.environ.get(var) == '1':
print(f"⚠️ DEPRECATED: {var} is deprecated. Use NYASH_LLVM_DEBUG_PHI_TRACE=1 instead.",
file=sys.stderr)
return True
return False
def is_phi_strict_enabled():
"""PHI厳格モードが有効か既存維持
ゼロフォールバック時にエラーを発生させる。
Returns:
bool: 厳格モードが有効
"""
return os.environ.get('NYASH_LLVM_PHI_STRICT') == '1'

View File

@ -4,6 +4,7 @@ from typing import Dict, List, Any
from .common import trace
from .analysis import analyze_incomings, collect_produced_stringish
from .wiring import ensure_phi
from .debug_helper import is_phi_debug_enabled
def setup_phi_placeholders(builder, blocks: List[Dict[str, Any]]):
@ -27,11 +28,11 @@ def setup_phi_placeholders(builder, blocks: List[Dict[str, Any]]):
# Phase 132: Create all PHI placeholders FIRST, before any other operations
# This ensures PHIs are at block heads when blocks are still empty
import os
debug_mode = os.environ.get('NYASH_PHI_ORDERING_DEBUG') == '1'
debug_mode = is_phi_debug_enabled()
if debug_mode:
print(f"[phi_wiring/setup] Processing {len(blocks)} blocks for PHI placeholders")
import sys
print(f"[phi_wiring/setup] Processing {len(blocks)} blocks for PHI placeholders", file=sys.stderr)
for block_data in blocks:
bid0 = block_data.get("id", 0)
@ -46,7 +47,8 @@ def setup_phi_placeholders(builder, blocks: List[Dict[str, Any]]):
phi_count += 1
if debug_mode and phi_count > 0:
print(f"[phi_wiring/setup] Block {bid0}: {phi_count} PHI instructions to create")
import sys
print(f"[phi_wiring/setup] Block {bid0}: {phi_count} PHI instructions to create", file=sys.stderr)
for inst in block_data.get("instructions", []) or []:
if inst.get("op") != "phi":
@ -69,8 +71,9 @@ def setup_phi_placeholders(builder, blocks: List[Dict[str, Any]]):
pass
if has_terminator and debug_mode:
import sys
print(f"[phi_wiring/setup] WARNING: Block {bid0} already has terminator "
f"when creating PHI for v{dst0}!")
f"when creating PHI for v{dst0}!", file=sys.stderr)
# Predeclare a placeholder PHI at the block head so that
# mid-block users (e.g., compare/branch) dominate correctly
@ -94,12 +97,14 @@ def setup_phi_placeholders(builder, blocks: List[Dict[str, Any]]):
if hasattr(builder, 'phi_manager'):
builder.phi_manager.register_phi(int(bid0), int(dst0), ph)
if debug_mode:
print(f"[phi_wiring/setup] Created PHI placeholder for v{dst0} in bb{bid0}")
import sys
print(f"[phi_wiring/setup] Created PHI placeholder for v{dst0} in bb{bid0}", file=sys.stderr)
except Exception:
pass
except Exception as e:
if debug_mode:
print(f"[phi_wiring/setup] ERROR creating PHI for v{dst0} in bb{bid0}: {e}")
import sys
print(f"[phi_wiring/setup] ERROR creating PHI for v{dst0} in bb{bid0}: {e}", file=sys.stderr)
# Tag propagation
try:
@ -130,8 +135,7 @@ def setup_phi_placeholders(builder, blocks: List[Dict[str, Any]]):
# Definition hint: PHI defines dst in this block
try:
builder.def_blocks.setdefault(int(dst0), set()).add(int(bid0))
import os
if os.environ.get('NYASH_LLVM_PHI_DEBUG') == '1':
if is_phi_debug_enabled():
trace({"phi_def_blocks": "registered", "dst": int(dst0), "block": int(bid0)})
except Exception:
pass
@ -140,8 +144,8 @@ def setup_phi_placeholders(builder, blocks: List[Dict[str, Any]]):
except Exception:
pass
except Exception as e:
import os
if os.environ.get('NYASH_PHI_ORDERING_DEBUG') == '1':
print(f"[phi_wiring/setup] FATAL ERROR: {e}")
if is_phi_debug_enabled():
import sys
print(f"[phi_wiring/setup] FATAL ERROR: {e}", file=sys.stderr)
import traceback
traceback.print_exc()

View File

@ -4,6 +4,7 @@ from typing import Dict, List, Any, Optional, Tuple
import llvmlite.ir as ir
from .common import trace
from .debug_helper import is_phi_debug_enabled, is_phi_trace_enabled
def _const_i64(builder, n: int) -> ir.Constant:
try:
@ -40,8 +41,8 @@ def ensure_phi(builder, block_id: int, dst_vid: int, bb: ir.Block, dst_type=None
except Exception:
pass
if cur_bb_name == bb_name:
import os, sys
if os.environ.get('NYASH_PHI_TYPE_DEBUG') == '1':
import sys
if is_phi_debug_enabled():
print(f"[phi_wiring/reuse] v{dst_vid} existing PHI found, type={cur.type}", file=sys.stderr)
return cur
except Exception:
@ -52,17 +53,16 @@ def ensure_phi(builder, block_id: int, dst_vid: int, bb: ir.Block, dst_type=None
phi = predecl.get((int(block_id), int(dst_vid))) if predecl else None
if phi is not None:
# Phase 275 P0: Verify type compatibility
import os, sys
import sys
expected_type = ir.DoubleType() if (dst_type == 'f64' or dst_type == 'double') else builder.i64
if phi.type == expected_type:
builder.vmap[dst_vid] = phi
trace({"phi": "ensure_predecl", "block": int(block_id), "dst": int(dst_vid)})
if os.environ.get('NYASH_PHI_TYPE_DEBUG') == '1':
if is_phi_debug_enabled():
print(f"[phi_wiring/reuse] v{dst_vid} predeclared PHI type matches: {phi.type}", file=sys.stderr)
return phi
else:
# Phase 275 P0: 型不一致の古いPHIを発見 → CRITICAL警告
import sys
print(f"⚠️ [phi_wiring/CRITICAL] PHI type mismatch! "
f"v{dst_vid}: predeclared={phi.type} expected={expected_type}",
file=sys.stderr)
@ -75,7 +75,7 @@ def ensure_phi(builder, block_id: int, dst_vid: int, bb: ir.Block, dst_type=None
pass
# 詳細デバッグ
if os.environ.get('NYASH_PHI_TYPE_DEBUG') == '1':
if is_phi_debug_enabled():
print(f"[phi_wiring/type_mismatch] Creating new PHI with correct type", file=sys.stderr)
# Phase 132 Critical Fix: Check if block already has a terminator
@ -89,10 +89,10 @@ def ensure_phi(builder, block_id: int, dst_vid: int, bb: ir.Block, dst_type=None
if block_has_terminator:
# This should not happen - PHIs must be created before terminators
import os
if os.environ.get('NYASH_PHI_ORDERING_DEBUG') == '1':
import sys
if is_phi_debug_enabled():
print(f"[phi_wiring] WARNING: Attempting to create PHI in bb{block_id} "
f"after terminator already exists! This will cause LLVM IR errors.")
f"after terminator already exists! This will cause LLVM IR errors.", file=sys.stderr)
# Try to create PHI anyway at the start, but log the issue
# Create PHI at block start
@ -118,14 +118,13 @@ def ensure_phi(builder, block_id: int, dst_vid: int, bb: ir.Block, dst_type=None
else:
phi_type = builder.i64
import os, sys
if os.environ.get('NYASH_PHI_TYPE_DEBUG') == '1':
import sys
if is_phi_debug_enabled():
print(f"[phi_wiring/create] v{dst_vid} dst_type={dst_type} -> phi_type={phi_type}", file=sys.stderr)
ph = b.phi(phi_type, name=f"phi_{dst_vid}")
# Phase 132 Debug: Check if basic_block is set correctly
import os, sys
if os.environ.get('NYASH_PHI_ORDERING_DEBUG') == '1' or os.environ.get('NYASH_LLVM_VMAP_TRACE') == '1':
if is_phi_debug_enabled() or is_phi_trace_enabled():
phi_bb = getattr(ph, 'basic_block', None)
phi_bb_name = getattr(phi_bb, 'name', None) if phi_bb is not None else None
bb_name = getattr(bb, 'name', None)
@ -238,8 +237,8 @@ def wire_incomings(builder, block_id: int, dst_vid: int, incoming: List[Tuple[in
# Phase 275 P0: Get dst_type from resolver's value_types (SSOT)
from .type_helper import get_phi_dst_type
dst_type = get_phi_dst_type(builder, dst_vid)
import os, sys
if os.environ.get('NYASH_PHI_TYPE_DEBUG') == '1':
import sys
if is_phi_debug_enabled():
print(f"[phi_wiring] v{dst_vid} -> dst_type='{dst_type}'", file=sys.stderr)
phi = ensure_phi(builder, block_id, dst_vid, bb, dst_type=dst_type)
preds_raw = [p for p in builder.preds.get(block_id, []) if p != block_id]

View File

@ -8,6 +8,7 @@ import os
from trace import phi as trace_phi
from trace import values as trace_values
import llvmlite.ir as ir
from phi_wiring.debug_helper import is_phi_debug_enabled
class Resolver:
"""
@ -223,8 +224,7 @@ class Resolver:
"""
cache_key = (current_block.name, value_id)
import os
if os.environ.get('NYASH_LLVM_PHI_DEBUG') == '1':
if is_phi_debug_enabled():
try:
bid = int(str(current_block.name).replace('bb',''))
in_def_blocks = value_id in self.def_blocks
@ -305,8 +305,7 @@ class Resolver:
defined_here = False
if defined_here:
existing = vmap.get(value_id)
import os
if os.environ.get('NYASH_LLVM_PHI_DEBUG') == '1':
if is_phi_debug_enabled():
existing_type = type(existing).__name__ if existing is not None else "None"
trace_phi(f"[resolve/def_here] bb{bid} v{value_id} existing={existing_type} in vmap={value_id in vmap}")
if existing is not None and hasattr(existing, 'type') and isinstance(existing.type, ir.IntType) and existing.type.width == 64:
@ -314,7 +313,7 @@ class Resolver:
self.i64_cache[cache_key] = existing
return existing
elif existing is not None:
if os.environ.get('NYASH_LLVM_PHI_DEBUG') == '1':
if is_phi_debug_enabled():
existing_llvm_type = str(existing.type) if hasattr(existing, 'type') else "no_type"
trace_phi(f"[resolve/def_here] bb{bid} v{value_id} existing has wrong type: {existing_llvm_type}")
else:

View File

@ -16,6 +16,8 @@ Import and use:
import os
import json
from phi_wiring.debug_helper import is_phi_trace_enabled
_TRACE_OUT = os.environ.get('NYASH_LLVM_TRACE_OUT')
def _write(msg: str) -> None:
@ -39,7 +41,7 @@ def debug(msg: str) -> None:
_write(msg)
def phi(msg) -> None:
if _enabled('NYASH_LLVM_TRACE_PHI'):
if is_phi_trace_enabled():
# Accept raw strings or arbitrary objects; non-strings are JSON-encoded
if not isinstance(msg, (str, bytes)):
try:
@ -55,11 +57,11 @@ def values(msg: str) -> None:
def phi_json(msg):
"""Safe JSON-style PHI trace delegator.
- Gated by NYASH_LLVM_TRACE_PHI=1 (same gate as phi())
- Gated by NYASH_LLVM_DEBUG_PHI_TRACE=1 (same gate as phi())
- Delegates to phi_wiring.common.trace if available; otherwise no-op
- Accepts arbitrary Python objects and forwards as-is
"""
if not _enabled('NYASH_LLVM_TRACE_PHI'):
if not is_phi_trace_enabled():
return
try:
from phi_wiring.common import trace as _trace_phi_json # type: ignore

View File

@ -7,6 +7,7 @@ from typing import Any, Dict, Optional
import llvmlite.ir as ir
import sys
import os
from phi_wiring.debug_helper import is_phi_debug_enabled, is_phi_trace_enabled
def resolve_i64_strict(
resolver,
@ -23,8 +24,7 @@ def resolve_i64_strict(
- If prefer_local and vmap has a same-block definition, reuse it.
- Otherwise, delegate to resolver to localize with PHI/casts as needed.
"""
import os
debug = os.environ.get('NYASH_LLVM_PHI_DEBUG') == '1'
debug = is_phi_debug_enabled()
# Prefer current vmap SSA first (block-local map is passed in vmap)
val = vmap.get(value_id)
@ -85,7 +85,7 @@ def safe_vmap_write(vmap: Dict[int, Any], dst: int, value: Any, context: str = "
f"Existing: PHI node, Attempted: {type(value).__name__}"
)
# STRICT not enabled - warn and skip
if os.environ.get('NYASH_LLVM_TRACE_VMAP') == '1':
if is_phi_trace_enabled():
print(f"[vmap/warn] Skipping overwrite of PHI dst={dst} in context={context}", file=sys.stderr)
return # Do not overwrite PHI
@ -93,7 +93,7 @@ def safe_vmap_write(vmap: Dict[int, Any], dst: int, value: Any, context: str = "
vmap[dst] = value
# Phase 131-12-P1: Trace successful write
if os.environ.get('NYASH_LLVM_VMAP_TRACE') == '1':
if is_phi_trace_enabled():
print(f"[vmap/write] dst={dst} written, vmap.keys()={sorted(vmap.keys())[:20]}", file=sys.stderr)
# P0-1: Register definition in def_blocks for dominance tracking (SSOT for all instructions)