Use MD5 checksums for recompilation checking (fixes #1372, #1959)
[ghc-hetmet.git] / compiler / main / HscMain.lhs
index 0e9d7ba..9ded3f5 100644 (file)
@@ -8,6 +8,10 @@
 module HscMain
     ( newHscEnv, hscCmmFile
     , hscParseIdentifier
+    , hscSimplify
+    , evalComp
+    , hscNormalIface, hscWriteIface, hscOneShot
+    , CompState (..)
 #ifdef GHCI
     , hscStmt, hscTcExpr, hscKcType
     , compileExpr
@@ -28,15 +32,12 @@ module HscMain
     , makeSimpleDetails
     ) where
 
-#include "HsVersions.h"
-
 #ifdef GHCI
 import CodeOutput      ( outputForeignStubs )
 import ByteCodeGen     ( byteCodeGen, coreExprToBCOs )
 import Linker          ( HValue, linkExpr )
 import CoreTidy                ( tidyExpr )
 import CorePrep                ( corePrepExpr )
-import Flattening      ( flattenExpr )
 import Desugar          ( deSugarExpr )
 import SimplCore        ( simplifyExpr )
 import TcRnDriver      ( tcRnStmt, tcRnExpr, tcRnType ) 
@@ -60,7 +61,7 @@ import StringBuffer
 import Parser
 import Lexer
 import SrcLoc          ( mkSrcLoc )
-import TcRnDriver      ( tcRnModule, tcRnExtCore )
+import TcRnDriver      ( tcRnModule )
 import TcIface         ( typecheckIface )
 import TcRnMonad       ( initIfaceCheck, TcGblEnv(..) )
 import IfaceEnv                ( initNameCache )
@@ -97,10 +98,8 @@ import Outputable
 import HscStats                ( ppSourceStats )
 import HscTypes
 import MkExternalCore  ( emitExternalCore )
-import ParserCore
-import ParserCoreUtils
 import FastString
-import UniqFM          ( emptyUFM )
+import LazyUniqFM              ( emptyUFM )
 import UniqSupply       ( initUs_ )
 import Bag             ( unitBag )
 
@@ -217,7 +216,7 @@ deSugarModule hsc_env mod_summary tc_result
 makeSimpleIface :: HscEnv -> Maybe ModIface -> TcGblEnv -> ModDetails
                 -> IO (ModIface,Bool)
 makeSimpleIface hsc_env maybe_old_iface tc_result details = do
-  mkIfaceTc hsc_env maybe_old_iface details tc_result
+  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.
@@ -405,11 +404,8 @@ genComp :: (ModGuts  -> Comp (Maybe a))
 genComp backend boot_backend = do
     mod_summary <- gets compModSummary
     case ms_hsc_src mod_summary of
-       ExtCoreFile -> do 
-          mb_modguts <- hscCoreFrontEnd
-          case mb_modguts of
-            Nothing -> return Nothing
-            Just guts -> backend guts
+       ExtCoreFile -> do
+          panic "GHC does not currently support reading External Core files"
        _not_core -> do
           mb_tc <- hscFileFrontEnd
           case mb_tc of
@@ -480,32 +476,6 @@ batchMsg mb_mod_index recomp
 --------------------------------------------------------------
 -- FrontEnds
 --------------------------------------------------------------
-
-hscCoreFrontEnd :: Comp (Maybe ModGuts)
-hscCoreFrontEnd =
-    do hsc_env <- gets compHscEnv
-       mod_summary <- gets compModSummary
-       liftIO $ do
-            -------------------
-            -- PARSE
-            -------------------
-       inp <- readFile (ms_hspp_file mod_summary)
-       case parseCore inp 1 of
-         FailP s
-             -> do errorMsg (hsc_dflags hsc_env) (text s{-ToDo: wrong-})
-                   return Nothing
-         OkP rdr_module
-             -------------------
-             -- RENAME and TYPECHECK
-             -------------------
-             -> do (tc_msgs, maybe_tc_result) <- {-# SCC "TypeCheck" #-}
-                                                 tcRnExtCore hsc_env rdr_module
-                   printErrorsAndWarnings (hsc_dflags hsc_env) tc_msgs
-                   case maybe_tc_result of
-                     Nothing       -> return Nothing
-                     Just mod_guts -> return (Just mod_guts)         -- No desugaring to do!
-
-        
 hscFileFrontEnd :: Comp (Maybe TcGblEnv)
 hscFileFrontEnd =
     do hsc_env <- gets compHscEnv
@@ -578,7 +548,7 @@ hscSimpleIface tc_result
        details <- mkBootModDetailsTc hsc_env tc_result
        (new_iface, no_change) 
            <- {-# SCC "MkFinalIface" #-}
-              mkIfaceTc hsc_env maybe_old_iface details tc_result
+              mkIfaceTc hsc_env (fmap mi_iface_hash maybe_old_iface) details tc_result
        -- And the answer is ...
        dumpIfaceStats hsc_env
        return (new_iface, no_change, details, tc_result)
@@ -603,9 +573,13 @@ hscNormalIface simpl_result
            -- until after code output
        (new_iface, no_change)
                <- {-# SCC "MkFinalIface" #-}
-                  mkIface hsc_env maybe_old_iface details simpl_result
+                  mkIface hsc_env (fmap mi_iface_hash maybe_old_iface)
+                         details simpl_result
        -- Emit external core
-       emitExternalCore (hsc_dflags hsc_env) (availsToNameSet (mg_exports simpl_result)) cg_guts -- Move this? --Lemmih 03/07/2006
+       -- This should definitely be here and not after CorePrep,
+       -- because CorePrep produces unqualified constructor wrapper declarations,
+       -- so its output isn't valid External Core (without some preprocessing).
+       emitExternalCore (hsc_dflags hsc_env) cg_guts 
        dumpIfaceStats hsc_env
 
            -------------------
@@ -954,7 +928,7 @@ hscParseThing parser dflags str
 
       buf <- stringToStringBuffer str
 
-      let loc  = mkSrcLoc FSLIT("<interactive>") 1 0
+      let loc  = mkSrcLoc (fsLit "<interactive>") 1 0
 
       case unP parser (mkPState buf loc dflags) of {
 
@@ -988,11 +962,8 @@ compileExpr hsc_env srcspan ds_expr
   = do { let { dflags  = hsc_dflags hsc_env ;
                lint_on = dopt Opt_DoCoreLinting dflags }
              
-               -- Flatten it
-       ; flat_expr <- flattenExpr hsc_env ds_expr
-
                -- Simplify it
-       ; simpl_expr <- simplifyExpr dflags flat_expr
+       ; simpl_expr <- simplifyExpr dflags ds_expr
 
                -- Tidy it (temporary, until coreSat does cloning)
        ; let tidy_expr = tidyExpr emptyTidyEnv simpl_expr