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:
@ -67,14 +67,14 @@ pub enum ConditionPattern {
|
||||
/// };
|
||||
/// assert_eq!(analyze_condition_pattern(&simple), ConditionPattern::SimpleComparison);
|
||||
///
|
||||
/// // Complex: i % 2 == 1
|
||||
/// // Phase 242-EX-A: Now Simple: i % 2 == 1 (BinaryOp in LHS)
|
||||
/// let complex = ASTNode::BinaryOp {
|
||||
/// operator: BinaryOperator::Equal,
|
||||
/// left: Box::new(ASTNode::BinaryOp { ... }), // BinaryOp in LHS
|
||||
/// right: Box::new(ASTNode::Literal { value: LiteralValue::Integer(1), span: Span::unknown() }),
|
||||
/// span: Span::unknown(),
|
||||
/// };
|
||||
/// assert_eq!(analyze_condition_pattern(&complex), ConditionPattern::Complex);
|
||||
/// assert_eq!(analyze_condition_pattern(&complex), ConditionPattern::SimpleComparison);
|
||||
/// ```
|
||||
pub fn analyze_condition_pattern(cond: &ASTNode) -> ConditionPattern {
|
||||
match cond {
|
||||
@ -96,11 +96,16 @@ pub fn analyze_condition_pattern(cond: &ASTNode) -> ConditionPattern {
|
||||
return ConditionPattern::Complex;
|
||||
}
|
||||
|
||||
// Phase 242-EX-A: Accept any expr CmpOp expr pattern
|
||||
// The lowerer (loop_with_if_phi_if_sum.rs) will handle BinaryOp via lower_value_expression
|
||||
|
||||
// Check LHS/RHS patterns
|
||||
let left_is_var = matches!(left.as_ref(), ASTNode::Variable { .. });
|
||||
let left_is_literal = matches!(left.as_ref(), ASTNode::Literal { .. });
|
||||
let left_is_binop = matches!(left.as_ref(), ASTNode::BinaryOp { .. });
|
||||
let right_is_var = matches!(right.as_ref(), ASTNode::Variable { .. });
|
||||
let right_is_literal = matches!(right.as_ref(), ASTNode::Literal { .. });
|
||||
let right_is_binop = matches!(right.as_ref(), ASTNode::BinaryOp { .. });
|
||||
|
||||
// Phase 219: var CmpOp literal (e.g., i > 0)
|
||||
if left_is_var && right_is_literal {
|
||||
@ -117,7 +122,32 @@ pub fn analyze_condition_pattern(cond: &ASTNode) -> ConditionPattern {
|
||||
return ConditionPattern::SimpleComparison;
|
||||
}
|
||||
|
||||
// Complex LHS/RHS (e.g., i % 2 == 1, method_call() > 0)
|
||||
// Phase 242-EX-A: BinaryOp CmpOp literal (e.g., i % 2 == 1)
|
||||
if left_is_binop && right_is_literal {
|
||||
return ConditionPattern::SimpleComparison;
|
||||
}
|
||||
|
||||
// Phase 242-EX-A: BinaryOp CmpOp var (e.g., i + j > k)
|
||||
if left_is_binop && right_is_var {
|
||||
return ConditionPattern::SimpleComparison;
|
||||
}
|
||||
|
||||
// Phase 242-EX-A: var CmpOp BinaryOp (e.g., i > j + 1)
|
||||
if left_is_var && right_is_binop {
|
||||
return ConditionPattern::SimpleComparison;
|
||||
}
|
||||
|
||||
// Phase 242-EX-A: literal CmpOp BinaryOp (e.g., 0 < i + 1)
|
||||
if left_is_literal && right_is_binop {
|
||||
return ConditionPattern::SimpleComparison;
|
||||
}
|
||||
|
||||
// Phase 242-EX-A: BinaryOp CmpOp BinaryOp (e.g., a + b > c + d)
|
||||
if left_is_binop && right_is_binop {
|
||||
return ConditionPattern::SimpleComparison;
|
||||
}
|
||||
|
||||
// Complex LHS/RHS (e.g., method_call() > 0) - MethodCall not yet supported
|
||||
ConditionPattern::Complex
|
||||
}
|
||||
// Any other node type → Complex
|
||||
@ -350,21 +380,21 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_complex_binop_in_lhs() {
|
||||
// i % 2 == 1 (BinaryOp in LHS)
|
||||
fn test_simple_binop_in_lhs() {
|
||||
// Phase 242-EX-A: i % 2 == 1 (BinaryOp in LHS) is now SimpleComparison
|
||||
let lhs = binop(BinaryOperator::Modulo, var("i"), int_lit(2));
|
||||
let cond = binop(BinaryOperator::Equal, lhs, int_lit(1));
|
||||
assert_eq!(analyze_condition_pattern(&cond), ConditionPattern::Complex);
|
||||
assert!(!is_simple_comparison(&cond));
|
||||
assert_eq!(analyze_condition_pattern(&cond), ConditionPattern::SimpleComparison);
|
||||
assert!(is_simple_comparison(&cond));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_complex_binop_in_rhs() {
|
||||
// i == a + b (BinaryOp in RHS)
|
||||
fn test_simple_binop_in_rhs() {
|
||||
// Phase 242-EX-A: i == a + b (BinaryOp in RHS) is now SimpleComparison
|
||||
let rhs = binop(BinaryOperator::Add, var("a"), var("b"));
|
||||
let cond = binop(BinaryOperator::Equal, var("i"), rhs);
|
||||
assert_eq!(analyze_condition_pattern(&cond), ConditionPattern::Complex);
|
||||
assert!(!is_simple_comparison(&cond));
|
||||
assert_eq!(analyze_condition_pattern(&cond), ConditionPattern::SimpleComparison);
|
||||
assert!(is_simple_comparison(&cond));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -470,8 +500,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_fails_on_complex() {
|
||||
// i % 2 == 1 → 正規化失敗(BinaryOp in LHS)
|
||||
fn test_normalize_fails_on_binop() {
|
||||
// Phase 242-EX-A: i % 2 == 1 → 正規化失敗(BinaryOp in LHS)
|
||||
// Note: This is OK - normalization is only for simple cases.
|
||||
// The if-sum lowerer will use lower_value_expression() instead.
|
||||
let lhs = binop(BinaryOperator::Modulo, var("i"), int_lit(2));
|
||||
let cond = binop(BinaryOperator::Equal, lhs, int_lit(1));
|
||||
assert_eq!(normalize_comparison(&cond), None);
|
||||
|
||||
Reference in New Issue
Block a user