Phase 123 proper完了:hako_check JoinIR実装(環境変数選択可能化)
## 実装内容 ### 1. 環境変数フラグ追加 - NYASH_HAKO_CHECK_JOINIR でJoinIR/Legacy経路を切り替え可能 - src/config/env/hako_check.rs で hako_check_joinir_enabled() 実装 - デフォルト: false(レガシー経路)で後方互換性確保 ### 2. MIR Builder JoinIR スイッチ - cf_if() メソッドにフラグチェック追加 - try_cf_if_joinir() プレースホルダー実装(Phase 124で完全実装) - JoinIR → legacy フォールバック機構を構築 ### 3. テストケース作成(4個) - phase123_simple_if.hako - phase123_nested_if.hako - phase123_while_loop.hako - phase123_if_in_loop.hako ### 4. テスト結果 ✅ Legacy path: 4/4 PASS ✅ JoinIR path: 4/4 PASS (JoinIR path は現在フォールバック経由で動作) ### 5. ドキュメント更新 - environment-variables.md: NYASH_HAKO_CHECK_JOINIR 記載 - phase121_hako_check_joinir_design.md: Phase 123実装セクション追加 - hako_check_design.md: 2パス実行フロー図を追加 - CURRENT_TASK.md: Phase 123完了を記録 ## 数値成果 - 新規ファイル: 2個 (config/env/hako_check.rs, test cases × 4, test script) - 修正ファイル: 6個 - 総追加行数: 335行 - ビルド: Zero errors ## 設計・実装の特徴 ✅ Environment variable で簡単に経路切り替え可能 ✅ レガシー経路を完全に保持(後方互換性) ✅ JoinIR基盤を Phase 124 での完全実装に向けて構築 ✅ フォールバック機構でリスク最小化 ## 次のステップ Phase 124: JoinIR 完全実装&デフォルト化 - try_cf_if_joinir() を IfSelectLowerer と統合 - Loop JoinIR 統合追加 - JoinIR をデフォルト経路に変更 - NYASH_LEGACY_PHI=1 で legacy フォールバック可能に 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -10,16 +10,83 @@ impl super::MirBuilder {
|
||||
}
|
||||
|
||||
/// Control-flow: if
|
||||
///
|
||||
/// # Phase 123: hako_check JoinIR Integration
|
||||
///
|
||||
/// When NYASH_HAKO_CHECK_JOINIR=1 is set, if statements will be routed through
|
||||
/// JoinIR lowering path instead of the legacy PHI generation path.
|
||||
///
|
||||
/// Default: legacy path (for backward compatibility)
|
||||
/// Phase 124: JoinIR will become the default
|
||||
pub(super) fn cf_if(
|
||||
&mut self,
|
||||
condition: ASTNode,
|
||||
then_branch: ASTNode,
|
||||
else_branch: Option<ASTNode>,
|
||||
) -> Result<ValueId, String> {
|
||||
// Phase 123: Check hako_check JoinIR flag
|
||||
let use_joinir = crate::config::env::hako_check_joinir_enabled();
|
||||
|
||||
if use_joinir {
|
||||
let debug = std::env::var("NYASH_HAKO_CHECK_JOINIR_DEBUG").is_ok();
|
||||
if debug {
|
||||
eprintln!("[cf_if/joinir] Routing if statement through JoinIR lowering");
|
||||
}
|
||||
|
||||
// Phase 123: For now, try JoinIR path and fallback to legacy if needed
|
||||
// Phase 124 will make this strict (no fallback)
|
||||
match self.try_cf_if_joinir(&condition, &then_branch, &else_branch, debug) {
|
||||
Ok(Some(value)) => {
|
||||
if debug {
|
||||
eprintln!("[cf_if/joinir] Successfully lowered through JoinIR");
|
||||
}
|
||||
return Ok(value);
|
||||
}
|
||||
Ok(None) => {
|
||||
if debug {
|
||||
eprintln!("[cf_if/joinir] JoinIR not applicable, falling back to legacy");
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
if debug {
|
||||
eprintln!("[cf_if/joinir] JoinIR error: {}, falling back to legacy", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// current impl is a simple forward to canonical lowering
|
||||
self.lower_if_form(condition, then_branch, else_branch)
|
||||
}
|
||||
|
||||
/// Phase 123: Try JoinIR lowering for if statements
|
||||
///
|
||||
/// Returns:
|
||||
/// - Ok(Some(value)): Successfully lowered through JoinIR
|
||||
/// - Ok(None): JoinIR not applicable (pattern not recognized)
|
||||
/// - Err(e): JoinIR error
|
||||
fn try_cf_if_joinir(
|
||||
&mut self,
|
||||
_condition: &ASTNode,
|
||||
_then_branch: &ASTNode,
|
||||
_else_branch: &Option<ASTNode>,
|
||||
_debug: bool,
|
||||
) -> Result<Option<ValueId>, String> {
|
||||
// Phase 123: Placeholder for JoinIR if lowering
|
||||
// The actual JoinIR lowering requires a complete function to work on,
|
||||
// so we need to build the MIR first and then apply lowering.
|
||||
// For Phase 123, we'll return None to fallback to legacy path.
|
||||
// Phase 124 will implement the full JoinIR integration.
|
||||
|
||||
// TODO Phase 124: Implement actual JoinIR if lowering here
|
||||
// This will require:
|
||||
// 1. Build if statement with legacy path
|
||||
// 2. Apply JoinIR IfSelectLowerer to the resulting MIR
|
||||
// 3. Return the lowered result
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
/// Control-flow: loop
|
||||
///
|
||||
/// # Phase 49: JoinIR Frontend Mainline Integration
|
||||
|
||||
Reference in New Issue
Block a user