Files
hakorune/src/mir/builder/control_flow/joinir/patterns/mod.rs
nyash-codex b6ed6295a3 refactor(joinir): Move Trim logic from Pattern2 to TrimLoopLowerer
Phase 180-3: Extract Pattern2 Trim/P5 logic to dedicated module

Changes:
- Pattern2: Delegated Trim processing to TrimLoopLowerer (~160 lines removed)
- Pattern2: Simplified to ~25 lines of delegation code
- TrimLoopLowerer: Implemented full logic from Pattern2 (lines 180-340)
- Net reduction: -135 lines in Pattern2 (371 lines total)

Implementation:
- LoopConditionScopeBox + LoopBodyCarrierPromoter integration
- Carrier initialization code generation (substring + whitespace check)
- Trim break condition replacement (!is_carrier)
- ConditionEnv bindings setup (carrier + original variable)

Testing:
- cargo build --release: SUCCESS (0 errors, warnings only)
- All existing Pattern2 tests: PASS
- No behavior changes, refactoring only
2025-12-08 21:07:39 +09:00

60 lines
2.8 KiB
Rust

//! Pattern lowerers for different loop constructs
//!
//! Phase 2: Extracted from control_flow.rs
//! - Pattern 1: Simple While Loop (pattern1_minimal.rs)
//! - Pattern 2: Loop with Conditional Break (pattern2_with_break.rs)
//! - Pattern 3: Loop with If-Else PHI (pattern3_with_if_phi.rs)
//! - Pattern 4: Loop with Continue (pattern4_with_continue.rs) [Phase 194+]
//!
//! Phase 194: Table-driven router for pattern dispatch
//! - Router module provides table-driven pattern matching
//! - Each pattern exports can_lower() and lower() functions
//! - See router.rs for how to add new patterns
//!
//! Phase 193: AST Feature Extraction Modularization
//! - ast_feature_extractor.rs: Pure function module for analyzing loop AST
//! - High reusability for Pattern 5-6 and pattern analysis tools
//!
//! Phase 193-4: Exit Binding Builder
//! - exit_binding.rs: Fully boxified exit binding generation
//! - Eliminates hardcoded variable names and ValueId assumptions
//! - Supports both single and multi-carrier loop patterns
//!
//! Phase 33-22: Common Pattern Infrastructure
//! - common_init.rs: CommonPatternInitializer for unified initialization
//! - conversion_pipeline.rs: JoinIRConversionPipeline for unified conversion flow
//!
//! Phase 171-172: Refactoring Infrastructure
//! - loop_scope_shape_builder.rs: Unified LoopScopeShape initialization (Issue 4)
//! - condition_env_builder.rs: Unified ConditionEnv construction (Issue 5)
//!
//! Phase 33-23: Pattern-Specific Analyzers (Stage 2)
//! - pattern4_carrier_analyzer.rs: Pattern 4 carrier analysis and normalization (Issue 2)
//!
//! Stage 3 + Issue 1: Trim Pattern Extraction
//! - trim_pattern_validator.rs: Trim pattern validation and whitespace check generation
//! - trim_pattern_lowerer.rs: Trim-specific JoinIR lowering
//!
//! Phase 179-B: Generic Pattern Framework
//! - pattern_pipeline.rs: Unified preprocessing pipeline for Patterns 1-4
pub(in crate::mir::builder) mod ast_feature_extractor;
pub(in crate::mir::builder) mod common_init;
pub(in crate::mir::builder) mod condition_env_builder;
pub(in crate::mir::builder) mod conversion_pipeline;
pub(in crate::mir::builder) mod exit_binding;
pub(in crate::mir::builder) mod loop_scope_shape_builder;
pub(in crate::mir::builder) mod pattern_pipeline;
pub(in crate::mir::builder) mod pattern1_minimal;
pub(in crate::mir::builder) mod pattern2_with_break;
pub(in crate::mir::builder) mod pattern3_with_if_phi;
pub(in crate::mir::builder) mod pattern4_carrier_analyzer;
pub(in crate::mir::builder) mod pattern4_with_continue;
pub(in crate::mir::builder) mod router;
pub(in crate::mir::builder) mod trim_loop_lowering; // Phase 180: Dedicated Trim/P5 lowering module
pub(in crate::mir::builder) mod trim_pattern_validator;
pub(in crate::mir::builder) mod trim_pattern_lowerer;
// Re-export router for convenience
pub(in crate::mir::builder) use router::{route_loop_pattern, LoopPatternContext};