Perform 'tidying' on the implicit bindings before emitting
External Core. We were getting silly bindings like
\ tpl -> case tpl of tpl -> (tpl,tpl) -> tpl
Maybe we should add these implicit bindings in CoreTidy,
rather than in both MkExternalCore and CorePrep?
------------ Expressions --------------
-tidyCoreExpr :: CoreExpr -> IO CoreExpr
-tidyCoreExpr expr = return (tidyExpr emptyTidyEnv expr)
-
tidyExpr env (Var v) = Var (tidyVarOcc env v)
tidyExpr env (Type ty) = Type (tidyType env ty)
tidyExpr env (Lit lit) = Lit lit
import Var
import IdInfo
import Id( idUnfolding )
+import CoreTidy( tidyExpr )
+import VarEnv( emptyTidyEnv )
import Literal
import Name
import CostCentre
implicit_ids other = []
get_defn :: Id -> CoreBind
-get_defn id = NonRec id (unfoldingTemplate (idUnfolding id))
+get_defn id = NonRec id rhs
+ where
+ rhs = tidyExpr emptyTidyEnv body
+ body = unfoldingTemplate (idUnfolding id)
+ -- Don't forget to tidy the body ! Otherwise you get silly things like
+ -- \ tpl -> case tpl of tpl -> (tpl,tpl) -> tpl
+ -- Maybe we should inject these bindings during CoreTidy?
collect_tdefs :: TyCon -> [C.Tdef] -> [C.Tdef]
collect_tdefs tcon tdefs