feat(mir): Phase 25.1f完了 - Conservative PHI + ControlForm観測レイヤー

🎉 Conservative PHI Box理論による完全SSA構築

**Phase 7-B: Conservative PHI実装**
- 片方branchのみ定義変数に対応(emit_void使用)
- 全変数にPHI生成(Conservative Box理論)
- Stage-1 resolver全テスト緑化(3/3 PASS)

**Phase 25.1f: ControlForm観測レイヤー**
- LoopShape/IfShape/ControlForm構造定義
- Loop/If統一インターフェース実装
- debug_dump/debug_validate機能追加
- NYASH_CONTROL_FORM_TRACE環境変数対応

**主な変更**:
- src/mir/builder/phi.rs: Conservative PHI実装
- src/mir/control_form.rs: ControlForm構造(NEW)
- src/mir/loop_builder.rs: LoopForm v2デフォルト化

**テスト結果**:
 mir_stage1_using_resolver_min_fragment_verifies
 mir_stage1_using_resolver_full_collect_entries_verifies
 mir_parserbox_parse_program2_harness_parses_minimal_source

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: ChatGPT <chatgpt@openai.com>
This commit is contained in:
nyash-codex
2025-11-18 18:56:35 +09:00
parent 8b37e9711d
commit d3cbc71c9b
81 changed files with 907 additions and 147 deletions

View File

@ -2,7 +2,7 @@ use super::ast::{ProgramV0, StmtV0, ExprV0};
use crate::mir::Callee;
use crate::mir::{
BasicBlockId, ConstValue, EffectMask, FunctionSignature, MirFunction, MirInstruction, MirModule,
MirPrinter, MirType, ValueId, BinaryOp,
MirPrinter, MirType, ValueId,
};
use std::collections::HashMap;
use std::cell::RefCell;
@ -103,6 +103,7 @@ pub(super) struct BridgeEnv {
}
impl BridgeEnv {
#[allow(dead_code)]
pub(super) fn load() -> Self {
Self::with_imports(HashMap::new())
}

View File

@ -3,7 +3,7 @@ use super::BridgeEnv;
use super::ternary;
use super::match_expr;
use crate::mir::{
BasicBlockId, BinaryOp, ConstValue, EffectMask, MirFunction, MirInstruction, ValueId,
BasicBlockId, ConstValue, EffectMask, MirFunction, MirInstruction, ValueId,
};
use std::collections::HashMap;

View File

@ -1,5 +1,5 @@
use super::{lower_stmt_list_with_vars, merge_var_maps, new_block, BridgeEnv, LoopContext};
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
use crate::mir::{BasicBlockId, MirFunction, ValueId};
use std::collections::HashMap;
use super::super::ast::StmtV0;
use super::super::ast::ExprV0;

View File

@ -5,7 +5,7 @@
use super::merge::new_block;
use super::BridgeEnv;
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
use crate::mir::{BasicBlockId, MirFunction, ValueId};
use super::super::ast::ExprV0;
use super::expr::{lower_expr_with_scope, VarScope};
@ -35,7 +35,7 @@ pub(super) fn lower_ternary_expr_with_scope<S: VarScope>(
}
let out = f.next_value_id();
// フェーズM.2: PHI統一処理no_phi分岐削除
let mut inputs = vec![(tend, tval), (eend, eval)];
let inputs = vec![(tend, tval), (eend, eval)];
crate::mir::ssot::cf_common::insert_phi_at_head(f, merge_bb, out, inputs);
Ok((out, merge_bb))
}

View File

@ -1,4 +1,4 @@
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
use crate::mir::{BasicBlockId, MirFunction, ValueId};
use std::cell::RefCell;
thread_local! {