diff --git a/CURRENT_TASK.md b/CURRENT_TASK.md index acaa6aff..6dce7f08 100644 --- a/CURRENT_TASK.md +++ b/CURRENT_TASK.md @@ -212,6 +212,25 @@ - 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` 更新済み +### 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 テスト PASS(test_type_hint_propagation_simple 含む) + - JoinIR 全 57 テスト PASS +- 削減実績: 0行(縮退のみ、削除なし) +- 削除条件達成率: 3/5(60%)← Phase 63-5 完了で +20% +- 技術的成果: 型ヒント優先インターフェース確立、lifecycle.rs 呼び出し経路統一 +- 次のステップ: Phase 63-6 で P1 ケース(IfSelectTest.simple/local)への型ヒント供給を実装 + --- ## 2. 中期 TODO(ざっくり) diff --git a/src/mir/builder/lifecycle.rs b/src/mir/builder/lifecycle.rs index ae2b99a1..bd36bf07 100644 --- a/src/mir/builder/lifecycle.rs +++ b/src/mir/builder/lifecycle.rs @@ -278,7 +278,11 @@ impl super::MirBuilder { inferred = Some(mt); 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, *v, &self.value_types, @@ -293,7 +297,11 @@ impl super::MirBuilder { inferred = Some(mt); 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, *v, &self.value_types, diff --git a/src/mir/phi_core/if_phi.rs b/src/mir/phi_core/if_phi.rs index ebc9a474..3be62398 100644 --- a/src/mir/phi_core/if_phi.rs +++ b/src/mir/phi_core/if_phi.rs @@ -59,6 +59,51 @@ use crate::ast::{ASTNode, Span}; use crate::mir::{MirFunction, MirInstruction, MirType, ValueId}; 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, + function: &MirFunction, + ret_val: ValueId, + types: &BTreeMap, +) -> Option { + // 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 /// 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 の型伝播強化 /// pub fn infer_type_from_phi(