[project @ 2001-02-12 13:33:46 by simonmar]
[ghc-hetmet.git] / ghc / compiler / compMan / CompManager.lhs
index 3426035..f136af7 100644 (file)
@@ -36,6 +36,7 @@ import DriverUtil     ( splitFilename3 )
 import ErrUtils                ( showPass )
 import Util
 import DriverUtil
+import TmpFiles
 import Outputable
 import Panic
 import CmdLineOpts     ( DynFlags(..) )
@@ -201,17 +202,7 @@ cmLoadModule cmstate1 rootname
         let mg2_with_srcimps = topological_sort True mg2unsorted
 
        -- Sort out which linkables we wish to keep in the unlinked image.
-       -- For each module, we take:
-       --
-       --      - the old in-core linkable, if available
-       --      - an on-disk linkable, if available
-       --
-       -- and we take the youngest of these, provided it is younger than the
-       -- source file.
-       --
-       -- If a module has a valid linkable, then it may be STABLE (see below),
-       -- and it is classified as SOURCE UNCHANGED for the purposes of calling
-       -- compile.
+       -- See getValidLinkables below for details.
        valid_linkables <- getValidLinkables ui1 mg2unsorted_names 
                                mg2_with_srcimps
 
@@ -294,6 +285,10 @@ cmLoadModule cmstate1 rootname
            -- Easy; just relink it all.
            do when (verb >= 2) $ 
                 hPutStrLn stderr "Upsweep completely successful."
+
+             -- clean up after ourselves
+             cleanTempFilesExcept verb (ppFilesFromSummaries modsDone)
+
               linkresult 
                  <- link ghci_mode dflags a_root_is_Main ui3 pls2
               case linkresult of
@@ -331,6 +326,9 @@ cmLoadModule cmstate1 rootname
                      = map (unJust "linkables_to_link" . findModuleLinkable_maybe ui4)
                            mods_to_keep_names
 
+             -- clean up after ourselves
+             cleanTempFilesExcept verb (ppFilesFromSummaries mods_to_keep)
+
               linkresult <- link ghci_mode dflags False linkables_to_link pls2
               case linkresult of
                  LinkErrs _ _
@@ -344,9 +342,27 @@ cmLoadModule cmstate1 rootname
                                   map ms_mod mods_to_keep)
 
 
+ppFilesFromSummaries summaries
+  = [ fn | Just fn <- map (ml_hspp_file . ms_location) summaries ]
+
 -----------------------------------------------------------------------------
 -- getValidLinkables
 
+-- For each module (or SCC of modules), we take:
+--
+--     - the old in-core linkable, if available
+--     - an on-disk linkable, if available
+--
+-- and we take the youngest of these, provided it is younger than the
+-- source file.  We ignore the on-disk linkables unless all of the
+-- dependents of this SCC also have on-disk linkables.
+--
+-- If a module has a valid linkable, then it may be STABLE (see below),
+-- and it is classified as SOURCE UNCHANGED for the purposes of calling
+-- compile.
+--
+-- ToDo: this pass could be merged with the preUpsweep.
+
 getValidLinkables
        :: [Linkable]           -- old linkables
        -> [ModuleName]         -- all home modules
@@ -797,7 +813,7 @@ downsweep rootNm old_summaries
                let all_home = map (moduleName.ms_mod) home_summaries
 
                -- imports for modules we don't already have
-                let needed_imps = filter (`notElem` all_home) imps
+                let needed_imps = nub (filter (`notElem` all_home) imps)
 
                -- summarise them
                 needed_summaries <- mapM getSummary needed_imps