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

@ -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