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
//!
//! - 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 => {
// Phase 142 P0: Accept both LoopOnly and LoopWithPost
// Normalization unit is now "statement (loop 1個)", not "block suffix"
if debug {
trace.routing(
"suffix_router",
func_name,
"Loop-only pattern detected, not a suffix (routing.rs should handle this)",
);
}
return Ok(None);
}
let description = match &plan.kind {
PlanKind::LoopOnly => "Loop-only pattern".to_string(),
PlanKind::LoopWithPost { post_assign_count } => {
if debug {
trace.routing(
"suffix_router",
func_name,
&format!(
"Loop+post pattern detected: {} post assigns",
post_assign_count
),
);
}
format!("Loop+post pattern: {} post assigns", post_assign_count)
}
};
trace.routing("suffix_router", func_name, &description);
}
// Phase 134 P0: Delegate execution to NormalizationExecuteBox (SSOT)