Previously, cheapEqExpr would always return False if it encountered a cast.
This was bad for two reasons. Firstly, CSE (which uses cheapEqExpr to compare
expressions) never eliminated expressions which contained casts and secondly,
it was inconsistent with exprIsBig. This patch fixes this.
exprEtaExpandArity, etaExpand,
-- Size
exprEtaExpandArity, etaExpand,
-- Size
+ coreBindsSize, exprSize,
cheapEqExpr (App f1 a1) (App f2 a2)
= f1 `cheapEqExpr` f2 && a1 `cheapEqExpr` a2
cheapEqExpr (App f1 a1) (App f2 a2)
= f1 `cheapEqExpr` f2 && a1 `cheapEqExpr` a2
+cheapEqExpr (Cast e1 t1) (Cast e2 t2)
+ = e1 `cheapEqExpr` e2 && t1 `coreEqCoercion` t2
+
cheapEqExpr _ _ = False
exprIsBig :: Expr b -> Bool
cheapEqExpr _ _ = False
exprIsBig :: Expr b -> Bool
transCoercionTyCon, leftCoercionTyCon,
rightCoercionTyCon, instCoercionTyCon, -- needed by TysWiredIn
transCoercionTyCon, leftCoercionTyCon,
rightCoercionTyCon, instCoercionTyCon, -- needed by TysWiredIn
+ -- Comparison
+ coreEqCoercion,
+
-- CoercionI
CoercionI(..),
isIdentityCoercion,
-- CoercionI
CoercionI(..),
isIdentityCoercion,
-- This case handled by coreView
splitNewTypeRepCo_maybe _
= Nothing
-- This case handled by coreView
splitNewTypeRepCo_maybe _
= Nothing
+
+-------------------------------------
+-- Syntactic equality of coercions
+
+coreEqCoercion :: Coercion -> Coercion -> Bool
+coreEqCoercion = coreEqType