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

@ -5,11 +5,8 @@
* Replaces 6 different call instructions with a single unified system
*/
use crate::mir::{Callee, Effect, EffectMask, ValueId};
use crate::mir::definitions::call_unified::{CallFlags, MirCall, TypeCertainty};
use super::call_target::CallTarget;
use super::method_resolution;
use super::extern_calls;
use crate::mir::{Callee, EffectMask, ValueId};
use crate::mir::definitions::call_unified::{CallFlags, MirCall};
/// Check if unified call system is enabled
pub fn is_unified_call_enabled() -> bool {

View File

@ -5,9 +5,9 @@
//! - emit_legacy_call: レガシーCall発行既存互換
//! - emit_global_call/emit_method_call/emit_constructor_call: 便利ラッパー
use super::super::{Effect, EffectMask, MirBuilder, MirInstruction, ValueId};
use super::super::{EffectMask, MirBuilder, MirInstruction, ValueId};
use crate::mir::definitions::call_unified::Callee;
use super::{CallTarget, call_unified};
use super::CallTarget;
impl MirBuilder {
/// Unified call emission - delegates to UnifiedCallEmitterBox
@ -139,6 +139,7 @@ impl MirBuilder {
// ========================================
/// Try fallback handlers for global functions (delegates to CallMaterializerBox)
#[allow(dead_code)]
pub(super) fn try_global_fallback_handlers(
&mut self,
dst: Option<ValueId>,
@ -149,6 +150,7 @@ impl MirBuilder {
}
/// Ensure receiver is materialized in Callee::Method (delegates to CallMaterializerBox)
#[allow(dead_code)]
pub(super) fn materialize_receiver_in_callee(
&mut self,
callee: Callee,

View File

@ -155,6 +155,7 @@ pub fn parse_extern_name(name: &str) -> (String, String) {
}
/// Check if a name refers to an environment interface
#[allow(dead_code)]
pub fn is_env_interface(name: &str) -> bool {
matches!(name,
"env" | "env.console" | "env.fs" | "env.net" |

View File

@ -1,3 +1,5 @@
#![allow(dead_code)]
/*!
* Function Lowering Utilities
*
@ -147,4 +149,4 @@ pub fn method_likely_returns_value(method_name: &str) -> bool {
"add" | "sub" | "mul" | "div" |
"min" | "max" | "abs"
)
}
}

View File

@ -96,6 +96,7 @@ impl<'a> CalleeGuardBox<'a> {
/// receiver型の検証ヘルパー
///
/// 指定されたreceiverがBox型を持っているか確認
#[allow(dead_code)]
pub fn has_box_type(&self, receiver: ValueId) -> bool {
matches!(self.value_types.get(&receiver), Some(MirType::Box(_)))
}
@ -103,6 +104,7 @@ impl<'a> CalleeGuardBox<'a> {
/// receiver型の取得ヘルパー
///
/// 指定されたreceiverのBox型名を返す存在しない場合はNone
#[allow(dead_code)]
pub fn get_box_type(&self, receiver: ValueId) -> Option<&String> {
match self.value_types.get(&receiver) {
Some(MirType::Box(box_name)) => Some(box_name),
@ -114,6 +116,7 @@ impl<'a> CalleeGuardBox<'a> {
///
/// box_name と receiver型が一致するか判定
/// (静的メソッド呼び出しの検出用)
#[allow(dead_code)]
pub fn is_me_call(&self, box_name: &str, receiver: ValueId) -> bool {
match self.get_box_type(receiver) {
Some(recv_box) => recv_box == box_name,

View File

@ -28,8 +28,13 @@ pub mod effects_analyzer; // Phase 3-B: Effects analyzer (エフェクト解析
pub mod materializer; // Phase 3-C: Call materializer (Call前処理・準備専用箱)
// Re-export public interfaces
#[allow(unused_imports)]
pub use call_target::CallTarget;
#[allow(unused_imports)]
pub use lowering::*;
#[allow(unused_imports)]
pub use utils::*;
#[allow(unused_imports)]
pub use emit::*;
#[allow(unused_imports)]
pub use build::*;

View File

@ -1,3 +1,5 @@
#![allow(dead_code)]
/*!
* Special Call Handlers
*
@ -137,4 +139,4 @@ pub fn suggest_alternative_for_reserved(name: &str) -> String {
"from" => "Use 'from Parent.method()' syntax for delegation".to_string(),
_ => format!("'{}' is a reserved keyword", name),
}
}
}