..
This commit is contained in:
@@ -21,6 +21,10 @@ pub fn optimize_expr(expr: TypedExpr) -> TypedExpr {
|
||||
}
|
||||
|
||||
pub fn bubble_binop_vars(expr: TypedExpr) -> TypedExpr {
|
||||
if expr.is_const() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
let expr = reorder_commutative_expr(expr);
|
||||
|
||||
let expr = match expr {
|
||||
@@ -138,6 +142,10 @@ fn optimize_special_cases(lhs: TypedExpr, op: BinOp, rhs: TypedExpr) -> TypedExp
|
||||
lhs
|
||||
},
|
||||
|
||||
// Subtraction by zero
|
||||
(lhs, TypedExpr::Int { value: 0, .. }) if matches!(op, BinOp::Sub) => lhs,
|
||||
(lhs, TypedExpr::Float { value: 0.0, .. }) if matches!(op, BinOp::Sub) => lhs,
|
||||
|
||||
// Multiplication/Division by one
|
||||
(lhs, TypedExpr::Int { value: 1, .. }) if matches!(op, BinOp::Mul | BinOp::Div) => lhs,
|
||||
(lhs, TypedExpr::Float { value: 1.0, .. }) if matches!(op, BinOp::Mul | BinOp::Div) => lhs,
|
||||
|
||||
@@ -78,8 +78,11 @@ impl fmt::Display for Type {
|
||||
|
||||
impl TypedExpr {
|
||||
pub fn cast_to_float(self) -> TypedExpr {
|
||||
Self::IntToFloat {
|
||||
value: Box::new(self),
|
||||
match self {
|
||||
Self::IntToFloat { .. } | Self::Float { .. } => self,
|
||||
_ => Self::IntToFloat {
|
||||
value: Box::new(self),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user