X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FFinder.lhs;h=29e1fb6c2125f9296823add0b12471833c33d67d;hb=9c84f11b774960077d33d94a23ebc42af79d2ec4;hp=a1558c87c674114c353209b90f075c97a219d63e;hpb=8209ac8cf9f7aeeef1f590cc6d93940afec7fbad;p=ghc-hetmet.git diff --git a/compiler/main/Finder.lhs b/compiler/main/Finder.lhs index a1558c8..29e1fb6 100644 --- a/compiler/main/Finder.lhs +++ b/compiler/main/Finder.lhs @@ -32,14 +32,15 @@ import Packages import FastString import Util import PrelNames ( gHC_PRIM ) -import DynFlags ( DynFlags(..), isOneShot, GhcMode(..) ) +import DynFlags import Outputable -import FiniteMap -import LazyUniqFM +import UniqFM import Maybes ( expectJust ) +import Exception ( evaluate ) +import Distribution.Text import Distribution.Package hiding (PackageId) -import Data.IORef ( IORef, writeIORef, readIORef, modifyIORef ) +import Data.IORef ( IORef, writeIORef, readIORef, atomicModifyIORef ) import System.Directory import System.FilePath import Control.Monad @@ -66,6 +67,7 @@ type BaseName = String -- Basename of file -- assumed to not move around during a session. flushFinderCaches :: HscEnv -> IO () flushFinderCaches hsc_env = do + -- Ideally the update to both caches be a single atomic operation. writeIORef fc_ref emptyUFM flushModLocationCache this_pkg mlc_ref where @@ -75,23 +77,27 @@ flushFinderCaches hsc_env = do flushModLocationCache :: PackageId -> IORef ModLocationCache -> IO () flushModLocationCache this_pkg ref = do - fm <- readIORef ref - writeIORef ref $! filterFM is_ext fm + atomicModifyIORef ref $ \fm -> (filterModuleEnv is_ext fm, ()) + _ <- evaluate =<< readIORef ref return () where is_ext mod _ | modulePackageId mod /= this_pkg = True | otherwise = False addToFinderCache :: IORef FinderCache -> ModuleName -> FindResult -> IO () -addToFinderCache ref key val = modifyIORef ref $ \c -> addToUFM c key val +addToFinderCache ref key val = + atomicModifyIORef ref $ \c -> (addToUFM c key val, ()) addToModLocationCache :: IORef ModLocationCache -> Module -> ModLocation -> IO () -addToModLocationCache ref key val = modifyIORef ref $ \c -> addToFM c key val +addToModLocationCache ref key val = + atomicModifyIORef ref $ \c -> (extendModuleEnv c key val, ()) removeFromFinderCache :: IORef FinderCache -> ModuleName -> IO () -removeFromFinderCache ref key = modifyIORef ref $ \c -> delFromUFM c key +removeFromFinderCache ref key = + atomicModifyIORef ref $ \c -> (delFromUFM c key, ()) removeFromModLocationCache :: IORef ModLocationCache -> Module -> IO () -removeFromModLocationCache ref key = modifyIORef ref $ \c -> delFromFM c key +removeFromModLocationCache ref key = + atomicModifyIORef ref $ \c -> (delModuleEnv c key, ()) lookupFinderCache :: IORef FinderCache -> ModuleName -> IO (Maybe FindResult) lookupFinderCache ref key = do @@ -102,7 +108,7 @@ lookupModLocationCache :: IORef ModLocationCache -> Module -> IO (Maybe ModLocation) lookupModLocationCache ref key = do c <- readIORef ref - return $! lookupFM c key + return $! lookupModuleEnv c key -- ----------------------------------------------------------------------------- -- The two external entry points @@ -599,7 +605,17 @@ cantFindErr cannot_find _ dflags mod_name find_result hang (ptext (sLit "locations searched:")) 2 $ vcat (map text files) pkg_hidden pkg = - ptext (sLit "it is a member of the hidden package") <+> quotes (ppr pkg) + ptext (sLit "It is a member of the hidden package") <+> quotes (ppr pkg) + <> dot $$ cabal_pkg_hidden_hint pkg + cabal_pkg_hidden_hint pkg + | dopt Opt_BuildingCabalPackage dflags + = case simpleParse (packageIdString pkg) of + Just pid -> + ptext (sLit "Perhaps you need to add") <+> + quotes (text (display (pkgName pid))) <+> + ptext (sLit "to the build-depends in your .cabal file.") + Nothing -> empty + | otherwise = empty mod_hidden pkg = ptext (sLit "it is a hidden module in the package") <+> quotes (ppr pkg)