X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FcoreSyn%2FCoreTidy.lhs;h=b77186e7f86787386ffbce7136540e5b7a655f3c;hp=696cadd964cebe0bf7a078d460ac52d3b485c1ac;hb=2662dbc5b2c30fc11ccb99e7f9b2dba794d680ba;hpb=ad94d40948668032189ad22a0ad741ac1f645f50 diff --git a/compiler/coreSyn/CoreTidy.lhs b/compiler/coreSyn/CoreTidy.lhs index 696cadd..b77186e 100644 --- a/compiler/coreSyn/CoreTidy.lhs +++ b/compiler/coreSyn/CoreTidy.lhs @@ -7,13 +7,6 @@ This module contains "tidying" code for *nested* expressions, bindings, rules. The code for *top-level* bindings is in TidyPgm. \begin{code} -{-# OPTIONS -w #-} --- The above warning supression flag is a temporary kludge. --- While working on this module you are encouraged to remove it and fix --- any warnings in the module. See --- http://hackage.haskell.org/trac/ghc/wiki/CodingStyle#Warnings --- for details - module CoreTidy ( tidyExpr, tidyVarOcc, tidyRule, tidyRules ) where @@ -21,7 +14,7 @@ module CoreTidy ( #include "HsVersions.h" import CoreSyn -import CoreUtils +import CoreArity import Id import IdInfo import Type @@ -29,7 +22,6 @@ import Var import VarEnv import UniqFM import Name hiding (tidyNameOcc) -import OccName import SrcLoc import Maybes @@ -62,7 +54,7 @@ tidyBind env (Rec prs) tidyExpr :: TidyEnv -> CoreExpr -> CoreExpr tidyExpr env (Var v) = Var (tidyVarOcc env v) tidyExpr env (Type ty) = Type (tidyType env ty) -tidyExpr env (Lit lit) = Lit lit +tidyExpr _ (Lit lit) = Lit lit tidyExpr env (App f a) = App (tidyExpr env f) (tidyExpr env a) tidyExpr env (Note n e) = Note (tidyNote env n) (tidyExpr env e) tidyExpr env (Cast e co) = Cast (tidyExpr env e) (tidyType env co) @@ -81,23 +73,25 @@ tidyExpr env (Lam b e) Lam b (tidyExpr env' e) ------------ Case alternatives -------------- -tidyAlt case_bndr env (con, vs, rhs) +tidyAlt :: CoreBndr -> TidyEnv -> CoreAlt -> CoreAlt +tidyAlt _case_bndr env (con, vs, rhs) = tidyBndrs env vs =: \ (env', vs) -> (con, vs, tidyExpr env' rhs) ------------ Notes -------------- -tidyNote env note = note +tidyNote :: TidyEnv -> Note -> Note +tidyNote _ note = note ------------ Rules -------------- tidyRules :: TidyEnv -> [CoreRule] -> [CoreRule] -tidyRules env [] = [] +tidyRules _ [] = [] tidyRules env (rule : rules) = tidyRule env rule =: \ rule -> tidyRules env rules =: \ rules -> (rule : rules) tidyRule :: TidyEnv -> CoreRule -> CoreRule -tidyRule env rule@(BuiltinRule {}) = rule +tidyRule _ rule@(BuiltinRule {}) = rule tidyRule env rule@(Rule { ru_bndrs = bndrs, ru_args = args, ru_rhs = rhs, ru_fn = fn, ru_rough = mb_ns }) = tidyBndrs env bndrs =: \ (env', bndrs) -> @@ -159,10 +153,10 @@ tidyLetBndr env (id,rhs) -- separate compilation boundaries final_id = new_id `setIdInfo` new_info idinfo = idInfo id - new_info = vanillaIdInfo + new_info = idInfo new_id `setArityInfo` exprArity rhs - `setAllStrictnessInfo` newStrictnessInfo idinfo - `setNewDemandInfo` newDemandInfo idinfo + `setStrictnessInfo` strictnessInfo idinfo + `setDemandInfo` demandInfo idinfo `setInlinePragInfo` inlinePragInfo idinfo -- Override the env we get back from tidyId with the new IdInfo @@ -172,7 +166,7 @@ tidyLetBndr env (id,rhs) -- Non-top-level variables tidyIdBndr :: TidyEnv -> Id -> (TidyEnv, Id) tidyIdBndr env@(tidy_env, var_env) id - = -- do this pattern match strictly, otherwise we end up holding on to + = -- Do this pattern match strictly, otherwise we end up holding on to -- stuff in the OccName. case tidyOccName tidy_env (getOccName id) of { (tidy_env', occ') -> let @@ -180,18 +174,37 @@ tidyIdBndr env@(tidy_env, var_env) id -- The SrcLoc isn't important now, -- though we could extract it from the Id -- - -- All nested Ids now have the same IdInfo, namely vanillaIdInfo, - -- which should save some space. - -- But note that tidyLetBndr puts some of it back. - ty' = tidyType env (idType id) - id' = mkUserLocal occ' (idUnique id) ty' noSrcSpan - `setIdInfo` vanillaIdInfo - var_env' = extendVarEnv var_env id id' + ty' = tidyType env (idType id) + name' = mkInternalName (idUnique id) occ' noSrcSpan + id' = mkLocalIdWithInfo name' ty' new_info + var_env' = extendVarEnv var_env id id' + + -- Note [Tidy IdInfo] + new_info = vanillaIdInfo `setOccInfo` occInfo old_info + old_info = idInfo id in - ((tidy_env', var_env'), id') + ((tidy_env', var_env'), id') } \end{code} +Note [Tidy IdInfo] +~~~~~~~~~~~~~~~~~~ +All nested Ids now have the same IdInfo, namely vanillaIdInfo, which +should save some space; except that we preserve occurrence info for +two reasons: + + (a) To make printing tidy core nicer + + (b) Because we tidy RULES and InlineRules, which may then propagate + via --make into the compilation of the next module, and we want + the benefit of that occurrence analysis when we use the rule or + or inline the function. In particular, it's vital not to lose + loop-breaker info, else we get an infinite inlining loop + +Note that tidyLetBndr puts more IdInfo back. + + \begin{code} +(=:) :: a -> (a -> b) -> b m =: k = m `seq` k m \end{code}