fix(mir): PHI検証panic修正 - update_cfg()を検証前に呼び出し

A案実装: debug_verify_phi_inputs呼び出し前にCFG predecessorを更新

修正箇所(7箇所):
- src/mir/builder/phi.rs:50, 73, 132, 143
- src/mir/builder/ops.rs:273, 328, 351

根本原因:
- Branch/Jump命令でsuccessorは即座に更新
- predecessorはupdate_cfg()で遅延再構築
- PHI検証が先に実行されてpredecessor未更新でpanic

解決策:
- 各debug_verify_phi_inputs呼び出し前に
  if let Some(func) = self.current_function.as_mut() {
      func.update_cfg();
  }
  を挿入してCFGを同期

影響: if/else文、論理演算子(&&/||)のPHI生成が正常動作
This commit is contained in:
nyash-codex
2025-11-01 13:28:56 +09:00
parent 149ec61d4d
commit 6a452b2dca
174 changed files with 2432 additions and 1014 deletions

View File

@ -19,10 +19,18 @@ impl MirInterpreter {
let saved_fn = self.cur_fn.clone();
self.cur_fn = Some(func.signature.name.clone());
if let Some(args) = arg_vals {
for (i, pid) in func.params.iter().enumerate() {
let v = args.get(i).cloned().unwrap_or(VMValue::Void);
self.regs.insert(*pid, v);
match arg_vals {
Some(args) => {
for (i, pid) in func.params.iter().enumerate() {
let v = args.get(i).cloned().unwrap_or(VMValue::Void);
self.regs.insert(*pid, v);
}
}
None => {
// Seed all parameters with Void so SSA consumers observe defined values.
for pid in &func.params {
self.regs.insert(*pid, VMValue::Void);
}
}
}

View File

@ -23,6 +23,34 @@ pub(super) fn try_handle_map_box(
if let Some(d) = dst { this.regs.insert(d, VMValue::Void); }
return Ok(true);
}
// Field bridge: treat getField/setField as get/set with string key
"getField" => {
if args.len() != 1 {
return Err(VMError::InvalidInstruction(
"MapBox.getField expects 1 arg".into(),
));
}
let k = this.reg_load(args[0])?.to_nyash_box();
let ret = mb.get(k);
if let Some(d) = dst {
this.regs.insert(d, VMValue::from_nyash_box(ret));
}
return Ok(true);
}
"setField" => {
if args.len() != 2 {
return Err(VMError::InvalidInstruction(
"MapBox.setField expects 2 args".into(),
));
}
let k = this.reg_load(args[0])?.to_nyash_box();
let v = this.reg_load(args[1])?.to_nyash_box();
let ret = mb.set(k, v);
if let Some(d) = dst {
this.regs.insert(d, VMValue::from_nyash_box(ret));
}
return Ok(true);
}
"set" => {
if args.len() != 2 { return Err(VMError::InvalidInstruction("MapBox.set expects 2 args".into())); }
let k = this.reg_load(args[0])?.to_nyash_box();