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,31 +6,31 @@
static box GcBox {
// Return JSON string with counters {safepoints, barrier_reads, barrier_writes}
stats() {
return call("env.gc.stats/0")
return gc.stats()
}
// Return total roots count (host handles + modules), besteffort integer
roots_snapshot() {
return call("env.gc.roots_snapshot/0")
return gc.roots_snapshot()
}
// Request collection (noop until host supports it)
collect() {
// Host may ignore; keep FailFast if extern missing
call("env.gc.collect/0")
gc.collect()
}
// Optional lifecycle hooks (noop unless host implements)
start() { call("env.gc.start/0"); }
stop() { call("env.gc.stop/0"); }
start() { gc.start(); }
stop() { gc.stop(); }
// Example (dev): a tiny cadence policy, OFF by default.
// Enable with: HAKO_GC_POLICY_TICK=1 (docs only; call manually from scripts)
policy_tick() {
if (call("env.local.get/1", "HAKO_GC_POLICY_TICK") == "1") {
if (env.get("HAKO_GC_POLICY_TICK") == "1") {
// Read metrics and print a compact line for observation
local s = me.stats()
call("env.console.log/1", "[GcBox] stats=" + s)
console.log("[GcBox] stats=" + s)
// Example threshold (no-op unless host implements collect):
// me.collect()
}
@ -41,12 +41,12 @@ static box GcBox {
// HAKO_GC_POLICY_FORCE=1 → call collect() each tick (may be no-op; guard expected)
// HAKO_GC_POLICY_EVERY_N=K → best-effort modulus trigger (tick_count % K == 0)
tick_with_policy(tick_count) {
local log = call("env.local.get/1", "HAKO_GC_POLICY_LOG")
local every = call("env.local.get/1", "HAKO_GC_POLICY_EVERY_N")
local force = call("env.local.get/1", "HAKO_GC_POLICY_FORCE")
local log = env.get("HAKO_GC_POLICY_LOG")
local every = env.get("HAKO_GC_POLICY_EVERY_N")
local force = env.get("HAKO_GC_POLICY_FORCE")
if (log == "1") {
call("env.console.log/1", "[GcBox] stats=" + me.stats())
console.log("[GcBox] stats=" + me.stats())
}
if (force == "1") {
// Gate: host may not implement collect() yet