docs(router): Phase 282 P2 - Comment archaeology + TODO cleanup

Step 2: Router comment updates
- Update Phase references (183, 273, 282 retained)
- Document ExtractionBased status (Pattern8/9 already done)
- Remove obsolete Phase references (187, 193, 195)

Step 3: TODO cleanup
- pattern5: Remove completed TODO (lowering fully implemented)
- pattern_pipeline: Clarify loop_update_summary status (reserved)
- apply_policy: Mark current_static_box_name as low-priority refactor

Step 4: Pattern3 legacy references
- Simplify module docstring (remove legacy mode details)
- Update inline comments (legacy removal Phase 242-EX-A)

Changes: Comment/docstring only (zero behavior change)
Test: cargo build --release (0 errors)
This commit is contained in:
2025-12-23 05:35:42 +09:00
parent 519e58a977
commit a2be79b875
5 changed files with 30 additions and 44 deletions

View File

@ -1,7 +1,6 @@
//! Pattern Router - Table-driven dispatch for loop patterns
//!
//! Phase 194: Replace if/else chain with table-driven routing
//! Phase 193: Modularized feature extraction using ast_feature_extractor module
//!
//! # Architecture
//!
@ -30,8 +29,7 @@ use crate::mir::builder::control_flow::plan::lowerer::PlanLowerer;
use crate::mir::builder::control_flow::plan::normalizer::PlanNormalizer;
use crate::mir::builder::control_flow::plan::verifier::PlanVerifier;
/// Phase 193: Import AST Feature Extractor Box
/// (declared in mod.rs as pub module, import from parent)
/// AST Feature Extractor (declared in mod.rs as pub module, import from parent)
use super::ast_feature_extractor as ast_features;
/// Phase 92 P0-2: Import LoopSkeleton for Option A
@ -81,24 +79,21 @@ pub(crate) struct LoopPatternContext<'a> {
impl<'a> LoopPatternContext<'a> {
/// Create new context from routing parameters
///
/// Phase 194+: Automatically detects continue/break statements in body
/// Phase 192: Extract features and classify pattern from AST
/// Phase 193: Feature extraction delegated to ast_feature_extractor module
/// Phase 131-11: Detects infinite loop condition
/// Phase 137-6-S1: Use choose_pattern_kind() SSOT entry point
/// Phase 92 P0-2: Added skeleton parameter (None for backward compatibility)
/// Automatically detects continue/break statements in body
/// Extracts features and classifies pattern from AST
/// Detects infinite loop condition
/// Uses choose_pattern_kind() SSOT entry point
pub(crate) fn new(
condition: &'a ASTNode,
body: &'a [ASTNode],
func_name: &'a str,
debug: bool,
) -> Self {
// Phase 193: Use AST Feature Extractor Box for break/continue detection
// Use AST Feature Extractor for break/continue detection
let has_continue = ast_features::detect_continue_in_body(body);
let has_break = ast_features::detect_break_in_body(body);
// Phase 193: Extract features using modularized extractor
// Phase 131-11: Pass condition for infinite loop detection
// Extract features (includes infinite loop detection)
let features = ast_features::extract_features(condition, body, has_continue, has_break);
// Phase 137-6-S1: Use SSOT pattern selection entry point
@ -140,9 +135,6 @@ impl<'a> LoopPatternContext<'a> {
}
}
/// Phase 193: Feature extraction moved to ast_feature_extractor module
/// See: src/mir/builder/control_flow/joinir/patterns/ast_feature_extractor.rs
/// Phase 272 P0.2 Refactoring: can_lower() strategy classification
///
/// Clarifies the two main detection strategies used across patterns:
@ -198,9 +190,12 @@ pub(crate) struct LoopPatternEntry {
/// Array order defines priority - earlier entries are tried first.
/// Pattern5 (most specific) → Pattern4 → Pattern3 → Pattern1 → Pattern2
///
/// # Current Patterns (Phase 131-11: Pattern 5 added)
/// # Current Patterns (Structure-based detection, established Phase 131-11+)
///
/// All patterns now use structure-based detection via LoopFeatures and classify():
/// Pattern detection strategies (updated Phase 282 P0):
/// - Pattern6/7: ExtractionBased (Plan line, Phase 273+)
/// - Pattern8/9: ExtractionBased (extraction functions, already implemented)
/// - Pattern1-5: StructureBased (LoopFeatures classification, legacy)
///
/// - Pattern 5: Infinite Loop with Early Exit (llvm_stage3_loop_only.hako) [Phase 131-11]
/// - Detection: pattern_kind == InfiniteEarlyExit
@ -271,14 +266,14 @@ pub(crate) static LOOP_PATTERNS: &[LoopPatternEntry] = &[
/// Returns Ok(None) if no pattern matched.
/// Returns Err if a pattern matched but lowering failed.
///
/// # Phase 183: Structure-based routing
/// # Router Architecture (Structure-based routing established Phase 183)
///
/// This router uses the centralized pattern classification system:
/// - Pattern detection: `ctx.pattern_kind` (from `loop_pattern_detection::classify`)
/// - No redundant pattern detection in detect functions
/// - All patterns use structure-based classification
/// 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)
///
/// # Phase 273 P3: Plan Line is Current SSOT for Pattern6/7
/// # 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
@ -375,7 +370,6 @@ pub(crate) fn route_loop_pattern(
// Phase 273 P0.1: Pattern6 skip logic removed (entry no longer in LOOP_PATTERNS)
for entry in LOOP_PATTERNS {
if (entry.detect)(builder, ctx) {
// Phase 195: Use unified trace for pattern matching
let log_msg = format!("route=joinir pattern={} (Phase 194+)", entry.name);
trace::trace().pattern("route", &log_msg, true);
return (entry.lower)(builder, ctx);
@ -383,7 +377,6 @@ pub(crate) fn route_loop_pattern(
}
// No pattern matched - return None (caller will handle error)
// Phase 187-2: Legacy LoopBuilder removed, all loops must use JoinIR
if ctx.debug {
trace::trace().debug(
"route",