feat(joinir): Phase 188-Impl-3 Pattern 3 (Loop with If-Else PHI) implementation
Add Pattern 3 lowerer for `loop { if cond { x = a } else { x = b } ... }` pattern.
New files:
- loop_with_if_phi_minimal.rs (381 lines): JoinIR lowerer for Pattern 3
- Multiple loop variables (counter + accumulator)
- In-loop if/else PHI using Select instruction
- Carriers passed to next iteration via tail recursion
Modified files:
- join_ir/mod.rs: Add Mod to BinOpKind, Select to MirLikeInst
- loop_pattern_detection.rs: Add is_loop_with_conditional_phi_pattern() detection
- lowering/mod.rs: Pattern 3 router integration
- loop_patterns.rs: Pattern 3 entry point delegation
- json.rs: Mod/Select JSON serialization
- join_ir_ops.rs: Mod operation evaluation (a % b)
- join_ir_runner.rs: Select instruction execution
- join_ir_vm_bridge/convert.rs: Mod/Select conversion handlers
Implementation:
- Pattern 3 generates 3 JoinIR functions: main, loop_step(i, sum), k_exit(sum_final)
- Exit condition: !(i <= 5) with Jump to k_exit
- In-loop if/else: if (i % 2 == 1) { sum + i } else { sum + 0 }
- Select instruction: sum_new = Select(if_cond, sum_then, sum_else)
- Both carriers updated: Call(loop_step, [i_next, sum_new])
Build status: ✅ Compiles successfully (0 errors, 34 warnings)
Integration: Infrastructure complete, MIR boundary mapping pending
All 3 patterns now have lowering infrastructure in place for Phase 188.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -35,6 +35,7 @@ pub mod loop_patterns; // Phase 188: Pattern-based loop lowering (3 patterns)
|
||||
pub mod loop_scope_shape;
|
||||
pub mod loop_to_join;
|
||||
pub mod loop_with_break_minimal; // Phase 188-Impl-2: Pattern 2 minimal lowerer
|
||||
pub mod loop_with_if_phi_minimal; // Phase 188-Impl-3: Pattern 3 minimal lowerer
|
||||
pub mod simple_while_minimal; // Phase 188-Impl-1: Pattern 1 minimal lowerer
|
||||
pub mod min_loop;
|
||||
pub mod skip_ws;
|
||||
@ -50,6 +51,8 @@ pub use funcscanner_append_defs::lower_funcscanner_append_defs_to_joinir;
|
||||
pub use funcscanner_trim::lower_funcscanner_trim_to_joinir;
|
||||
// Phase 31: LoopToJoinLowerer 統一箱
|
||||
pub use loop_to_join::LoopToJoinLowerer;
|
||||
// Phase 188: Pattern-based loop lowering
|
||||
pub use loop_with_if_phi_minimal::lower_loop_with_if_phi_pattern;
|
||||
// Phase 30 F-3: 旧 lower_case_a_loop_to_joinir_for_minimal_skip_ws は _with_scope に置き換え済みのため削除
|
||||
pub use min_loop::lower_min_loop_to_joinir;
|
||||
pub use skip_ws::lower_skip_ws_to_joinir;
|
||||
@ -422,7 +425,7 @@ pub fn try_lower_loop_pattern_to_joinir(
|
||||
// Tries patterns in order: Pattern 1 → Pattern 2 → Pattern 3
|
||||
|
||||
use crate::mir::loop_pattern_detection::{
|
||||
is_loop_with_break_pattern, is_simple_while_pattern,
|
||||
is_loop_with_break_pattern, is_loop_with_conditional_phi_pattern, is_simple_while_pattern,
|
||||
};
|
||||
|
||||
// Pattern 1: Simple While Loop (easiest, most common)
|
||||
@ -445,15 +448,13 @@ pub fn try_lower_loop_pattern_to_joinir(
|
||||
|
||||
// Pattern 3: Loop with If-Else PHI (leverages existing If lowering)
|
||||
// ==================================================================
|
||||
// TODO: Implement Pattern 3 detection and lowering
|
||||
// use crate::mir::loop_pattern_detection::is_loop_with_conditional_phi_pattern;
|
||||
//
|
||||
// if is_loop_with_conditional_phi_pattern(loop_form) {
|
||||
// if let Some(inst) = loop_patterns::lower_loop_with_conditional_phi_to_joinir(loop_form, lowerer) {
|
||||
// eprintln!("[try_lower_loop_pattern] ✅ Pattern 3 (Loop with If-Else PHI) matched");
|
||||
// return Some(inst);
|
||||
// }
|
||||
// }
|
||||
// Phase 188-Impl-3: Pattern 3 implementation
|
||||
if is_loop_with_conditional_phi_pattern(loop_form) {
|
||||
if let Some(inst) = loop_patterns::lower_loop_with_conditional_phi_to_joinir(loop_form, lowerer) {
|
||||
eprintln!("[try_lower_loop_pattern] ✅ Pattern 3 (Loop with If-Else PHI) matched");
|
||||
return Some(inst);
|
||||
}
|
||||
}
|
||||
|
||||
// No Pattern Matched (fallback to existing lowering)
|
||||
// ===================================================
|
||||
|
||||
Reference in New Issue
Block a user