docs(plan): Phase 273 P4 - Plan Line SSOT Documentation Finalization
Phase 273 P4 では、Plan ライン(Extractor → Normalizer → Verifier → Lowerer)を "current operational SSOT" として文書化し、アーキテクチャの収束を明文化した。 ## Changes ### router.rs docstring 更新 - "Phase 273 P3: Plan Line is Current SSOT for Pattern6/7" セクション追加 - ルーティング戦略を明示(Plan entry points → legacy table) - SSOT Entry Points を列挙(Pattern6/7 Normalizer, Pattern1-5 各 Lowerer) ### phase-273/README.md 更新 - P3 completion section 追加(generalized CoreLoopPlan 移行完了) - P3+ Legacy Removal section 追加(~174 lines 削除記録) - P4 Proposal section 追加(Documentation Finalization チェックリスト) - SSOT Documentation Entry Points リスト追加(5 つの SSOT 入口) ### joinir-architecture-overview.md 更新 - Section 2.1.2 "Plan-Based Patterns (Pattern6-7, Phase 273 P3)" 追加 - Plan Extractor, Normalizer, Verifier, Lowerer の Box 構造を文書化 - Plan line vs JoinIR line 比較表追加(収束性・SSOT 特性の対比) - SSOT characteristics リスト追加(Normalizer SSOT, emit_frag SSOT 等) ## SSOT Entry Points(Phase 273 P3 完了時点) 1. **ルーティング**: `router.rs::route_loop_pattern()` - Pattern6/7 Plan entry points 2. **型定義**: `plan/mod.rs` - DomainPlan/CorePlan 固定語彙 3. **正規化**: `plan/normalizer.rs` - Pattern 固有知識一元管理 4. **検証**: `plan/verifier.rs` - fail-fast 不変条件(V2-V9) 5. **降格**: `plan/lowerer.rs` - Pattern-agnostic MIR emission ## Test - ✅ VM regression: phase254_p0_index_of_vm.sh (PASS) - ✅ LLVM regression: phase258_p0_index_of_string_llvm_exe.sh (PASS) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -440,6 +440,90 @@ Local Region (1000..=LOCAL_MAX):
|
||||
- JoinIR → MIR 変換フロー統一化(JoinModule → MirModule → merge_joinir_mir_blocks)。
|
||||
- JoinIR/MIR の関数数・ブロック数をログ出力し、全パターンが同じ入口でマージする。
|
||||
|
||||
### 2.1.2 Plan-Based Patterns (Pattern6-7, Phase 273 P3)
|
||||
|
||||
**Phase 273 P3 Status**: SSOT for Pattern6/7 lowering
|
||||
|
||||
Pattern6/7 は **Plan line(Extractor → Normalizer → Verifier → Lowerer)** を使用する。これは Pattern1-5 の JoinIR 経路とは独立した、新しい SSOT アーキテクチャである。
|
||||
|
||||
- **Plan Extractor Box** (pure)
|
||||
- ファイル:
|
||||
- `src/mir/builder/control_flow/joinir/patterns/pattern6_scan_with_init.rs::extract_scan_with_init_plan()`
|
||||
- `src/mir/builder/control_flow/joinir/patterns/pattern7_split_scan.rs::extract_split_scan_plan()`
|
||||
- 責務:
|
||||
- Pattern 固有構造を抽出(builder アクセスなし)。
|
||||
- DomainPlan(pattern-specific)または None を返す。
|
||||
- Pure function(builder を触らない)。
|
||||
- 入力: AST(condition, body, post_loop_code)
|
||||
- 出力: `Result<Option<DomainPlan>, String>`
|
||||
- `Ok(Some(domain_plan))`: Pattern マッチ成功
|
||||
- `Ok(None)`: 不一致(次の pattern へフォールスルー)
|
||||
- `Err(...)`: close-but-unsupported(fail-fast)
|
||||
|
||||
- **PlanNormalizer Box** (SSOT for pattern knowledge)
|
||||
- ファイル: `src/mir/builder/control_flow/plan/normalizer.rs`
|
||||
- 責務:
|
||||
- DomainPlan(pattern-specific)→ CorePlan(fixed vocabulary)変換。
|
||||
- Pattern 固有知識の展開(SSOT):
|
||||
- ScanWithInit (Pattern6): スキャン方向、init block、body effects、step
|
||||
- SplitScan (Pattern7): Split セマンティクス、accumulator updates
|
||||
- 中間 ValueId 生成(Const/BinOp/Compare/MethodCall)。
|
||||
- CoreLoopPlan 構築(block_effects/phis/frag/final_values)。
|
||||
- 入力: `DomainPlan`, `MirBuilder`, `LoopPatternContext`
|
||||
- 出力: `CorePlan`
|
||||
|
||||
- **PlanVerifier Box** (fail-fast validation)
|
||||
- ファイル: `src/mir/builder/control_flow/plan/verifier.rs`
|
||||
- 責務:
|
||||
- CorePlan 不変条件検証(曖昧さなし)。
|
||||
- Phase gating(P0/P1/P2/P3 specific checks)。
|
||||
- 不正な Plan の早期検出。
|
||||
- 検証項目(V2-V9):
|
||||
- V2: Condition validity (valid ValueId)
|
||||
- V3: Exit validity (Return in function, Break/Continue in loop)
|
||||
- V4: Seq non-empty
|
||||
- V5: If completeness (then_plans non-empty)
|
||||
- V6: ValueId validity (all ValueIds pre-generated)
|
||||
- V7: PHI non-empty (loops require at least one carrier)
|
||||
- V8: Frag entry matches header_bb
|
||||
- V9: block_effects contains header_bb
|
||||
|
||||
- **PlanLowerer Box** (pattern-agnostic)
|
||||
- ファイル: `src/mir/builder/control_flow/plan/lowerer.rs`
|
||||
- 責務:
|
||||
- CorePlan のみを処理(DomainPlan 知識なし)。
|
||||
- Block 割り当て(preheader/header/body/step/after/found)。
|
||||
- PHI node 挿入(LoopHeaderPhiBuilder)。
|
||||
- Block emission(body_bb, step_bb)。
|
||||
- EdgeCFG Frag 構築(emit_frag() で terminator SSOT)。
|
||||
- variable_map 更新(final_values)。
|
||||
- 入力: `CorePlan`, `MirBuilder`, `LoopPatternContext`
|
||||
- 出力: `Result<Option<ValueId>, String>`
|
||||
|
||||
- **Routing in route_loop_pattern()**
|
||||
- 場所: `src/mir/builder/control_flow/joinir/patterns/router.rs::route_loop_pattern()` (lines 294-354)
|
||||
- Entry points(LOOP_PATTERNS table より前にチェック):
|
||||
1. Try Plan-based Pattern6 (extract_scan_with_init_plan)
|
||||
2. Try Plan-based Pattern7 (extract_split_scan_plan)
|
||||
3. Fall through to LOOP_PATTERNS table (Pattern1-5, 8-9)
|
||||
|
||||
**Plan line vs JoinIR line**:
|
||||
|
||||
| 項目 | Plan line (Pattern6/7) | JoinIR line (Pattern1-5) |
|
||||
|------|------------------------|-------------------------|
|
||||
| 入口 | Extractor (pure) | Pattern Lowerer (builder access) |
|
||||
| 中間表現 | DomainPlan → CorePlan | JoinModule (JoinIR) |
|
||||
| Pattern 知識 | Normalizer SSOT | Pattern Lowerer 各自 |
|
||||
| Terminator | emit_frag() SSOT | 各 Pattern 固有 emission |
|
||||
| Block/Value 生成 | Normalizer (pre-allocated) | Pattern Lowerer |
|
||||
| 収束性 | ✅ 完全収束(P3) | 🔄 段階的収束中 |
|
||||
|
||||
**SSOT 特性**:
|
||||
- Normalizer が Pattern 知識を一元管理(scan/split セマンティクス)
|
||||
- Lowerer は CorePlan のみを処理(pattern-agnostic)
|
||||
- emit_frag() が terminator 生成の唯一の入口(SSOT)
|
||||
- Pattern6/7 は JoinIR を経由せず直接 MIR へ
|
||||
|
||||
### 2.2 条件式ライン(式の箱)
|
||||
|
||||
- **BoolExprLowerer / condition_to_joinir**
|
||||
|
||||
@ -121,17 +121,75 @@ AOT ランタイム(nyrt)は `ny_main()` の返り値が **raw i64** か **h
|
||||
- P0 Claude Code: `docs/development/current/main/phases/phase-273/P0-CLAUDE.md`
|
||||
- P1 Claude Code: `docs/development/current/main/phases/phase-273/P1-CLAUDE.md`
|
||||
- P2 Completion: `docs/development/current/main/phases/phase-273/P2-COMPLETION.md`
|
||||
- P3 Claude Code: `docs/development/current/main/phases/phase-273/P3-CLAUDE.md`
|
||||
|
||||
## Next (P3 proposal)
|
||||
## P3 完了 (2025-12-23)
|
||||
|
||||
P2 で追加した “legacy fallback” を残したままだと、Lowerer の中に `emit_scan_with_init_edgecfg()` 等の旧経路が残り続ける。
|
||||
収束を完成させるには、次を P3 で行うのが良い:
|
||||
P3 では Pattern6 を generalized CoreLoopPlan に移行し、legacy fallback を撤去して Plan ラインの収束を完成させた。
|
||||
|
||||
- Pattern6 を generalized CoreLoopPlan(`frag/block_effects/phis/final_values`)に移行
|
||||
- `lower_loop_legacy()` を撤去し、generalized 経路を SSOT 化(Fail-Fast)
|
||||
- CoreLoopPlan の `Option<...>` フィールドを必須化(構造で “揺れ” を消す)
|
||||
- ✅ Pattern6: generalized CoreLoopPlan(`frag/block_effects/phis/final_values`)へ完全移行
|
||||
- ✅ CoreLoopPlan: すべてのフィールドを必須化(`Option` 削除)
|
||||
- ✅ Lowerer: `lower_loop_legacy()` 撤去、CorePlan SSOT 化(Fail-Fast)
|
||||
- ✅ PlanLowerer: Pattern 固有参照(`emit_scan_with_init_edgecfg()` 等)を完全削除
|
||||
- ✅ route_loop_pattern(): Plan ラインを明示的 SSOT として文書化
|
||||
|
||||
## Future Work (P2+)
|
||||
### SSOT Documentation Entry Points
|
||||
|
||||
P3 完了により、以下が Plan ライン SSOT の入口となった:
|
||||
|
||||
1. **ルーティング SSOT**: `src/mir/builder/control_flow/joinir/patterns/router.rs::route_loop_pattern()`
|
||||
- Pattern6/7 Plan-based entry points(lines 294-354)
|
||||
- Legacy patterns (1-5, 8-9) LOOP_PATTERNS table(lines 362-368)
|
||||
|
||||
2. **型定義 SSOT**: `src/mir/builder/control_flow/plan/mod.rs`
|
||||
- `DomainPlan { ScanWithInit, SplitScan, ... }`
|
||||
- `CorePlan { Seq, Loop, If, Effect, Exit }`
|
||||
- `CoreLoopPlan { block_effects, phis, frag, final_values }`
|
||||
|
||||
3. **正規化 SSOT**: `src/mir/builder/control_flow/plan/normalizer.rs`
|
||||
- Pattern 固有知識の一元管理(ScanWithInit/SplitScan normalization)
|
||||
|
||||
4. **検証 SSOT**: `src/mir/builder/control_flow/plan/verifier.rs`
|
||||
- fail-fast 不変条件チェック(V2-V9)
|
||||
|
||||
5. **降格 SSOT**: `src/mir/builder/control_flow/plan/lowerer.rs`
|
||||
- Pattern 知識なし、CorePlan のみ処理
|
||||
- emit_frag() で terminator SSOT
|
||||
|
||||
### P3+ Legacy Removal (2025-12-23)
|
||||
|
||||
P3 完了後、さらにレガシーコードを削除:
|
||||
|
||||
- ✅ `emit_scan_with_init_edgecfg()` 関数削除(~144 lines)
|
||||
- ✅ `CoreCarrierInfo` 構造体削除(~15 lines)
|
||||
- ✅ `verify_carrier()` 関数削除(~15 lines)
|
||||
- ✅ 未使用 import 削除(cargo fix、~30 files)
|
||||
|
||||
**Total lines removed**: ~174 lines (net reduction)
|
||||
|
||||
---
|
||||
|
||||
## P4 Proposal (Documentation Finalization)
|
||||
|
||||
P4 では、アーキテクチャドキュメントを Plan ラインで完全更新し、「現行 SSOT」を明確に標記する:
|
||||
|
||||
1. **router.rs docstring 更新** ✅
|
||||
- "Phase 273 P3: Plan Line is Current SSOT for Pattern6/7" 追加
|
||||
- ルーティング戦略を明示(Plan entry points → legacy table)
|
||||
- SSOT Entry Points を列挙
|
||||
|
||||
2. **joinir-architecture-overview.md 更新**
|
||||
- Section 2.1.2 追加(Plan-based patterns 専用セクション)
|
||||
- Section 0 の「target shape」を「current operational shape」に更新
|
||||
- routing order diagram を Plan entry points 込みで再描画
|
||||
|
||||
3. **Phase 273 README.md 更新** ✅
|
||||
- P3 completion section 追加
|
||||
- P4 proposal → "Documentation Finalization"
|
||||
|
||||
---
|
||||
|
||||
## Future Work (P5+)
|
||||
|
||||
1. **Pattern7/8/9 DomainPlan 追加**: Split, BoolPredicate 等を DomainPlan に追加
|
||||
2. **Normalizer 拡張**: 各 DomainPlan → CorePlan 変換
|
||||
|
||||
@ -278,13 +278,27 @@ pub(crate) static LOOP_PATTERNS: &[LoopPatternEntry] = &[
|
||||
/// - No redundant pattern detection in detect functions
|
||||
/// - All patterns use structure-based classification
|
||||
///
|
||||
/// # Phase 273 P1: DomainPlan → Normalizer → Verifier → Lowerer
|
||||
/// # Phase 273 P3: Plan Line is Current SSOT for Pattern6/7
|
||||
///
|
||||
/// Pattern6 uses the new two-layer Plan architecture:
|
||||
/// - extract_scan_with_init_plan() → DomainPlan (pure extraction)
|
||||
/// - PlanNormalizer::normalize() → CorePlan (pattern knowledge expansion)
|
||||
/// This function implements the following routing strategy:
|
||||
/// 1. Try Plan-based Pattern6 (extract_scan_with_init_plan) → DomainPlan
|
||||
/// 2. Try Plan-based Pattern7 (extract_split_scan_plan) → DomainPlan
|
||||
/// 3. Fall through to legacy Pattern1-5 table for other patterns
|
||||
///
|
||||
/// The Plan line (Extractor → Normalizer → Verifier → Lowerer) is the
|
||||
/// current operational SSOT for Pattern6/7. Legacy patterns (1-5) use
|
||||
/// the traditional LoopPatternContext-based routing.
|
||||
///
|
||||
/// Plan-based architecture (Phase 273 P1-P3):
|
||||
/// - extract_*_plan() → DomainPlan (pure extraction, no builder)
|
||||
/// - PlanNormalizer::normalize() → CorePlan (pattern knowledge expansion, SSOT)
|
||||
/// - PlanVerifier::verify() → fail-fast validation
|
||||
/// - PlanLowerer::lower() → MIR emission (pattern-agnostic)
|
||||
/// - PlanLowerer::lower() → MIR emission (pattern-agnostic, emit_frag SSOT)
|
||||
///
|
||||
/// SSOT Entry Points:
|
||||
/// - Pattern6: src/mir/builder/control_flow/plan/normalizer.rs (ScanWithInit normalization)
|
||||
/// - Pattern7: src/mir/builder/control_flow/plan/normalizer.rs (SplitScan normalization)
|
||||
/// - Pattern1-5: src/mir/builder/control_flow/joinir/patterns/pattern*.rs (direct lowering)
|
||||
pub(crate) fn route_loop_pattern(
|
||||
builder: &mut MirBuilder,
|
||||
ctx: &LoopPatternContext,
|
||||
|
||||
Reference in New Issue
Block a user