phase29ap(p12): remove joinir legacy loop table
This commit is contained in:
@ -1,22 +1,19 @@
|
||||
//! Pattern Router - Table-driven dispatch for loop patterns
|
||||
//! Pattern Router - Plan/Composer routing for loop patterns
|
||||
//!
|
||||
//! Phase 194: Replace if/else chain with table-driven routing
|
||||
//! Phase 29ap P12: Legacy loop table removed (plan/composer SSOT only)
|
||||
//!
|
||||
//! # Architecture
|
||||
//!
|
||||
//! - Each pattern registers a detect function and a lower function
|
||||
//! - Patterns are tried in priority order (lower = tried first)
|
||||
//! - First matching pattern wins
|
||||
//! - Feature extraction delegated to ast_feature_extractor module
|
||||
//! - single_planner derives a DomainPlan + facts outcome (SSOT)
|
||||
//! - composer adopts CorePlan (strict/dev shadow or release adopt)
|
||||
//! - PlanLowerer emits MIR from CorePlan (emit_frag SSOT)
|
||||
//!
|
||||
//! # Adding New Patterns
|
||||
//!
|
||||
//! 1. Create a new module in `patterns/` (e.g., `pattern4_your_name.rs`)
|
||||
//! 2. Implement `pub fn can_lower(ctx: &LoopPatternContext) -> bool`
|
||||
//! 3. Implement `pub fn lower(builder: &mut MirBuilder, ctx: &LoopPatternContext) -> Result<Option<ValueId>, String>`
|
||||
//! 4. Add entry to `LOOP_PATTERNS` table below
|
||||
//!
|
||||
//! That's it! No need to modify routing logic.
|
||||
//! 1. Add Facts/Planner extraction in plan layer
|
||||
//! 2. Normalize/verify in plan normalizer/verifier
|
||||
//! 3. Compose CorePlan in composer (shadow/release adopt as needed)
|
||||
//! 4. Keep router unchanged (it only delegates to plan/composer)
|
||||
|
||||
use crate::ast::ASTNode;
|
||||
use crate::mir::builder::MirBuilder;
|
||||
@ -169,109 +166,16 @@ fn lower_via_plan(
|
||||
|
||||
// Phase 29ai P5: Plan extractor routing moved to `plan::single_planner`.
|
||||
|
||||
/// Phase 272 P0.2 Refactoring: can_lower() strategy classification
|
||||
/// Route loop patterns via plan/composer SSOT.
|
||||
///
|
||||
/// Clarifies the two main detection strategies used across patterns:
|
||||
/// Returns Ok(Some(value_id)) if a plan matched and lowered successfully.
|
||||
/// Returns Ok(None) if no plan matched.
|
||||
/// Returns Err if a plan matched but lowering failed.
|
||||
///
|
||||
/// ## ExtractionBased (SSOT Approach)
|
||||
/// - Used by: Pattern6, Pattern7
|
||||
/// - Strategy: Try pattern extraction, if successful → match
|
||||
/// - Pros: Single source of truth (extract function defines pattern)
|
||||
/// - Cons: Extraction can be expensive (but amortized over lowering)
|
||||
/// # Router Architecture (Plan/Composer SSOT)
|
||||
///
|
||||
/// ## StructureBased (Feature Classification)
|
||||
/// - Used by: Pattern6_NestedLoopMinimal (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)
|
||||
///
|
||||
/// ## Rationale for Dual Strategy:
|
||||
/// - Pattern6/7: Complex extraction logic (variable step, carrier tracking)
|
||||
/// → ExtractionBased avoids duplication between detect and extract
|
||||
/// - Other patterns: Legacy structural features
|
||||
/// → StructureBased leverages centralized LoopFeatures classification
|
||||
///
|
||||
/// This documentation prevents bugs like Phase 272 P0.2's Pattern7 issue
|
||||
/// (pattern_kind check was too restrictive, extraction-based approach fixed it).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[allow(dead_code)] // Documentation purpose - not enforced in code yet
|
||||
pub(crate) enum CanLowerStrategy {
|
||||
/// Extraction-based detection: Try extract(), success → match
|
||||
/// Used by Pattern6, Pattern7
|
||||
ExtractionBased,
|
||||
|
||||
/// Structure-based detection: Check pattern_kind from LoopPatternContext
|
||||
/// Used by legacy patterns
|
||||
StructureBased,
|
||||
}
|
||||
|
||||
/// Entry in the loop pattern router table.
|
||||
/// Each pattern registers a detect function and a lower function.
|
||||
pub(crate) struct LoopPatternEntry {
|
||||
/// Human-readable pattern name for debugging
|
||||
pub(crate) name: &'static str,
|
||||
|
||||
/// Detection function: returns true if this pattern matches
|
||||
pub(crate) detect: fn(&MirBuilder, &LoopPatternContext) -> bool,
|
||||
|
||||
/// Lowering function: performs the actual JoinIR generation
|
||||
pub(crate) lower: fn(&mut MirBuilder, &LoopPatternContext) -> Result<Option<ValueId>, String>,
|
||||
}
|
||||
|
||||
/// Static table of all registered loop patterns.
|
||||
///
|
||||
/// **IMPORTANT**: Patterns are tried in array order (SSOT).
|
||||
/// Array order defines priority - earlier entries are tried first.
|
||||
/// Pattern6_NestedLoopMinimal (legacy)
|
||||
///
|
||||
/// # Current Patterns (Structure-based detection, established Phase 131-11+)
|
||||
///
|
||||
/// Pattern detection strategies (updated Phase 286):
|
||||
/// - Pattern6/7: ExtractionBased (Plan line, Phase 273+)
|
||||
/// - Pattern8/9: ExtractionBased (extraction functions, Plan line Phase 286+)
|
||||
///
|
||||
/// - Pattern3: moved to plan-based routing (planner+composer SSOT)
|
||||
///
|
||||
/// Note: func_name is now only used for debug logging, not pattern detection
|
||||
/// Phase 286: Pattern5 removed (migrated to Plan-based routing)
|
||||
/// Phase 29ap P4: Pattern8 removed (migrated to Plan-based routing)
|
||||
/// Phase 29ap P5: Pattern2 removed (migrated to Plan-based routing)
|
||||
/// Phase 29ap P7: Pattern9 removed (migrated to Plan-based routing)
|
||||
pub(crate) static LOOP_PATTERNS: &[LoopPatternEntry] = &[
|
||||
LoopPatternEntry {
|
||||
name: "Pattern6_NestedLoopMinimal", // Phase 188.3: 1-level nested loop
|
||||
detect: super::pattern6_nested_minimal::can_lower,
|
||||
lower: super::pattern6_nested_minimal::lower,
|
||||
},
|
||||
// Phase 273 P0.1: Pattern6 entry removed (migrated to Plan-based routing)
|
||||
// Pattern6_ScanWithInit now handled via extract_scan_with_init_plan() + PlanLowerer
|
||||
// Phase 273 P2: Pattern7 entry removed (migrated to Plan-based routing)
|
||||
// Pattern7_SplitScan now handled via extract_split_scan_plan() + PlanLowerer
|
||||
];
|
||||
|
||||
/// Try all registered patterns in priority order.
|
||||
///
|
||||
/// Returns Ok(Some(value_id)) if a pattern matched and lowered successfully.
|
||||
/// Returns Ok(None) if no pattern matched.
|
||||
/// Returns Err if a pattern matched but lowering failed.
|
||||
///
|
||||
/// # Router Architecture (Structure-based routing established Phase 183)
|
||||
///
|
||||
/// 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 (Pattern6_NestedLoopMinimal): 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 Pattern6_NestedLoopMinimal table for other patterns
|
||||
///
|
||||
/// The Plan line (Extractor → Normalizer → Verifier → Lowerer) is the
|
||||
/// current operational SSOT for Pattern6/7. Legacy patterns
|
||||
/// (Pattern6_NestedLoopMinimal) use the traditional LoopPatternContext-based routing.
|
||||
/// The plan line (Extractor → Normalizer → Verifier → Lowerer) is the
|
||||
/// operational SSOT for loop routing (Phase 273+).
|
||||
///
|
||||
/// Plan-based architecture (Phase 273 P1-P3):
|
||||
/// - extract_*_plan() → DomainPlan (pure extraction, no builder)
|
||||
@ -282,7 +186,6 @@ 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)
|
||||
/// - Pattern6_NestedLoopMinimal: src/mir/builder/control_flow/joinir/patterns/pattern6_nested_minimal.rs
|
||||
pub(crate) fn route_loop_pattern(
|
||||
builder: &mut MirBuilder,
|
||||
ctx: &LoopPatternContext,
|
||||
@ -344,20 +247,6 @@ pub(crate) fn route_loop_pattern(
|
||||
return lower_via_plan(builder, domain_plan, ctx);
|
||||
}
|
||||
|
||||
// Phase 183: Route based on pre-classified pattern kind
|
||||
// Pattern kind was already determined by ctx.pattern_kind in LoopPatternContext::new()
|
||||
// This eliminates duplicate detection logic across routers.
|
||||
|
||||
// Find matching pattern entry based on pattern_kind
|
||||
// Phase 273 P0.1: Pattern6 skip logic removed (entry no longer in LOOP_PATTERNS)
|
||||
for entry in LOOP_PATTERNS {
|
||||
if (entry.detect)(builder, ctx) {
|
||||
let log_msg = format!("route=joinir strategy=extract pattern={} (Phase 194+)", entry.name);
|
||||
trace::trace().pattern("route", &log_msg, true);
|
||||
return (entry.lower)(builder, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
// No pattern matched - return None (caller will handle error)
|
||||
if ctx.debug {
|
||||
trace::trace().debug(
|
||||
|
||||
Reference in New Issue
Block a user