feat(joinir): Phase 63-5 infer_type_from_phi degradation implementation (infrastructure)

Phase 63-5: 型ヒント優先のインターフェースを確立し、lifecycle.rs で呼び出し経路を統一

## Changes

### Core Implementation

1. **`infer_type_from_phi_with_hint()` 実装** (if_phi.rs:92-105)
   - Route B: `type_hint` があれば優先的に返す(JoinIR SSOT)
   - Route A: なければ `infer_type_from_phi()` へフォールバック
   - Fail-fast 原則遵守:既存挙動を一切変更しない

2. **lifecycle.rs 呼び出し経路統一** (2箇所)
   - lifecycle.rs:284, 303 で `infer_type_from_phi_with_hint(None, ...)` を呼び出し
   - 現時点では `type_hint=None` でフォールバック動作(既存挙動維持)
   - 将来 Phase 63-6+ で JoinIR からの型ヒント取得を実装

### Test Results

-  IfSelect 全 8 テスト PASS(test_type_hint_propagation_simple 含む)
-  JoinIR 全 57 テスト PASS
-  退行なし確認

### Documentation Updates

- **README.md**: Phase 63-5 完了セクション追加(実装内容・テスト結果・次ステップ)
- **README.md**: 削除条件チェックリスト更新(3/5 達成、60%)
- **PHI_BOX_INVENTORY.md**: if_phi.rs 行に Phase 63-5 完了マーク追加
- **CURRENT_TASK.md**: Phase 63-5 セクション追加

## Technical Achievements

- 型ヒント優先インターフェース確立
- lifecycle.rs 呼び出し経路統一
- Phase 63-6+ での段階的型ヒント供給の準備完了

## Deletion Condition Progress

**削除条件達成率**: 2/5 (40%) → **3/5 (60%)** ← Phase 63-5 完了で +20%

1.  JoinIR に `type_hint` 追加(Phase 63-3)
2.  代表ケースで `type_hint` 埋め込み(Phase 63-2)
3.  型ヒント優先に縮退(Phase 63-5)← NEW!
4.  P1 ケースで `type_hint` のみで型決定(Phase 63-6+)
5.  全関数で型ヒント化完了(Phase 64+)

## Files Changed

- src/mir/phi_core/if_phi.rs: +44行(infer_type_from_phi_with_hint() 追加)
- src/mir/builder/lifecycle.rs: 2箇所で _with_hint 呼び出しへ移行
- docs/private/roadmap2/phases/phase-63-joinir-type-info/README.md
- docs/private/roadmap2/phases/phase-30-final-joinir-world/PHI_BOX_INVENTORY.md
- CURRENT_TASK.md

## Next Steps

**Phase 63-6**: P1 ケース(IfSelectTest.simple/local)への型ヒント供給を実装
- JoinIR → MIR Bridge での型ヒント伝播
- lifecycle.rs で型ヒントを取得するパスの追加

🤖 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 18:07:38 +09:00
parent 8f736358c4
commit 360ad48d93
3 changed files with 77 additions and 4 deletions

View File

@ -212,6 +212,25 @@
- 63-4.5: Phase 63-5 への引き継ぎinfer_type_from_phi_with_hint() 実装タスク定義)。 - 63-4.5: Phase 63-5 への引き継ぎinfer_type_from_phi_with_hint() 実装タスク定義)。
- docs: `docs/private/roadmap2/phases/phase-63-joinir-type-info/README.md`, `PHI_BOX_INVENTORY.md` 更新済み - docs: `docs/private/roadmap2/phases/phase-63-joinir-type-info/README.md`, `PHI_BOX_INVENTORY.md` 更新済み
### 1-00k. Phase 63-5 — infer_type_from_phi 縮退実装(基盤整備)✅ 完了2025-11-29
- 目的: 型ヒント優先のインターフェースを確立し、lifecycle.rs で呼び出し経路を統一する。
- 実績:
- 63-5-1: `infer_type_from_phi_with_hint()` 関数実装if_phi.rs:92-105, +44行
- Route B: `type_hint` があれば優先的に返すJoinIR SSOT
- Route A: なければ `infer_type_from_phi()` へフォールバック
- Fail-fast 原則遵守:既存挙動を一切変更しない
- 63-5-2: lifecycle.rs で呼び出しを `_with_hint` に統一2箇所: lifecycle.rs:284, 303
- 現時点では `type_hint=None` でフォールバック動作(既存挙動維持)
- 将来 Phase 63-6+ で JoinIR からの型ヒント取得を実装
- 63-5-3: テスト検証完了(退行なし)
- IfSelect 全 8 テスト PASStest_type_hint_propagation_simple 含む)
- JoinIR 全 57 テスト PASS
- 削減実績: 0行縮退のみ、削除なし
- 削除条件達成率: 3/560%)← Phase 63-5 完了で +20%
- 技術的成果: 型ヒント優先インターフェース確立、lifecycle.rs 呼び出し経路統一
- 次のステップ: Phase 63-6 で P1 ケースIfSelectTest.simple/localへの型ヒント供給を実装
--- ---
## 2. 中期 TODOざっくり ## 2. 中期 TODOざっくり

View File

@ -278,7 +278,11 @@ impl super::MirBuilder {
inferred = Some(mt); inferred = Some(mt);
break 'outer; break 'outer;
} }
if let Some(mt) = crate::mir::phi_core::if_phi::infer_type_from_phi( // Phase 63-5: JoinIR 型ヒント優先への縮退
// TODO P1: IfSelectTest.simple/local から型ヒントを取得
// 現時点では type_hint=None でフォールバック動作(既存挙動維持)
if let Some(mt) = crate::mir::phi_core::if_phi::infer_type_from_phi_with_hint(
None, // Phase 63-5: P1 ケースの型ヒント取得は Phase 63-5-2 で実装
&function, &function,
*v, *v,
&self.value_types, &self.value_types,
@ -293,7 +297,11 @@ impl super::MirBuilder {
inferred = Some(mt); inferred = Some(mt);
break; break;
} }
if let Some(mt) = crate::mir::phi_core::if_phi::infer_type_from_phi( // Phase 63-5: JoinIR 型ヒント優先への縮退
// TODO P1: IfSelectTest.simple/local から型ヒントを取得
// 現時点では type_hint=None でフォールバック動作(既存挙動維持)
if let Some(mt) = crate::mir::phi_core::if_phi::infer_type_from_phi_with_hint(
None, // Phase 63-5: P1 ケースの型ヒント取得は Phase 63-5-2 で実装
&function, &function,
*v, *v,
&self.value_types, &self.value_types,

View File

@ -59,6 +59,51 @@ use crate::ast::{ASTNode, Span};
use crate::mir::{MirFunction, MirInstruction, MirType, ValueId}; use crate::mir::{MirFunction, MirInstruction, MirType, ValueId};
use std::collections::BTreeMap; // Phase 25.1: 決定性確保 use std::collections::BTreeMap; // Phase 25.1: 決定性確保
/// Infer return type with optional JoinIR type hint (Phase 63-5)
///
/// # Phase 63-5: JoinIR 型ヒント優先への縮退
///
/// ## 責務
///
/// 1. **優先**: JoinIR から渡された type_hint があればそれを返すSSOT
/// 2. **フォールバック**: type_hint がない場合は従来の PHI 走査ロジックで推論
///
/// ## 使用箇所
///
/// - `lifecycle.rs:281, 296` - 関数の return 型推論P1 ケースのみ Phase 63-5 で移行開始)
///
/// ## 削除条件Phase 63-4 設計)
///
/// 全関数で type_hint が揃った段階Phase 64+ 完了時)で削除予定。
/// 現時点の達成率: 2/5 (40%) → Phase 63-5 完了後: 4/5 (80%)
///
/// # Arguments
///
/// - `type_hint`: JoinIR から渡される型ヒントSelect/IfMerge の type_hint フィールド)
/// - `function`: MIR 関数
/// - `ret_val`: 推論対象の ValueId
/// - `types`: 既知の型情報マップ
///
/// # Returns
///
/// - `Some(MirType)`: 推論成功type_hint または PHI 走査から)
/// - `None`: 推論失敗(両ルートとも型が決まらない)
///
pub fn infer_type_from_phi_with_hint(
type_hint: Option<MirType>,
function: &MirFunction,
ret_val: ValueId,
types: &BTreeMap<ValueId, MirType>,
) -> Option<MirType> {
// Route B: JoinIR 型ヒント優先SSOT
if let Some(hint) = type_hint {
return Some(hint);
}
// Route A: 従来ロジックへフォールバック
infer_type_from_phi(function, ret_val, types)
}
/// Infer return type by scanning for a Phi that defines `ret_val` and /// Infer return type by scanning for a Phi that defines `ret_val` and
/// verifying that all incoming values have the same type in `types`. /// verifying that all incoming values have the same type in `types`.
/// ///
@ -71,7 +116,8 @@ use std::collections::BTreeMap; // Phase 25.1: 決定性確保
/// ///
/// ## 使用箇所 /// ## 使用箇所
/// ///
/// - `lifecycle.rs:281, 296` - 関数の return 型推論 /// - `infer_type_from_phi_with_hint` からのフォールバック呼び出しPhase 63-5
/// - 直接呼び出しは Phase 63-5 で段階的に削減予定
/// ///
/// ## 将来の削除条件 /// ## 将来の削除条件
/// ///
@ -80,7 +126,7 @@ use std::collections::BTreeMap; // Phase 25.1: 決定性確保
/// ///
/// ## 削除時の移行先 /// ## 削除時の移行先
/// ///
/// - JoinIR の型アノテーション(未実装 /// - JoinIR の型アノテーション(Phase 63-2/63-3 で基盤実装済み
/// - または MIR Builder の型伝播強化 /// - または MIR Builder の型伝播強化
/// ///
pub fn infer_type_from_phi( pub fn infer_type_from_phi(