From 43c13fec6c7ce3eccb509b7b136789704ae2f952 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 14 Jul 2009 15:31:56 +0200 Subject: [PATCH] Don't create selector cases for unused binders. Previously, no selector cases were created for wild binders, using the hacky is_wild predicate. Now, this checks the free variables of the case value instead. --- Normalize.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Normalize.hs b/Normalize.hs index 16d7969..3f9389a 100644 --- a/Normalize.hs +++ b/Normalize.hs @@ -220,14 +220,16 @@ casewild expr@(Case scrut b ty alts) = do where -- Make all binders wild wildbndrs = map (\bndr -> Id.mkWildId (Id.idType bndr)) bndrs + -- A set of all the binders that are used by the expression + free_vars = CoreFVs.exprSomeFreeVars (`elem` bndrs) expr -- Creates a case statement to retrieve the ith element from the scrutinee -- and binds that to b. mkextracts :: CoreBndr -> Int -> TransformMonad (Maybe (CoreBndr, CoreExpr)) mkextracts b i = - -- TODO: Use free variables instead of is_wild. is_wild is a hack. - if is_wild b || Type.isFunTy (Id.idType b) - -- Don't create extra bindings for binders that are already wild, or - -- for binders that bind function types (to prevent loops with + if not (VarSet.elemVarSet b free_vars) || Type.isFunTy (Id.idType b) + -- Don't create extra bindings for binders that are already wild + -- (e.g. not in the free variables of expr, so unused), or for + -- binders that bind function types (to prevent loops with -- inlinefun). then return Nothing else do -- 2.30.2