Files
hakorune/lang/src/vm/hakorune-vm/json_scan_guard.hako
nyash-codex 6a452b2dca 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生成が正常動作
2025-11-01 13:28:56 +09:00

64 lines
2.0 KiB
Plaintext

// json_scan_guard.hako — JsonScanGuardBox
// Responsibility: escape-aware JSON scanning with step budget (Fail-Fast)
using "lang/src/shared/json/core/string_scan.hako" as StringScanBox
static box JsonScanGuardBox {
// Seek the end index (inclusive) of an object starting at `start` (must be '{').
// Returns: end index or -1 on failure/budget exceeded.
seek_obj_end(text, start, budget) {
if text == null { return -1 }
if start < 0 || start >= text.length() { return -1 }
if text.substring(start, start+1) != "{" { return -1 }
local n = text.length()
local depth = 0
local i = start
local steps = 0
loop (i < n) {
if steps >= budget { return -1 }
steps = steps + 1
local ch = StringScanBox.read_char(text, i)
if ch == "\\" { i = i + 2 continue }
if ch == "\"" {
// jump to end quote (escape-aware)
local j = StringScanBox.find_quote(text, i+1)
if j < 0 { return -1 }
i = j + 1
continue
}
if ch == "{" { depth = depth + 1 }
if ch == "}" { depth = depth - 1 if depth == 0 { return i } }
i = i + 1
}
return -1
}
// Seek the end index (inclusive) of an array starting at `start` (must be '[').
// Returns: end index or -1 on failure/budget exceeded.
seek_array_end(text, start, budget) {
if text == null { return -1 }
if start < 0 || start >= text.length() { return -1 }
if text.substring(start, start+1) != "[" { return -1 }
local n = text.length()
local depth = 0
local i = start
local steps = 0
loop (i < n) {
if steps >= budget { return -1 }
steps = steps + 1
local ch = StringScanBox.read_char(text, i)
if ch == "\\" { i = i + 2 continue }
if ch == "\"" {
local j = StringScanBox.find_quote(text, i+1)
if j < 0 { return -1 }
i = j + 1
continue
}
if ch == "[" { depth = depth + 1 }
if ch == "]" { depth = depth - 1 if depth == 0 { return i } }
i = i + 1
}
return -1
}
}