- LinkOK pls4
- -> do let pcms4 = PersistentCMState { hst=hst4, hit=hit4,
- ui=ui4, mg=mods_to_keep,
- pci=pcii, gmode=ghci_mode }
- let cmstate4
- = CmState { pcms=pcms4, pcs=pcs3, pls=pls4 }
- return (cmstate4,
- -- choose rather arbitrarily who to return
- if null mods_to_keep then Nothing
- else Just (last mods_to_keep_names))
-
-
--- Given a bunch of old summaries and a new summary, try and
--- find the corresponding old summary, and, if found, compare
--- its source timestamp with that of the new summary. If in
--- doubt say True.
-summary_indicates_source_changed :: [ModSummary] -> ModSummary -> Bool
-summary_indicates_source_changed old_summaries new_summary
- = case [old | old <- old_summaries,
- name_of_summary old == name_of_summary new_summary] of
-
- (_:_:_) -> panic "summary_indicates_newer_source"
-
- [] -> -- can't find a corresponding old summary, so
- -- compare source and iface dates in the new summary.
- trace (showSDoc (text "SISC: no old summary, new ="
- <+> pprSummaryTimes new_summary)) (
- case (ms_hs_date new_summary, ms_hi_date new_summary) of
- (Just hs_t, Just hi_t) -> hs_t > hi_t
- other -> True
- )
-
- [old] -> -- found old summary; compare source timestamps
- trace (showSDoc (text "SISC: old ="
- <+> pprSummaryTimes old
- <+> pprSummaryTimes new_summary)) (
- case (ms_hs_date old, ms_hs_date new_summary) of
- (Just old_t, Just new_t) -> new_t > old_t
- other -> True
- )
+ LinkOK pls3
+ -> do let cmstate4
+ = CmState { hst=hst4, hit=hit4,
+ ui=ui4, mg=mods_to_keep,
+ gmode=ghci_mode, pcs=pcs3, pls=pls3 }
+ return (cmstate4, False,
+ map ms_mod mods_to_keep)
+
+
+-----------------------------------------------------------------------------
+-- getValidLinkables
+
+getValidLinkables
+ :: [Linkable] -- old linkables
+ -> [ModSummary] -- all modules in the program
+ -> IO [Linkable] -- still-valid linkables
+
+getValidLinkables old_linkables summaries
+ = do lis <- mapM (getValidLinkable old_linkables) summaries
+ return (concat lis)
+
+getValidLinkable old_linkables summary
+ = do let mod_name = moduleName (ms_mod summary)
+ maybe_disk_linkable
+ <- case ml_obj_file (ms_location summary) of
+ Nothing -> return Nothing
+ Just obj_fn -> maybe_getFileLinkable mod_name obj_fn
+
+ -- find an old in-core linkable if we have one. (forget about
+ -- on-disk linkables for now, we'll check again whether there's
+ -- one here below, just in case a new one has popped up recently).
+ let old_linkable = findModuleLinkable_maybe old_linkables mod_name
+ maybe_old_linkable =
+ case old_linkable of
+ Just (LM _ _ ls) | all isInterpretable ls -> old_linkable
+ _ -> Nothing
+
+ -- The most recent of the old UI linkable or whatever we could
+ -- find on disk is returned as the linkable if compile
+ -- doesn't think we need to recompile.
+ let linkable_list
+ = case (maybe_old_linkable, maybe_disk_linkable) of
+ (Nothing, Nothing) -> []
+ (Nothing, Just di) -> [di]
+ (Just ui, Nothing) -> [ui]
+ (Just ui, Just di)
+ | linkableTime ui >= linkableTime di -> [ui]
+ | otherwise -> [di]
+
+ -- only linkables newer than the source code are valid
+ let maybe_src_date = ms_hs_date summary
+
+ valid_linkable_list
+ = case maybe_src_date of
+ Nothing -> panic "valid_linkable_list"
+ Just src_date
+ -> filter (\li -> linkableTime li > src_date) linkable_list
+
+ return valid_linkable_list
+
+
+
+maybe_getFileLinkable :: ModuleName -> FilePath -> IO (Maybe Linkable)
+maybe_getFileLinkable mod_name obj_fn
+ = do obj_exist <- doesFileExist obj_fn
+ if not obj_exist
+ then return Nothing
+ else
+ do let stub_fn = case splitFilename3 obj_fn of
+ (dir, base, ext) -> dir ++ "/" ++ base ++ ".stub_o"
+ stub_exist <- doesFileExist stub_fn
+ obj_time <- getModificationTime obj_fn
+ if stub_exist
+ then return (Just (LM obj_time mod_name [DotO obj_fn, DotO stub_fn]))
+ else return (Just (LM obj_time mod_name [DotO obj_fn]))
+
+
+-----------------------------------------------------------------------------
+-- Do a pre-upsweep without use of "compile", to establish a
+-- (downward-closed) set of stable modules for which we won't call compile.
+
+preUpsweep :: [Linkable] -- new valid linkables
+ -> [Linkable] -- old linkables
+ -> [ModuleName] -- names of all mods encountered in downsweep
+ -> [ModuleName] -- accumulating stable modules
+ -> [SCC ModSummary] -- scc-ified mod graph, including src imps
+ -> IO [ModuleName] -- stable modules
+
+preUpsweep valid_lis old_lis all_home_mods stable []
+ = return stable
+preUpsweep valid_lis old_lis all_home_mods stable (scc0:sccs)
+ = do let scc = flattenSCC scc0
+ scc_allhomeimps :: [ModuleName]
+ scc_allhomeimps
+ = nub (filter (`elem` all_home_mods) (concatMap ms_allimps scc))
+ all_imports_in_scc_or_stable
+ = all in_stable_or_scc scc_allhomeimps
+ scc_names
+ = map name_of_summary scc
+ in_stable_or_scc m
+ = --trace (showSDoc (text "ISOS" <+> ppr m <+> ppr scc_names <+> ppr stable)) (
+ m `elem` scc_names || m `elem` stable
+ --)
+
+ -- now we check for valid linkables: each module in the SCC must
+ -- have a valid linkable (see getValidLinkables above), and the
+ -- newest linkable must be the same as the previous linkable for
+ -- this module (if one exists).
+ has_valid_linkable new_summary
+ = case findModuleLinkable_maybe valid_lis modname of
+ Nothing -> False
+ Just l -> case findModuleLinkable_maybe old_lis modname of
+ Nothing -> True
+ Just m -> linkableTime l == linkableTime m
+ where modname = name_of_summary new_summary
+
+ scc_is_stable = all_imports_in_scc_or_stable
+ && all has_valid_linkable scc
+
+ if scc_is_stable
+ then preUpsweep valid_lis old_lis all_home_mods
+ (scc_names++stable) sccs
+ else preUpsweep valid_lis old_lis all_home_mods
+ stable sccs
+
+ where
+
+
+-- Helper for preUpsweep. Assuming that new_summary's imports are all
+-- stable (in the sense of preUpsweep), determine if new_summary is itself
+-- stable, and, if so, in batch mode, return its linkable.
+findInSummaries :: [ModSummary] -> ModuleName -> [ModSummary]
+findInSummaries old_summaries mod_name
+ = [s | s <- old_summaries, name_of_summary s == mod_name]
+
+findModInSummaries :: [ModSummary] -> Module -> Maybe ModSummary
+findModInSummaries old_summaries mod
+ = case [s | s <- old_summaries, ms_mod s == mod] of
+ [] -> Nothing
+ (s:_) -> Just s