module Finder (
Finder, -- = ModuleName -> IO (Maybe (Module, ModuleLocation))
newFinder, -- :: PackageConfigInfo -> IO Finder,
- ModuleLocation(..)
+ ModuleLocation(..),
+ mkHomeModuleLocn
) where
#include "HsVersions.h"
import Monad
\end{code}
+The Finder provides a thin filesystem abstraction to the rest of the
+compiler. For a given module, it knows (a) which package the module
+lives in, so it can make a Module from a ModuleName, and (b) where the
+source, interface, and object files for a module live.
+
\begin{code}
type Finder = ModuleName -> IO (Maybe (Module, ModuleLocation))
+-- For a module in another package, the hs_file and obj_file
+-- components of ModuleLocation are undefined.
+
+-- The locations specified by a ModuleLocation may or may not
+-- correspond to actual files yet: for example, even if the object
+-- file doesn't exist, the ModuleLocation still contains the path to
+-- where the object file will reside if/when it is created.
+
data ModuleLocation
= ModuleLocation {
hs_file :: FilePath,
lhs = basename ++ ".lhs"
case lookupFM home_cache hs of {
- Just path -> mkHomeModuleLocn mod_name basename path hs;
+ Just path -> mkHomeModuleLocn mod_name (path ++ '/':basename) hs;
Nothing ->
case lookupFM home_cache lhs of {
- Just path -> mkHomeModuleLocn mod_name basename path lhs;
+ Just path -> mkHomeModuleLocn mod_name (path ++ '/':basename) lhs;
Nothing -> return Nothing
}}
-mkHomeModuleLocn mod_name basename path source_fn = do
+mkHomeModuleLocn mod_name basename source_fn = do
-- figure out the .hi file name: it lives in the same dir as the
-- source, unless there's a -ohi flag on the command line.
ohi <- readIORef output_hi
hisuf <- readIORef hi_suf
let hifile = case ohi of
- Nothing -> path ++ '/':basename ++ hisuf
+ Nothing -> basename ++ hisuf
Just fn -> fn
-- figure out the .o file name. It also lives in the same dir
-- as the source, but can be overriden by a -odir flag.
- o_file <- odir_ify (path ++ '/':basename ++ '.':phaseInputExt Ln)
+ o_file <- odir_ify (basename ++ '.':phaseInputExt Ln)
return (Just (mkHomeModule mod_name,
ModuleLocation{