refactor(joinir): Phase 242-EX-A - Delete legacy Pattern3 lowerer
Remove hardcoded Pattern3 PoC implementation (loop_with_if_phi_minimal.rs) and enhance if-sum mode to handle complex conditions like `i % 2 == 1`. Key changes: - condition_pattern.rs: Accept BinaryOp in comparison operands (+58 lines) - loop_with_if_phi_if_sum.rs: Dynamic complex condition lowering (+147 lines) - pattern3_with_if_phi.rs: Remove lower_pattern3_legacy() (-130 lines) - loop_with_if_phi_minimal.rs: Delete entire file (-437 lines) - loop_patterns/with_if_phi.rs: Update stub (-45 lines) - mod.rs: Remove module reference (-4 lines) Net reduction: -664 lines of hardcoded PoC code Test results: 909/909 PASS (legacy mode completely removed) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -79,15 +79,16 @@ impl MirBuilder {
|
||||
PatternVariant::Pattern3,
|
||||
)?;
|
||||
|
||||
// Phase 213: Dual-mode dispatch based on if-sum pattern detection
|
||||
if ctx.is_if_sum_pattern() {
|
||||
trace::trace().debug("pattern3", "Detected if-sum pattern, using AST-based lowerer");
|
||||
return self.lower_pattern3_if_sum(&ctx, condition, body, debug);
|
||||
// Phase 213: AST-based if-sum pattern detection
|
||||
// Phase 242-EX-A: Legacy mode removed - all if-sum patterns now handled dynamically
|
||||
if !ctx.is_if_sum_pattern() {
|
||||
// Not an if-sum pattern → let router try other patterns or fall back
|
||||
trace::trace().debug("pattern3", "Not an if-sum pattern, returning None to try other patterns");
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
// Legacy mode: Use hardcoded PoC lowering (e.g., loop_if_phi.hako)
|
||||
trace::trace().debug("pattern3", "Using legacy PoC lowerer (hardcoded conditions)");
|
||||
self.lower_pattern3_legacy(&ctx, debug)
|
||||
trace::trace().debug("pattern3", "Detected if-sum pattern, using AST-based lowerer");
|
||||
self.lower_pattern3_if_sum(&ctx, condition, body, debug)
|
||||
}
|
||||
|
||||
/// Phase 213: AST-based if-sum lowerer
|
||||
@ -242,118 +243,5 @@ impl MirBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Phase 188-195: Legacy PoC lowerer (hardcoded conditions)
|
||||
///
|
||||
/// Kept for backward compatibility with existing tests like `loop_if_phi.hako`.
|
||||
fn lower_pattern3_legacy(
|
||||
&mut self,
|
||||
ctx: &super::pattern_pipeline::PatternPipelineContext,
|
||||
debug: bool,
|
||||
) -> Result<Option<ValueId>, String> {
|
||||
use crate::mir::join_ir::lowering::loop_with_if_phi_minimal::lower_loop_with_if_phi_pattern;
|
||||
|
||||
// Phase 195: Use unified trace
|
||||
trace::trace().varmap("pattern3_start", &self.variable_map);
|
||||
|
||||
// Phase 202-B: Create JoinValueSpace for unified ValueId allocation
|
||||
use crate::mir::join_ir::lowering::join_value_space::JoinValueSpace;
|
||||
let mut join_value_space = JoinValueSpace::new();
|
||||
|
||||
// Call Pattern 3 lowerer with preprocessed scope
|
||||
let (join_module, fragment_meta) = match lower_loop_with_if_phi_pattern(ctx.loop_scope.clone(), &mut join_value_space) {
|
||||
Ok(result) => result,
|
||||
Err(e) => {
|
||||
trace::trace().debug("pattern3", &format!("Pattern 3 lowerer failed: {}", e));
|
||||
return Err(format!("[cf_loop/pattern3] Lowering failed: {}", e));
|
||||
}
|
||||
};
|
||||
|
||||
let exit_meta = &fragment_meta.exit_meta;
|
||||
|
||||
trace::trace().debug(
|
||||
"pattern3",
|
||||
&format!("ExitMeta: {} exit values", exit_meta.exit_values.len())
|
||||
);
|
||||
for (carrier_name, join_value) in &exit_meta.exit_values {
|
||||
trace::trace().debug(
|
||||
"pattern3",
|
||||
&format!(" {} → ValueId({})", carrier_name, join_value.0)
|
||||
);
|
||||
}
|
||||
|
||||
// Phase 195: Create boundary from context (multi-carrier support with backward compatibility)
|
||||
// Phase 201: Use JoinInlineBoundaryBuilder for clean construction
|
||||
// Canonical Builder pattern - see docs/development/current/main/joinir-boundary-builder-pattern.md
|
||||
self.trace_varmap("pattern3_before_merge");
|
||||
use crate::mir::join_ir::lowering::JoinInlineBoundaryBuilder;
|
||||
|
||||
// Phase 213: Use ExitMetaCollector for dynamic exit binding generation
|
||||
// Note: ExitMetaCollector internally validates that all exit carriers in ExitMeta
|
||||
// have corresponding variable_map entries. No additional validation needed here.
|
||||
// Phase 228-8: Pass None for carrier_info (legacy path doesn't have ConditionOnly carriers)
|
||||
let exit_bindings = ExitMetaCollector::collect(
|
||||
self,
|
||||
exit_meta,
|
||||
None, // Phase 228-8: No carrier_info in legacy path
|
||||
debug,
|
||||
);
|
||||
|
||||
// Phase 214: Dynamically generate join_inputs based on exit_bindings
|
||||
// Count: 1 loop_var + exit_bindings.len() = total inputs
|
||||
// NOTE: exit_bindings already filtered out non-existent carriers
|
||||
let total_inputs = 1 + exit_bindings.len();
|
||||
|
||||
// Allocate join_inputs dynamically from JoinValueSpace
|
||||
let join_inputs: Vec<ValueId> = (0..total_inputs)
|
||||
.map(|i| ValueId(i as u32))
|
||||
.collect();
|
||||
|
||||
// Build host_inputs: loop_var + exit_bindings (in order)
|
||||
let mut host_inputs = vec![ctx.loop_var_id];
|
||||
for binding in &exit_bindings {
|
||||
host_inputs.push(binding.host_slot);
|
||||
}
|
||||
|
||||
// Phase 214: Verify length consistency (fail-fast assertion)
|
||||
debug_assert_eq!(
|
||||
join_inputs.len(),
|
||||
host_inputs.len(),
|
||||
"[pattern3/legacy] join_inputs.len({}) != host_inputs.len({})",
|
||||
join_inputs.len(),
|
||||
host_inputs.len()
|
||||
);
|
||||
|
||||
trace::trace().debug(
|
||||
"pattern3/legacy",
|
||||
&format!(
|
||||
"Boundary inputs: {} total (loop_var + {} exit bindings)",
|
||||
total_inputs, exit_bindings.len()
|
||||
)
|
||||
);
|
||||
|
||||
let boundary = JoinInlineBoundaryBuilder::new()
|
||||
.with_inputs(join_inputs, host_inputs)
|
||||
.with_exit_bindings(exit_bindings)
|
||||
.with_loop_var_name(Some(ctx.loop_var_name.clone())) // Phase 33-16: Enable header PHI generation for SSA correctness
|
||||
.build();
|
||||
|
||||
// Phase 33-22: Use JoinIRConversionPipeline for unified conversion flow
|
||||
use super::conversion_pipeline::JoinIRConversionPipeline;
|
||||
let _ = JoinIRConversionPipeline::execute(
|
||||
self,
|
||||
join_module,
|
||||
Some(&boundary),
|
||||
"pattern3",
|
||||
debug,
|
||||
)?;
|
||||
self.trace_varmap("pattern3_after_merge");
|
||||
|
||||
// Phase 179-B: Return Void (loop doesn't produce values)
|
||||
let void_val = crate::mir::builder::emission::constant::emit_void(self);
|
||||
|
||||
// Phase 195: Use unified trace
|
||||
trace::trace().debug("pattern3", &format!("Loop complete, returning Void {:?}", void_val));
|
||||
|
||||
Ok(Some(void_val))
|
||||
}
|
||||
// Phase 242-EX-A: lower_pattern3_legacy removed - all patterns now use AST-based lowering
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user