From f071b4cc3c95e6e02cc9fd1c8dfd5c2d7896192c Mon Sep 17 00:00:00 2001 From: tomoaki Date: Mon, 22 Dec 2025 04:15:37 +0900 Subject: [PATCH] refactor(joinir): Eliminate call instruction generation duplication MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../joinir_block_converter.rs | 59 ++++++++----------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/src/mir/join_ir_vm_bridge/joinir_block_converter.rs b/src/mir/join_ir_vm_bridge/joinir_block_converter.rs index a0d0e8e2..2456a403 100644 --- a/src/mir/join_ir_vm_bridge/joinir_block_converter.rs +++ b/src/mir/join_ir_vm_bridge/joinir_block_converter.rs @@ -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) };