feat(joinir): Phase 63-4 infer_type_from_phi degradation design
Phase 63-4: infer_type_from_phi を『JoinIR 型ヒント優先+従来ロジックフォールバック』に縮退する仕様を設計(実装は Phase 63-5+)
## Changes
### Documentation Updates
- **README.md**: Added complete Phase 63-4 design (63-4.1 through 63-4.5)
- 63-4.1: Current state analysis (definition location, callsites, role, JoinIR preparation)
- 63-4.2: Degradation spec (type_hint priority + fallback pattern)
- 63-4.3: Representative cases and A/B testing strategy (P1/P2/P3)
- 63-4.4: Deletion conditions (5 conditions, current: 2/5 = 40%)
- 63-4.5: Phase 63-5 handoff (infer_type_from_phi_with_hint() implementation tasks)
- **PHI_BOX_INVENTORY.md**: Updated if_phi.rs entry with Phase 63-4 deletion plan
- Added: "Phase 63-4完了: infer_type_from_phi の JoinIR type_hint 優先への縮退案を設計(実装は Phase 63-5+)"
- **CURRENT_TASK.md**: Added Phase 63-4 section with summary of design work
## Design Highlights
### Degradation Pattern
```rust
pub fn infer_type_from_phi_with_hint(
function: &MirFunction,
ret_val: ValueId,
types: &BTreeMap<ValueId, MirType>,
type_hint: Option<MirType>,
) -> Option<MirType> {
if let Some(hint) = type_hint {
return Some(hint); // Route B: JoinIR priority (SSOT)
}
infer_type_from_phi(function, ret_val, types) // Route A: Fallback
}
```
### Representative Cases
- **P1**: IfSelectTest.simple/local (Phase 63-5 target)
- **P2**: read_quoted_from (Phase 63-6+ target)
- **P3**: MethodCall/Box constructors (Phase 64+ expansion)
### Deletion Conditions (2/5 achieved)
1. ✅ JoinIR has type_hint field (Phase 63-3)
2. ✅ Type hints populated for representative cases (Phase 63-2)
3. ⏳ Degraded to type_hint priority (Phase 63-5)
4. ⏳ P1 cases determined by type_hint only (Phase 63-5)
5. ⏳ All functions use type hints (Phase 64+)
## Files Changed
- 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-5: Implement degradation for P1 cases (IfSelectTest.simple/local)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -202,6 +202,7 @@ impl IfMergeLowerer {
|
||||
dst,
|
||||
then_val,
|
||||
else_val,
|
||||
type_hint: None, // Phase 63-3: 現時点では型ヒントなし
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,8 @@
|
||||
|
||||
use crate::mir::join_ir::JoinInst;
|
||||
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
|
||||
// Phase 63-2: Type hint inference from MIR
|
||||
use crate::mir::{ConstValue, MirType};
|
||||
|
||||
// Phase 61-1: If-in-loop context support
|
||||
use super::if_phi_context::IfPhiContext;
|
||||
@ -118,11 +120,16 @@ impl IfSelectLowerer {
|
||||
// Select 命令を生成
|
||||
let dst = pattern.dst.unwrap_or(pattern.then_val);
|
||||
|
||||
// Phase 63-2: MIR の Const 命令から型ヒントを推論
|
||||
let type_hint = infer_type_from_mir_pattern(func, pattern.then_val)
|
||||
.or_else(|| infer_type_from_mir_pattern(func, pattern.else_val));
|
||||
|
||||
Some(JoinInst::Select {
|
||||
dst,
|
||||
cond: pattern.cond,
|
||||
then_val: pattern.then_val,
|
||||
else_val: pattern.else_val,
|
||||
type_hint, // Phase 63-2: Const 命令から推論した型(Integer/Bool/String など)
|
||||
})
|
||||
}
|
||||
|
||||
@ -364,3 +371,29 @@ 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user