refactor(joinir): Eliminate call instruction generation duplication

Problem:
- 3 duplicate call instruction patterns
- Lines ~404-417 (handle_call non-tail)
- Lines ~506-518 (exit block tail call)
- Lines ~530-540 (unconditional jump tail call)

Solution:
- Use existing call_generator.rs helpers
- emit_call_pair() for current_instructions (no separate spans)
- emit_call_pair_with_spans() for BasicBlock with spans

Result:
-  ~15 lines eliminated (3 duplicate patterns removed)
-  Tests pass, no regression
-  Cleaner handle_jump implementation

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-22 04:15:37 +09:00
parent f7437957b7
commit f071b4cc3c

View File

@ -13,6 +13,7 @@ use crate::mir::types::ConstValue;
use std::collections::BTreeMap;
use super::block_allocator::BlockAllocator; // Phase 269 P1.2+: Use BlockAllocator for deduplication
use super::call_generator::{emit_call_pair, emit_call_pair_with_spans}; // Phase 269 P1.2+: Call instruction deduplication
use super::merge_variable_handler::{emit_merge_copies, MergeBranch}; // Phase 269 P1.2+: Merge copy deduplication
use super::{convert_mir_like_inst, join_func_name, JoinIrVmBridgeError};
@ -400,21 +401,16 @@ impl JoinIrBlockConverter {
));
}
self.current_instructions.push(MirInstruction::Const {
dst: func_name_id,
value: crate::mir::ConstValue::String(func_name),
});
match dst {
Some(result_dst) => {
// Non-tail call
self.current_instructions.push(MirInstruction::Call {
dst: Some(*result_dst),
func: func_name_id,
callee: None,
args: args.to_vec(),
effects: EffectMask::PURE,
});
emit_call_pair(
&mut self.current_instructions,
func_name_id,
*result_dst,
&func_name,
args,
);
}
None => {
// Tail call
@ -507,19 +503,14 @@ impl JoinIrBlockConverter {
let mut exit_block = crate::mir::BasicBlock::new(exit_block_id);
// Phase 256 P1.9: Generate tail call to continuation
exit_block.instructions.push(MirInstruction::Const {
dst: func_name_id,
value: crate::mir::ConstValue::String(cont_name.clone()),
});
exit_block.instruction_spans.push(Span::unknown());
exit_block.instructions.push(MirInstruction::Call {
dst: Some(call_result_id),
func: func_name_id,
callee: None,
args: args.to_vec(),
effects: EffectMask::PURE,
});
exit_block.instruction_spans.push(Span::unknown());
emit_call_pair_with_spans(
&mut exit_block.instructions,
&mut exit_block.instruction_spans,
func_name_id,
call_result_id,
&cont_name,
args,
);
exit_block.set_terminator(MirInstruction::Return { value: Some(call_result_id) });
exit_block.set_return_env(crate::mir::EdgeArgs {
layout: JumpArgsLayout::CarriersOnly,
@ -536,17 +527,13 @@ impl JoinIrBlockConverter {
None => {
// Unconditional jump → tail call to continuation
// Finalize current block with tail call
self.current_instructions.push(MirInstruction::Const {
dst: func_name_id,
value: crate::mir::ConstValue::String(cont_name),
});
self.current_instructions.push(MirInstruction::Call {
dst: Some(call_result_id),
func: func_name_id,
callee: None,
args: args.to_vec(),
effects: EffectMask::PURE,
});
emit_call_pair(
&mut self.current_instructions,
func_name_id,
call_result_id,
&cont_name,
args,
);
let return_terminator = MirInstruction::Return { value: Some(call_result_id) };