From b9496000f9fa1340494ce0b65a6004dbf4de7d48 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Tue, 2 Dec 2025 15:39:19 +0900 Subject: [PATCH] =?UTF-8?q?refactor(phase82):=20DRY=E5=8C=96=20-=20Case?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92?= =?UTF-8?q?=E3=83=98=E3=83=AB=E3=83=91=E3=83=BC=E9=96=A2=E6=95=B0=E3=81=AB?= =?UTF-8?q?=E7=B5=B1=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### リファクタ内容 - 2箇所の callsite で重複していた Case 判定ロジックを統一化 - classify_phi_fallback_case() ヘルパー関数を追加 ### 変更前(重複) - Callsite 1: L321-328 で Case 判定(9行) - Callsite 2: L378-385 で Case 判定(9行) - 完全に同一のロジックが重複 ### 変更後(DRY) - classify_phi_fallback_case() ヘルパー関数(14行) - 各 callsite は 1 行の呼び出しのみ ### メリット - ✅ DRY原則: ロジック重複削減 - ✅ 保守性: Case 分類変更が 1 箇所で完結 - ✅ テスト: ヘルパー関数単独でテスト可能 - ✅ 可読性: panic 処理が簡潔に ### 動作確認 - ビルド成功(warning のみ、既存のもの) - テスト結果: 482 PASS, 34 FAIL(既存の失敗のみ) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/mir/builder/lifecycle.rs | 39 +++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/mir/builder/lifecycle.rs b/src/mir/builder/lifecycle.rs index 43b5116d..863f34e1 100644 --- a/src/mir/builder/lifecycle.rs +++ b/src/mir/builder/lifecycle.rs @@ -42,6 +42,27 @@ use crate::mir::join_ir::lowering::type_hint_policy::TypeHintPolicy; // Phase 67: P3-C ジェネリック型推論箱 use crate::mir::join_ir::lowering::generic_type_resolver::GenericTypeResolver; +// Phase 82: dev ガード用ヘルパー - Case 分類ロジック統一化 +// +// infer_type_from_phi_with_hint() の 2 つの callsite で重複していた +// Case 判定ロジックを DRY 化。 +// +// Case 分類: +// - Case A: hint 付き(GenericTypeResolver 不要) +// - Case B: P1/P2/P3-A/B で hint 失敗(理論上不可) +// - Case D: P3-C で GenericTypeResolver 失敗(PHI 走査フォールバック) +// +// Note: dev フラグで制御されるので、#[cfg] は不要(環境変数で制御) +fn classify_phi_fallback_case(hint: Option<&MirType>, function_name: &str) -> &'static str { + if hint.is_some() { + "Case A (hint付き)" + } else if TypeHintPolicy::is_target(function_name) { + "Case B (P1/P2/P3-A/B hint失敗)" + } else { + "Case D (P3-C GenericTypeResolver失敗)" + } +} + impl super::MirBuilder { /// Unified declaration indexing (Phase A): collect symbols before lowering /// - user_defined_boxes: non-static Box names (for NewBox birth() skip) @@ -319,13 +340,8 @@ impl super::MirBuilder { } // Phase 82: dev ガード - if_phi フォールバック禁止モード if crate::config::env::phi_fallback_disabled() { - let case = if hint.is_some() { - "Case A (hint付き)" - } else if TypeHintPolicy::is_target(&function.signature.name) { - "Case B (P1/P2/P3-A/B hint失敗)" - } else { - "Case D (P3-C GenericTypeResolver失敗)" - }; + let case = + classify_phi_fallback_case(hint.as_ref(), &function.signature.name); panic!( "[phase82/phi_fallback] disabled but infer_type_from_phi called\n\ Function: {}\n\ @@ -376,13 +392,8 @@ impl super::MirBuilder { } // Phase 82: dev ガード - if_phi フォールバック禁止モード if crate::config::env::phi_fallback_disabled() { - let case = if hint.is_some() { - "Case A (hint付き)" - } else if TypeHintPolicy::is_target(&function.signature.name) { - "Case B (P1/P2/P3-A/B hint失敗)" - } else { - "Case D (P3-C GenericTypeResolver失敗)" - }; + let case = + classify_phi_fallback_case(hint.as_ref(), &function.signature.name); panic!( "[phase82/phi_fallback] disabled but infer_type_from_phi called\n\ Function: {}\n\