1
0

do not bubble_binop_vars when not needed

This commit is contained in:
2024-11-13 21:00:41 +03:00
parent ca51061ddd
commit 7c766e45a0

View File

@@ -29,9 +29,8 @@ pub fn bubble_binop_vars(expr: TypedExpr) -> TypedExpr {
let rhs = *rhs;
let lhs = bubble_binop_vars(lhs);
let rhs = bubble_binop_vars(rhs);
let (lhs, rhs, op) = match (lhs, rhs) {
let (lhs, rhs, op, rebubble) = match (lhs, rhs) {
(
TypedExpr::BinOp {
lhs: lhs1,
@@ -47,18 +46,22 @@ pub fn bubble_binop_vars(expr: TypedExpr) -> TypedExpr {
},
*rhs1,
op1,
true,
),
(lhs, rhs) if !lhs.is_const() && rhs.is_const() && op.swappable(&op) => {
(rhs, lhs, op)
(rhs, lhs, op, false)
},
(lhs, rhs) if op.precedence() < lhs.precedence() && op.swappable(&op) => {
(rhs, lhs, op)
(rhs, lhs, op, true)
},
(lhs, rhs) => (lhs, rhs, op),
(lhs, rhs) => (lhs, rhs, op, false),
};
let lhs = bubble_binop_vars(lhs);
let rhs = bubble_binop_vars(rhs);
let lhs = if rebubble {
bubble_binop_vars(lhs)
} else {
lhs
};
TypedExpr::BinOp {
lhs: Box::new(lhs),