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)"
This commit is contained in:
2025-12-19 04:31:45 +09:00
parent 1742f0412e
commit 21a3c6b5d4

View File

@ -1,8 +1,8 @@
//! Phase 134 P0: Suffix router box - unified with NormalizationPlanBox //! Phase 142 P0: Normalized shadow loop router box
//! //!
//! ## Responsibility //! ## 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 NormalizationPlanBox for pattern detection (SSOT)
//! - Delegate to NormalizationExecuteBox for lowering and merge //! - Delegate to NormalizationExecuteBox for lowering and merge
//! - Return consumed count to skip processed statements in build_block() //! - Return consumed count to skip processed statements in build_block()
@ -13,11 +13,11 @@
//! - Returns Ok(None): Pattern not matched, use default behavior //! - Returns Ok(None): Pattern not matched, use default behavior
//! - Returns Err(_): Internal error //! - Returns Err(_): Internal error
//! //!
//! ## Design (Phase 134 P0) //! ## Design (Phase 134 P0, updated Phase 142 P0)
//! //!
//! - Uses NormalizationPlanBox for detection (no duplication) //! - Uses NormalizationPlanBox for detection (no duplication)
//! - Uses NormalizationExecuteBox for execution (shared logic) //! - 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::ast::ASTNode;
use crate::mir::builder::MirBuilder; use crate::mir::builder::MirBuilder;
@ -27,10 +27,11 @@ use crate::mir::builder::control_flow::normalization::{NormalizationPlanBox, Nor
pub struct NormalizedShadowSuffixRouterBox; pub struct NormalizedShadowSuffixRouterBox;
impl 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 134 P0: Unified with NormalizationPlanBox for pattern detection
/// Phase 141 P1.5: Added prefix_variables parameter for external env inputs /// Phase 141 P1.5: Added prefix_variables parameter for external env inputs
/// Phase 142 P0: Accepts both LoopOnly and LoopWithPost patterns
/// ///
/// Returns: /// Returns:
/// - Ok(Some(consumed)): Successfully processed remaining[..consumed] /// - Ok(Some(consumed)): Successfully processed remaining[..consumed]
@ -60,31 +61,16 @@ impl NormalizedShadowSuffixRouterBox {
} }
}; };
// Only handle suffix patterns (loop + post statements) // Phase 142 P0: Accept both LoopOnly and LoopWithPost
// Loop-only patterns should go through try_normalized_shadow() instead // Normalization unit is now "statement (loop 1個)", not "block suffix"
match &plan.kind { if debug {
PlanKind::LoopOnly => { let description = match &plan.kind {
if debug { PlanKind::LoopOnly => "Loop-only pattern".to_string(),
trace.routing( PlanKind::LoopWithPost { post_assign_count } => {
"suffix_router", format!("Loop+post pattern: {} post assigns", post_assign_count)
func_name,
"Loop-only pattern detected, not a suffix (routing.rs should handle this)",
);
} }
return Ok(None); };
} trace.routing("suffix_router", func_name, &description);
PlanKind::LoopWithPost { post_assign_count } => {
if debug {
trace.routing(
"suffix_router",
func_name,
&format!(
"Loop+post pattern detected: {} post assigns",
post_assign_count
),
);
}
}
} }
// Phase 134 P0: Delegate execution to NormalizationExecuteBox (SSOT) // Phase 134 P0: Delegate execution to NormalizationExecuteBox (SSOT)