refactor(vm): Phase 8 - Debug Trace Macro統一化(12行削減)
trace_dispatch!マクロで6箇所のVM_TRACEパターンを統一 実装内容: - mod.rsにtrace_dispatch!マクロ定義 - boxes.rs: 6箇所の3行if文→1行マクロ呼び出し - 削減: 18行→6行(12行削減) 対象箇所: - object_fields handler trace - instance_box handler trace - string_box handler trace - array_box handler trace - map_box handler trace - fallback(length=0) handler trace 効果: - 保守性向上: trace条件の一元管理 - 可読性向上: 冗長なif文→簡潔なマクロ - 一貫性向上: 全handler統一フォーマット テスト: ビルド成功(0エラー、87警告)
This commit is contained in:
@ -283,8 +283,9 @@ impl super::MirBuilder {
|
||||
t_id
|
||||
};
|
||||
let then_exit_block = self.current_block()?;
|
||||
let then_reaches_merge = !self.is_current_block_terminated();
|
||||
let then_var_map_end = self.variable_map.clone();
|
||||
if !self.is_current_block_terminated() {
|
||||
if then_reaches_merge {
|
||||
self.hint_scope_leave(0);
|
||||
crate::mir::builder::emission::branch::emit_jump(self, merge_block)?;
|
||||
}
|
||||
@ -338,8 +339,9 @@ impl super::MirBuilder {
|
||||
rhs_bool
|
||||
};
|
||||
let else_exit_block = self.current_block()?;
|
||||
let else_reaches_merge = !self.is_current_block_terminated();
|
||||
let else_var_map_end = self.variable_map.clone();
|
||||
if !self.is_current_block_terminated() {
|
||||
if else_reaches_merge {
|
||||
self.hint_scope_leave(0);
|
||||
self.emit_instruction(MirInstruction::Jump { target: merge_block })?;
|
||||
}
|
||||
@ -350,24 +352,32 @@ impl super::MirBuilder {
|
||||
self.start_new_block(merge_block)?;
|
||||
self.push_if_merge(merge_block);
|
||||
|
||||
// Result PHI (bool)
|
||||
let result_val = self.value_gen.next();
|
||||
let inputs = vec![(then_exit_block, then_value_raw), (else_exit_block, else_value_raw)];
|
||||
if let Some(func) = self.current_function.as_mut() {
|
||||
func.update_cfg();
|
||||
}
|
||||
if let (Some(func), Some(cur_bb)) = (&self.current_function, self.current_block) {
|
||||
crate::mir::phi_core::common::debug_verify_phi_inputs(func, cur_bb, &inputs);
|
||||
}
|
||||
self.emit_instruction(MirInstruction::Phi { dst: result_val, inputs })?;
|
||||
self.value_types.insert(result_val, MirType::Bool);
|
||||
// Result PHI (bool) — consider only reachable predecessors
|
||||
let mut inputs: Vec<(crate::mir::BasicBlockId, ValueId)> = Vec::new();
|
||||
if then_reaches_merge { inputs.push((then_exit_block, then_value_raw)); }
|
||||
if else_reaches_merge { inputs.push((else_exit_block, else_value_raw)); }
|
||||
let result_val = if inputs.len() >= 2 {
|
||||
if let Some(func) = self.current_function.as_mut() { func.update_cfg(); }
|
||||
if let (Some(func), Some(cur_bb)) = (&self.current_function, self.current_block) {
|
||||
crate::mir::phi_core::common::debug_verify_phi_inputs(func, cur_bb, &inputs);
|
||||
}
|
||||
let dst = self.value_gen.next();
|
||||
self.emit_instruction(MirInstruction::Phi { dst, inputs })?;
|
||||
self.value_types.insert(dst, MirType::Bool);
|
||||
dst
|
||||
} else if inputs.len() == 1 {
|
||||
inputs[0].1
|
||||
} else {
|
||||
// Unreachable fallthrough: synthesize false (defensive)
|
||||
crate::mir::builder::emission::constant::emit_bool(self, false)
|
||||
};
|
||||
|
||||
// Merge modified vars from both branches back into current scope
|
||||
self.merge_modified_vars(
|
||||
then_block,
|
||||
else_block,
|
||||
then_exit_block,
|
||||
Some(else_exit_block),
|
||||
if then_reaches_merge { Some(then_exit_block) } else { None },
|
||||
if else_reaches_merge { Some(else_exit_block) } else { None },
|
||||
&pre_if_var_map,
|
||||
&then_var_map_end,
|
||||
&Some(else_var_map_end),
|
||||
|
||||
Reference in New Issue
Block a user