- -> Module -- Guaranteed a home-package module
- -> IsBootInterface
- -> ModLocation -> Maybe ModSummary
- -> IO (Maybe ModSummary)
-summarise dflags mod is_boot location old_summary
- = do { -- Find the source file to summarise
- src_fn <- if is_boot then
- hiBootFilePath location
- else
- case ml_hs_file location of
- Nothing -> noHsFileErr mod
- Just src_fn -> return src_fn
-
- -- Find its timestamp
- ; src_timestamp <- getModificationTime src_fn
-
- -- return the cached summary if the source didn't change
- ; case old_summary of {
- Just s | ms_hs_date s == src_timestamp -> return (Just s);
- _ -> do
-
- -- For now, we never pre-process hi-boot files
- { hspp_fn <- if is_boot then return src_fn
- else preprocess dflags src_fn
-
+ -> NodeMap ModSummary -- Map of old summaries
+ -> Maybe FilePath -- Importing module (for error messages)
+ -> IsBootInterface -- True <=> a {-# SOURCE #-} import
+ -> Module -- Imported module to be summarised
+ -> [Module] -- Modules to exclude
+ -> IO (Maybe ModSummary) -- Its new summary
+
+summarise dflags old_summary_map cur_mod is_boot wanted_mod excl_mods
+ | wanted_mod `elem` excl_mods
+ = return Nothing
+
+ | Just old_summary <- lookupFM old_summary_map (wanted_mod, hsc_src)
+ = do { -- Find its new timestamp; all the
+ -- ModSummaries in the old map have valid ml_hs_files
+ let location = ms_location old_summary
+ src_fn = fromJust (ml_hs_file location)
+
+ ; src_timestamp <- getModificationTime src_fn
+
+ -- return the cached summary if the source didn't change
+ ; if ms_hs_date old_summary == src_timestamp
+ then return (Just old_summary)
+ else new_summary location
+ }
+
+ | otherwise
+ = do { found <- findModule dflags wanted_mod True {-explicit-}
+ ; case found of
+ Found location pkg
+ | not (isHomePackage pkg) -> return Nothing -- Drop external-pkg
+ | isJust (ml_hs_file location) -> new_summary location -- Home package
+ err -> noModError dflags cur_mod wanted_mod err -- Not found
+ }
+ where
+ hsc_src = if is_boot then HsBootFile else HsSrcFile
+
+ new_summary location
+ = do { -- Adjust location to point to the hs-boot source file,
+ -- hi file, object file, when is_boot says so
+ let location' | is_boot = addBootSuffixLocn location
+ | otherwise = location
+ src_fn = fromJust (ml_hs_file location')
+
+ -- Check that it exists
+ -- It might have been deleted since the Finder last found it
+ ; exists <- doesFileExist src_fn
+ ; if exists then return () else noHsFileErr cur_mod src_fn
+
+ -- Preprocess the source file and get its imports
+ -- The dflags' contains the OPTIONS pragmas
+ ; (dflags', hspp_fn) <- preprocess dflags src_fn