+showIface :: FilePath -> IO ()
+showIface filename = do
+ 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
+\end{code}
+
+%************************************************************************
+%* *
+\subsection{Completing an interface}
+%* *
+%************************************************************************
+
+\begin{code}
+mkIface :: HscEnv
+ -> ModLocation
+ -> Maybe ModIface -- The old interface, if we have it
+ -> ModGuts -- The compiled, tidied module
+ -> IO ModIface -- The new one, complete with decls and versions
+-- mkFinalIface
+-- a) completes the interface
+-- b) writes it out to a file if necessary
+
+mkIface hsc_env location maybe_old_iface
+ impl@ModGuts{ mg_module = this_mod,
+ mg_usages = usages,
+ mg_deps = deps,
+ mg_exports = exports,
+ mg_rdr_env = rdr_env,
+ mg_fix_env = fix_env,
+ mg_deprecs = deprecs,
+ mg_insts = insts,
+ mg_rules = rules,
+ mg_types = types }
+ = do { -- Sort the exports to make them easier to compare for versions
+ let { my_exports = groupAvails this_mod exports ;
+
+ iface_w_decls = ModIface { mi_module = this_mod,
+ mi_package = opt_InPackage,
+ mi_version = initialVersionInfo,
+ mi_deps = deps,
+ mi_usages = usages,
+ mi_exports = my_exports,
+ mi_decls = new_decls,
+ mi_orphan = orphan_mod,
+ mi_boot = False,
+ mi_fixities = fix_env,
+ mi_globals = Just rdr_env,
+ mi_deprecs = deprecs } }
+
+ -- Add version information
+ ; let (final_iface, maybe_diffs) = _scc_ "versioninfo" addVersionInfo maybe_old_iface iface_w_decls
+
+ -- Write the interface file, if necessary
+ ; when (must_write_hi_file maybe_diffs)
+ (writeBinIface hi_file_path final_iface)
+-- (writeIface hi_file_path final_iface)
+
+ -- Debug printing
+ ; write_diffs dflags final_iface maybe_diffs
+
+ ; orphan_mod `seq`
+ return final_iface }
+
+ where
+ dflags = hsc_dflags hsc_env
+ ghci_mode = hsc_mode hsc_env
+
+ must_write_hi_file Nothing = False
+ must_write_hi_file (Just _diffs) = ghci_mode /= Interactive
+ -- We must write a new .hi file if there are some changes
+ -- and we're not in interactive mode
+ -- maybe_diffs = '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.
+
+ hi_file_path = ml_hi_file location
+ new_decls = mkIfaceDecls ty_cls_dcls rule_dcls inst_dcls
+ inst_dcls = map ifaceInstance insts
+ ty_cls_dcls = foldNameEnv ifaceTyThing_acc [] types
+ rule_dcls = map ifaceRule rules
+ orphan_mod = isOrphanModule impl
+
+write_diffs :: DynFlags -> ModIface -> Maybe SDoc -> IO ()
+write_diffs dflags new_iface Nothing
+ = do when (dopt Opt_D_dump_hi_diffs dflags) (printDump (text "INTERFACE UNCHANGED"))
+ dumpIfSet_dyn dflags Opt_D_dump_hi "UNCHANGED FINAL INTERFACE" (pprIface new_iface)
+
+write_diffs dflags new_iface (Just sdoc_diffs)
+ = do dumpIfSet_dyn dflags Opt_D_dump_hi_diffs "INTERFACE HAS CHANGED" sdoc_diffs
+ dumpIfSet_dyn dflags Opt_D_dump_hi "NEW FINAL INTERFACE" (pprIface new_iface)