diff --git a/dag_in_context/src/interpreter.rs b/dag_in_context/src/interpreter.rs index a29f2b96..27bf5f8f 100644 --- a/dag_in_context/src/interpreter.rs +++ b/dag_in_context/src/interpreter.rs @@ -4,7 +4,12 @@ //! shared as the same Rc pointer. Otherwise, effects may be executed multiple times. //! The invariant is maintained by translation from RVSDG, type checking, and translation from egglog. -use std::{collections::HashMap, fmt::Display, ops::{Shl, Shr}, rc::Rc}; +use std::{ + collections::HashMap, + fmt::Display, + ops::{Shl, Shr}, + rc::Rc, +}; use crate::{ schema::{BinaryOp, Constant, Expr, RcExpr, TernaryOp, TreeProgram, UnaryOp}, @@ -246,18 +251,14 @@ impl<'a> VirtualMachine<'a> { let a = get_int(e1, self); let b = get_int(e2, self); Const(Constant::Int(if a > b { a } else { b })) - }, + } BinaryOp::Smin => { let a = get_int(e1, self); let b = get_int(e2, self); Const(Constant::Int(if a < b { a } else { b })) - }, - BinaryOp::Shl => Const(Constant::Int( - get_int(e1, self).shl(get_int(e2, self)) - )), - BinaryOp::Shr => Const(Constant::Int( - get_int(e1, self).shr(get_int(e2, self)) - )), + } + BinaryOp::Shl => Const(Constant::Int(get_int(e1, self).shl(get_int(e2, self)))), + BinaryOp::Shr => Const(Constant::Int(get_int(e1, self).shr(get_int(e2, self)))), BinaryOp::Eq => Const(Constant::Bool(get_int(e1, self) == get_int(e2, self))), BinaryOp::LessThan => Const(Constant::Bool(get_int(e1, self) < get_int(e2, self))), BinaryOp::GreaterThan => Const(Constant::Bool(get_int(e1, self) > get_int(e2, self))), @@ -323,13 +324,12 @@ impl<'a> VirtualMachine<'a> { let a = get_float(e1, self); let b = get_float(e2, self); Const(Constant::Float(if a > b { a } else { b })) - }, + } BinaryOp::Fmin => { let a = get_float(e1, self); let b = get_float(e2, self); Const(Constant::Float(if a < b { a } else { b })) - }, - + } } } diff --git a/dag_in_context/src/optimizations/purity_analysis.rs b/dag_in_context/src/optimizations/purity_analysis.rs index 0e82ced7..dae713f3 100644 --- a/dag_in_context/src/optimizations/purity_analysis.rs +++ b/dag_in_context/src/optimizations/purity_analysis.rs @@ -13,8 +13,10 @@ fn top_is_pure(top: &TernaryOp) -> bool { fn bop_is_pure(bop: &BinaryOp) -> bool { use BinaryOp::*; match bop { - Add | Sub | Mul | LessThan | Div | Eq | GreaterThan | LessEq | GreaterEq | Smax | Smin | Shl | Shr => true, - FAdd | FSub | FMul | FLessThan | FDiv | FEq | FGreaterThan | FLessEq | FGreaterEq | Fmax | Fmin => true, + Add | Sub | Mul | LessThan | Div | Eq | GreaterThan | LessEq | GreaterEq | Smax | Smin + | Shl | Shr => true, + FAdd | FSub | FMul | FLessThan | FDiv | FEq | FGreaterThan | FLessEq | FGreaterEq + | Fmax | Fmin => true, PtrAdd => true, And | Or => true, Load | Print | Free => false, diff --git a/dag_in_context/src/schema_helpers.rs b/dag_in_context/src/schema_helpers.rs index 2ef51cb3..30c3fb22 100644 --- a/dag_in_context/src/schema_helpers.rs +++ b/dag_in_context/src/schema_helpers.rs @@ -696,12 +696,20 @@ impl BinaryOp { /// When a binary op has concrete input sorts, return them. pub fn types(&self) -> Option<(Type, Type, Type)> { match self { - BinaryOp::Add | BinaryOp::Sub | BinaryOp::Mul | BinaryOp::Div | BinaryOp::Smax | BinaryOp::Smin | BinaryOp::Shl | BinaryOp::Shr => { - Some((base(intt()), base(intt()), base(intt()))) - } - BinaryOp::FAdd | BinaryOp::FSub | BinaryOp::FMul | BinaryOp::FDiv | BinaryOp::Fmax | BinaryOp::Fmin => { - Some((base(floatt()), base(floatt()), base(floatt()))) - } + BinaryOp::Add + | BinaryOp::Sub + | BinaryOp::Mul + | BinaryOp::Div + | BinaryOp::Smax + | BinaryOp::Smin + | BinaryOp::Shl + | BinaryOp::Shr => Some((base(intt()), base(intt()), base(intt()))), + BinaryOp::FAdd + | BinaryOp::FSub + | BinaryOp::FMul + | BinaryOp::FDiv + | BinaryOp::Fmax + | BinaryOp::Fmin => Some((base(floatt()), base(floatt()), base(floatt()))), BinaryOp::And | BinaryOp::Or => Some((base(boolt()), base(boolt()), base(boolt()))), BinaryOp::LessThan | BinaryOp::GreaterThan