feat(joinir): Phase 61-1 If-in-loop JoinIR化インフラ整備完了

## 実装内容

### 新規ファイル
- `if_phi_context.rs`: If-in-loop用PHIコンテキスト構造体 (135行)
  - `IfPhiContext::for_loop_body()`: ループ内if用コンストラクタ
  - `is_carrier()`: ループキャリア変数判定
  - 単体テスト2個完全動作

### 既存ファイル拡張
- `if_select.rs`, `if_merge.rs`: context パラメータ追加 (+68行)
  - `with_context()` コンストラクタ実装
  - Pure If との完全互換性維持
- `mod.rs`: `try_lower_if_to_joinir()` シグネチャ拡張 (+25行)
  - `context: Option<&IfPhiContext>` パラメータ追加
  - 既存呼び出し箇所6箇所修正完了
- `loop_builder.rs`: JoinIR経路実装 (+43行)
  - `NYASH_JOINIR_IF_SELECT=1` で試行
  - フォールバック設計(PhiBuilderBox経路保持)
  - デバッグログ完備

## テスト結果
-  loopform テスト 14/14 PASS(退行なし)
-  ビルド成功(エラー0件)
-  Borrow Checker 問題解決

## コード変更量
- 新規: +135行
- 拡張: +136行
- 削除: -18行
- 純増: +253行(インフラ投資、Phase 61-3で-226行削減予定)

## 次のステップ
Phase 61-2: join_inst dry-run実装で実際のPHI生成を行う

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-11-29 11:53:57 +09:00
parent 540f503c24
commit 3ea397fd3e
8 changed files with 292 additions and 33 deletions

View File

@ -13,8 +13,13 @@
use crate::mir::join_ir::JoinInst;
use crate::mir::{BasicBlockId, MirFunction, MirInstruction, ValueId};
// Phase 61-1: If-in-loop context support
use super::if_phi_context::IfPhiContext;
pub struct IfSelectLowerer {
debug_level: u8,
// Phase 61-1: If-in-loop context (None = Pure If)
context: Option<IfPhiContext>,
}
/// If/Else パターンの分類
@ -46,13 +51,37 @@ struct IfBranch {
impl IfSelectLowerer {
pub fn new(debug_level: u8) -> Self {
Self { debug_level }
Self {
debug_level,
context: None, // Phase 61-1: デフォルトは Pure If
}
}
/// Phase 33-8: debug-level backward compat wrapper
pub fn with_debug(debug: bool) -> Self {
Self {
debug_level: if debug { 1 } else { 0 },
context: None, // Phase 61-1: デフォルトは Pure If
}
}
/// Phase 61-1: If-in-loop 用コンストラクタ
///
/// # Arguments
///
/// * `debug_level` - デバッグログレベル (0-3)
/// * `context` - If-in-loop コンテキストcarrier_names 情報を含む)
///
/// # Example
///
/// ```ignore
/// let context = IfPhiContext::for_loop_body(carrier_names);
/// let lowerer = IfSelectLowerer::with_context(debug_level, context);
/// ```
pub fn with_context(debug_level: u8, context: IfPhiContext) -> Self {
Self {
debug_level,
context: Some(context),
}
}