-mkModDetails :: TypeEnv -> [DFunId] -- From typechecker
- -> [CoreBind] -> [Id] -- Final bindings, plus the top-level Ids from the
- -- code generator; they have authoritative arity info
- -> [IdCoreRule] -- Tidy orphan rules
- -> ModDetails
-mkModDetails type_env dfun_ids tidy_binds stg_ids orphan_rules
- = ModDetails { md_types = new_type_env,
- md_rules = rule_dcls,
- md_insts = dfun_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, plus Ids
- -- accessible from them (notably via unfoldings)
- -- 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 = mkNameEnv [(getName tycl, tycl) | tycl <- orig_type_env, isTyClThing tycl]
- `plusNameEnv`
- mkNameEnv [(idName id, AnId id) | id <- final_ids]
-
- orig_type_env = nameEnvElts type_env
-
- final_ids = bindsToIds (mkVarSet dfun_ids `unionVarSet` orphan_rule_ids)
- (mkVarSet stg_ids)
- tidy_binds
-
- -- 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)
-
- orphan_rule_ids = unionVarSets [ ruleSomeFreeVars interestingId rule
- | (_, rule) <- orphan_rules]
-
-
--- 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 -> [DFunId] -- From typechecker
- -> [TypecheckedRuleDecl]
- -> ModDetails
-mkModDetailsFromIface type_env dfun_ids rules
- = ModDetails { md_types = type_env,
- md_rules = rule_dcls,
- md_insts = dfun_ids }
- where
- rule_dcls = [(id,rule) | IfaceRuleOut id rule <- rules]
- -- All the rules from an interface are of the IfaceRuleOut form
-
-
-completeIface :: Maybe ModIface -- The old interface, if we have it
- -> ModIface -- The new one, minus the decls and versions
- -> ModDetails -- The ModDetails for this module
- -> (ModIface, Maybe SDoc) -- The new one, complete with decls and versions
- -- The SDoc is a debug document giving differences
- -- Nothing => no change
-
- -- NB: 'Nothing' means that even the usages havn't changed, so there's no
- -- need to write a new interface file. But even if the usages have
- -- changed, the module version may not have.
-completeIface maybe_old_iface new_iface mod_details
- = addVersionInfo maybe_old_iface (new_iface { mi_decls = new_decls })
- where
- new_decls = mkIfaceDecls ty_cls_dcls rule_dcls inst_dcls
- inst_dcls = map ifaceInstance (md_insts mod_details)
- ty_cls_dcls = foldNameEnv ifaceTyCls [] (md_types mod_details)
- rule_dcls = map ifaceRule (md_rules mod_details)
+showIface :: FilePath -> IO ()
+showIface filename = do
+ -- skip the version check; we don't want to worry about profiled vs.
+ -- non-profiled interfaces, for example.
+ writeIORef v_IgnoreHiVersion True
+ parsed_iface <- Binary.getBinFileWithDict filename
+ let ParsedIface{
+ pi_mod=pi_mod, pi_pkg=pi_pkg, pi_vers=pi_vers,
+ pi_deps=pi_deps,
+ pi_orphan=pi_orphan, pi_usages=pi_usages,
+ pi_exports=pi_exports, pi_decls=pi_decls,
+ pi_fixity=pi_fixity, pi_insts=pi_insts,
+ pi_rules=pi_rules, pi_deprecs=pi_deprecs } = parsed_iface
+ putStrLn (showSDoc (vcat [
+ text "__interface" <+> doubleQuotes (ppr pi_pkg)
+ <+> ppr pi_mod <+> ppr pi_vers
+ <+> (if pi_orphan then char '!' else empty)
+ <+> ptext SLIT("where"),
+ -- no instance Outputable (WhatsImported):
+ pprExports id (snd pi_exports),
+ pprDeps pi_deps,
+ pprUsages id pi_usages,
+ hsep (map ppr_fix pi_fixity) <> semi,
+ vcat (map ppr_inst pi_insts),
+ vcat (map ppr_decl pi_decls),
+ ppr pi_rules
+ -- no instance Outputable (Either):
+ -- ppr pi_deprecs
+ ]))
+ where
+ ppr_fix (FixitySig n f _) = ppr f <+> ppr n
+ ppr_inst i = ppr i <+> semi
+ ppr_decl (v,d) = int v <+> ppr d <> semi