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-16 15:01:46 +09:00
|
|
|
//!
|
|
|
|
|
//! Phase 91 P5b: Escape Pattern Recognizer
|
|
|
|
|
//! - escape_pattern_recognizer.rs: P5b (escape sequence handling) pattern detection
|
|
|
|
|
//! - Extracted from ast_feature_extractor for improved modularity
|
2025-12-17 00:59:33 +09:00
|
|
|
//!
|
|
|
|
|
//! Phase 93/94: Pattern Policies
|
|
|
|
|
//! - policies/: Pattern recognition and routing decision (future expansion)
|
|
|
|
|
//! - Currently a placeholder directory for future policy box organization
|
2025-12-19 23:48:49 +09:00
|
|
|
//!
|
|
|
|
|
//! Phase 255 P2: Common Utilities
|
|
|
|
|
//! - common/: Shared helper functions (var() etc.) to eliminate code duplication
|
2025-12-05 20:45:23 +09:00
|
|
|
|
2025-12-19 23:48:49 +09:00
|
|
|
pub(in crate::mir::builder) mod common; // Phase 255 P2: Common AST helpers
|
2025-12-06 03:30:03 +09:00
|
|
|
pub(in crate::mir::builder) mod ast_feature_extractor;
|
2025-12-17 00:59:33 +09:00
|
|
|
pub(in crate::mir::builder) mod policies; // Phase 93/94: Pattern routing policies (future expansion)
|
2025-12-16 21:37:07 +09:00
|
|
|
pub(in crate::mir::builder) mod body_local_policy; // Phase 92 P3: promotion vs slot routing
|
2025-12-16 15:01:46 +09:00
|
|
|
pub(in crate::mir::builder) mod escape_pattern_recognizer; // Phase 91 P5b
|
2025-12-07 21:02:20 +09:00
|
|
|
pub(in crate::mir::builder) mod common_init;
|
2025-12-17 18:29:27 +09:00
|
|
|
pub(in crate::mir::builder) mod loop_true_counter_extractor; // Phase 104: loop(true) counter extraction for Pattern2
|
|
|
|
|
pub(in crate::mir::builder) mod read_digits_break_condition_box; // Phase 104: break cond normalization for read_digits(loop(true))
|
2025-12-21 11:07:36 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern2; // Phase 263 P0.2: Pattern2 module (api/ SSOT entry point)
|
2025-12-17 21:24:46 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern2_break_condition_policy_router; // Phase 105: policy router box for Pattern2 break condition
|
2025-12-17 23:30:08 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern2_policy_router; // Phase 108: unified Pattern2 policy router (balanced/read_digits/default)
|
2025-12-17 21:34:11 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern2_inputs_facts_box; // Phase 105: Pattern2 input facts (analysis only)
|
|
|
|
|
pub(in crate::mir::builder) mod pattern2_lowering_orchestrator; // Phase 105: Pattern2 orchestration (wiring/emission)
|
2025-12-17 22:01:19 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern2_steps; // Phase 106: Pattern2 step boxes (pipeline SSOT)
|
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-19 23:32:25 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern6_scan_with_init; // Phase 254 P0: index_of/find/contains pattern
|
2025-12-20 01:24:04 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern7_split_scan; // Phase 256 P0: split/tokenization with variable step
|
2025-12-21 02:40:07 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern8_scan_bool_predicate; // Phase 259 P0: boolean predicate scan (is_integer/is_valid)
|
2025-12-21 23:12:52 +09:00
|
|
|
pub(in crate::mir::builder) mod pattern9_accum_const_loop; // Phase 270 P1: accumulator const loop (橋渡しパターン)
|
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)
|
2025-12-19 08:36:45 +09:00
|
|
|
pub(crate) use ast_feature_extractor::detect_skip_whitespace_pattern;
|
2025-12-16 09:08:37 +09:00
|
|
|
|
2025-12-17 18:29:27 +09:00
|
|
|
// Phase 104: Re-export read_digits(loop(true)) detection for loop_canonicalizer
|
2025-12-19 08:36:45 +09:00
|
|
|
pub(crate) use ast_feature_extractor::detect_read_digits_loop_true_pattern;
|
2025-12-17 18:29:27 +09:00
|
|
|
|
2025-12-16 09:08:37 +09:00
|
|
|
// Phase 142-P1: Re-export continue pattern detection for loop_canonicalizer
|
2025-12-19 08:36:45 +09:00
|
|
|
pub(crate) use ast_feature_extractor::detect_continue_pattern;
|
2025-12-16 09:08:37 +09:00
|
|
|
|
|
|
|
|
// Phase 143-P0: Re-export parse_number pattern detection for loop_canonicalizer
|
2025-12-19 08:36:45 +09:00
|
|
|
pub(crate) use ast_feature_extractor::detect_parse_number_pattern;
|
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
|
2025-12-19 08:36:45 +09:00
|
|
|
pub(crate) use ast_feature_extractor::detect_parse_string_pattern;
|
2025-12-16 14:36:32 +09:00
|
|
|
|
|
|
|
|
// Phase 91 P5b: Re-export escape skip pattern detection for loop_canonicalizer
|
2025-12-19 08:36:45 +09:00
|
|
|
pub(crate) use ast_feature_extractor::detect_escape_skip_pattern;
|