+-- -----------------------------------------------------------------------------
+-- | Rename some import declarations
+
+hscRnImportDecls
+ :: HscEnv
+ -> Module
+ -> [LImportDecl RdrName]
+ -> IO GlobalRdrEnv
+
+-- It is important that we use tcRnImports instead of calling rnImports directly
+-- because tcRnImports will force-load any orphan modules necessary, making extra
+-- instances/family instances visible (GHC #4832)
+hscRnImportDecls hsc_env this_mod import_decls
+ = runHsc hsc_env $ ioMsgMaybe $ initTc hsc_env HsSrcFile False this_mod $
+ fmap tcg_rdr_env $ tcRnImports hsc_env this_mod import_decls
+
+-- -----------------------------------------------------------------------------
+-- | parse a file, returning the abstract syntax
+
+hscParse :: HscEnv -> ModSummary -> IO (Located (HsModule RdrName))
+hscParse hsc_env mod_summary = runHsc hsc_env $ hscParse' mod_summary
+
+-- internal version, that doesn't fail due to -Werror
+hscParse' :: ModSummary -> Hsc (Located (HsModule RdrName))
+hscParse' mod_summary
+ = do
+ dflags <- getDynFlags
+ let
+ src_filename = ms_hspp_file mod_summary
+ maybe_src_buf = ms_hspp_buf mod_summary
+
+ -------------------------- Parser ----------------
+ liftIO $ showPass dflags "Parser"
+ {-# SCC "Parser" #-} do
+
+ -- sometimes we already have the buffer in memory, perhaps
+ -- because we needed to parse the imports out of it, or get the
+ -- module name.
+ buf <- case maybe_src_buf of
+ Just b -> return b
+ Nothing -> liftIO $ hGetStringBuffer src_filename
+
+ let loc = mkSrcLoc (mkFastString src_filename) 1 1
+
+ case unP parseModule (mkPState dflags buf loc) of
+ PFailed span err ->
+ liftIO $ throwOneError (mkPlainErrMsg span err)
+
+ POk pst rdr_module -> do
+ logWarningsReportErrors (getMessages pst)
+ liftIO $ dumpIfSet_dyn dflags Opt_D_dump_parsed "Parser" $
+ ppr rdr_module
+ liftIO $ dumpIfSet_dyn dflags Opt_D_source_stats "Source Statistics" $
+ ppSourceStats False rdr_module
+ return rdr_module
+ -- ToDo: free the string buffer later.
+
+-- XXX: should this really be a Maybe X? Check under which circumstances this
+-- can become a Nothing and decide whether this should instead throw an
+-- exception/signal an error.
+type RenamedStuff =
+ (Maybe (HsGroup Name, [LImportDecl Name], Maybe [LIE Name],
+ Maybe LHsDocString))
+
+-- | Rename and typecheck a module, additionally returning the renamed syntax
+hscTypecheckRename :: HscEnv -> ModSummary -> Located (HsModule RdrName)
+ -> IO (TcGblEnv, RenamedStuff)
+hscTypecheckRename hsc_env mod_summary rdr_module
+ = runHsc hsc_env $ do
+ tc_result
+ <- {-# SCC "Typecheck-Rename" #-}
+ ioMsgMaybe $
+ tcRnModule hsc_env (ms_hsc_src mod_summary) True rdr_module
+
+ let -- This 'do' is in the Maybe monad!
+ rn_info = do decl <- tcg_rn_decls tc_result
+ let imports = tcg_rn_imports tc_result
+ exports = tcg_rn_exports tc_result
+ doc_hdr = tcg_doc_hdr tc_result
+ return (decl,imports,exports,doc_hdr)
+
+ return (tc_result, rn_info)
+
+-- | Convert a typechecked module to Core
+hscDesugar :: HscEnv -> ModSummary -> TcGblEnv -> IO ModGuts
+hscDesugar hsc_env mod_summary tc_result
+ = runHsc hsc_env $ hscDesugar' mod_summary tc_result
+
+hscDesugar' :: ModSummary -> TcGblEnv -> Hsc ModGuts
+hscDesugar' mod_summary tc_result
+ = do
+ hsc_env <- getHscEnv
+ r <- ioMsgMaybe $
+ deSugar hsc_env (ms_location mod_summary) tc_result
+
+ handleWarnings
+ -- always check -Werror after desugaring, this is
+ -- the last opportunity for warnings to arise before
+ -- the backend.
+ return r
+
+-- | Make a 'ModIface' from the results of typechecking. Used when
+-- not optimising, and the interface doesn't need to contain any
+-- unfoldings or other cross-module optimisation info.
+-- ToDo: the old interface is only needed to get the version numbers,
+-- we should use fingerprint versions instead.
+makeSimpleIface :: HscEnv ->
+ Maybe ModIface -> TcGblEnv -> ModDetails
+ -> IO (ModIface,Bool)
+makeSimpleIface hsc_env maybe_old_iface tc_result details
+ = runHsc hsc_env $
+ ioMsgMaybe $
+ mkIfaceTc hsc_env (fmap mi_iface_hash maybe_old_iface) details tc_result
+
+-- | Make a 'ModDetails' from the results of typechecking. Used when
+-- typechecking only, as opposed to full compilation.
+makeSimpleDetails :: HscEnv -> TcGblEnv -> IO ModDetails
+makeSimpleDetails hsc_env tc_result = mkBootModDetailsTc hsc_env tc_result
+\end{code}