X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fmain%2FFinder.lhs;h=29e1fb6c2125f9296823add0b12471833c33d67d;hb=997c87bcdca78ad60c129a0da29a425bc5bac638;hp=b923b92223b34a489bbf711707bbdab26e74de0f;hpb=305b24aa09287ce3d3b5e9817a5be745e0f17232;p=ghc-hetmet.git diff --git a/compiler/main/Finder.lhs b/compiler/main/Finder.lhs index b923b92..29e1fb6 100644 --- a/compiler/main/Finder.lhs +++ b/compiler/main/Finder.lhs @@ -10,6 +10,7 @@ module Finder ( findImportedModule, findExactModule, findHomeModule, + findExposedPackageModule, mkHomeModLocation, mkHomeModLocation2, mkHiOnlyModLocation, @@ -31,18 +32,17 @@ 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.List +import Data.IORef ( IORef, writeIORef, readIORef, atomicModifyIORef ) import System.Directory import System.FilePath -import System.IO import Control.Monad import System.Time ( ClockTime ) @@ -67,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 @@ -76,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 @@ -103,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 @@ -181,10 +186,10 @@ findExposedPackageModule hsc_env mod_name mb_pkg | null found_exposed = return (NotFound [] Nothing mod_hiddens pkg_hiddens) -- found in just one exposed package: | [(pkg_conf, _)] <- found_exposed - = let pkgid = mkPackageId (package pkg_conf) in + = let pkgid = packageConfigId pkg_conf in findPackageModule_ hsc_env (mkModule pkgid mod_name) pkg_conf | otherwise - = return (FoundMultiple (map (mkPackageId.package.fst) found_exposed)) + = return (FoundMultiple (map (packageConfigId.fst) found_exposed)) where dflags = hsc_dflags hsc_env found = lookupModuleInAllPackages dflags mod_name @@ -197,10 +202,10 @@ findExposedPackageModule hsc_env mod_name mb_pkg is_exposed (pkg_conf,exposed_mod) = exposed pkg_conf && exposed_mod - mod_hiddens = [ mkPackageId (package pkg_conf) + mod_hiddens = [ packageConfigId pkg_conf | (pkg_conf,False) <- found ] - pkg_hiddens = [ mkPackageId (package pkg_conf) + pkg_hiddens = [ packageConfigId pkg_conf | (pkg_conf,_) <- found, not (exposed pkg_conf) ] _pkg_conf `matches` Nothing = True @@ -498,23 +503,14 @@ mkStubPaths dflags mod location stub_basename = stub_basename0 ++ "_stub" - -- this is the filename we're going to use when - -- \#including the stub_h file from the .hc file. - -- Without -stubdir, we just #include the basename - -- (eg. for a module A.B, we #include "B_stub.h"), - -- relying on the fact that we add an implicit -I flag - -- for the directory in which the source file resides - -- (see DriverPipeline.hs). With -stubdir, we - -- \#include "A/B.h", assuming that the user has added - -- -I