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

@ -6,14 +6,14 @@
// - ParserBox.extract_usings delegates to this box (Phase 2 split)
// - Pure string scan依存ゼロ。FailFastはせず、安全にスキップでループを進める
using lang.compiler.parser.scan.parser_common_utils_box as Utils
using lang.compiler.parser.scan.parser_common_utils_box as ParserCommonUtilsBox
static box UsingCollectorBox {
// Public API: collect line-based using declarations to JSON array string
collect(src) {
if src == null { return "[]" }
local n = src.size()
local n = src.length()
local i = 0
local first = 1
local out = "["
@ -24,30 +24,30 @@ static box UsingCollectorBox {
local line = src.substring(i, j)
// trim left spaces/tabs
local k = 0
loop(k < line.size() && (line.substring(k,k+1) == " " || line.substring(k,k+1) == "\t")) { k = k + 1 }
if Utils.starts_with(line, k, "using ") == 1 {
local rest = Utils.trim(line.substring(k + 6, line.size()))
loop(k < line.length() && (line.substring(k,k+1) == " " || line.substring(k,k+1) == "\t")) { k = k + 1 }
if ParserCommonUtilsBox.starts_with(line, k, "using ") == 1 {
local rest = ParserCommonUtilsBox.trim(line.substring(k + 6, line.length()))
// split on ' as '
local as_pos = Utils.index_of(rest, 0, " as ")
local as_pos = ParserCommonUtilsBox.index_of(rest, 0, " as ")
local target = rest
local alias = null
if as_pos >= 0 { target = Utils.trim(rest.substring(0, as_pos)) alias = Utils.trim(rest.substring(as_pos + 4, rest.size())) }
if as_pos >= 0 { target = ParserCommonUtilsBox.trim(rest.substring(0, as_pos)) alias = ParserCommonUtilsBox.trim(rest.substring(as_pos + 4, rest.length())) }
// path or namespace
local is_path = 0
if target.size() > 0 {
if Utils.starts_with(target, 0, Utils.dq()) == 1 { is_path = 1 }
if Utils.starts_with(target, 0, "./") == 1 { is_path = 1 }
if Utils.starts_with(target, 0, "/") == 1 { is_path = 1 }
if target.size() >= 5 && Utils.starts_with(target, target.size()-5, ".hako") == 1 { is_path = 1 }
if target.size() >= 6 && Utils.starts_with(target, target.size()-6, ".nyash") == 1 { is_path = 1 }
if target.length() > 0 {
if ParserCommonUtilsBox.starts_with(target, 0, ParserCommonUtilsBox.dq()) == 1 { is_path = 1 }
if ParserCommonUtilsBox.starts_with(target, 0, "./") == 1 { is_path = 1 }
if ParserCommonUtilsBox.starts_with(target, 0, "/") == 1 { is_path = 1 }
if target.length() >= 5 && ParserCommonUtilsBox.starts_with(target, target.length()-5, ".hako") == 1 { is_path = 1 }
if target.length() >= 6 && ParserCommonUtilsBox.starts_with(target, target.length()-6, ".nyash") == 1 { is_path = 1 }
}
local name = ""
local path = null
if is_path == 1 {
// strip quotes
if Utils.starts_with(target, 0, Utils.dq()) == 1 {
target = target.substring(1, target.size())
if target.size() > 0 && target.substring(target.size()-1, target.size()) == Utils.dq() { target = target.substring(0, target.size()-1) }
if ParserCommonUtilsBox.starts_with(target, 0, ParserCommonUtilsBox.dq()) == 1 {
target = target.substring(1, target.length())
if target.length() > 0 && target.substring(target.length()-1, target.length()) == ParserCommonUtilsBox.dq() { target = target.substring(0, target.length()-1) }
}
path = target
if alias != null { name = alias } else {
@ -55,11 +55,11 @@ static box UsingCollectorBox {
local p = target
local idx = -1
local t = 0
loop(t < p.size()) { if p.substring(t,t+1) == "/" { idx = t } t = t + 1 }
if idx >= 0 { p = p.substring(idx+1, 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.length()) }
// strip extension
if p.size() > 5 && Utils.starts_with(p, p.size()-5, ".hako") == 1 { p = p.substring(0, p.size()-5) }
else { if p.size() > 6 && Utils.starts_with(p, p.size()-6, ".nyash") == 1 { p = p.substring(0, p.size()-6) } }
if p.length() > 5 && ParserCommonUtilsBox.starts_with(p, p.length()-5, ".hako") == 1 { p = p.substring(0, p.length()-5) }
else { if p.length() > 6 && ParserCommonUtilsBox.starts_with(p, p.length()-6, ".nyash") == 1 { p = p.substring(0, p.length()-6) } }
name = p
}
} else {
@ -67,8 +67,8 @@ static box UsingCollectorBox {
}
// append entry
if first == 0 { out = out + "," } else { first = 0 }
out = out + "{" + Utils.dq() + "name" + Utils.dq() + ":" + Utils.dq() + Utils.esc_json(name) + Utils.dq()
if path != null { out = out + "," + Utils.dq() + "path" + Utils.dq() + ":" + Utils.dq() + Utils.esc_json(path) + Utils.dq() }
out = out + "{" + ParserCommonUtilsBox.dq() + "name" + ParserCommonUtilsBox.dq() + ":" + ParserCommonUtilsBox.dq() + ParserCommonUtilsBox.esc_json(name) + ParserCommonUtilsBox.dq()
if path != null { out = out + "," + ParserCommonUtilsBox.dq() + "path" + ParserCommonUtilsBox.dq() + ":" + ParserCommonUtilsBox.dq() + ParserCommonUtilsBox.esc_json(path) + ParserCommonUtilsBox.dq() }
out = out + "}"
}
i = j + 1
@ -77,4 +77,3 @@ static box UsingCollectorBox {
return out
}
}