[project @ 2001-08-01 12:07:50 by simonmar]
[ghc-hetmet.git] / ghc / compiler / compMan / CompManager.lhs
index 144144e..4623970 100644 (file)
@@ -16,10 +16,12 @@ module CompManager (
     cmGetContext, -- :: CmState -> IO String
 
 #ifdef GHCI
-    cmRunStmt,   --  :: CmState -> DynFlags -> String -> IO (CmState, [Name])
+    cmInfoThing,  -- :: CmState -> DynFlags -> String -> IO (Maybe TyThing)
 
-    cmTypeOfExpr, --  :: CmState -> DynFlags -> String
-                 --  -> IO (CmState, Maybe String)
+    cmRunStmt,   -- :: CmState -> DynFlags -> String -> IO (CmState, [Name])
+
+    cmTypeOfExpr, -- :: CmState -> DynFlags -> String
+                 -- -> IO (CmState, Maybe String)
 
     cmTypeOfName, -- :: CmState -> Name -> IO (Maybe String)
 
@@ -34,13 +36,16 @@ where
 
 import CmLink
 import CmTypes
-import CmStaticInfo    ( GhciMode(..) )
 import DriverPipeline
 import DriverFlags     ( getDynFlags )
 import DriverPhases
 import DriverUtil
 import Finder
+#ifdef GHCI
+import HscMain         ( initPersistentCompilerState, hscThing )
+#else
 import HscMain         ( initPersistentCompilerState )
+#endif
 import HscTypes
 import RnEnv           ( unQualInScope )
 import Id              ( idType, idName )
@@ -171,6 +176,11 @@ moduleNameToModule mn
 -- cmRunStmt:  Run a statement/expr.
 
 #ifdef GHCI
+cmInfoThing :: CmState -> DynFlags -> String -> IO (Maybe TyThing)
+cmInfoThing CmState{ hst=hst, hit=hit, pcs=pcs, pls=pls, ic=icontext } dflags id
+   = do (pcs, thing) <- hscThing dflags hst hit pcs icontext id
+       return thing
+
 cmRunStmt :: CmState -> DynFlags -> String
        -> IO (CmState,                 -- new state
               [Name])                  -- names bound by this evaluation
@@ -344,12 +354,12 @@ cmUnload state@CmState{ gmode=mode, pls=pls, pcs=pcs } dflags
 -- the system state at the same time.
 
 cmLoadModule :: CmState 
-             -> FilePath
+             -> [FilePath]
              -> IO (CmState,           -- new state
                    Bool,               -- was successful
                    [String])           -- list of modules loaded
 
-cmLoadModule cmstate1 rootname
+cmLoadModule cmstate1 rootnames
    = do -- version 1's are the original, before downsweep
         let pls1      = pls    cmstate1
         let pcs1      = pcs    cmstate1
@@ -369,9 +379,11 @@ cmLoadModule cmstate1 rootname
 
        showPass dflags "Chasing dependencies"
         when (verb >= 1 && ghci_mode == Batch) $
-           hPutStrLn stderr (progName ++ ": chasing modules from: " ++ rootname)
+           hPutStrLn stderr (showSDoc (hcat [
+            text progName, text ": chasing modules from: ",
+            hcat (punctuate comma (map text rootnames))]))
 
-        (mg2unsorted, a_root_is_Main) <- downsweep [rootname] mg1
+        (mg2unsorted, a_root_is_Main) <- downsweep rootnames mg1
         let mg2unsorted_names = map name_of_summary mg2unsorted
 
         -- reachable_from follows source as well as normal imports
@@ -420,7 +432,7 @@ cmLoadModule cmstate1 rootname
 
        -- unload any modules which aren't going to be re-linked this
        -- time around.
-       pls2 <- unload ghci_mode dflags stable_linkables pls1
+       pls2 <- CmLink.unload ghci_mode dflags stable_linkables pls1
 
         -- We could at this point detect cycles which aren't broken by
         -- a source-import, and complain immediately, but it seems better
@@ -538,8 +550,18 @@ cmLoadFinish ok linkresult hst hit ui mods ghci_mode pcs
        return (new_cmstate, ok, mods_loaded)
     }
 
+-- used to fish out the preprocess output files for the purposes
+-- of cleaning up.
 ppFilesFromSummaries summaries
-  = [ fn | Just fn <- map (ml_hspp_file . ms_location) summaries ]
+  = [ fn | Just fn <- map toPpFile summaries ]
+  where
+   toPpFile sum
+     | hspp /= ml_hs_file loc = hspp
+     | otherwise              = Nothing
+    where
+      loc  = ms_location sum
+      hspp = ml_hspp_file loc
+
 
 -----------------------------------------------------------------------------
 -- getValidLinkables
@@ -639,7 +661,13 @@ getValidLinkable old_linkables objects_allowed new_linkables summary
            src_date = ms_hs_date summary
 
           valid_linkable
-             =  filter (\l -> linkableTime l > src_date) linkable
+             =  filter (\l -> linkableTime l >= src_date) linkable
+               -- why '>=' rather than '>' above?  If the filesystem stores
+               -- times to the nearset second, we may occasionally find that
+               -- the object & source have the same modification time, 
+               -- especially if the source was automatically generated
+               -- and compiled.  Using >= is slightly unsafe, but it matches
+               -- make's behaviour.
 
        return (valid_linkable ++ new_linkables)
 
@@ -889,10 +917,9 @@ downwards_closure_of_module summaries root
 
          res = simple_transitive_closure (map toEdge summaries) [root]
      in
-         --trace (showSDoc (text "DC of mod" <+> ppr root
-         --                 <+> text "=" <+> ppr res)) (
+--         trace (showSDoc (text "DC of mod" <+> ppr root
+--                          <+> text "=" <+> ppr res)) $
          res
-         --)
 
 -- Calculate transitive closures from a set of roots given an adjacency list
 simple_transitive_closure :: Eq a => [(a,[a])] -> [a] -> [a]