feat(joinir): Phase 202-A Pattern 1 uses JoinValueSpace
Migrated Pattern 1 (Simple While) to use JoinValueSpace for unified ValueId allocation, following the same pattern as Pattern 2 (Phase 201). Changes: - simple_while_minimal.rs: Added join_value_space parameter, replaced value_counter with join_value_space.alloc_local() - pattern1_minimal.rs: Create JoinValueSpace before calling lowerer - loop_view_builder.rs: Create JoinValueSpace in try_pattern1() Pattern 1 uses Local region (1000+) only, since it doesn't need ConditionEnv (no Param region allocation required). Tested: - cargo build --release --lib: Success (0 errors, 4 warnings) - cargo test --release --lib pattern: 119 passed - E2E test apps/tests/loop_min_while.hako: Outputs "0 1 2" correctly 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -28,6 +28,7 @@ pub fn lower(
|
|||||||
|
|
||||||
impl MirBuilder {
|
impl MirBuilder {
|
||||||
/// Phase 179-B: Pattern 1 (Simple While Loop) minimal lowerer
|
/// Phase 179-B: Pattern 1 (Simple While Loop) minimal lowerer
|
||||||
|
/// Phase 202-A: JoinValueSpace Integration
|
||||||
///
|
///
|
||||||
/// **Refactored**: Now uses PatternPipelineContext for unified preprocessing
|
/// **Refactored**: Now uses PatternPipelineContext for unified preprocessing
|
||||||
///
|
///
|
||||||
@ -60,8 +61,13 @@ impl MirBuilder {
|
|||||||
// Phase 195: Use unified trace
|
// Phase 195: Use unified trace
|
||||||
trace::trace().varmap("pattern1_start", &self.variable_map);
|
trace::trace().varmap("pattern1_start", &self.variable_map);
|
||||||
|
|
||||||
|
// Phase 202-A: Create JoinValueSpace for unified ValueId allocation
|
||||||
|
// Pattern 1 uses Local region only (no Param region needed - no ConditionEnv)
|
||||||
|
use crate::mir::join_ir::lowering::join_value_space::JoinValueSpace;
|
||||||
|
let mut join_value_space = JoinValueSpace::new();
|
||||||
|
|
||||||
// Call Pattern 1 lowerer with preprocessed scope
|
// Call Pattern 1 lowerer with preprocessed scope
|
||||||
let join_module = match lower_simple_while_minimal(ctx.loop_scope) {
|
let join_module = match lower_simple_while_minimal(ctx.loop_scope, &mut join_value_space) {
|
||||||
Some(module) => module,
|
Some(module) => module,
|
||||||
None => {
|
None => {
|
||||||
// Phase 195: Use unified trace
|
// Phase 195: Use unified trace
|
||||||
|
|||||||
@ -118,6 +118,8 @@ impl LoopViewBuilder {
|
|||||||
/// - 関数名に "main" が含まれる
|
/// - 関数名に "main" が含まれる
|
||||||
/// - Pinned vars がない
|
/// - Pinned vars がない
|
||||||
/// - Carriers が1つ以上
|
/// - Carriers が1つ以上
|
||||||
|
///
|
||||||
|
/// # Phase 202-A: JoinValueSpace Integration
|
||||||
fn try_pattern1(&self, scope: &LoopScopeShape, name: &str) -> Option<JoinModule> {
|
fn try_pattern1(&self, scope: &LoopScopeShape, name: &str) -> Option<JoinModule> {
|
||||||
if !name.contains("main") {
|
if !name.contains("main") {
|
||||||
return None;
|
return None;
|
||||||
@ -128,7 +130,14 @@ impl LoopViewBuilder {
|
|||||||
eprintln!("[LoopViewBuilder] Trying Pattern 1 lowering for {:?}", name);
|
eprintln!("[LoopViewBuilder] Trying Pattern 1 lowering for {:?}", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(result) = super::simple_while_minimal::lower_simple_while_minimal(scope.clone()) {
|
// Phase 202-A: Create JoinValueSpace for Pattern 1
|
||||||
|
use super::join_value_space::JoinValueSpace;
|
||||||
|
let mut join_value_space = JoinValueSpace::new();
|
||||||
|
|
||||||
|
if let Some(result) = super::simple_while_minimal::lower_simple_while_minimal(
|
||||||
|
scope.clone(),
|
||||||
|
&mut join_value_space,
|
||||||
|
) {
|
||||||
if self.debug {
|
if self.debug {
|
||||||
eprintln!("[LoopViewBuilder] Pattern 1 lowering succeeded for {:?}", name);
|
eprintln!("[LoopViewBuilder] Pattern 1 lowering succeeded for {:?}", name);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,21 +42,21 @@
|
|||||||
//!
|
//!
|
||||||
//! Following the "80/20 rule" from CLAUDE.md - get it working first, generalize later.
|
//! 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::lowering::loop_scope_shape::LoopScopeShape;
|
||||||
use crate::mir::join_ir::{
|
use crate::mir::join_ir::{
|
||||||
BinOpKind, CompareOp, ConstValue, JoinFuncId, JoinFunction, JoinInst, JoinModule,
|
BinOpKind, CompareOp, ConstValue, JoinFuncId, JoinFunction, JoinInst, JoinModule,
|
||||||
MirLikeInst, UnaryOp,
|
MirLikeInst, UnaryOp,
|
||||||
};
|
};
|
||||||
use crate::mir::ValueId;
|
|
||||||
|
|
||||||
|
|
||||||
/// Lower Pattern 1 (Simple While Loop) to JoinIR
|
/// Lower Pattern 1 (Simple While Loop) to JoinIR
|
||||||
///
|
///
|
||||||
/// # Phase 188-Impl-3: Pure JoinIR Fragment Generation
|
/// # Phase 188-Impl-3: Pure JoinIR Fragment Generation
|
||||||
|
/// # Phase 202-A: JoinValueSpace Integration
|
||||||
///
|
///
|
||||||
/// This version generates JoinIR using **local ValueIds only** (0, 1, 2, ...).
|
/// This version generates JoinIR using **JoinValueSpace** for unified ValueId allocation.
|
||||||
/// It has NO knowledge of the host function's ValueId space. The boundary mapping
|
/// It uses the Local region (1000+) to avoid collision with Param region (100-999).
|
||||||
/// is handled separately via JoinInlineBoundary.
|
|
||||||
///
|
///
|
||||||
/// ## Design Philosophy
|
/// ## Design Philosophy
|
||||||
///
|
///
|
||||||
@ -73,6 +73,7 @@ use crate::mir::ValueId;
|
|||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `_scope` - LoopScopeShape (reserved for future generic implementation)
|
/// * `_scope` - LoopScopeShape (reserved for future generic implementation)
|
||||||
|
/// * `join_value_space` - Unified ValueId allocator (Phase 202-A)
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
@ -84,15 +85,13 @@ use crate::mir::ValueId;
|
|||||||
/// This function returns a JoinModule with:
|
/// This function returns a JoinModule with:
|
||||||
/// - **Input slot**: ValueId(0) in loop_step function represents the loop variable
|
/// - **Input slot**: ValueId(0) in loop_step function represents the loop variable
|
||||||
/// - **Caller responsibility**: Create JoinInlineBoundary to map ValueId(0) to host's loop var
|
/// - **Caller responsibility**: Create JoinInlineBoundary to map ValueId(0) to host's loop var
|
||||||
pub(crate) fn lower_simple_while_minimal(_scope: LoopScopeShape) -> Option<JoinModule> {
|
pub(crate) fn lower_simple_while_minimal(
|
||||||
// Phase 188-Impl-3: Use local ValueId allocator (sequential from 0)
|
_scope: LoopScopeShape,
|
||||||
// JoinIR has NO knowledge of host ValueIds - boundary handled separately
|
join_value_space: &mut JoinValueSpace,
|
||||||
let mut value_counter = 0u32;
|
) -> Option<JoinModule> {
|
||||||
let mut alloc_value = || {
|
// Phase 202-A: Use JoinValueSpace for Local region allocation (1000+)
|
||||||
let id = ValueId(value_counter);
|
// This ensures no collision with Param region (100-999) used by ConditionEnv/CarrierInfo
|
||||||
value_counter += 1;
|
let mut alloc_value = || join_value_space.alloc_local();
|
||||||
id
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut join_module = JoinModule::new();
|
let mut join_module = JoinModule::new();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user