refactor(phi): Phase 57 PHI code reduction

## Changes

### 57-2-alt: Remove redundant ConservativeMerge call
- phi.rs called ConservativeMerge::analyze twice (once directly,
  once via merge_all_vars)
- Now merge_all_vars returns changed_vars, eliminating redundancy

### 57-3: Delete PhiMergeOps trait (dead code, 17 lines)
- PhiMergeOps trait was defined but never called
- Only impl in loop_builder.rs was unused
- PhiBuilderOps has replaced it

### 57-4: Add responsibility comments to infer_type_from_phi
- Document that it's the "last resort" for type inference
- Specify deletion conditions (JoinIR type annotations)

## Cumulative PHI reduction
- Phase 38: 90 lines
- Phase 40-4.1: 35 lines
- Phase 41-1: 99 lines
- Phase 47: 33 lines
- Phase 57: 17 lines (PhiMergeOps) + optimization
- Total: 365+ lines removed

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-29 09:04:42 +09:00
parent d6ce661923
commit 50bb58f2a1
4 changed files with 63 additions and 57 deletions

View File

@ -36,10 +36,16 @@
* - **置換**: conservative.rs::ConservativeMerge::analyze 内にインライン化
* - **理由**: callsite 1箇所のみ、if_phi.rs責務縮小
*
* ## ✅ Phase 57で削除済みデッドコード、17行
*
* - `PhiMergeOps` trait (17行) → **削除完了 2025-11-29**
* - **理由**: 完全にデッドコードtrait定義あるがメソッド呼び出しゼロ
* - **置換**: PhiBuilderOps に統一済み
*
* ## 現在の状態
*
* - **if_phi.rs**: 321行 → 288Phase 47後、33行削減)
* - **累計削減**: 348Phase 38: 90行, Phase 40-4.1: 35行, Phase 41-1: 99行, Phase 47: 33行+ conservative 48行
* - **if_phi.rs**: 288行 → 271Phase 57後、17行削減)
* - **累計削減**: 365Phase 38: 90行, Phase 40-4.1: 35行, Phase 41-1: 99行, Phase 47: 33行, Phase 57: 17行+ conservative 48行
*
* ## 参照ドキュメント
*
@ -55,6 +61,28 @@ use std::collections::BTreeMap; // Phase 25.1: 決定性確保
/// Infer return type by scanning for a Phi that defines `ret_val` and
/// verifying that all incoming values have the same type in `types`.
///
/// # Phase 57 責務明示(削除予定だが現時点では保持)
///
/// ## 責務
///
/// 型情報が Unknown のブランチを最低限救う「最後の砦」。
/// PHI 命令の incoming values から統一された型を推論する。
///
/// ## 使用箇所
///
/// - `lifecycle.rs:281, 296` - 関数の return 型推論
///
/// ## 将来の削除条件
///
/// JoinIR 側に型情報(`Option<MirType>`)を持たせた後、
/// この関数は不要になる。現時点では lifecycle.rs が依存しているため保持。
///
/// ## 削除時の移行先
///
/// - JoinIR の型アノテーション(未実装)
/// - または MIR Builder の型伝播強化
///
pub fn infer_type_from_phi(
function: &MirFunction,
ret_val: ValueId,
@ -230,23 +258,23 @@ fn extract_vars_from_json_stmt(
// - ロジックをconservative.rs内にインライン化完了
// - if_phi.rsの責務縮小JoinIR移行準備
/// Operations required for emitting a PHI or direct binding at a merge point.
pub trait PhiMergeOps {
fn new_value(&mut self) -> ValueId;
fn emit_phi_at_block_start(
&mut self,
block: crate::mir::BasicBlockId,
dst: ValueId,
inputs: Vec<(crate::mir::BasicBlockId, ValueId)>,
) -> Result<(), String>;
fn update_var(&mut self, name: String, value: ValueId);
fn debug_verify_phi_inputs(
&mut self,
_merge_bb: crate::mir::BasicBlockId,
_inputs: &[(crate::mir::BasicBlockId, ValueId)],
) {
}
}
// ========================================
// Phase 57: PhiMergeOps trait 削除2025-11-29
// ========================================
// 削除日: 2025-11-29
// 削除行数: 17行
// 理由: 完全にデッドコード
// - trait定義はあったが、どのメソッドも呼ばれていない
// - 唯一のimplloop_builder.rsもメソッドが使われていなかった
// - PhiBuilderOps に統一され、PhiMergeOps は不要に
//
// 旧定義:
// pub trait PhiMergeOps {
// fn new_value(&mut self) -> ValueId;
// fn emit_phi_at_block_start(...);
// fn update_var(...);
// fn debug_verify_phi_inputs(...);
// }
// ========================================
// Phase 41-1削除済み2025-11-29