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

@ -25,7 +25,7 @@ static box StringHelpers {
local i = 0
local neg = 0
if s.substring(0,1) == "-" { neg = 1 i = 1 }
local n = s.size()
local n = s.length()
if i >= n { return 0 }
local acc = 0
loop (i < n) {
@ -46,7 +46,7 @@ static box StringHelpers {
if s == null { return "\"\"" }
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 + "\\\\" }
@ -65,7 +65,7 @@ static box StringHelpers {
// Check if string is numeric-like (optional leading '-', then digits).
is_numeric_str(s) {
if s == null { return 0 }
local n = s.size()
local n = s.length()
if n == 0 { return 0 }
local i = 0
if s.substring(0,1) == "-" { if n == 1 { return 0 } i = 1 }
@ -95,8 +95,8 @@ static box StringHelpers {
// Pattern matching
starts_with(src, i, pat) {
local n = src.size()
local m = pat.size()
local n = src.length()
local m = pat.length()
if i + m > n { return 0 }
local k = 0
loop(k < m) {
@ -109,8 +109,8 @@ static box StringHelpers {
// Keyword match with word boundary (next char not [A-Za-z0-9_])
starts_with_kw(src, i, kw) {
if me.starts_with(src, i, kw) == 0 { return 0 }
local n = src.size()
local j = i + kw.size()
local n = src.length()
local j = i + kw.length()
if j >= n { return 1 }
local ch = src.substring(j, j+1)
if me.is_alpha(ch) || me.is_digit(ch) { return 0 }
@ -119,8 +119,8 @@ static box StringHelpers {
// String search
index_of(src, i, pat) {
local n = src.size()
local m = pat.size()
local n = src.length()
local m = pat.length()
if m == 0 { return i }
local j = i
loop(j + m <= n) {
@ -133,7 +133,7 @@ static box StringHelpers {
// Trim spaces and tabs (with optional semicolon at end)
trim(s) {
local i = 0
local n = s.size()
local n = s.length()
loop(i < n && (s.substring(i,i+1) == " " || s.substring(i,i+1) == "\t")) { i = i + 1 }
local j = n
loop(j > i && (s.substring(j-1,j) == " " || s.substring(j-1,j) == "\t" || s.substring(j-1,j) == ";")) { j = j - 1 }
@ -143,7 +143,7 @@ static box StringHelpers {
// Skip whitespace from position i
skip_ws(src, i) {
if src == null { return i }
local n = src.size()
local n = src.length()
local cont = 1
local guard = 0
local max = 100000
@ -160,8 +160,8 @@ static box StringHelpers {
last_index_of(src, pat) {
if src == null { return -1 }
if pat == null { return -1 }
local n = src.size()
local m = pat.size()
local n = src.length()
local m = pat.length()
if m == 0 { return n }
if m > n { return -1 }
local i = n - m