+type LocalFindResult = MaybeErr [FilePath] FinderCacheEntry
+ -- LocalFindResult is used for internal functions which
+ -- return a more informative type; it's munged into
+ -- the external FindResult by 'cached'
+
+cached :: (DynFlags -> Module -> IO LocalFindResult)
+ -> DynFlags -> Module -> Bool -> IO FindResult
+cached wrapped_fn dflags name explicit
+ = do { -- First try the cache
+ mb_entry <- lookupFinderCache name
+ ; case mb_entry of {
+ Just old_entry -> return (found old_entry) ;
+ Nothing -> do
+
+ { -- Now try the wrapped function
+ mb_entry <- wrapped_fn dflags name
+ ; case mb_entry of
+ Failed paths -> return (NotFound paths)
+ Succeeded new_entry -> do { addToFinderCache name new_entry
+ ; return (found new_entry) }
+ }}}
+ where
+ -- We've found the module, so the remaining question is
+ -- whether it's visible or not
+ found :: FinderCacheEntry -> FindResult
+ found (loc, Nothing) = Found loc HomePackage
+ found (loc, Just (pkg, exposed_mod))
+ | explicit && not exposed_mod = ModuleHidden pkg_name
+ | explicit && not (exposed pkg) = PackageHidden pkg_name
+ | otherwise = Found loc (ExtPackage (mkPackageId (package pkg)))
+ where
+ pkg_name = packageConfigId pkg
+
+addHomeModuleToFinder :: Module -> ModLocation -> IO ()
+addHomeModuleToFinder mod loc = addToFinderCache mod (loc, Nothing)
+
+
+-- -----------------------------------------------------------------------------
+-- The two external entry points
+
+