-\begin{code}
-eqExpr :: IdUnfoldingFun -> RnEnv2 -> CoreExpr -> CoreExpr -> Bool
--- ^ A kind of shallow equality used in rule matching, so does
--- /not/ look through newtypes or predicate types
-
-eqExpr _ env (Var v1) (Var v2)
- | rnOccL env v1 == rnOccR env v2
- = True
-
--- The next two rules expand non-local variables
--- C.f. Note [Expanding variables]
--- and Note [Do not expand locally-bound variables]
-eqExpr id_unfolding_fun env (Var v1) e2
- | not (locallyBoundL env v1)
- , Just e1' <- expandUnfolding (id_unfolding_fun (lookupRnInScope env v1))
- = eqExpr id_unfolding_fun (nukeRnEnvL env) e1' e2
-
-eqExpr id_unfolding_fun env e1 (Var v2)
- | not (locallyBoundR env v2)
- , Just e2' <- expandUnfolding (id_unfolding_fun (lookupRnInScope env v2))
- = eqExpr id_unfolding_fun (nukeRnEnvR env) e1 e2'
-
-eqExpr _ _ (Lit lit1) (Lit lit2) = lit1 == lit2
-eqExpr idu env (App f1 a1) (App f2 a2) = eqExpr idu env f1 f2 && eqExpr idu env a1 a2
-eqExpr idu env (Lam v1 e1) (Lam v2 e2) = eqExpr idu (rnBndr2 env v1 v2) e1 e2
-eqExpr idu env (Note n1 e1) (Note n2 e2) = eq_note env n1 n2 && eqExpr idu env e1 e2
-eqExpr idu env (Cast e1 co1) (Cast e2 co2) = tcEqTypeX env co1 co2 && eqExpr idu env e1 e2
-eqExpr _ env (Type t1) (Type t2) = tcEqTypeX env t1 t2
-
-eqExpr idu env (Let (NonRec v1 r1) e1)
- (Let (NonRec v2 r2) e2) = eqExpr idu env r1 r2
- && eqExpr idu (rnBndr2 env v1 v2) e1 e2
-eqExpr idu env (Let (Rec ps1) e1)
- (Let (Rec ps2) e2) = equalLength ps1 ps2
- && and (zipWith eq_rhs ps1 ps2)
- && eqExpr idu env' e1 e2
- where
- env' = foldl2 rn_bndr2 env ps2 ps2
- rn_bndr2 env (b1,_) (b2,_) = rnBndr2 env b1 b2
- eq_rhs (_,r1) (_,r2) = eqExpr idu env' r1 r2
-eqExpr idu env (Case e1 v1 t1 a1)
- (Case e2 v2 t2 a2) = eqExpr idu env e1 e2
- && tcEqTypeX env t1 t2
- && equalLength a1 a2
- && and (zipWith eq_alt a1 a2)
- where
- env' = rnBndr2 env v1 v2
- eq_alt (c1,vs1,r1) (c2,vs2,r2)
- = c1==c2 && eqExpr idu (rnBndrs2 env' vs1 vs2) r1 r2
-eqExpr _ _ _ _ = False
-
-eq_note :: RnEnv2 -> Note -> Note -> Bool
-eq_note _ (SCC cc1) (SCC cc2) = cc1 == cc2
-eq_note _ (CoreNote s1) (CoreNote s2) = s1 == s2
-eq_note _ _ _ = False
-\end{code}
-
-Auxiliary functions
-
-\begin{code}
-locallyBoundL, locallyBoundR :: RnEnv2 -> Var -> Bool
-locallyBoundL rn_env v = inRnEnvL rn_env v
-locallyBoundR rn_env v = inRnEnvR rn_env v
-
-
-expandUnfolding :: Unfolding -> Maybe CoreExpr
-expandUnfolding unfolding
- | isExpandableUnfolding unfolding = Just (unfoldingTemplate unfolding)
- | otherwise = Nothing
-\end{code}
-