From a4835b8b82170a11fde4a5d05b3f4ecea7376d97 Mon Sep 17 00:00:00 2001 From: Roman Leshchinskiy Date: Wed, 6 Feb 2008 03:50:07 +0000 Subject: [PATCH] Teach cheapEqExpr about casts 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. --- compiler/coreSyn/CoreUtils.lhs | 5 ++++- compiler/types/Coercion.lhs | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/coreSyn/CoreUtils.lhs b/compiler/coreSyn/CoreUtils.lhs index a00a529..05d429e 100644 --- a/compiler/coreSyn/CoreUtils.lhs +++ b/compiler/coreSyn/CoreUtils.lhs @@ -34,7 +34,7 @@ module CoreUtils ( exprEtaExpandArity, etaExpand, -- Size - coreBindsSize, + coreBindsSize, exprSize, -- Hashing hashExpr, @@ -1271,6 +1271,9 @@ cheapEqExpr (Type t1) (Type t2) = t1 `coreEqType` t2 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 diff --git a/compiler/types/Coercion.lhs b/compiler/types/Coercion.lhs index b74a8af..756026b 100644 --- a/compiler/types/Coercion.lhs +++ b/compiler/types/Coercion.lhs @@ -42,6 +42,9 @@ module Coercion ( transCoercionTyCon, leftCoercionTyCon, rightCoercionTyCon, instCoercionTyCon, -- needed by TysWiredIn + -- Comparison + coreEqCoercion, + -- CoercionI CoercionI(..), isIdentityCoercion, @@ -482,6 +485,12 @@ splitNewTypeRepCo_maybe (TyConApp tc tys) -- This case handled by coreView splitNewTypeRepCo_maybe _ = Nothing + +------------------------------------- +-- Syntactic equality of coercions + +coreEqCoercion :: Coercion -> Coercion -> Bool +coreEqCoercion = coreEqType \end{code} -- 1.7.10.4