refactor(joinir): Phase 223 cleanup - impl consolidation & comment cleanup
Improves code organization and readability after Phase 223-3 implementation. ## Task R-1: impl Block Consolidation **loop_body_cond_promoter.rs**: - Merged 2 separate impl blocks into single unified impl - Added section headers for better organization: - Public API (extract_continue_condition, try_promote_for_condition) - Private Helpers (contains_continue) - Improved logical flow and discoverability ## Task R-2: Phase Comment Cleanup **pattern4_with_continue.rs**: - Simplified Phase 223-3 comments (removed redundant phase numbers) - Added concise section header explaining LoopBodyLocal promotion - Clarified inline comments for better understanding - Maintained implementation intent while reducing noise ## Impact - No functional changes - All tests PASS (5 cond_promoter tests, 8 pattern4 tests) - Better code organization for future maintenance - Cleaner git history for Phase 223 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -209,16 +209,18 @@ impl MirBuilder {
|
||||
// Phase 195: Use unified trace
|
||||
trace::trace().varmap("pattern4_start", &self.variable_map);
|
||||
|
||||
// Phase 223-3: LoopBodyCondPromoter integration
|
||||
// Check for LoopBodyLocal in continue condition and attempt promotion
|
||||
// Phase 223-3: LoopBodyLocal Condition Promotion
|
||||
//
|
||||
// Check for LoopBodyLocal in loop/continue conditions and attempt promotion.
|
||||
// Safe Trim patterns (Category A-3: skip_whitespace) are promoted to carriers.
|
||||
{
|
||||
use crate::mir::loop_pattern_detection::loop_condition_scope::LoopConditionScopeBox;
|
||||
use crate::mir::loop_pattern_detection::loop_body_cond_promoter::{
|
||||
LoopBodyCondPromoter, ConditionPromotionRequest, ConditionPromotionResult,
|
||||
};
|
||||
|
||||
// Phase 223-3: Extract continue condition from body (if present)
|
||||
// This handles skip_whitespace pattern: if ch == " " || ... { continue }
|
||||
// Extract continue condition from body (if present)
|
||||
// Handles skip_whitespace pattern: if ch == " " || ... { continue }
|
||||
let continue_cond = LoopBodyCondPromoter::extract_continue_condition(body_to_analyze);
|
||||
|
||||
// Analyze both header condition and continue condition for LoopBodyLocal
|
||||
@ -235,7 +237,7 @@ impl MirBuilder {
|
||||
);
|
||||
|
||||
if cond_scope.has_loop_body_local() {
|
||||
// Phase 223-3: Try promotion using LoopBodyCondPromoter
|
||||
// Try promotion using LoopBodyCondPromoter
|
||||
let promotion_req = ConditionPromotionRequest {
|
||||
loop_param_name: &loop_var_name,
|
||||
cond_scope: &cond_scope,
|
||||
@ -256,7 +258,7 @@ impl MirBuilder {
|
||||
promoted_var, carrier_name
|
||||
);
|
||||
|
||||
// Phase 223-3: Merge promoted carrier into existing CarrierInfo
|
||||
// Merge promoted carrier into existing CarrierInfo
|
||||
carrier_info.merge_from(&promoted_carrier);
|
||||
|
||||
eprintln!(
|
||||
@ -265,7 +267,7 @@ impl MirBuilder {
|
||||
carrier_info.carrier_count()
|
||||
);
|
||||
|
||||
// Phase 223-3: Check if this is a safe Trim pattern
|
||||
// Check if this is a safe Trim pattern
|
||||
if let Some(helper) = carrier_info.trim_helper() {
|
||||
if helper.is_safe_trim() {
|
||||
eprintln!(
|
||||
@ -275,8 +277,7 @@ impl MirBuilder {
|
||||
"[pattern4/cond_promoter] Carrier: '{}', original var: '{}', whitespace chars: {:?}",
|
||||
helper.carrier_name, helper.original_var, helper.whitespace_chars
|
||||
);
|
||||
// Phase 223-3: Continue with Pattern4 lowering
|
||||
// (fall through to normal lowering path)
|
||||
// Continue with Pattern4 lowering (fall through)
|
||||
} else {
|
||||
return Err(format!(
|
||||
"[cf_loop/pattern4] Trim pattern detected but not safe: carrier='{}', whitespace_count={}",
|
||||
@ -285,11 +286,10 @@ impl MirBuilder {
|
||||
));
|
||||
}
|
||||
}
|
||||
// Phase 223-3: Continue with normal Pattern4 lowering
|
||||
// The carrier has been promoted and merged, lowering can proceed
|
||||
// Carrier promoted and merged, proceed with normal lowering
|
||||
}
|
||||
ConditionPromotionResult::CannotPromote { reason, vars } => {
|
||||
// Phase 223-3: Fail-Fast on promotion failure
|
||||
// Fail-Fast on promotion failure
|
||||
return Err(format!(
|
||||
"[cf_loop/pattern4] Cannot promote LoopBodyLocal variables {:?}: {}",
|
||||
vars, reason
|
||||
|
||||
Reference in New Issue
Block a user