+-- FIXME: The old interface and module index are only using in 'batch' and
+-- 'interactive' mode. They should be removed from 'oneshot' mode.
+type Compiler result = GhcMonad m =>
+ HscEnv
+ -> ModSummary
+ -> Bool -- True <=> source unchanged
+ -> Maybe ModIface -- Old interface, if available
+ -> Maybe (Int,Int) -- Just (i,n) <=> module i of n (for msgs)
+ -> m result
+
+class HsCompiler a where
+ -- | The main interface.
+ hscCompile :: GhcMonad m =>
+ HscEnv -> ModSummary -> Bool
+ -> Maybe ModIface -> Maybe (Int, Int)
+ -> m a
+
+ -- | Called when no recompilation is necessary.
+ hscNoRecomp :: GhcMonad m =>
+ ModIface -> m a
+
+ -- | Called to recompile the module.
+ hscRecompile :: GhcMonad m =>
+ ModSummary -> Maybe Fingerprint -> m a
+
+ -- | Code generation for Boot modules.
+ hscGenBootOutput :: GhcMonad m =>
+ TcGblEnv -> ModSummary -> Maybe Fingerprint -> m a
+
+ -- | Code generation for normal modules.
+ hscGenOutput :: GhcMonad m =>
+ ModGuts -> ModSummary -> Maybe Fingerprint -> m a
+
+
+genericHscCompile :: (HsCompiler a, GhcMonad m) =>
+ (Maybe (Int,Int) -> Bool -> ModSummary -> m ())
+ -> HscEnv -> ModSummary -> Bool
+ -> Maybe ModIface -> Maybe (Int, Int)
+ -> m a
+genericHscCompile hscMessage
+ hsc_env mod_summary source_unchanged
+ mb_old_iface0 mb_mod_index =
+ withTempSession (\_ -> hsc_env) $ do
+ (recomp_reqd, mb_checked_iface)
+ <- {-# SCC "checkOldIface" #-}
+ liftIO $ checkOldIface hsc_env mod_summary
+ source_unchanged mb_old_iface0
+ -- save the interface that comes back from checkOldIface.
+ -- In one-shot mode we don't have the old iface until this
+ -- point, when checkOldIface reads it from the disk.
+ let mb_old_hash = fmap mi_iface_hash mb_checked_iface
+ case mb_checked_iface of
+ Just iface | not recomp_reqd
+ -> do hscMessage mb_mod_index False mod_summary
+ hscNoRecomp iface
+ _otherwise
+ -> do hscMessage mb_mod_index True mod_summary
+ hscRecompile mod_summary mb_old_hash
+
+genericHscRecompile :: (HsCompiler a, GhcMonad m) =>
+ ModSummary -> Maybe Fingerprint
+ -> m a
+genericHscRecompile mod_summary mb_old_hash
+ | ExtCoreFile <- ms_hsc_src mod_summary =
+ panic "GHC does not currently support reading External Core files"
+ | otherwise = do
+ tc_result <- hscFileFrontEnd mod_summary
+ case ms_hsc_src mod_summary of
+ HsBootFile ->
+ hscGenBootOutput tc_result mod_summary mb_old_hash
+ _other -> do
+ guts <- hscDesugar mod_summary tc_result
+ hscGenOutput guts mod_summary mb_old_hash