Phase 33-2: JoinInst::Select implementation + minimal If JoinIR lowering
Implementation:
- Add JoinInst::Select variant to JoinIR schema
- Implement Select execution in JoinIR Runner (Bool/Int cond support)
- Add Select handling in JoinIR→MIR Bridge (4-block structure)
- Create test cases (joinir_if_select_simple/local.hako)
- Add dev toggle NYASH_JOINIR_IF_SELECT=1
- Create lowering infrastructure (if_select.rs, stub for Phase 33-3)
Tests:
- 3/3 unit tests pass (test_select_true/false/int_cond)
- Integration tests pass (RC: 0)
- A/B execution verified (existing if_phi vs JoinIR Select)
Files changed:
- New: apps/tests/joinir_if_select_{simple,local}.hako
- New: src/mir/join_ir/lowering/if_select.rs
- Modified: src/mir/join_ir/{mod,json,runner,vm_bridge}.rs
- Modified: src/config/env.rs (joinir_if_select_enabled)
- Modified: docs/reference/environment-variables.md
Phase 33-3 ready: MIR pattern recognition + auto-lowering pending
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
46
src/mir/join_ir/lowering/if_select.rs
Normal file
46
src/mir/join_ir/lowering/if_select.rs
Normal file
@ -0,0 +1,46 @@
|
||||
//! Phase 33: If/Else の Select 命令への lowering
|
||||
//!
|
||||
//! 最小の if/else(副作用なし、単純な値選択)を JoinInst::Select に変換する。
|
||||
|
||||
use crate::mir::join_ir::JoinInst;
|
||||
use crate::mir::{BasicBlockId, MirFunction};
|
||||
|
||||
pub struct IfSelectLowerer {
|
||||
debug: bool,
|
||||
}
|
||||
|
||||
impl IfSelectLowerer {
|
||||
pub fn new(debug: bool) -> Self {
|
||||
Self { debug }
|
||||
}
|
||||
|
||||
/// if/else が Select に lowering できるかチェック
|
||||
pub fn can_lower_to_select(&self, _func: &MirFunction, _if_block_id: BasicBlockId) -> bool {
|
||||
// パターン:
|
||||
// 1. if_block に Branch がある
|
||||
// 2. then/else ブロックが存在
|
||||
// 3. merge ブロックに 1 つの PHI がある
|
||||
// 4. PHI の incoming が then/else から来ている
|
||||
|
||||
// 実装: Phase 33-2 では保守的に false を返す(フォールバック)
|
||||
// Phase 33-3 で実装予定
|
||||
if self.debug {
|
||||
eprintln!("[joinir/if_select] can_lower_to_select: Phase 33-2 stub (always false)");
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// if/else を Select に変換
|
||||
pub fn lower_if_to_select(
|
||||
&self,
|
||||
_func: &MirFunction,
|
||||
_if_block_id: BasicBlockId,
|
||||
) -> Option<JoinInst> {
|
||||
// 実装: Phase 33-2 では None を返す(フォールバック)
|
||||
// Phase 33-3 で実装予定
|
||||
if self.debug {
|
||||
eprintln!("[joinir/if_select] lower_if_to_select: Phase 33-2 stub (always None)");
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
@ -12,12 +12,14 @@
|
||||
//! - `funcscanner_trim.rs`: FuncScannerBox.trim/1 の trim lowering
|
||||
//! - `stage1_using_resolver.rs`: Stage1UsingResolverBox.resolve_for_source entries loop lowering(Phase 27.12)
|
||||
//! - `funcscanner_append_defs.rs`: FuncScannerBox._append_defs/2 の配列結合 lowering(Phase 27.14)
|
||||
//! - `if_select.rs`: Phase 33 If/Else → Select lowering
|
||||
|
||||
pub mod common;
|
||||
pub mod exit_args_resolver;
|
||||
pub mod funcscanner_append_defs;
|
||||
pub mod funcscanner_trim;
|
||||
pub mod generic_case_a;
|
||||
pub mod if_select; // Phase 33
|
||||
pub mod loop_form_intake;
|
||||
pub mod loop_scope_shape;
|
||||
pub mod loop_to_join;
|
||||
|
||||
Reference in New Issue
Block a user