feat(phi): Phase 26-E-3 - PhiBuilderOps委譲実装(has-a設計)
Phase 26-E Phase 3 完了: ChatGPT+Claude 合意による委譲設計実装 **設計合意 (ChatGPT + Claude consensus):** - PhiBuilderOps = 低レベル「PHI命令発行」道具箱 - LoopFormOps = 高レベル「ループ構造構築」作業場 - 関係: has-a(委譲) ではなく is-a(継承) - LoopBuilder は両方のインターフェースを個別実装で提供 **実装内容:** 1. LoopFormOps trait 設計コメント更新 - 継承ではなく委譲の設計rationale明記 - 段階的統合方針: If側→Loop側→将来統合 2. LoopBuilder に PhiBuilderOps 委譲実装 (64行) - 委譲パターン: LoopFormOps 既存実装を再利用 - HashSet → Vec 変換 + ソート(決定性保証) - emit_phi: block 引数差を吸収(current_block 設定) - 自己呼び出し回避: <Self as LoopFormOps>::method 明示 **技術的成果:** - 重複コードゼロ: 既存 LoopFormOps 実装に完全委譲 - 決定性保証: pred_vec.sort_by_key(|bb| bb.0) で決定的順序 - シグネチャ差分吸収: PhiBuilderOps/LoopFormOps の違いを吸収 - 破壊的変更なし: 既存コード保護 **委譲実装の利点:** 1. 抽象化レベル分離: 低レベル(PHI発行)と高レベル(ループ構築) 2. 既存コード保護: LoopFormOps 実装は変更なし 3. 段階的統合: If側から先に PhiBuilderOps 安定化 4. テスト容易性: PhiBuilderOps/LoopFormOps それぞれでテスト可能 **関連ファイル:** - src/mir/phi_core/loopform_builder.rs (設計コメント更新) - src/mir/loop_builder.rs (PhiBuilderOps委譲実装, +64行) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -695,6 +695,23 @@ impl LoopFormBuilder {
|
||||
/// This trait abstracts the underlying MIR builder operations,
|
||||
/// allowing LoopFormBuilder to work with both Rust MIR builder
|
||||
/// and selfhost compiler's JSON-based approach.
|
||||
/// Phase 26-E-3: LoopFormOps と PhiBuilderOps の関係(委譲設計)
|
||||
///
|
||||
/// **Design Rationale (ChatGPT + Claude consensus, 2025-11-22):**
|
||||
/// - PhiBuilderOps = 低レベル「PHI命令発行」道具箱
|
||||
/// - LoopFormOps = 高レベル「ループ構造構築」作業場
|
||||
/// - 関係: **has-a(委譲)** ではなく is-a(継承)
|
||||
///
|
||||
/// **実装方針:**
|
||||
/// - LoopFormOps trait: そのまま(継承なし)
|
||||
/// - PhiBuilderOps 実装: 必要な型に個別実装
|
||||
/// - `impl<'a> PhiBuilderOps for LoopBuilder<'a>` で委譲
|
||||
/// - HashSet → Vec 変換 + ソートで決定性保証
|
||||
///
|
||||
/// **段階的統合:**
|
||||
/// 1. If側: PhiBuilderBox 経由(既に完了)
|
||||
/// 2. Loop側: LoopFormOps + ExitPhiBuilder/HeaderPhiBuilder(現状維持)
|
||||
/// 3. 将来: 必要に応じて LoopBuilder に PhiBuilderOps 実装追加
|
||||
pub trait LoopFormOps {
|
||||
/// Allocate a new ValueId
|
||||
fn new_value(&mut self) -> ValueId;
|
||||
|
||||
Reference in New Issue
Block a user