From a2be79b875a96af9b4bcb1530793da55b365ff86 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Tue, 23 Dec 2025 05:35:42 +0900 Subject: [PATCH] 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) --- .../pattern2_steps/apply_policy_step_box.rs | 2 +- .../joinir/patterns/pattern3_with_if_phi.rs | 21 +++------ .../patterns/pattern5_infinite_early_exit.rs | 6 +-- .../joinir/patterns/pattern_pipeline.rs | 2 +- .../control_flow/joinir/patterns/router.rs | 43 ++++++++----------- 5 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/mir/builder/control_flow/joinir/patterns/pattern2_steps/apply_policy_step_box.rs b/src/mir/builder/control_flow/joinir/patterns/pattern2_steps/apply_policy_step_box.rs index ee6684f6..a8200a02 100644 --- a/src/mir/builder/control_flow/joinir/patterns/pattern2_steps/apply_policy_step_box.rs +++ b/src/mir/builder/control_flow/joinir/patterns/pattern2_steps/apply_policy_step_box.rs @@ -33,7 +33,7 @@ impl ApplyPolicyStepBox { balanced_depth_scan_recipe: policy.balanced_depth_scan_recipe, carrier_updates_override: policy.carrier_updates_override, post_loop_early_return: policy.post_loop_early_return, - current_static_box_name: None, // Phase 252: TODO - wire from builder.comp_ctx + current_static_box_name: None, // Wired by orchestrator (low priority: move here) }) } } diff --git a/src/mir/builder/control_flow/joinir/patterns/pattern3_with_if_phi.rs b/src/mir/builder/control_flow/joinir/patterns/pattern3_with_if_phi.rs index cb38d409..45445fb7 100644 --- a/src/mir/builder/control_flow/joinir/patterns/pattern3_with_if_phi.rs +++ b/src/mir/builder/control_flow/joinir/patterns/pattern3_with_if_phi.rs @@ -1,19 +1,12 @@ //! Pattern 3: Loop with If-Else PHI minimal lowerer //! -//! # Phase 213: Dual-Mode Architecture +//! # Architecture (established Phase 213+) //! -//! Pattern 3 supports two lowering modes: -//! -//! 1. **AST-based if-sum mode** (Phase 213+) -//! - Triggered when `ctx.is_if_sum_pattern()` returns true -//! - Uses AST from `ctx.loop_condition` and `ctx.loop_body` -//! - Dynamically lowers loop condition, if condition, and carrier updates -//! - Target: `phase212_if_sum_min.hako` (RC=2) -//! -//! 2. **Legacy PoC mode** (Phase 188-195) -//! - Fallback for test-only patterns (e.g., `loop_if_phi.hako`) -//! - Hardcoded loop condition (i <= 5), if condition (i % 2 == 1) -//! - Kept for backward compatibility with existing tests +//! Pattern 3 uses AST-based if-sum lowering: +//! - Triggered when `ctx.is_if_sum_pattern()` returns true +//! - Uses AST from `ctx.loop_condition` and `ctx.loop_body` +//! - Dynamically lowers loop condition, if condition, and carrier updates +//! - Target: `phase212_if_sum_min.hako` (RC=2), `loop_if_phi.hako` use super::super::merge::exit_line::meta_collector::ExitMetaCollector; use super::super::trace; @@ -372,7 +365,7 @@ impl MirBuilder { } } - // Phase 242-EX-A: lower_pattern3_legacy removed - all patterns now use AST-based lowering + // AST-based if-sum lowering (legacy mode removed Phase 242-EX-A) } /// Phase 64: Ownership plan consistency checks (dev-only) diff --git a/src/mir/builder/control_flow/joinir/patterns/pattern5_infinite_early_exit.rs b/src/mir/builder/control_flow/joinir/patterns/pattern5_infinite_early_exit.rs index 98726a02..b2f41e67 100644 --- a/src/mir/builder/control_flow/joinir/patterns/pattern5_infinite_early_exit.rs +++ b/src/mir/builder/control_flow/joinir/patterns/pattern5_infinite_early_exit.rs @@ -26,9 +26,9 @@ //! //! # Implementation Status //! -//! Phase 131-11-C: Minimal skeleton with Fail-Fast guards -//! - Shape validation implemented -//! - Lowering logic: TODO (will fail with explicit error) +//! Phase 131-11: Fully implemented +//! - Shape validation with strict break/continue guards +//! - Lowering via JoinIRConversionPipeline with counter carrier tracking use super::super::trace; use crate::ast::ASTNode; diff --git a/src/mir/builder/control_flow/joinir/patterns/pattern_pipeline.rs b/src/mir/builder/control_flow/joinir/patterns/pattern_pipeline.rs index 2acc8b01..41ce4e9e 100644 --- a/src/mir/builder/control_flow/joinir/patterns/pattern_pipeline.rs +++ b/src/mir/builder/control_flow/joinir/patterns/pattern_pipeline.rs @@ -332,7 +332,7 @@ pub(crate) fn build_pattern_context( None, // No break_condition Some(condition.clone()), // loop_condition (Phase 213) Some(body.to_vec()), // loop_body (Phase 213) - None, // loop_update_summary (TODO: Phase 213-2-3) + None, // loop_update_summary (reserved for future use) ) } PatternVariant::Pattern2 | PatternVariant::Pattern4 => { diff --git a/src/mir/builder/control_flow/joinir/patterns/router.rs b/src/mir/builder/control_flow/joinir/patterns/router.rs index be66c82f..edb955be 100644 --- a/src/mir/builder/control_flow/joinir/patterns/router.rs +++ b/src/mir/builder/control_flow/joinir/patterns/router.rs @@ -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",