refactor(joinir): Phase 185 code cleanup - extract shared function, remove dead code

- Extract infer_type_from_mir_pattern() to common.rs (was duplicated in if_select.rs & if_merge.rs)
- Remove unused JOINIR_HEADER_BYPASS_TARGETS and is_joinir_header_bypass_target() from loopform_builder.rs
- Warnings reduced: 13 → 11

Lines removed: ~45 (duplicate function + dead code)

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-04 22:33:56 +09:00
parent 6561832545
commit c2f524bb26
4 changed files with 42 additions and 67 deletions

View File

@ -252,3 +252,39 @@ where
handwritten(module)
}
}
// ============================================================================
// Phase 185: Type inference utilities (shared by if_select / if_merge)
// ============================================================================
use crate::mir::{MirFunction, MirType, ValueId};
/// Phase 185: MIR から ValueId の型を推論(共通化)
///
/// Const 命令を探して、ValueId に対応する MirType を返す。
/// Select/IfMerge の then_val / else_val から型ヒントを埋めるために使用。
///
/// # Usage
/// - `if_select.rs`: Select の型ヒント埋め込み
/// - `if_merge.rs`: IfMerge の型ヒント埋め込み
pub fn infer_type_from_mir_pattern(func: &MirFunction, val_id: ValueId) -> Option<MirType> {
// 全ブロックの全命令を走査して Const 命令を探す
for block in func.blocks.values() {
for inst in &block.instructions {
if let MirInstruction::Const { dst, value } = inst {
if *dst == val_id {
return Some(match value {
ConstValue::Integer(_) => MirType::Integer,
ConstValue::Bool(_) => MirType::Bool,
ConstValue::String(_) => MirType::String,
ConstValue::Void => MirType::Void,
ConstValue::Null => MirType::Unknown, // Null は Unknown として扱う
// Float は現状未サポート
_ => return None,
});
}
}
}
}
None
}

View File

@ -276,33 +276,8 @@ impl IfMergeLowerer {
}
}
/// Phase 64-2: MIR から ValueId の型を推論
///
/// Const 命令を探して、ValueId に対応する MirType を返す。
/// IfMerge の then_val / else_val から型ヒントを埋めるために使用。
fn infer_type_from_mir_pattern(func: &MirFunction, val_id: ValueId) -> Option<MirType> {
use crate::mir::{ConstValue, MirInstruction, MirType};
// 全ブロックの全命令を走査して Const 命令を探す
for block in func.blocks.values() {
for inst in &block.instructions {
if let MirInstruction::Const { dst, value } = inst {
if *dst == val_id {
return Some(match value {
ConstValue::Integer(_) => MirType::Integer,
ConstValue::Bool(_) => MirType::Bool,
ConstValue::String(_) => MirType::String,
ConstValue::Void => MirType::Void,
ConstValue::Null => MirType::Unknown, // Null は Unknown として扱う
// Float は現状未サポート
_ => return None,
});
}
}
}
}
None
}
// Phase 185: infer_type_from_mir_pattern() moved to common.rs
use super::common::infer_type_from_mir_pattern;
#[cfg(test)]
mod tests {

View File

@ -372,28 +372,5 @@ impl IfSelectLowerer {
}
}
/// Phase 63-2: MIR から ValueId の型を推論
///
/// Const 命令を探して、ValueId に対応する MirType を返す。
/// Select の then_val / else_val から型ヒントを埋めるために使用。
fn infer_type_from_mir_pattern(func: &MirFunction, val_id: ValueId) -> Option<MirType> {
// 全ブロックの全命令を走査して Const 命令を探す
for block in func.blocks.values() {
for inst in &block.instructions {
if let MirInstruction::Const { dst, value } = inst {
if *dst == val_id {
return Some(match value {
ConstValue::Integer(_) => MirType::Integer,
ConstValue::Bool(_) => MirType::Bool,
ConstValue::String(_) => MirType::String,
ConstValue::Void => MirType::Void,
ConstValue::Null => MirType::Unknown, // Null は Unknown として扱う
// Float は現状未サポート
_ => return None,
});
}
}
}
}
None
}
// Phase 185: infer_type_from_mir_pattern() moved to common.rs
use super::common::infer_type_from_mir_pattern;

View File

@ -27,21 +27,8 @@ pub(crate) fn is_loopform_debug_enabled() -> bool {
// Phase 30 F-2.1: JoinIR バイパスフラグheader_phi_builder から移動)
// ============================================================================
/// Phase 27.4C Cleanup: JoinIR Header φ バイパス対象関数リスト
///
/// Phase 27.4-C のスコープは以下の 2 関数のみ:
/// - `Main.skip/1` (minimal_ssa_skip_ws.hako)
/// - `FuncScannerBox.trim/1` (funcscanner_trim_min.hako)
///
/// **重要**: 他の関数では Header φ を絶対にスキップしないこと。
const JOINIR_HEADER_BYPASS_TARGETS: &[&str] = &["Main.skip/1", "FuncScannerBox.trim/1"];
/// Phase 27.4-C: JoinIR Header φ バイパス対象関数かチェック
///
/// `JOINIR_HEADER_BYPASS_TARGETS` に含まれる関数のみ true を返す。
pub(crate) fn is_joinir_header_bypass_target(fn_name: &str) -> bool {
JOINIR_HEADER_BYPASS_TARGETS.contains(&fn_name)
}
// Phase 185: JOINIR_HEADER_BYPASS_TARGETS and is_joinir_header_bypass_target() removed
// (Unused legacy code from Phase 27.4-C, superseded by JOINIR_TARGETS in targets.rs)
/// Phase 27.4-C Refactor: JoinIR Loop φ バイパスフラグ統合
///