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

@ -44,7 +44,7 @@ box ParserBox {
esc_json(s) {
local out = ""
local i = 0
local n = s.size()
local n = s.length()
loop(i < n) {
local ch = s.substring(i, i+1)
if ch == "\\" { out = out + "\\\\" }
@ -84,7 +84,7 @@ box ParserBox {
local at = pair.lastIndexOf("@")
local content = pair.substring(0, at)
local pos = 0
if at >= 0 { pos = me.to_int(pair.substring(at+1, pair.size())) }
if at >= 0 { pos = me.to_int(pair.substring(at+1, pair.length())) }
else { pos = i }
me.gpos_set(pos)
return content
@ -93,7 +93,7 @@ box ParserBox {
// === using system ===
add_using(kind, target, alias) {
local cur = me.usings_json
if cur == null || cur.size() == 0 { cur = "[]" }
if cur == null || cur.length() == 0 { cur = "[]" }
local name = ""
local path = null
@ -106,17 +106,17 @@ box ParserBox {
local p = target
local idx = -1
local t = 0
loop(t < p.size()) {
loop(t < p.length()) {
if p.substring(t,t+1) == "/" { idx = t }
t = t + 1
}
if idx >= 0 { p = p.substring(idx+1, p.size()) }
if idx >= 0 { p = p.substring(idx+1, p.length()) }
if p.size() > 5 && me.starts_with(p, p.size()-5, ".hako") == 1 {
p = p.substring(0, p.size()-5)
if p.length() > 5 && me.starts_with(p, p.length()-5, ".hako") == 1 {
p = p.substring(0, p.length()-5)
} else {
if p.size() > 6 && me.starts_with(p, p.size()-6, ".nyash") == 1 {
p = p.substring(0, p.size()-6)
if p.length() > 6 && me.starts_with(p, p.length()-6, ".nyash") == 1 {
p = p.substring(0, p.length()-6)
}
}
name = p
@ -163,7 +163,7 @@ box ParserBox {
if func_name == null { func_name = "" }
local entry = "{\"symbol\":\"" + me.esc_json(sym) + "\",\"func\":\"" + me.esc_json(func_name) + "\"}"
local cur = me.externs_json
if cur == null || cur.size() == 0 { cur = "[]" }
if cur == null || cur.length() == 0 { cur = "[]" }
if cur == "[]" {
me.externs_json = "[" + entry + "]"
return 0
@ -188,20 +188,17 @@ box ParserBox {
// === Delegation to ParserExprBox ===
parse_expr2(src, i) {
local expr = new ParserExprBox()
return expr.parse_expr2(src, i, me)
return ParserExprBox.parse_expr2(src, i, me)
}
// === Delegation to ParserStmtBox ===
parse_stmt2(src, i) {
local stmt = new ParserStmtBox()
return stmt.parse(src, i, me)
return ParserStmtBox.parse(src, i, me)
}
// === Delegation to ParserControlBox ===
parse_block2(src, i) {
local ctrl = new ParserControlBox()
return ctrl.parse_block(src, i, me)
return ParserControlBox.parse_block(src, i, me)
}
// === Top-level program parser ===
@ -214,7 +211,7 @@ box ParserBox {
loop(cont_prog == 1) {
i = me.skip_ws(src, i)
if i >= src.size() {
if i >= src.length() {
cont_prog = 0
} else {
local start_i = i
@ -223,8 +220,8 @@ box ParserBox {
// Progress guard
if i <= start_i {
if i < src.size() { i = i + 1 }
else { i = src.size() }
if i < src.length() { i = i + 1 }
else { i = src.length() }
me.gpos_set(i)
}
@ -240,7 +237,7 @@ box ParserBox {
local before2 = i
i = me.skip_ws(src, i)
if i < src.size() && src.substring(i, i+1) == ";" {
if i < src.length() && src.substring(i, i+1) == ";" {
i = i + 1
} else {
done2 = 1
@ -249,7 +246,7 @@ box ParserBox {
if i == before2 { done2 = 1 }
}
if s.size() > 0 {
if s.length() > 0 {
if first == 1 {
body = body + s
first = 0