-mkModDetails :: TypeEnv -- From typechecker
- -> [CoreBind] -- Final bindings
- -> [Id] -- Top-level Ids from the code generator;
- -- they have authoritative arity info
- -> [IdCoreRule] -- Tidy orphan rules
- -> ModDetails
-mkModDetails type_env tidy_binds stg_ids orphan_rules
- = ModDetails { md_types = new_type_env,
- md_rules = rule_dcls,
- md_insts = filter isDictFunId final_ids }
- where
- -- The competed type environment is gotten from
- -- a) keeping the types and classes
- -- b) removing all Ids,
- -- c) adding Ids with correct IdInfo, including unfoldings,
- -- gotten from the bindings
- -- From (c) we keep only those Ids with Global names;
- -- the CoreTidy pass makes sure these are all and only
- -- the externally-accessible ones
- -- This truncates the type environment to include only the
- -- exported Ids and things needed from them, which saves space
- --
- -- However, we do keep things like constructors, which should not appear
- -- in interface files, because they are needed by importing modules when
- -- using the compilation manager
- new_type_env = extendTypeEnvList (filterNameEnv keep_it type_env)
- (map AnId final_ids)
-
- -- We keep constructor workers, because they won't appear
- -- in the bindings from which final_ids are derived!
- keep_it (AnId id) = hasNoBinding id
- keep_it other = True
-
- stg_id_set = mkVarSet stg_ids
- final_ids = [addStgInfo stg_id_set id | bind <- tidy_binds
- , id <- bindersOf bind
- , isGlobalName (idName id)]
-
- -- The complete rules are gotten by combining
- -- a) the orphan rules
- -- b) rules embedded in the top-level Ids
- rule_dcls | opt_OmitInterfacePragmas = []
- | otherwise = getRules orphan_rules tidy_binds (mkVarSet final_ids)
-
--- This version is used when we are re-linking a module
--- so we've only run the type checker on its previous interface
-mkModDetailsFromIface :: TypeEnv
- -> [TypecheckedRuleDecl]
- -> ModDetails
-mkModDetailsFromIface type_env rules
- = ModDetails { md_types = type_env,
- md_rules = rule_dcls,
- md_insts = dfun_ids }
- where
- dfun_ids = [dfun_id | AnId dfun_id <- nameEnvElts type_env, isDictFunId dfun_id]
- rule_dcls = [(id,rule) | IfaceRuleOut id rule <- rules]
- -- All the rules from an interface are of the IfaceRuleOut form
-\end{code}