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:
@ -13,7 +13,7 @@ impl MirBuilder {
|
||||
&mut self,
|
||||
_then_block: super::BasicBlockId,
|
||||
else_block: super::BasicBlockId,
|
||||
then_exit_block: super::BasicBlockId,
|
||||
then_exit_block_opt: Option<super::BasicBlockId>,
|
||||
else_exit_block_opt: Option<super::BasicBlockId>,
|
||||
pre_if_snapshot: &std::collections::HashMap<String, super::ValueId>,
|
||||
then_map_end: &std::collections::HashMap<String, super::ValueId>,
|
||||
@ -42,18 +42,25 @@ impl MirBuilder {
|
||||
.unwrap_or(pre);
|
||||
// フェーズM: 常にPHI命令を使用(no_phi_mode撤廃)
|
||||
// incoming の predecessor は "実際に merge に遷移してくる出口ブロック" を使用する
|
||||
let then_pred = then_exit_block;
|
||||
let else_pred = else_exit_block_opt.unwrap_or(else_block);
|
||||
let merged = self.value_gen.next();
|
||||
let inputs = vec![(then_pred, then_v), (else_pred, else_v)];
|
||||
if let Some(func) = self.current_function.as_mut() {
|
||||
func.update_cfg();
|
||||
let mut inputs: Vec<(super::BasicBlockId, super::ValueId)> = Vec::new();
|
||||
if let Some(tp) = then_exit_block_opt { inputs.push((tp, then_v)); }
|
||||
if let Some(ep) = else_exit_block_opt.or(Some(else_block)) { inputs.push((ep, else_v)); }
|
||||
match inputs.len() {
|
||||
0 => {}
|
||||
1 => {
|
||||
let (_pred, v) = inputs[0];
|
||||
self.variable_map.insert(name, v);
|
||||
}
|
||||
_ => {
|
||||
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 merged = self.value_gen.next();
|
||||
self.emit_instruction(MirInstruction::Phi { dst: merged, inputs })?;
|
||||
self.variable_map.insert(name, merged);
|
||||
}
|
||||
}
|
||||
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: merged, inputs })?;
|
||||
self.variable_map.insert(name, merged);
|
||||
}
|
||||
|
||||
// Ensure pinned synthetic slots ("__pin$...") have a block-local definition at the merge,
|
||||
@ -68,18 +75,25 @@ impl MirBuilder {
|
||||
.as_ref()
|
||||
.and_then(|m| m.get(pin_name.as_str()).copied())
|
||||
.unwrap_or(*pre_val);
|
||||
let then_pred = then_exit_block;
|
||||
let else_pred = else_exit_block_opt.unwrap_or(else_block);
|
||||
let merged = self.value_gen.next();
|
||||
let inputs = vec![(then_pred, then_v), (else_pred, else_v)];
|
||||
if let Some(func) = self.current_function.as_mut() {
|
||||
func.update_cfg();
|
||||
let mut inputs: Vec<(super::BasicBlockId, super::ValueId)> = Vec::new();
|
||||
if let Some(tp) = then_exit_block_opt { inputs.push((tp, then_v)); }
|
||||
if let Some(ep) = else_exit_block_opt.or(Some(else_block)) { inputs.push((ep, else_v)); }
|
||||
match inputs.len() {
|
||||
0 => {}
|
||||
1 => {
|
||||
let (_pred, v) = inputs[0];
|
||||
self.variable_map.insert(pin_name.clone(), v);
|
||||
}
|
||||
_ => {
|
||||
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 merged = self.value_gen.next();
|
||||
self.emit_instruction(MirInstruction::Phi { dst: merged, inputs })?;
|
||||
self.variable_map.insert(pin_name.clone(), merged);
|
||||
}
|
||||
}
|
||||
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: merged, inputs })?;
|
||||
self.variable_map.insert(pin_name.clone(), merged);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -129,32 +143,49 @@ impl MirBuilder {
|
||||
// Else doesn't assign: use pre-if value if available
|
||||
pre_then_var_value.unwrap_or(else_value_raw)
|
||||
};
|
||||
// predecessor を then/else の exit ブロックに揃える
|
||||
let then_pred = then_exit_block_opt.unwrap_or(then_block);
|
||||
let else_pred = else_exit_block_opt.unwrap_or(else_block);
|
||||
// Emit Phi for the assigned variable and bind it
|
||||
let inputs = vec![(then_pred, then_value_for_var), (else_pred, else_value_for_var)];
|
||||
if let Some(func) = self.current_function.as_mut() {
|
||||
func.update_cfg();
|
||||
// Build inputs from reachable predecessors only
|
||||
let mut inputs: Vec<(BasicBlockId, ValueId)> = Vec::new();
|
||||
if let Some(tp) = then_exit_block_opt { inputs.push((tp, then_value_for_var)); }
|
||||
if let Some(ep) = else_exit_block_opt.or(Some(else_block)) { inputs.push((ep, else_value_for_var)); }
|
||||
match inputs.len() {
|
||||
0 => {}
|
||||
1 => {
|
||||
// Direct bind (no PHI needed)
|
||||
self.variable_map = pre_if_var_map.clone();
|
||||
self.variable_map.insert(var_name, inputs[0].1);
|
||||
return Ok(inputs[0].1);
|
||||
}
|
||||
_ => {
|
||||
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 })?;
|
||||
}
|
||||
}
|
||||
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.variable_map = pre_if_var_map.clone();
|
||||
self.variable_map.insert(var_name, result_val);
|
||||
} else {
|
||||
// No variable assignment pattern detected – just emit Phi for expression result
|
||||
let then_pred = then_exit_block_opt.unwrap_or(then_block);
|
||||
let else_pred = else_exit_block_opt.unwrap_or(else_block);
|
||||
let inputs = vec![(then_pred, then_value_raw), (else_pred, else_value_raw)];
|
||||
if let Some(func) = self.current_function.as_mut() {
|
||||
func.update_cfg();
|
||||
let mut inputs: Vec<(BasicBlockId, ValueId)> = Vec::new();
|
||||
if let Some(tp) = then_exit_block_opt { inputs.push((tp, then_value_raw)); }
|
||||
if let Some(ep) = else_exit_block_opt.or(Some(else_block)) { inputs.push((ep, else_value_raw)); }
|
||||
match inputs.len() {
|
||||
0 => { /* leave result_val as fresh, but unused; synthesize void */
|
||||
let v = crate::mir::builder::emission::constant::emit_void(self);
|
||||
return Ok(v);
|
||||
}
|
||||
1 => {
|
||||
return Ok(inputs[0].1);
|
||||
}
|
||||
_ => {
|
||||
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 })?;
|
||||
}
|
||||
}
|
||||
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 })?;
|
||||
// Merge variable map conservatively to pre-if snapshot (no new bindings)
|
||||
self.variable_map = pre_if_var_map.clone();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user