phase29ap(p0): reduce legacy extractors (pattern1/3)

This commit is contained in:
2025-12-30 22:13:24 +09:00
parent 49f6457619
commit ab81747d6a
8 changed files with 49 additions and 199 deletions

View File

@ -180,7 +180,7 @@ fn lower_via_plan(
/// - Cons: Extraction can be expensive (but amortized over lowering)
///
/// ## StructureBased (Feature Classification)
/// - Used by: Pattern1, Pattern2, Pattern3, Pattern4, Pattern5, Pattern8, Pattern9
/// - Used by: Pattern1, Pattern2, Pattern4 (legacy)
/// - Strategy: Check pattern_kind (from LoopPatternContext), plus optional structural checks
/// - Pros: Fast classification, reuses centralized feature detection
/// - Cons: Two sources of truth (classify + structural checks)
@ -201,7 +201,7 @@ pub(crate) enum CanLowerStrategy {
ExtractionBased,
/// Structure-based detection: Check pattern_kind from LoopPatternContext
/// Used by Pattern1, Pattern2, Pattern3, Pattern4, Pattern5, Pattern8, Pattern9
/// Used by Pattern1, Pattern2, Pattern4
StructureBased,
}
@ -222,26 +222,20 @@ pub(crate) struct LoopPatternEntry {
///
/// **IMPORTANT**: Patterns are tried in array order (SSOT).
/// Array order defines priority - earlier entries are tried first.
/// Pattern4 → Pattern8 → Pattern9 → Pattern3 → Pattern1 → Pattern2
/// Pattern4 → Pattern8 → Pattern9 → Pattern1 → Pattern2
///
/// # Current Patterns (Structure-based detection, established Phase 131-11+)
///
/// Pattern detection strategies (updated Phase 286):
/// - Pattern6/7: ExtractionBased (Plan line, Phase 273+)
/// - Pattern5/8/9: ExtractionBased (extraction functions, Plan line Phase 286+)
/// - Pattern1-4: StructureBased (LoopFeatures classification, legacy)
/// - Pattern8/9: ExtractionBased (extraction functions, Plan line Phase 286+)
/// - Pattern1/2/4: StructureBased (LoopFeatures classification, legacy)
///
/// - Pattern 4: Loop with Continue (loop_continue_pattern4.hako)
/// - Detection: pattern_kind == Pattern4Continue
/// - Structure: has_continue && !has_break
///
/// - Pattern 3: Loop with If-Else PHI (loop_if_phi.hako)
/// - Detection: pattern_kind == Pattern3IfPhi
/// - Structure: has_if_else_phi && !has_break && !has_continue
///
/// - Pattern 1: Simple While Loop (loop_min_while.hako)
/// - Detection: pattern_kind == Pattern1SimpleWhile
/// - Structure: !has_break && !has_continue && !has_if_else_phi
/// - Pattern3: moved to plan-based routing (planner+composer SSOT)
///
/// - Pattern 2: Loop with Conditional Break (joinir_min_loop.hako)
/// - Detection: pattern_kind == Pattern2Break
@ -274,11 +268,6 @@ pub(crate) static LOOP_PATTERNS: &[LoopPatternEntry] = &[
detect: super::pattern9_accum_const_loop::can_lower,
lower: super::pattern9_accum_const_loop::lower,
},
LoopPatternEntry {
name: "Pattern3_WithIfPhi",
detect: super::pattern3_with_if_phi::can_lower,
lower: super::pattern3_with_if_phi::lower,
},
LoopPatternEntry {
name: "Pattern1_Minimal",
detect: super::pattern1_minimal::can_lower,
@ -302,17 +291,17 @@ pub(crate) static LOOP_PATTERNS: &[LoopPatternEntry] = &[
/// This router uses multiple detection strategies:
/// - Plan-based (Pattern6/7): extract_*_plan() → DomainPlan (Phase 273+ SSOT)
/// - Extraction-based (Pattern8/9): extract_*() functions (already implemented)
/// - Structure-based (Pattern1-5): ctx.pattern_kind classification (legacy)
/// - Structure-based (Pattern1/2/4): ctx.pattern_kind classification (legacy)
///
/// # Plan Line SSOT for Pattern6/7 (Phase 273+)
///
/// This function implements the following routing strategy:
/// 1. Try Plan-based Pattern6 (extract_scan_with_init_plan) → DomainPlan
/// 2. Try Plan-based Pattern7 (extract_split_scan_plan) → DomainPlan
/// 3. Fall through to legacy Pattern1-5 table for other patterns
/// 3. Fall through to legacy Pattern1/2/4/8/9 table for other patterns
///
/// The Plan line (Extractor → Normalizer → Verifier → Lowerer) is the
/// current operational SSOT for Pattern6/7. Legacy patterns (1-5) use
/// current operational SSOT for Pattern6/7. Legacy patterns (1/2/4/8/9) use
/// the traditional LoopPatternContext-based routing.
///
/// Plan-based architecture (Phase 273 P1-P3):
@ -324,7 +313,7 @@ pub(crate) static LOOP_PATTERNS: &[LoopPatternEntry] = &[
/// SSOT Entry Points:
/// - Pattern6: src/mir/builder/control_flow/plan/normalizer.rs (ScanWithInit normalization)
/// - Pattern7: src/mir/builder/control_flow/plan/normalizer.rs (SplitScan normalization)
/// - Pattern1-5: src/mir/builder/control_flow/joinir/patterns/pattern*.rs (direct lowering)
/// - Pattern1/2/4/8/9: src/mir/builder/control_flow/joinir/patterns/pattern*.rs (direct lowering)
pub(crate) fn route_loop_pattern(
builder: &mut MirBuilder,
ctx: &LoopPatternContext,