+ ; let prs = pcs_PRS pcs
+ orig_ns = prsOrig prs
+
+ init_tidy_env = (orig_ns, initTidyOccEnv avoids, emptyVarEnv)
+ avoids = [getOccName name | bndr <- typeEnvIds env_tc,
+ let name = idName bndr,
+ isExternalName name]
+ -- In computing our "avoids" list, we must include
+ -- all implicit Ids
+ -- all things with global names (assigned once and for
+ -- all by the renamer)
+ -- since their names are "taken".
+ -- The type environment is a convenient source of such things.
+
+ ; let ((orig_ns', occ_env, subst_env), tidy_binds)
+ = mapAccumL (tidyTopBind mod ext_ids cg_info_env)
+ init_tidy_env binds_in
+
+ ; let tidy_rules = tidyIdCoreRules (occ_env,subst_env) ext_rules
+
+ ; let prs' = prs { prsOrig = orig_ns' }
+ pcs' = pcs { pcs_PRS = prs' }
+
+ ; let final_ids = [ id
+ | bind <- tidy_binds
+ , id <- bindersOf bind
+ , isExternalName (idName id)]
+
+ -- Dfuns are local Ids that might have
+ -- changed their unique during tidying
+ ; let lookup_dfun_id id = lookupVarEnv subst_env id `orElse`
+ pprPanic "lookup_dfun_id" (ppr id)
+
+
+ ; let tidy_type_env = mkFinalTypeEnv env_tc final_ids
+ tidy_dfun_ids = map lookup_dfun_id insts_tc
+
+ ; let tidy_details = ModDetails { md_types = tidy_type_env,
+ md_rules = tidy_rules,
+ md_insts = tidy_dfun_ids,
+ md_binds = tidy_binds }
+
+ ; endPass dflags "Tidy Core" Opt_D_dump_simpl tidy_binds
+ ; dumpIfSet_core dflags Opt_D_dump_simpl
+ "Tidy Core Rules"
+ (pprIdRules tidy_rules)
+
+ ; return (pcs', tidy_details)
+ }
+
+tidyCoreExpr :: CoreExpr -> IO CoreExpr
+tidyCoreExpr expr = return (tidyExpr emptyTidyEnv expr)
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Write a new interface file}
+%* *
+%************************************************************************