feat(joinir): Phase 202-B Pattern 3 uses JoinValueSpace
Replace sequential value_counter (0u32) with JoinValueSpace allocator in Pattern 3 (If-PHI) lowering for unified ValueId management. Changes: - loop_with_if_phi_minimal.rs: Replace value_counter with join_value_space.alloc_local() - pattern3_with_if_phi.rs: Create JoinValueSpace and pass to lowerer - loop_patterns/with_if_phi.rs: Update legacy wrapper to use JoinValueSpace Benefits: - Consistent with Pattern 2 implementation (Phase 201) - Prevents ValueId collision in Local region (1000+) - Clean separation: Param region (100-999) vs Local region (1000+) Test status: - All unit tests pass (5/5) - E2E tests pass: loop_if_phi.hako, loop_if_phi_continue.hako 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -101,8 +101,12 @@ impl MirBuilder {
|
||||
// Phase 195: Use unified trace
|
||||
trace::trace().varmap("pattern3_start", &self.variable_map);
|
||||
|
||||
// Phase 202-B: Create JoinValueSpace for unified ValueId allocation
|
||||
use crate::mir::join_ir::lowering::join_value_space::JoinValueSpace;
|
||||
let mut join_value_space = JoinValueSpace::new();
|
||||
|
||||
// Call Pattern 3 lowerer with preprocessed scope
|
||||
let join_module = match lower_loop_with_if_phi_pattern(ctx.loop_scope) {
|
||||
let join_module = match lower_loop_with_if_phi_pattern(ctx.loop_scope, &mut join_value_space) {
|
||||
Some(module) => module,
|
||||
None => {
|
||||
// Phase 195: Use unified trace
|
||||
|
||||
@ -85,6 +85,7 @@ pub fn lower_loop_with_conditional_phi_to_joinir(
|
||||
) -> Option<JoinInst> {
|
||||
// Phase 188-Impl-3: Delegate to minimal lowerer
|
||||
// TODO: Extract LoopScopeShape from loop_form for generic implementation
|
||||
use crate::mir::join_ir::lowering::join_value_space::JoinValueSpace;
|
||||
use crate::mir::join_ir::lowering::loop_scope_shape::LoopScopeShape;
|
||||
use crate::mir::join_ir::lowering::loop_with_if_phi_minimal::lower_loop_with_if_phi_pattern;
|
||||
use crate::mir::BasicBlockId;
|
||||
@ -105,8 +106,11 @@ pub fn lower_loop_with_conditional_phi_to_joinir(
|
||||
variable_definitions: BTreeMap::new(),
|
||||
};
|
||||
|
||||
// Phase 202-B: Create JoinValueSpace for unified ValueId allocation
|
||||
let mut join_value_space = JoinValueSpace::new();
|
||||
|
||||
// Generate JoinIR module
|
||||
let _join_module = lower_loop_with_if_phi_pattern(placeholder_scope)?;
|
||||
let _join_module = lower_loop_with_if_phi_pattern(placeholder_scope, &mut join_value_space)?;
|
||||
|
||||
// Phase 188-Impl-3: Pattern 3 is now integrated via the router
|
||||
// This function delegates to loop_with_if_phi_minimal which generates JoinModule
|
||||
|
||||
@ -67,6 +67,7 @@
|
||||
//!
|
||||
//! Following the "80/20 rule" from CLAUDE.md - get it working first, generalize later.
|
||||
|
||||
use crate::mir::join_ir::lowering::join_value_space::JoinValueSpace;
|
||||
use crate::mir::join_ir::lowering::loop_scope_shape::LoopScopeShape;
|
||||
use crate::mir::join_ir::{
|
||||
BinOpKind, CompareOp, ConstValue, JoinFuncId, JoinFunction, JoinInst, JoinModule,
|
||||
@ -97,6 +98,7 @@ use crate::mir::ValueId;
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `_scope` - LoopScopeShape (reserved for future generic implementation)
|
||||
/// * `join_value_space` - Phase 202-B: Unified JoinIR ValueId allocator (Local region: 1000+)
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
@ -109,15 +111,13 @@ use crate::mir::ValueId;
|
||||
/// - **Input slots**: ValueId(0), ValueId(1) in main function (i_init, sum_init)
|
||||
/// - **Output slot**: k_exit returns the final sum value
|
||||
/// - **Caller responsibility**: Create JoinInlineBoundary to map ValueIds
|
||||
pub(crate) fn lower_loop_with_if_phi_pattern(_scope: LoopScopeShape) -> Option<JoinModule> {
|
||||
// Phase 188-Impl-3: Use local ValueId allocator (sequential from 0)
|
||||
// JoinIR has NO knowledge of host ValueIds - boundary handled separately
|
||||
let mut value_counter = 0u32;
|
||||
let mut alloc_value = || {
|
||||
let id = ValueId(value_counter);
|
||||
value_counter += 1;
|
||||
id
|
||||
};
|
||||
pub(crate) fn lower_loop_with_if_phi_pattern(
|
||||
_scope: LoopScopeShape,
|
||||
join_value_space: &mut JoinValueSpace,
|
||||
) -> Option<JoinModule> {
|
||||
// Phase 202-B: Use JoinValueSpace for unified ValueId allocation
|
||||
// - Local region (1000+) ensures no collision with Param region (100-999)
|
||||
let mut alloc_value = || join_value_space.alloc_local();
|
||||
|
||||
let mut join_module = JoinModule::new();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user