From: Matthijs Kooijman Date: Tue, 14 Jul 2009 13:31:56 +0000 (+0200) Subject: Don't create selector cases for unused binders. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=43c13fec6c7ce3eccb509b7b136789704ae2f952;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git 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. --- 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