From 21a3c6b5d4db643250a43a0539630b1ce99d9882 Mon Sep 17 00:00:00 2001 From: tomoaki Date: Fri, 19 Dec 2025 04:31:45 +0900 Subject: [PATCH] docs(normalization): Update suffix_router comments for Phase 142 P0 - Reflect that post statements are no longer required - Document LoopOnly pattern acceptance - Update responsibility description Phase 142 P0: Normalization unit changed to "statement (loop only)" --- .../normalized_shadow_suffix_router_box.rs | 44 +++++++------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/mir/builder/control_flow/joinir/patterns/policies/normalized_shadow_suffix_router_box.rs b/src/mir/builder/control_flow/joinir/patterns/policies/normalized_shadow_suffix_router_box.rs index c86ee1c9..d146b49d 100644 --- a/src/mir/builder/control_flow/joinir/patterns/policies/normalized_shadow_suffix_router_box.rs +++ b/src/mir/builder/control_flow/joinir/patterns/policies/normalized_shadow_suffix_router_box.rs @@ -1,8 +1,8 @@ -//! Phase 134 P0: Suffix router box - unified with NormalizationPlanBox +//! Phase 142 P0: Normalized shadow loop router box //! //! ## Responsibility //! -//! - Detect block suffix starting with loop(true) { ... break } + post statements +//! - Detect loop(true) patterns at block suffix (with or without subsequent statements) //! - Delegate to NormalizationPlanBox for pattern detection (SSOT) //! - Delegate to NormalizationExecuteBox for lowering and merge //! - Return consumed count to skip processed statements in build_block() @@ -13,11 +13,11 @@ //! - Returns Ok(None): Pattern not matched, use default behavior //! - Returns Err(_): Internal error //! -//! ## Design (Phase 134 P0) +//! ## Design (Phase 134 P0, updated Phase 142 P0) //! //! - Uses NormalizationPlanBox for detection (no duplication) //! - Uses NormalizationExecuteBox for execution (shared logic) -//! - Only handles suffix-specific logic (return statement emission) +//! - Phase 142 P0: Accepts both LoopOnly (consumed=1) and LoopWithPost patterns use crate::ast::ASTNode; use crate::mir::builder::MirBuilder; @@ -27,10 +27,11 @@ use crate::mir::builder::control_flow::normalization::{NormalizationPlanBox, Nor pub struct NormalizedShadowSuffixRouterBox; impl NormalizedShadowSuffixRouterBox { - /// Try to lower a block suffix starting with loop(true) + post statements + /// Try to lower a loop(true) pattern in block suffix /// /// Phase 134 P0: Unified with NormalizationPlanBox for pattern detection /// Phase 141 P1.5: Added prefix_variables parameter for external env inputs + /// Phase 142 P0: Accepts both LoopOnly and LoopWithPost patterns /// /// Returns: /// - Ok(Some(consumed)): Successfully processed remaining[..consumed] @@ -60,31 +61,16 @@ impl NormalizedShadowSuffixRouterBox { } }; - // Only handle suffix patterns (loop + post statements) - // Loop-only patterns should go through try_normalized_shadow() instead - match &plan.kind { - PlanKind::LoopOnly => { - if debug { - trace.routing( - "suffix_router", - func_name, - "Loop-only pattern detected, not a suffix (routing.rs should handle this)", - ); + // Phase 142 P0: Accept both LoopOnly and LoopWithPost + // Normalization unit is now "statement (loop 1個)", not "block suffix" + if debug { + let description = match &plan.kind { + PlanKind::LoopOnly => "Loop-only pattern".to_string(), + PlanKind::LoopWithPost { post_assign_count } => { + format!("Loop+post pattern: {} post assigns", post_assign_count) } - return Ok(None); - } - PlanKind::LoopWithPost { post_assign_count } => { - if debug { - trace.routing( - "suffix_router", - func_name, - &format!( - "Loop+post pattern detected: {} post assigns", - post_assign_count - ), - ); - } - } + }; + trace.routing("suffix_router", func_name, &description); } // Phase 134 P0: Delegate execution to NormalizationExecuteBox (SSOT)