feat(llvm/phi): Phase 277 P1 - fail-fast validation for PHI strict mode
## Summary Implemented fail-fast validation for PHI ordering and value resolution in strict mode. ## Changes ### P1-1: Strict mode for "PHI after terminator" - File: `src/llvm_py/phi_wiring/wiring.py::ensure_phi` - Behavior: `NYASH_LLVM_PHI_STRICT=1` → RuntimeError if PHI created after terminator - Default: Warning only (no regression) ### P1-2: Strict mode for "fallback 0" - File: `src/llvm_py/phi_wiring/wiring.py::wire_incomings` - Behavior: Strict mode forbids silent fallback to 0 (2 locations) - Location 1: Unresolvable incoming value - Location 2: Type coercion failure - Error messages point to next debug file: `llvm_builder.py::_value_at_end_i64` ### P1-3: Connect verify_phi_ordering() to execution path - File: `src/llvm_py/builders/function_lower.py` - Behavior: Verify PHI ordering after all instructions emitted - Debug mode: Shows "✅ All N blocks have correct PHI ordering" - Strict mode: Raises RuntimeError with block list if violations found ## Testing ✅ Test 1: strict=OFF - passes without errors ✅ Test 2: strict=ON - passes without errors (no violations in test fixtures) ✅ Test 3: debug mode - verify_phi_ordering() connected and running ## Scope - LLVM harness (Python) changes only - No new environment variables (uses existing 3 from Phase 277 P2) - No JoinIR/Rust changes (root fix is Phase 279) - Default behavior unchanged (strict mode opt-in) ## Next Steps - Phase 278: Remove deprecated env var support - Phase 279: Root fix - unify "2本のコンパイラ" pipelines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -15,6 +15,72 @@
|
||||
|
||||
---
|
||||
|
||||
## 0.0 収束形(Target Shape / Convergence)
|
||||
|
||||
JoinIR/CFG 合成が「裾広がり」せずに収束していくための **目標形(target shape)** をここで固定する。
|
||||
通称: **Plan→Frag パイプライン**(会話・作業ログではこの短い呼び名を使う)。
|
||||
|
||||
狙いは「要素が増えても、本線が増えない」こと:
|
||||
- 増えてよい: extractor(検出)だけ
|
||||
- 増えてはいけない: block/value/PHI/terminator 生成の分岐点(= 生成本線の if/分岐増殖)
|
||||
|
||||
### 0.0.1 パイプライン(収束形)
|
||||
|
||||
```
|
||||
┌──────────────────────────────┐
|
||||
AST/Stmt → │ Plan Extractor Box (pure) │
|
||||
│ - patterns are just extractors
|
||||
│ - no block/value allocation
|
||||
│ - returns: Ok(None)/Ok(Plan)/Err
|
||||
└──────────────┬───────────────┘
|
||||
│
|
||||
v
|
||||
┌──────────────────────────────┐
|
||||
│ Plan Verifier Box (fail-fast)│
|
||||
│ - phase gating (P0/P1)
|
||||
│ - invariants (no ambiguity)
|
||||
└──────────────┬───────────────┘
|
||||
│
|
||||
v
|
||||
┌──────────────────────────────┐
|
||||
│ Plan Lowerer Box (only builder)│
|
||||
│ - alloc blocks/values/phi
|
||||
│ - builds Frag via small comb.
|
||||
│ - uses Expr/Scope boxes inside blocks
|
||||
└──────────────┬───────────────┘
|
||||
│
|
||||
v
|
||||
┌──────────────────────────────┐
|
||||
│ EdgeCFG Frag + emit_frag() │
|
||||
│ - terminator SSOT
|
||||
│ - succ/pred sync
|
||||
└──────────────┬───────────────┘
|
||||
│
|
||||
v
|
||||
Verify / DCE / CFG update / print
|
||||
(terminator operand only)
|
||||
```
|
||||
|
||||
### 0.0.2 「収束している」と呼ぶ条件(定義)
|
||||
|
||||
この定義を満たしている状態を、JoinIR/CFG 合成の「収束」と呼ぶ:
|
||||
|
||||
1) **pattern は Plan 抽出へ降格する**
|
||||
- pattern は「一致判定 + Plan を返す」だけ(builder を触らない)。
|
||||
|
||||
2) **CFG 生成(block/value/PHI)は PlanLowerer に一本化する**
|
||||
- `next_block_id()` / `next_value_id()` / PHI 挿入 / `emit_frag()` 呼び出しは PlanLowerer 側だけに置く。
|
||||
|
||||
3) **terminator 生成点は `emit_frag()` のみ(SSOT)**
|
||||
- Branch/Jump/Return を “別の場所で” 生成しない。
|
||||
|
||||
4) **増えても本線が増えない(成長境界)**
|
||||
- 新しい loop/if の形が増えても、増えるのは extractor(薄いファイル)だけ。
|
||||
- Plan の語彙と Lowerer/emit の本線は増殖しない(分岐増殖は設計上のバグとして扱う)。
|
||||
|
||||
参照(相談メモ / 背景):
|
||||
- `docs/development/current/main/investigations/phase-272-frag-plan-architecture-consult.md`
|
||||
|
||||
## 0. 読み方ガイド(Reader's Guide)
|
||||
|
||||
このファイルは情報量が多いので、「何を知りたいか」で読む場所を分けると楽だよ:
|
||||
|
||||
Reference in New Issue
Block a user