Make dumpIfSet_dyn_or use dumpSDoc
[ghc-hetmet.git] / compiler / main / Finder.lhs
1 %
2 % (c) The University of Glasgow, 2000-2006
3 %
4 \section[Finder]{Module Finder}
5
6 \begin{code}
7 module Finder (
8     flushFinderCaches,
9     FindResult(..),
10     findImportedModule,
11     findExactModule,
12     findHomeModule,
13     findExposedPackageModule,
14     mkHomeModLocation,
15     mkHomeModLocation2,
16     mkHiOnlyModLocation,
17     addHomeModuleToFinder,
18     uncacheModule,
19     mkStubPaths,
20
21     findObjectLinkableMaybe,
22     findObjectLinkable,
23
24     cannotFindModule,
25     cannotFindInterface,
26
27   ) where
28
29 #include "HsVersions.h"
30
31 import Module
32 import HscTypes
33 import Packages
34 import FastString
35 import Util
36 import PrelNames        ( gHC_PRIM )
37 import DynFlags
38 import Outputable
39 import UniqFM
40 import Maybes           ( expectJust )
41 import Exception        ( evaluate )
42
43 import Distribution.Text
44 import Distribution.Package hiding (PackageId)
45 import Data.IORef       ( IORef, writeIORef, readIORef, atomicModifyIORef )
46 import System.Directory
47 import System.FilePath
48 import Control.Monad
49 import System.Time      ( ClockTime )
50 import Data.List        ( partition )
51
52
53 type FileExt = String   -- Filename extension
54 type BaseName = String  -- Basename of file
55
56 -- -----------------------------------------------------------------------------
57 -- The Finder
58
59 -- The Finder provides a thin filesystem abstraction to the rest of
60 -- the compiler.  For a given module, it can tell you where the
61 -- source, interface, and object files for that module live.
62
63 -- It does *not* know which particular package a module lives in.  Use
64 -- Packages.lookupModuleInAllPackages for that.
65
66 -- -----------------------------------------------------------------------------
67 -- The finder's cache
68
69 -- remove all the home modules from the cache; package modules are
70 -- assumed to not move around during a session.
71 flushFinderCaches :: HscEnv -> IO ()
72 flushFinderCaches hsc_env = do
73   -- Ideally the update to both caches be a single atomic operation.
74   writeIORef fc_ref emptyUFM
75   flushModLocationCache this_pkg mlc_ref
76  where
77         this_pkg = thisPackage (hsc_dflags hsc_env)
78         fc_ref = hsc_FC hsc_env
79         mlc_ref = hsc_MLC hsc_env
80
81 flushModLocationCache :: PackageId -> IORef ModLocationCache -> IO ()
82 flushModLocationCache this_pkg ref = do
83   atomicModifyIORef ref $ \fm -> (filterModuleEnv is_ext fm, ())
84   _ <- evaluate =<< readIORef ref
85   return ()
86   where is_ext mod _ | modulePackageId mod /= this_pkg = True
87                      | otherwise = False
88
89 addToFinderCache :: IORef FinderCache -> ModuleName -> FindResult -> IO ()
90 addToFinderCache ref key val =
91   atomicModifyIORef ref $ \c -> (addToUFM c key val, ())
92
93 addToModLocationCache :: IORef ModLocationCache -> Module -> ModLocation -> IO ()
94 addToModLocationCache ref key val =
95   atomicModifyIORef ref $ \c -> (extendModuleEnv c key val, ())
96
97 removeFromFinderCache :: IORef FinderCache -> ModuleName -> IO ()
98 removeFromFinderCache ref key =
99   atomicModifyIORef ref $ \c -> (delFromUFM c key, ())
100
101 removeFromModLocationCache :: IORef ModLocationCache -> Module -> IO ()
102 removeFromModLocationCache ref key =
103   atomicModifyIORef ref $ \c -> (delModuleEnv c key, ())
104
105 lookupFinderCache :: IORef FinderCache -> ModuleName -> IO (Maybe FindResult)
106 lookupFinderCache ref key = do
107    c <- readIORef ref
108    return $! lookupUFM c key
109
110 lookupModLocationCache :: IORef ModLocationCache -> Module
111                        -> IO (Maybe ModLocation)
112 lookupModLocationCache ref key = do
113    c <- readIORef ref
114    return $! lookupModuleEnv c key
115
116 -- -----------------------------------------------------------------------------
117 -- The two external entry points
118
119 -- | Locate a module that was imported by the user.  We have the
120 -- module's name, and possibly a package name.  Without a package
121 -- name, this function will use the search path and the known exposed
122 -- packages to find the module, if a package is specified then only
123 -- that package is searched for the module.
124
125 findImportedModule :: HscEnv -> ModuleName -> Maybe FastString -> IO FindResult
126 findImportedModule hsc_env mod_name mb_pkg =
127   case mb_pkg of
128         Nothing                        -> unqual_import
129         Just pkg | pkg == fsLit "this" -> home_import -- "this" is special
130                  | otherwise           -> pkg_import
131   where
132     home_import   = findHomeModule hsc_env mod_name
133
134     pkg_import    = findExposedPackageModule hsc_env mod_name mb_pkg
135
136     unqual_import = home_import
137                     `orIfNotFound`
138                     findExposedPackageModule hsc_env mod_name Nothing
139
140 -- | Locate a specific 'Module'.  The purpose of this function is to
141 -- create a 'ModLocation' for a given 'Module', that is to find out
142 -- where the files associated with this module live.  It is used when
143 -- reading the interface for a module mentioned by another interface,
144 -- for example (a "system import").
145
146 findExactModule :: HscEnv -> Module -> IO FindResult
147 findExactModule hsc_env mod =
148     let dflags = hsc_dflags hsc_env
149     in if modulePackageId mod == thisPackage dflags
150        then findHomeModule hsc_env (moduleName mod)
151        else findPackageModule hsc_env mod
152
153 -- -----------------------------------------------------------------------------
154 -- Helpers
155
156 orIfNotFound :: IO FindResult -> IO FindResult -> IO FindResult
157 orIfNotFound this or_this = do
158   res <- this
159   case res of
160     NotFound { fr_paths = paths1, fr_mods_hidden = mh1
161              , fr_pkgs_hidden = ph1, fr_suggestions = s1 }
162      -> do res2 <- or_this
163            case res2 of
164              NotFound { fr_paths = paths2, fr_pkg = mb_pkg2, fr_mods_hidden = mh2
165                       , fr_pkgs_hidden = ph2, fr_suggestions = s2 }
166               -> return (NotFound { fr_paths = paths1 ++ paths2
167                                   , fr_pkg = mb_pkg2 -- snd arg is the package search
168                                   , fr_mods_hidden = mh1 ++ mh2
169                                   , fr_pkgs_hidden = ph1 ++ ph2
170                                   , fr_suggestions = s1  ++ s2 })
171              _other -> return res2
172     _other -> return res
173
174
175 homeSearchCache :: HscEnv -> ModuleName -> IO FindResult -> IO FindResult
176 homeSearchCache hsc_env mod_name do_this = do
177   m <- lookupFinderCache (hsc_FC hsc_env) mod_name
178   case m of
179     Just result -> return result
180     Nothing     -> do
181         result <- do_this
182         addToFinderCache (hsc_FC hsc_env) mod_name result
183         case result of
184            Found loc mod -> addToModLocationCache (hsc_MLC hsc_env) mod loc
185            _other        -> return ()
186         return result
187
188 findExposedPackageModule :: HscEnv -> ModuleName -> Maybe FastString
189                          -> IO FindResult
190 findExposedPackageModule hsc_env mod_name mb_pkg
191         -- not found in any package:
192   = case lookupModuleWithSuggestions (hsc_dflags hsc_env) mod_name of
193        Left suggest -> return (NotFound { fr_paths = [], fr_pkg = Nothing
194                                         , fr_pkgs_hidden = [], fr_mods_hidden = []
195                                         , fr_suggestions = suggest })
196        Right found
197          | null found_exposed   -- Found, but with no exposed copies
198           -> return (NotFound { fr_paths = [], fr_pkg = Nothing
199                               , fr_pkgs_hidden = pkg_hiddens, fr_mods_hidden = mod_hiddens
200                               , fr_suggestions = [] })
201
202          | [(pkg_conf,_)] <- found_exposed     -- Found uniquely
203          -> let pkgid = packageConfigId pkg_conf in
204             findPackageModule_ hsc_env (mkModule pkgid mod_name) pkg_conf
205
206          | otherwise           -- Found in more than one place
207          -> return (FoundMultiple (map (packageConfigId.fst) found_exposed))
208          where
209            for_this_pkg  = case mb_pkg of
210                              Nothing -> found
211                              Just p  -> filter ((`matches` p) . fst) found
212            found_exposed = filter is_exposed for_this_pkg
213            is_exposed (pkg_conf,exposed_mod) = exposed pkg_conf && exposed_mod
214
215            mod_hiddens = [ packageConfigId pkg_conf
216                          | (pkg_conf,False) <- found ]
217
218            pkg_hiddens = [ packageConfigId pkg_conf
219                          | (pkg_conf,_) <- found, not (exposed pkg_conf) ]
220
221            pkg_conf  `matches` pkg
222               = case packageName pkg_conf of
223                   PackageName n -> pkg == mkFastString n
224
225 modLocationCache :: HscEnv -> Module -> IO FindResult -> IO FindResult
226 modLocationCache hsc_env mod do_this = do
227   mb_loc <- lookupModLocationCache mlc mod
228   case mb_loc of
229      Just loc -> return (Found loc mod)
230      Nothing  -> do
231         result <- do_this
232         case result of
233             Found loc mod -> addToModLocationCache (hsc_MLC hsc_env) mod loc
234             _other -> return ()
235         return result
236   where
237     mlc = hsc_MLC hsc_env
238
239 addHomeModuleToFinder :: HscEnv -> ModuleName -> ModLocation -> IO Module
240 addHomeModuleToFinder hsc_env mod_name loc = do
241   let mod = mkModule (thisPackage (hsc_dflags hsc_env)) mod_name
242   addToFinderCache (hsc_FC hsc_env) mod_name (Found loc mod)
243   addToModLocationCache (hsc_MLC hsc_env) mod loc
244   return mod
245
246 uncacheModule :: HscEnv -> ModuleName -> IO ()
247 uncacheModule hsc_env mod = do
248   let this_pkg = thisPackage (hsc_dflags hsc_env)
249   removeFromFinderCache (hsc_FC hsc_env) mod
250   removeFromModLocationCache (hsc_MLC hsc_env) (mkModule this_pkg mod)
251
252 -- -----------------------------------------------------------------------------
253 --      The internal workers
254
255 -- | Search for a module in the home package only.
256 findHomeModule :: HscEnv -> ModuleName -> IO FindResult
257 findHomeModule hsc_env mod_name =
258    homeSearchCache hsc_env mod_name $
259    let 
260      dflags = hsc_dflags hsc_env
261      home_path = importPaths dflags
262      hisuf = hiSuf dflags
263      mod = mkModule (thisPackage dflags) mod_name
264
265      source_exts =
266       [ ("hs",   mkHomeModLocationSearched dflags mod_name "hs")
267       , ("lhs",  mkHomeModLocationSearched dflags mod_name "lhs")
268       ]
269
270      hi_exts = [ (hisuf,                mkHiOnlyModLocation dflags hisuf)
271                , (addBootSuffix hisuf,  mkHiOnlyModLocation dflags hisuf)
272                ]
273
274         -- In compilation manager modes, we look for source files in the home
275         -- package because we can compile these automatically.  In one-shot
276         -- compilation mode we look for .hi and .hi-boot files only.
277      exts | isOneShot (ghcMode dflags) = hi_exts
278           | otherwise                  = source_exts
279    in
280
281   -- special case for GHC.Prim; we won't find it in the filesystem.
282   -- This is important only when compiling the base package (where GHC.Prim
283   -- is a home module).
284   if mod == gHC_PRIM
285         then return (Found (error "GHC.Prim ModLocation") mod)
286         else searchPathExts home_path mod exts
287
288
289 -- | Search for a module in external packages only.
290 findPackageModule :: HscEnv -> Module -> IO FindResult
291 findPackageModule hsc_env mod = do
292   let
293         dflags = hsc_dflags hsc_env
294         pkg_id = modulePackageId mod
295         pkg_map = pkgIdMap (pkgState dflags)
296   --
297   case lookupPackage pkg_map pkg_id of
298      Nothing -> return (NoPackage pkg_id)
299      Just pkg_conf -> findPackageModule_ hsc_env mod pkg_conf
300
301 findPackageModule_ :: HscEnv -> Module -> PackageConfig -> IO FindResult
302 findPackageModule_ hsc_env mod pkg_conf =
303   modLocationCache hsc_env mod $
304
305   -- special case for GHC.Prim; we won't find it in the filesystem.
306   if mod == gHC_PRIM
307         then return (Found (error "GHC.Prim ModLocation") mod)
308         else
309
310   let
311      dflags = hsc_dflags hsc_env
312      tag = buildTag dflags
313
314            -- hi-suffix for packages depends on the build tag.
315      package_hisuf | null tag  = "hi"
316                    | otherwise = tag ++ "_hi"
317
318      mk_hi_loc = mkHiOnlyModLocation dflags package_hisuf
319
320      import_dirs = importDirs pkg_conf
321       -- we never look for a .hi-boot file in an external package;
322       -- .hi-boot files only make sense for the home package.
323   in
324   case import_dirs of
325     [one] | MkDepend <- ghcMode dflags -> do
326           -- there's only one place that this .hi file can be, so
327           -- don't bother looking for it.
328           let basename = moduleNameSlashes (moduleName mod)
329           loc <- mk_hi_loc one basename
330           return (Found loc mod)
331     _otherwise ->
332           searchPathExts import_dirs mod [(package_hisuf, mk_hi_loc)]
333
334 -- -----------------------------------------------------------------------------
335 -- General path searching
336
337 searchPathExts
338   :: [FilePath]         -- paths to search
339   -> Module             -- module name
340   -> [ (
341         FileExt,                                -- suffix
342         FilePath -> BaseName -> IO ModLocation  -- action
343        )
344      ]
345   -> IO FindResult
346
347 searchPathExts paths mod exts
348    = do result <- search to_search
349 {-
350         hPutStrLn stderr (showSDoc $
351                 vcat [text "Search" <+> ppr mod <+> sep (map (text. fst) exts)
352                     , nest 2 (vcat (map text paths))
353                     , case result of
354                         Succeeded (loc, p) -> text "Found" <+> ppr loc
355                         Failed fs          -> text "not found"])
356 -}
357         return result
358
359   where
360     basename = moduleNameSlashes (moduleName mod)
361
362     to_search :: [(FilePath, IO ModLocation)]
363     to_search = [ (file, fn path basename)
364                 | path <- paths,
365                   (ext,fn) <- exts,
366                   let base | path == "." = basename
367                            | otherwise   = path </> basename
368                       file = base <.> ext
369                 ]
370
371     search [] = return (NotFound { fr_paths = map fst to_search
372                                  , fr_pkg   = Just (modulePackageId mod)
373                                  , fr_mods_hidden = [], fr_pkgs_hidden = []
374                                  , fr_suggestions = [] })
375
376     search ((file, mk_result) : rest) = do
377       b <- doesFileExist file
378       if b
379         then do { loc <- mk_result; return (Found loc mod) }
380         else search rest
381
382 mkHomeModLocationSearched :: DynFlags -> ModuleName -> FileExt
383                           -> FilePath -> BaseName -> IO ModLocation
384 mkHomeModLocationSearched dflags mod suff path basename = do
385    mkHomeModLocation2 dflags mod (path </> basename) suff
386
387 -- -----------------------------------------------------------------------------
388 -- Constructing a home module location
389
390 -- This is where we construct the ModLocation for a module in the home
391 -- package, for which we have a source file.  It is called from three
392 -- places:
393 --
394 --  (a) Here in the finder, when we are searching for a module to import,
395 --      using the search path (-i option).
396 --
397 --  (b) The compilation manager, when constructing the ModLocation for
398 --      a "root" module (a source file named explicitly on the command line
399 --      or in a :load command in GHCi).
400 --
401 --  (c) The driver in one-shot mode, when we need to construct a
402 --      ModLocation for a source file named on the command-line.
403 --
404 -- Parameters are:
405 --
406 -- mod
407 --      The name of the module
408 --
409 -- path
410 --      (a): The search path component where the source file was found.
411 --      (b) and (c): "."
412 --
413 -- src_basename
414 --      (a): (moduleNameSlashes mod)
415 --      (b) and (c): The filename of the source file, minus its extension
416 --
417 -- ext
418 --      The filename extension of the source file (usually "hs" or "lhs").
419
420 mkHomeModLocation :: DynFlags -> ModuleName -> FilePath -> IO ModLocation
421 mkHomeModLocation dflags mod src_filename = do
422    let (basename,extension) = splitExtension src_filename
423    mkHomeModLocation2 dflags mod basename extension
424
425 mkHomeModLocation2 :: DynFlags
426                    -> ModuleName
427                    -> FilePath  -- Of source module, without suffix
428                    -> String    -- Suffix
429                    -> IO ModLocation
430 mkHomeModLocation2 dflags mod src_basename ext = do
431    let mod_basename = moduleNameSlashes mod
432
433    obj_fn  <- mkObjPath  dflags src_basename mod_basename
434    hi_fn   <- mkHiPath   dflags src_basename mod_basename
435
436    return (ModLocation{ ml_hs_file   = Just (src_basename <.> ext),
437                         ml_hi_file   = hi_fn,
438                         ml_obj_file  = obj_fn })
439
440 mkHiOnlyModLocation :: DynFlags -> Suffix -> FilePath -> String
441                     -> IO ModLocation
442 mkHiOnlyModLocation dflags hisuf path basename
443  = do let full_basename = path </> basename
444       obj_fn  <- mkObjPath  dflags full_basename basename
445       return ModLocation{    ml_hs_file   = Nothing,
446                              ml_hi_file   = full_basename <.> hisuf,
447                                 -- Remove the .hi-boot suffix from
448                                 -- hi_file, if it had one.  We always
449                                 -- want the name of the real .hi file
450                                 -- in the ml_hi_file field.
451                              ml_obj_file  = obj_fn
452                   }
453
454 -- | Constructs the filename of a .o file for a given source file.
455 -- Does /not/ check whether the .o file exists
456 mkObjPath
457   :: DynFlags
458   -> FilePath           -- the filename of the source file, minus the extension
459   -> String             -- the module name with dots replaced by slashes
460   -> IO FilePath
461 mkObjPath dflags basename mod_basename
462   = do  let
463                 odir = objectDir dflags
464                 osuf = objectSuf dflags
465
466                 obj_basename | Just dir <- odir = dir </> mod_basename
467                              | otherwise        = basename
468
469         return (obj_basename <.> osuf)
470
471 -- | Constructs the filename of a .hi file for a given source file.
472 -- Does /not/ check whether the .hi file exists
473 mkHiPath
474   :: DynFlags
475   -> FilePath           -- the filename of the source file, minus the extension
476   -> String             -- the module name with dots replaced by slashes
477   -> IO FilePath
478 mkHiPath dflags basename mod_basename
479   = do  let
480                 hidir = hiDir dflags
481                 hisuf = hiSuf dflags
482
483                 hi_basename | Just dir <- hidir = dir </> mod_basename
484                             | otherwise         = basename
485
486         return (hi_basename <.> hisuf)
487
488
489 -- -----------------------------------------------------------------------------
490 -- Filenames of the stub files
491
492 -- We don't have to store these in ModLocations, because they can be derived
493 -- from other available information, and they're only rarely needed.
494
495 mkStubPaths
496   :: DynFlags
497   -> ModuleName
498   -> ModLocation
499   -> FilePath
500
501 mkStubPaths dflags mod location
502   = let
503         stubdir = stubDir dflags
504
505         mod_basename = moduleNameSlashes mod
506         src_basename = dropExtension $ expectJust "mkStubPaths"
507                                                   (ml_hs_file location)
508
509         stub_basename0
510             | Just dir <- stubdir = dir </> mod_basename
511             | otherwise           = src_basename
512
513         stub_basename = stub_basename0 ++ "_stub"
514      in
515         stub_basename <.> "h"
516
517 -- -----------------------------------------------------------------------------
518 -- findLinkable isn't related to the other stuff in here,
519 -- but there's no other obvious place for it
520
521 findObjectLinkableMaybe :: Module -> ModLocation -> IO (Maybe Linkable)
522 findObjectLinkableMaybe mod locn
523    = do let obj_fn = ml_obj_file locn
524         maybe_obj_time <- modificationTimeIfExists obj_fn
525         case maybe_obj_time of
526           Nothing -> return Nothing
527           Just obj_time -> liftM Just (findObjectLinkable mod obj_fn obj_time)
528
529 -- Make an object linkable when we know the object file exists, and we know
530 -- its modification time.
531 findObjectLinkable :: Module -> FilePath -> ClockTime -> IO Linkable
532 findObjectLinkable mod obj_fn obj_time = return (LM obj_time mod [DotO obj_fn])
533   -- We used to look for _stub.o files here, but that was a bug (#706)
534   -- Now GHC merges the stub.o into the main .o (#3687)
535
536 -- -----------------------------------------------------------------------------
537 -- Error messages
538
539 cannotFindModule :: DynFlags -> ModuleName -> FindResult -> SDoc
540 cannotFindModule = cantFindErr (sLit "Could not find module")
541                                (sLit "Ambiguous module name")
542
543 cannotFindInterface  :: DynFlags -> ModuleName -> FindResult -> SDoc
544 cannotFindInterface = cantFindErr (sLit "Failed to load interface for")
545                                   (sLit "Ambiguous interface for")
546
547 cantFindErr :: LitString -> LitString -> DynFlags -> ModuleName -> FindResult
548             -> SDoc
549 cantFindErr _ multiple_found _ mod_name (FoundMultiple pkgs)
550   = hang (ptext multiple_found <+> quotes (ppr mod_name) <> colon) 2 (
551        sep [ptext (sLit "it was found in multiple packages:"),
552                 hsep (map (text.packageIdString) pkgs)]
553     )
554 cantFindErr cannot_find _ dflags mod_name find_result
555   = ptext cannot_find <+> quotes (ppr mod_name)
556     $$ more_info
557   where
558     pkg_map :: PackageConfigMap
559     pkg_map = pkgIdMap (pkgState dflags)
560
561     more_info
562       = case find_result of
563             NoPackage pkg
564                 -> ptext (sLit "no package matching") <+> quotes (ppr pkg) <+>
565                    ptext (sLit "was found")
566
567             NotFound { fr_paths = files, fr_pkg = mb_pkg
568                      , fr_mods_hidden = mod_hiddens, fr_pkgs_hidden = pkg_hiddens
569                      , fr_suggestions = suggest }
570                 | Just pkg <- mb_pkg, pkg /= thisPackage dflags
571                 -> not_found_in_package pkg files
572
573                 | not (null suggest)
574                 -> pp_suggestions suggest $$ tried_these files
575
576                 | null files && null mod_hiddens && null pkg_hiddens
577                 -> ptext (sLit "It is not a module in the current program, or in any known package.")
578
579                 | otherwise
580                 -> vcat (map pkg_hidden pkg_hiddens) $$
581                    vcat (map mod_hidden mod_hiddens) $$
582                    tried_these files
583
584             _ -> panic "cantFindErr"
585
586     build_tag = buildTag dflags
587
588     not_found_in_package pkg files
589        | build_tag /= ""
590        = let
591             build = if build_tag == "p" then "profiling"
592                                         else "\"" ++ build_tag ++ "\""
593          in
594          ptext (sLit "Perhaps you haven't installed the ") <> text build <>
595          ptext (sLit " libraries for package ") <> quotes (ppr pkg) <> char '?' $$
596          tried_these files
597
598        | otherwise
599        = ptext (sLit "There are files missing in the ") <> quotes (ppr pkg) <>
600          ptext (sLit " package,") $$
601          ptext (sLit "try running 'ghc-pkg check'.") $$
602          tried_these files
603
604     tried_these files
605         | null files = empty
606         | verbosity dflags < 3 =
607               ptext (sLit "Use -v to see a list of the files searched for.")
608         | otherwise =
609                hang (ptext (sLit "Locations searched:")) 2 $ vcat (map text files)
610
611     pkg_hidden pkg =
612         ptext (sLit "It is a member of the hidden package") <+> quotes (ppr pkg)
613         <> dot $$ cabal_pkg_hidden_hint pkg
614     cabal_pkg_hidden_hint pkg
615      | dopt Opt_BuildingCabalPackage dflags
616         = case simpleParse (packageIdString pkg) of
617           Just pid ->
618               ptext (sLit "Perhaps you need to add") <+>
619               quotes (text (display (pkgName pid))) <+>
620               ptext (sLit "to the build-depends in your .cabal file.")
621           Nothing -> empty
622      | otherwise = empty
623
624     mod_hidden pkg =
625         ptext (sLit "it is a hidden module in the package") <+> quotes (ppr pkg)
626
627     pp_suggestions :: [Module] -> SDoc
628     pp_suggestions sugs
629       | null sugs = empty
630       | otherwise = hang (ptext (sLit "Perhaps you meant"))
631                        2 (vcat [ vcat (map pp_exp exposed_sugs)
632                                , vcat (map pp_hid hidden_sugs) ])
633       where
634         (exposed_sugs, hidden_sugs) = partition from_exposed_pkg sugs
635
636     from_exposed_pkg m = case lookupPackage pkg_map (modulePackageId m) of
637                             Just pkg_config -> exposed pkg_config
638                             Nothing         -> WARN( True, ppr m ) -- Should not happen
639                                                False
640
641     pp_exp mod = ppr (moduleName mod)
642                  <+> parens (ptext (sLit "from") <+> ppr (modulePackageId mod))
643     pp_hid mod = ppr (moduleName mod)
644                  <+> parens (ptext (sLit "needs flag -package") <+> ppr (modulePackageId mod))
645 \end{code}