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

@ -30,7 +30,8 @@ static box Main {
_collect_flags(args) {
// Stage-A flags: emit/source/return only
local flags = { emit: 0, ret: null, source: null, stage_b: 0 }
// Stage-B flags: prefer_cfg/stage3/v1_compat
local flags = { emit: 0, ret: null, source: null, stage_b: 0, prefer_cfg: 1, stage3: 0, v1_compat: 0 }
if args == null { return flags }
local i = 0
@ -48,6 +49,14 @@ static box Main {
local parsed = me._parse_signed_int(args.get(i + 1))
if parsed != null { flags.ret = parsed }
i = i + 1
} else if token == "--prefer-cfg" && i + 1 < n {
local parsed = me._parse_signed_int(args.get(i + 1))
if parsed != null { flags.prefer_cfg = parsed }
i = i + 1
} else if token == "--stage3" {
flags.stage3 = 1
} else if token == "--v1-compat" {
flags.v1_compat = 1
}
i = i + 1
}
@ -469,7 +478,9 @@ static box Main {
main(args) {
local flags = me._collect_flags(args)
if flags.stage_b == 1 {
return StageBMain.main(args)
local json = StageBMain._do_compile_stage_b(flags.source, flags.prefer_cfg, flags.stage3, flags.v1_compat)
print(json)
return 0
}
if flags.emit == 1 {
local json = me._compile_source_to_json_v0(flags.source)
@ -489,4 +500,5 @@ static box Main {
me._emit_program_json(ret)
return 0
}
}

View File

@ -1,9 +1,13 @@
// Stage-B compiler entry — ParserBox → FlowEntry emit-only
using "lang/src/compiler/parser/parser_box.hako" as ParserBox
using "lang/src/compiler/pipeline_v2/flow_entry.hako" as FlowEntryBox
using lang.compiler.parser.box as ParserBox
using lang.compiler.pipeline_v2.flow_entry as FlowEntryBox
static box StageBMain {
_fallback_program() {
return "{\"version\":0,\"kind\":\"Program\",\"body\":[{\"type\":\"Return\",\"expr\":{\"type\":\"Int\",\"value\":0}}]}"
}
_parse_signed_int(raw) {
if raw == null { return null }
local text = "" + raw
@ -52,23 +56,20 @@ static box StageBMain {
return flags
}
main(args) {
local flags = me._collect_flags(args)
local src = flags.source
_do_compile_stage_b(src, prefer_cfg, stage3, v1_compat) {
if src == null || src == "" {
print("{\"version\":0,\"kind\":\"Program\",\"body\":[{\"type\":\"Return\",\"expr\":{\"type\":\"Int\",\"value\":0}}]}")
return 0
return me._fallback_program()
}
local p = new ParserBox()
if flags.stage3 == 1 { p.stage3_enable(1) }
if stage3 == 1 { p.stage3_enable(1) }
p.extract_usings(src)
local usings_json = p.get_usings_json()
p.extract_externs(src)
local externs_json = p.get_externs_json()
local ast_json = p.parse_program2(src)
local prefer = flags.prefer_cfg
local prefer = prefer_cfg
local jv0 = null
if flags.v1_compat == 1 {
if v1_compat == 1 {
jv0 = FlowEntryBox.emit_v1_compat_from_ast_with_meta(ast_json, prefer, externs_json)
}
if jv0 == null || jv0 == "" {
@ -77,9 +78,21 @@ static box StageBMain {
if jv0 == null || jv0 == "" {
jv0 = FlowEntryBox.emit_v0_from_ast(ast_json, prefer)
}
// Attach usings metadata when availableStage-B pipeline consumes via resolver
if jv0 == null || jv0 == "" { jv0 = "{\"version\":0,\"kind\":\"Program\",\"body\":[{\"type\":\"Return\",\"expr\":{\"type\":\"Int\",\"value\":0}}]}" }
print(jv0)
if jv0 == null || jv0 == "" {
jv0 = me._fallback_program()
}
return jv0
}
main(args) {
local flags = me._collect_flags(args)
local src = flags.source
local prefer = flags.prefer_cfg
local stage3 = flags.stage3
local v1_compat = flags.v1_compat
local json = me._do_compile_stage_b(src, prefer, stage3, v1_compat)
if json == null || json == "" { json = me._fallback_program() }
print(json)
return 0
}
}