2025-12-05 20:45:23 +09:00
|
|
|
//! 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)
|
2025-12-06 00:10:27 +09:00
|
|
|
//! - Pattern 4: Loop with Continue (pattern4_with_continue.rs) [Phase 194+]
|
2025-12-05 22:11:39 +09:00
|
|
|
//!
|
|
|
|
|
//! 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
|
2025-12-06 03:30:03 +09:00
|
|
|
//!
|
|
|
|
|
//! 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
|
2025-12-06 11:09:03 +09:00
|
|
|
//!
|
2025-12-10 13:59:23 +09:00
|
|
|
//! Phase 193-4 / Phase 222.5-C: Exit Binding Builder
|
|
|
|
|
//! - exit_binding.rs: Fully boxified exit binding generation (orchestrator)
|
|
|
|
|
//! - exit_binding_validator.rs: CarrierInfo and ExitMeta validation
|
|
|
|
|
//! - exit_binding_constructor.rs: Exit binding construction and ValueId allocation
|
|
|
|
|
//! - exit_binding_applicator.rs: Boundary application logic
|
2025-12-06 11:09:03 +09:00
|
|
|
//! - Eliminates hardcoded variable names and ValueId assumptions
|
|
|
|
|
//! - Supports both single and multi-carrier loop patterns
|
2025-12-07 21:02:20 +09:00
|
|
|
//!
|
|
|
|
|
//! Phase 33-22: Common Pattern Infrastructure
|
|
|
|
|
//! - common_init.rs: CommonPatternInitializer for unified initialization
|
|
|
|
|
//! - conversion_pipeline.rs: JoinIRConversionPipeline for unified conversion flow
|
2025-12-08 03:39:46 +09:00
|
|
|
//!
|
|
|
|
|
//! Phase 171-172: Refactoring Infrastructure
|
|
|
|
|
//! - loop_scope_shape_builder.rs: Unified LoopScopeShape initialization (Issue 4)
|
2025-12-08 03:48:18 +09:00
|
|
|
//! - condition_env_builder.rs: Unified ConditionEnv construction (Issue 5)
|
2025-12-08 04:00:44 +09:00
|
|
|
//!
|
|
|
|
|
//! Phase 33-23: Pattern-Specific Analyzers (Stage 2)
|
|
|
|
|
//! - pattern4_carrier_analyzer.rs: Pattern 4 carrier analysis and normalization (Issue 2)
|
2025-12-08 04:14:28 +09:00
|
|
|
//!
|
|
|
|
|
//! 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
|
2025-12-08 19:32:04 +09:00
|
|
|
//!
|
|
|
|
|
//! Phase 179-B: Generic Pattern Framework
|
|
|
|
|
//! - pattern_pipeline.rs: Unified preprocessing pipeline for Patterns 1-4
|
2025-12-05 20:45:23 +09:00
|
|
|
|
2025-12-06 03:30:03 +09:00
|
|
|
pub(in crate::mir::builder) mod ast_feature_extractor;
|
2025-12-07 21:02:20 +09:00
|
|
|
pub(in crate::mir::builder) mod common_init;
|
2025-12-08 03:48:18 +09:00
|
|
|
pub(in crate::mir::builder) mod condition_env_builder;
|
2025-12-07 21:02:20 +09:00
|
|
|
pub(in crate::mir::builder) mod conversion_pipeline;
|
2025-12-06 11:09:03 +09:00
|
|
|
pub(in crate::mir::builder) mod exit_binding;
|
2025-12-11 20:54:33 +09:00
|
|
|
pub(in crate::mir::builder) mod exit_binding_applicator; // Phase 222.5-C
|
|
|
|
|
pub(in crate::mir::builder) mod exit_binding_constructor; // Phase 222.5-C
|
|
|
|
|
pub(in crate::mir::builder) mod exit_binding_validator; // Phase 222.5-C
|
2025-12-08 03:39:46 +09:00
|
|
|
pub(in crate::mir::builder) mod loop_scope_shape_builder;
|
2025-12-05 20:45:23 +09:00
|
|
|
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;
|
2025-12-08 04:00:44 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern4_carrier_analyzer;
|
2025-12-06 00:10:27 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern4_with_continue;
|
2025-12-14 09:59:34 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern5_infinite_early_exit; // Phase 131-11
|
2025-12-11 20:54:33 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern_pipeline;
|
2025-12-05 22:11:39 +09:00
|
|
|
pub(in crate::mir::builder) mod router;
|
2025-12-08 21:07:39 +09:00
|
|
|
pub(in crate::mir::builder) mod trim_loop_lowering; // Phase 180: Dedicated Trim/P5 lowering module
|
2025-12-08 04:14:28 +09:00
|
|
|
pub(in crate::mir::builder) mod trim_pattern_lowerer;
|
2025-12-11 20:54:33 +09:00
|
|
|
pub(in crate::mir::builder) mod trim_pattern_validator;
|
2025-12-05 22:11:39 +09:00
|
|
|
|
|
|
|
|
// Re-export router for convenience
|
|
|
|
|
pub(in crate::mir::builder) use router::{route_loop_pattern, LoopPatternContext};
|
2025-12-16 07:09:22 +09:00
|
|
|
|
|
|
|
|
// Phase 140-P4-A: Re-export for loop_canonicalizer SSOT (crate-wide visibility)
|
|
|
|
|
pub(crate) use ast_feature_extractor::{detect_skip_whitespace_pattern, SkipWhitespaceInfo};
|
2025-12-16 09:08:37 +09:00
|
|
|
|
|
|
|
|
// Phase 142-P1: Re-export continue pattern detection for loop_canonicalizer
|
|
|
|
|
pub(crate) use ast_feature_extractor::{detect_continue_pattern, ContinuePatternInfo};
|
|
|
|
|
|
|
|
|
|
// Phase 143-P0: Re-export parse_number pattern detection for loop_canonicalizer
|
|
|
|
|
pub(crate) use ast_feature_extractor::{detect_parse_number_pattern, ParseNumberInfo};
|
feat(mir): Phase 143 P1 - Add parse_string pattern to canonicalizer
Expand loop canonicalizer to recognize parse_string patterns with both
continue (escape handling) and return (quote found) statements.
## Implementation
### New Pattern Detection (ast_feature_extractor.rs)
- Add `detect_parse_string_pattern()` function
- Support nested continue detection using `has_continue_node()` helper
- Recognize both return and continue in same loop body
- Return ParseStringInfo { carrier_name, delta, body_stmts }
- ~120 lines added
### Canonicalizer Integration (canonicalizer.rs)
- Try parse_string pattern first (most specific)
- Build LoopSkeleton with HeaderCond, Body, Update steps
- Set ExitContract: has_continue=true, has_return=true
- Route to Pattern4Continue (both exits present)
- ~45 lines modified
### Export Chain
- Add re-exports through 7 module levels:
ast_feature_extractor → patterns → joinir → control_flow → builder → mir
- 10 lines total across 7 files
### Unit Test
- Add `test_parse_string_pattern_recognized()` in canonicalizer.rs
- Verify skeleton structure (3+ steps)
- Verify carrier (name="p", delta=1, role=Counter)
- Verify exit contract (continue=true, return=true, break=false)
- Verify routing decision (Pattern4Continue, no missing_caps)
- ~180 lines added
## Target Pattern
`tools/selfhost/test_pattern4_parse_string.hako`
Pattern structure:
- Check for closing quote → return
- Check for escape sequence → continue (nested inside another if)
- Regular character processing → p++
## Results
- ✅ Strict parity green: Pattern4Continue
- ✅ All 19 unit tests pass
- ✅ Nested continue detection working
- ✅ ExitContract correctly set (first pattern with both continue+return)
- ✅ Default behavior unchanged
## Technical Challenges
1. Nested continue detection required recursive search
2. First pattern with both has_continue=true AND has_return=true
3. Variable step updates (p++ vs p+=2) handled with base delta
## Statistics
- New patterns: 1 (parse_string)
- Total patterns: 4 (skip_whitespace, parse_number, continue, parse_string)
- New capabilities: 0 (uses existing ConstStep)
- Lines added: ~300
- Files modified: 9
- Parity status: Green ✅
Phase 143 P1: Complete
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-16 12:37:47 +09:00
|
|
|
|
|
|
|
|
// Phase 143-P1: Re-export parse_string pattern detection for loop_canonicalizer
|
|
|
|
|
pub(crate) use ast_feature_extractor::{detect_parse_string_pattern, ParseStringInfo};
|
2025-12-16 14:36:32 +09:00
|
|
|
|
|
|
|
|
// Phase 91 P5b: Re-export escape skip pattern detection for loop_canonicalizer
|
|
|
|
|
pub(crate) use ast_feature_extractor::{detect_escape_skip_pattern, EscapeSkipPatternInfo};
|