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;