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:
@ -145,6 +145,7 @@ mod tests {
|
||||
cond,
|
||||
then_val,
|
||||
else_val,
|
||||
..
|
||||
}) = result
|
||||
{
|
||||
eprintln!("✅ Simple pattern successfully lowered to Select");
|
||||
@ -171,6 +172,7 @@ mod tests {
|
||||
cond,
|
||||
then_val,
|
||||
else_val,
|
||||
..
|
||||
}) = result
|
||||
{
|
||||
eprintln!("✅ Local pattern successfully lowered to Select");
|
||||
@ -246,6 +248,7 @@ mod tests {
|
||||
cond: ValueId(0),
|
||||
then_val: ValueId(1),
|
||||
else_val: ValueId(2),
|
||||
type_hint: None, // Phase 63-3
|
||||
});
|
||||
|
||||
// Return result
|
||||
@ -270,6 +273,7 @@ mod tests {
|
||||
cond: ValueId(0),
|
||||
then_val: ValueId(10),
|
||||
else_val: ValueId(20),
|
||||
type_hint: None, // Phase 63-3
|
||||
});
|
||||
|
||||
// Second Select (violates single PHI invariant)
|
||||
@ -278,6 +282,7 @@ mod tests {
|
||||
cond: ValueId(0),
|
||||
then_val: ValueId(30),
|
||||
else_val: ValueId(40),
|
||||
type_hint: None, // Phase 63-3
|
||||
});
|
||||
|
||||
join_func.body.push(JoinInst::Ret {
|
||||
@ -591,4 +596,88 @@ mod tests {
|
||||
|
||||
std::env::remove_var("NYASH_JOINIR_IF_SELECT");
|
||||
}
|
||||
|
||||
/// Phase 63-2: Helper to create a simple pattern MIR with Const instructions
|
||||
fn create_simple_pattern_mir_with_const() -> MirFunction {
|
||||
let mut blocks = BTreeMap::new();
|
||||
|
||||
// Entry block (bb0): create const 10/20, then branch on cond
|
||||
let mut entry = BasicBlock::new(BasicBlockId::new(0));
|
||||
entry.instructions.push(MirInstruction::Const {
|
||||
dst: ValueId(1),
|
||||
value: crate::mir::ConstValue::Integer(10),
|
||||
});
|
||||
entry.instructions.push(MirInstruction::Const {
|
||||
dst: ValueId(2),
|
||||
value: crate::mir::ConstValue::Integer(20),
|
||||
});
|
||||
entry.terminator = Some(MirInstruction::Branch {
|
||||
condition: ValueId(0), // cond parameter
|
||||
then_bb: BasicBlockId::new(1),
|
||||
else_bb: BasicBlockId::new(2),
|
||||
});
|
||||
blocks.insert(BasicBlockId::new(0), entry);
|
||||
|
||||
// Then block (bb1): return 10
|
||||
let mut then_block = BasicBlock::new(BasicBlockId::new(1));
|
||||
then_block.terminator = Some(MirInstruction::Return {
|
||||
value: Some(ValueId(1)), // const 10
|
||||
});
|
||||
blocks.insert(BasicBlockId::new(1), then_block);
|
||||
|
||||
// Else block (bb2): return 20
|
||||
let mut else_block = BasicBlock::new(BasicBlockId::new(2));
|
||||
else_block.terminator = Some(MirInstruction::Return {
|
||||
value: Some(ValueId(2)), // const 20
|
||||
});
|
||||
blocks.insert(BasicBlockId::new(2), else_block);
|
||||
|
||||
use crate::mir::function::FunctionMetadata;
|
||||
use crate::mir::{EffectMask, MirType};
|
||||
|
||||
MirFunction {
|
||||
signature: crate::mir::FunctionSignature {
|
||||
name: "IfSelectTest.test/1".to_string(),
|
||||
params: vec![MirType::Unknown],
|
||||
return_type: MirType::Integer,
|
||||
effects: EffectMask::PURE,
|
||||
},
|
||||
entry_block: BasicBlockId::new(0),
|
||||
blocks: blocks.into_iter().collect(),
|
||||
locals: vec![],
|
||||
params: vec![ValueId(0)],
|
||||
next_value_id: 3,
|
||||
metadata: FunctionMetadata::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Phase 63-2: Test type hint propagation from MIR Const instructions
|
||||
#[test]
|
||||
fn test_type_hint_propagation_simple() {
|
||||
use crate::mir::MirType;
|
||||
|
||||
std::env::set_var("NYASH_JOINIR_IF_SELECT", "1");
|
||||
|
||||
let func = create_simple_pattern_mir_with_const();
|
||||
let entry_block = func.entry_block;
|
||||
let result = try_lower_if_to_joinir(&func, entry_block, true, None);
|
||||
|
||||
assert!(
|
||||
result.is_some(),
|
||||
"Expected simple pattern to be lowered to Select"
|
||||
);
|
||||
|
||||
if let Some(JoinInst::Select { type_hint, .. }) = result {
|
||||
assert_eq!(
|
||||
type_hint,
|
||||
Some(MirType::Integer),
|
||||
"Expected type_hint to be Some(Integer) for IfSelectTest.simple (Const 10/20)"
|
||||
);
|
||||
eprintln!("✅ Phase 63-2: Type hint propagation successful: {:?}", type_hint);
|
||||
} else {
|
||||
panic!("Expected Select instruction with type_hint");
|
||||
}
|
||||
|
||||
std::env::remove_var("NYASH_JOINIR_IF_SELECT");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user