{-# LANGUAGE CPP #-}
module Finder (
flushFinderCaches,
FindResult(..),
findImportedModule,
findPluginModule,
findExactModule,
findHomeModule,
findExposedPackageModule,
mkHomeModLocation,
mkHomeModLocation2,
mkHiOnlyModLocation,
mkHiPath,
mkObjPath,
addHomeModuleToFinder,
uncacheModule,
mkStubPaths,
findObjectLinkableMaybe,
findObjectLinkable,
cannotFindModule,
cannotFindInterface,
) where
#include "HsVersions.h"
import GhcPrelude
import Module
import HscTypes
import Packages
import FastString
import Util
import PrelNames ( gHC_PRIM )
import DynFlags
import Outputable
import Maybes ( expectJust )
import Data.IORef ( IORef, readIORef, atomicModifyIORef' )
import System.Directory
import System.FilePath
import Control.Monad
import Data.Time
type FileExt = String
type BaseName = String
flushFinderCaches :: HscEnv -> IO ()
flushFinderCaches :: HscEnv -> IO ()
flushFinderCaches hsc_env :: HscEnv
hsc_env =
IORef FinderCache -> (FinderCache -> (FinderCache, ())) -> IO ()
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef FinderCache
fc_ref ((FinderCache -> (FinderCache, ())) -> IO ())
-> (FinderCache -> (FinderCache, ())) -> IO ()
forall a b. (a -> b) -> a -> b
$ \fm :: FinderCache
fm -> ((InstalledModule -> InstalledFindResult -> Bool)
-> FinderCache -> FinderCache
forall a.
(InstalledModule -> a -> Bool)
-> InstalledModuleEnv a -> InstalledModuleEnv a
filterInstalledModuleEnv InstalledModule -> InstalledFindResult -> Bool
forall p. InstalledModule -> p -> Bool
is_ext FinderCache
fm, ())
where
this_pkg :: UnitId
this_pkg = DynFlags -> UnitId
thisPackage (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env)
fc_ref :: IORef FinderCache
fc_ref = HscEnv -> IORef FinderCache
hsc_FC HscEnv
hsc_env
is_ext :: InstalledModule -> p -> Bool
is_ext mod :: InstalledModule
mod _ | Bool -> Bool
not (InstalledModule -> InstalledUnitId
installedModuleUnitId InstalledModule
mod InstalledUnitId -> UnitId -> Bool
`installedUnitIdEq` UnitId
this_pkg) = Bool
True
| Bool
otherwise = Bool
False
addToFinderCache :: IORef FinderCache -> InstalledModule -> InstalledFindResult -> IO ()
addToFinderCache :: IORef FinderCache
-> InstalledModule -> InstalledFindResult -> IO ()
addToFinderCache ref :: IORef FinderCache
ref key :: InstalledModule
key val :: InstalledFindResult
val =
IORef FinderCache -> (FinderCache -> (FinderCache, ())) -> IO ()
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef FinderCache
ref ((FinderCache -> (FinderCache, ())) -> IO ())
-> (FinderCache -> (FinderCache, ())) -> IO ()
forall a b. (a -> b) -> a -> b
$ \c :: FinderCache
c -> (FinderCache
-> InstalledModule -> InstalledFindResult -> FinderCache
forall a.
InstalledModuleEnv a
-> InstalledModule -> a -> InstalledModuleEnv a
extendInstalledModuleEnv FinderCache
c InstalledModule
key InstalledFindResult
val, ())
removeFromFinderCache :: IORef FinderCache -> InstalledModule -> IO ()
removeFromFinderCache :: IORef FinderCache -> InstalledModule -> IO ()
removeFromFinderCache ref :: IORef FinderCache
ref key :: InstalledModule
key =
IORef FinderCache -> (FinderCache -> (FinderCache, ())) -> IO ()
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef FinderCache
ref ((FinderCache -> (FinderCache, ())) -> IO ())
-> (FinderCache -> (FinderCache, ())) -> IO ()
forall a b. (a -> b) -> a -> b
$ \c :: FinderCache
c -> (FinderCache -> InstalledModule -> FinderCache
forall a.
InstalledModuleEnv a -> InstalledModule -> InstalledModuleEnv a
delInstalledModuleEnv FinderCache
c InstalledModule
key, ())
lookupFinderCache :: IORef FinderCache -> InstalledModule -> IO (Maybe InstalledFindResult)
lookupFinderCache :: IORef FinderCache
-> InstalledModule -> IO (Maybe InstalledFindResult)
lookupFinderCache ref :: IORef FinderCache
ref key :: InstalledModule
key = do
FinderCache
c <- IORef FinderCache -> IO FinderCache
forall a. IORef a -> IO a
readIORef IORef FinderCache
ref
Maybe InstalledFindResult -> IO (Maybe InstalledFindResult)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe InstalledFindResult -> IO (Maybe InstalledFindResult))
-> Maybe InstalledFindResult -> IO (Maybe InstalledFindResult)
forall a b. (a -> b) -> a -> b
$! FinderCache -> InstalledModule -> Maybe InstalledFindResult
forall a. InstalledModuleEnv a -> InstalledModule -> Maybe a
lookupInstalledModuleEnv FinderCache
c InstalledModule
key
findImportedModule :: HscEnv -> ModuleName -> Maybe FastString -> IO FindResult
findImportedModule :: HscEnv -> ModuleName -> Maybe FastString -> IO FindResult
findImportedModule hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name mb_pkg :: Maybe FastString
mb_pkg =
case Maybe FastString
mb_pkg of
Nothing -> IO FindResult
unqual_import
Just pkg :: FastString
pkg | FastString
pkg FastString -> FastString -> Bool
forall a. Eq a => a -> a -> Bool
== String -> FastString
fsLit "this" -> IO FindResult
home_import
| Bool
otherwise -> IO FindResult
pkg_import
where
home_import :: IO FindResult
home_import = HscEnv -> ModuleName -> IO FindResult
findHomeModule HscEnv
hsc_env ModuleName
mod_name
pkg_import :: IO FindResult
pkg_import = HscEnv -> ModuleName -> Maybe FastString -> IO FindResult
findExposedPackageModule HscEnv
hsc_env ModuleName
mod_name Maybe FastString
mb_pkg
unqual_import :: IO FindResult
unqual_import = IO FindResult
home_import
IO FindResult -> IO FindResult -> IO FindResult
forall (m :: * -> *).
Monad m =>
m FindResult -> m FindResult -> m FindResult
`orIfNotFound`
HscEnv -> ModuleName -> Maybe FastString -> IO FindResult
findExposedPackageModule HscEnv
hsc_env ModuleName
mod_name Maybe FastString
forall a. Maybe a
Nothing
findPluginModule :: HscEnv -> ModuleName -> IO FindResult
findPluginModule :: HscEnv -> ModuleName -> IO FindResult
findPluginModule hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name =
HscEnv -> ModuleName -> IO FindResult
findHomeModule HscEnv
hsc_env ModuleName
mod_name
IO FindResult -> IO FindResult -> IO FindResult
forall (m :: * -> *).
Monad m =>
m FindResult -> m FindResult -> m FindResult
`orIfNotFound`
HscEnv -> ModuleName -> IO FindResult
findExposedPluginPackageModule HscEnv
hsc_env ModuleName
mod_name
findExactModule :: HscEnv -> InstalledModule -> IO InstalledFindResult
findExactModule :: HscEnv -> InstalledModule -> IO InstalledFindResult
findExactModule hsc_env :: HscEnv
hsc_env mod :: InstalledModule
mod =
let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
in if InstalledModule -> InstalledUnitId
installedModuleUnitId InstalledModule
mod InstalledUnitId -> UnitId -> Bool
`installedUnitIdEq` DynFlags -> UnitId
thisPackage DynFlags
dflags
then HscEnv -> ModuleName -> IO InstalledFindResult
findInstalledHomeModule HscEnv
hsc_env (InstalledModule -> ModuleName
installedModuleName InstalledModule
mod)
else HscEnv -> InstalledModule -> IO InstalledFindResult
findPackageModule HscEnv
hsc_env InstalledModule
mod
orIfNotFound :: Monad m => m FindResult -> m FindResult -> m FindResult
orIfNotFound :: m FindResult -> m FindResult -> m FindResult
orIfNotFound this :: m FindResult
this or_this :: m FindResult
or_this = do
FindResult
res <- m FindResult
this
case FindResult
res of
NotFound { fr_paths :: FindResult -> [String]
fr_paths = [String]
paths1, fr_mods_hidden :: FindResult -> [UnitId]
fr_mods_hidden = [UnitId]
mh1
, fr_pkgs_hidden :: FindResult -> [UnitId]
fr_pkgs_hidden = [UnitId]
ph1, fr_unusables :: FindResult -> [(UnitId, UnusablePackageReason)]
fr_unusables = [(UnitId, UnusablePackageReason)]
u1, fr_suggestions :: FindResult -> [ModuleSuggestion]
fr_suggestions = [ModuleSuggestion]
s1 }
-> do FindResult
res2 <- m FindResult
or_this
case FindResult
res2 of
NotFound { fr_paths :: FindResult -> [String]
fr_paths = [String]
paths2, fr_pkg :: FindResult -> Maybe UnitId
fr_pkg = Maybe UnitId
mb_pkg2, fr_mods_hidden :: FindResult -> [UnitId]
fr_mods_hidden = [UnitId]
mh2
, fr_pkgs_hidden :: FindResult -> [UnitId]
fr_pkgs_hidden = [UnitId]
ph2, fr_unusables :: FindResult -> [(UnitId, UnusablePackageReason)]
fr_unusables = [(UnitId, UnusablePackageReason)]
u2
, fr_suggestions :: FindResult -> [ModuleSuggestion]
fr_suggestions = [ModuleSuggestion]
s2 }
-> FindResult -> m FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (NotFound :: [String]
-> Maybe UnitId
-> [UnitId]
-> [UnitId]
-> [(UnitId, UnusablePackageReason)]
-> [ModuleSuggestion]
-> FindResult
NotFound { fr_paths :: [String]
fr_paths = [String]
paths1 [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
paths2
, fr_pkg :: Maybe UnitId
fr_pkg = Maybe UnitId
mb_pkg2
, fr_mods_hidden :: [UnitId]
fr_mods_hidden = [UnitId]
mh1 [UnitId] -> [UnitId] -> [UnitId]
forall a. [a] -> [a] -> [a]
++ [UnitId]
mh2
, fr_pkgs_hidden :: [UnitId]
fr_pkgs_hidden = [UnitId]
ph1 [UnitId] -> [UnitId] -> [UnitId]
forall a. [a] -> [a] -> [a]
++ [UnitId]
ph2
, fr_unusables :: [(UnitId, UnusablePackageReason)]
fr_unusables = [(UnitId, UnusablePackageReason)]
u1 [(UnitId, UnusablePackageReason)]
-> [(UnitId, UnusablePackageReason)]
-> [(UnitId, UnusablePackageReason)]
forall a. [a] -> [a] -> [a]
++ [(UnitId, UnusablePackageReason)]
u2
, fr_suggestions :: [ModuleSuggestion]
fr_suggestions = [ModuleSuggestion]
s1 [ModuleSuggestion] -> [ModuleSuggestion] -> [ModuleSuggestion]
forall a. [a] -> [a] -> [a]
++ [ModuleSuggestion]
s2 })
_other :: FindResult
_other -> FindResult -> m FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return FindResult
res2
_other :: FindResult
_other -> FindResult -> m FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return FindResult
res
homeSearchCache :: HscEnv -> ModuleName -> IO InstalledFindResult -> IO InstalledFindResult
homeSearchCache :: HscEnv
-> ModuleName -> IO InstalledFindResult -> IO InstalledFindResult
homeSearchCache hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name do_this :: IO InstalledFindResult
do_this = do
let mod :: InstalledModule
mod = DynFlags -> ModuleName -> InstalledModule
mkHomeInstalledModule (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env) ModuleName
mod_name
HscEnv
-> InstalledModule
-> IO InstalledFindResult
-> IO InstalledFindResult
modLocationCache HscEnv
hsc_env InstalledModule
mod IO InstalledFindResult
do_this
findExposedPackageModule :: HscEnv -> ModuleName -> Maybe FastString
-> IO FindResult
findExposedPackageModule :: HscEnv -> ModuleName -> Maybe FastString -> IO FindResult
findExposedPackageModule hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name mb_pkg :: Maybe FastString
mb_pkg
= HscEnv -> LookupResult -> IO FindResult
findLookupResult HscEnv
hsc_env
(LookupResult -> IO FindResult) -> LookupResult -> IO FindResult
forall a b. (a -> b) -> a -> b
$ DynFlags -> ModuleName -> Maybe FastString -> LookupResult
lookupModuleWithSuggestions
(HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env) ModuleName
mod_name Maybe FastString
mb_pkg
findExposedPluginPackageModule :: HscEnv -> ModuleName
-> IO FindResult
findExposedPluginPackageModule :: HscEnv -> ModuleName -> IO FindResult
findExposedPluginPackageModule hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name
= HscEnv -> LookupResult -> IO FindResult
findLookupResult HscEnv
hsc_env
(LookupResult -> IO FindResult) -> LookupResult -> IO FindResult
forall a b. (a -> b) -> a -> b
$ DynFlags -> ModuleName -> Maybe FastString -> LookupResult
lookupPluginModuleWithSuggestions
(HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env) ModuleName
mod_name Maybe FastString
forall a. Maybe a
Nothing
findLookupResult :: HscEnv -> LookupResult -> IO FindResult
findLookupResult :: HscEnv -> LookupResult -> IO FindResult
findLookupResult hsc_env :: HscEnv
hsc_env r :: LookupResult
r = case LookupResult
r of
LookupFound m :: Module
m pkg_conf :: PackageConfig
pkg_conf -> do
let im :: InstalledModule
im = (InstalledModule, Maybe IndefModule) -> InstalledModule
forall a b. (a, b) -> a
fst (Module -> (InstalledModule, Maybe IndefModule)
splitModuleInsts Module
m)
InstalledFindResult
r' <- HscEnv
-> InstalledModule -> PackageConfig -> IO InstalledFindResult
findPackageModule_ HscEnv
hsc_env InstalledModule
im PackageConfig
pkg_conf
case InstalledFindResult
r' of
InstalledFound loc :: ModLocation
loc _ -> FindResult -> IO FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (ModLocation -> Module -> FindResult
Found ModLocation
loc Module
m)
InstalledNoPackage _ -> FindResult -> IO FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (UnitId -> FindResult
NoPackage (Module -> UnitId
moduleUnitId Module
m))
InstalledNotFound fp :: [String]
fp _ -> FindResult -> IO FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (NotFound :: [String]
-> Maybe UnitId
-> [UnitId]
-> [UnitId]
-> [(UnitId, UnusablePackageReason)]
-> [ModuleSuggestion]
-> FindResult
NotFound{ fr_paths :: [String]
fr_paths = [String]
fp, fr_pkg :: Maybe UnitId
fr_pkg = UnitId -> Maybe UnitId
forall a. a -> Maybe a
Just (Module -> UnitId
moduleUnitId Module
m)
, fr_pkgs_hidden :: [UnitId]
fr_pkgs_hidden = []
, fr_mods_hidden :: [UnitId]
fr_mods_hidden = []
, fr_unusables :: [(UnitId, UnusablePackageReason)]
fr_unusables = []
, fr_suggestions :: [ModuleSuggestion]
fr_suggestions = []})
LookupMultiple rs :: [(Module, ModuleOrigin)]
rs ->
FindResult -> IO FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Module, ModuleOrigin)] -> FindResult
FoundMultiple [(Module, ModuleOrigin)]
rs)
LookupHidden pkg_hiddens :: [(Module, ModuleOrigin)]
pkg_hiddens mod_hiddens :: [(Module, ModuleOrigin)]
mod_hiddens ->
FindResult -> IO FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (NotFound :: [String]
-> Maybe UnitId
-> [UnitId]
-> [UnitId]
-> [(UnitId, UnusablePackageReason)]
-> [ModuleSuggestion]
-> FindResult
NotFound{ fr_paths :: [String]
fr_paths = [], fr_pkg :: Maybe UnitId
fr_pkg = Maybe UnitId
forall a. Maybe a
Nothing
, fr_pkgs_hidden :: [UnitId]
fr_pkgs_hidden = ((Module, ModuleOrigin) -> UnitId)
-> [(Module, ModuleOrigin)] -> [UnitId]
forall a b. (a -> b) -> [a] -> [b]
map (Module -> UnitId
moduleUnitId(Module -> UnitId)
-> ((Module, ModuleOrigin) -> Module)
-> (Module, ModuleOrigin)
-> UnitId
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Module, ModuleOrigin) -> Module
forall a b. (a, b) -> a
fst) [(Module, ModuleOrigin)]
pkg_hiddens
, fr_mods_hidden :: [UnitId]
fr_mods_hidden = ((Module, ModuleOrigin) -> UnitId)
-> [(Module, ModuleOrigin)] -> [UnitId]
forall a b. (a -> b) -> [a] -> [b]
map (Module -> UnitId
moduleUnitId(Module -> UnitId)
-> ((Module, ModuleOrigin) -> Module)
-> (Module, ModuleOrigin)
-> UnitId
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Module, ModuleOrigin) -> Module
forall a b. (a, b) -> a
fst) [(Module, ModuleOrigin)]
mod_hiddens
, fr_unusables :: [(UnitId, UnusablePackageReason)]
fr_unusables = []
, fr_suggestions :: [ModuleSuggestion]
fr_suggestions = [] })
LookupUnusable unusable :: [(Module, ModuleOrigin)]
unusable ->
let unusables' :: [(UnitId, UnusablePackageReason)]
unusables' = ((Module, ModuleOrigin) -> (UnitId, UnusablePackageReason))
-> [(Module, ModuleOrigin)] -> [(UnitId, UnusablePackageReason)]
forall a b. (a -> b) -> [a] -> [b]
map (Module, ModuleOrigin) -> (UnitId, UnusablePackageReason)
get_unusable [(Module, ModuleOrigin)]
unusable
get_unusable :: (Module, ModuleOrigin) -> (UnitId, UnusablePackageReason)
get_unusable (m :: Module
m, ModUnusable r :: UnusablePackageReason
r) = (Module -> UnitId
moduleUnitId Module
m, UnusablePackageReason
r)
get_unusable (_, r :: ModuleOrigin
r) =
String -> SDoc -> (UnitId, UnusablePackageReason)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "findLookupResult: unexpected origin" (ModuleOrigin -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleOrigin
r)
in FindResult -> IO FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (NotFound :: [String]
-> Maybe UnitId
-> [UnitId]
-> [UnitId]
-> [(UnitId, UnusablePackageReason)]
-> [ModuleSuggestion]
-> FindResult
NotFound{ fr_paths :: [String]
fr_paths = [], fr_pkg :: Maybe UnitId
fr_pkg = Maybe UnitId
forall a. Maybe a
Nothing
, fr_pkgs_hidden :: [UnitId]
fr_pkgs_hidden = []
, fr_mods_hidden :: [UnitId]
fr_mods_hidden = []
, fr_unusables :: [(UnitId, UnusablePackageReason)]
fr_unusables = [(UnitId, UnusablePackageReason)]
unusables'
, fr_suggestions :: [ModuleSuggestion]
fr_suggestions = [] })
LookupNotFound suggest :: [ModuleSuggestion]
suggest ->
FindResult -> IO FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (NotFound :: [String]
-> Maybe UnitId
-> [UnitId]
-> [UnitId]
-> [(UnitId, UnusablePackageReason)]
-> [ModuleSuggestion]
-> FindResult
NotFound{ fr_paths :: [String]
fr_paths = [], fr_pkg :: Maybe UnitId
fr_pkg = Maybe UnitId
forall a. Maybe a
Nothing
, fr_pkgs_hidden :: [UnitId]
fr_pkgs_hidden = []
, fr_mods_hidden :: [UnitId]
fr_mods_hidden = []
, fr_unusables :: [(UnitId, UnusablePackageReason)]
fr_unusables = []
, fr_suggestions :: [ModuleSuggestion]
fr_suggestions = [ModuleSuggestion]
suggest })
modLocationCache :: HscEnv -> InstalledModule -> IO InstalledFindResult -> IO InstalledFindResult
modLocationCache :: HscEnv
-> InstalledModule
-> IO InstalledFindResult
-> IO InstalledFindResult
modLocationCache hsc_env :: HscEnv
hsc_env mod :: InstalledModule
mod do_this :: IO InstalledFindResult
do_this = do
Maybe InstalledFindResult
m <- IORef FinderCache
-> InstalledModule -> IO (Maybe InstalledFindResult)
lookupFinderCache (HscEnv -> IORef FinderCache
hsc_FC HscEnv
hsc_env) InstalledModule
mod
case Maybe InstalledFindResult
m of
Just result :: InstalledFindResult
result -> InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return InstalledFindResult
result
Nothing -> do
InstalledFindResult
result <- IO InstalledFindResult
do_this
IORef FinderCache
-> InstalledModule -> InstalledFindResult -> IO ()
addToFinderCache (HscEnv -> IORef FinderCache
hsc_FC HscEnv
hsc_env) InstalledModule
mod InstalledFindResult
result
InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return InstalledFindResult
result
mkHomeInstalledModule :: DynFlags -> ModuleName -> InstalledModule
mkHomeInstalledModule :: DynFlags -> ModuleName -> InstalledModule
mkHomeInstalledModule dflags :: DynFlags
dflags mod_name :: ModuleName
mod_name =
let iuid :: InstalledUnitId
iuid = (InstalledUnitId, Maybe IndefUnitId) -> InstalledUnitId
forall a b. (a, b) -> a
fst (UnitId -> (InstalledUnitId, Maybe IndefUnitId)
splitUnitIdInsts (DynFlags -> UnitId
thisPackage DynFlags
dflags))
in InstalledUnitId -> ModuleName -> InstalledModule
InstalledModule InstalledUnitId
iuid ModuleName
mod_name
addHomeModuleToFinder :: HscEnv -> ModuleName -> ModLocation -> IO Module
addHomeModuleToFinder :: HscEnv -> ModuleName -> ModLocation -> IO Module
addHomeModuleToFinder hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name loc :: ModLocation
loc = do
let mod :: InstalledModule
mod = DynFlags -> ModuleName -> InstalledModule
mkHomeInstalledModule (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env) ModuleName
mod_name
IORef FinderCache
-> InstalledModule -> InstalledFindResult -> IO ()
addToFinderCache (HscEnv -> IORef FinderCache
hsc_FC HscEnv
hsc_env) InstalledModule
mod (ModLocation -> InstalledModule -> InstalledFindResult
InstalledFound ModLocation
loc InstalledModule
mod)
Module -> IO Module
forall (m :: * -> *) a. Monad m => a -> m a
return (UnitId -> ModuleName -> Module
mkModule (DynFlags -> UnitId
thisPackage (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env)) ModuleName
mod_name)
uncacheModule :: HscEnv -> ModuleName -> IO ()
uncacheModule :: HscEnv -> ModuleName -> IO ()
uncacheModule hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name = do
let mod :: InstalledModule
mod = DynFlags -> ModuleName -> InstalledModule
mkHomeInstalledModule (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env) ModuleName
mod_name
IORef FinderCache -> InstalledModule -> IO ()
removeFromFinderCache (HscEnv -> IORef FinderCache
hsc_FC HscEnv
hsc_env) InstalledModule
mod
findHomeModule :: HscEnv -> ModuleName -> IO FindResult
findHomeModule :: HscEnv -> ModuleName -> IO FindResult
findHomeModule hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name = do
InstalledFindResult
r <- HscEnv -> ModuleName -> IO InstalledFindResult
findInstalledHomeModule HscEnv
hsc_env ModuleName
mod_name
FindResult -> IO FindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (FindResult -> IO FindResult) -> FindResult -> IO FindResult
forall a b. (a -> b) -> a -> b
$ case InstalledFindResult
r of
InstalledFound loc :: ModLocation
loc _ -> ModLocation -> Module -> FindResult
Found ModLocation
loc (UnitId -> ModuleName -> Module
mkModule UnitId
uid ModuleName
mod_name)
InstalledNoPackage _ -> UnitId -> FindResult
NoPackage UnitId
uid
InstalledNotFound fps :: [String]
fps _ -> NotFound :: [String]
-> Maybe UnitId
-> [UnitId]
-> [UnitId]
-> [(UnitId, UnusablePackageReason)]
-> [ModuleSuggestion]
-> FindResult
NotFound {
fr_paths :: [String]
fr_paths = [String]
fps,
fr_pkg :: Maybe UnitId
fr_pkg = UnitId -> Maybe UnitId
forall a. a -> Maybe a
Just UnitId
uid,
fr_mods_hidden :: [UnitId]
fr_mods_hidden = [],
fr_pkgs_hidden :: [UnitId]
fr_pkgs_hidden = [],
fr_unusables :: [(UnitId, UnusablePackageReason)]
fr_unusables = [],
fr_suggestions :: [ModuleSuggestion]
fr_suggestions = []
}
where
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
uid :: UnitId
uid = DynFlags -> UnitId
thisPackage DynFlags
dflags
findInstalledHomeModule :: HscEnv -> ModuleName -> IO InstalledFindResult
findInstalledHomeModule :: HscEnv -> ModuleName -> IO InstalledFindResult
findInstalledHomeModule hsc_env :: HscEnv
hsc_env mod_name :: ModuleName
mod_name =
HscEnv
-> ModuleName -> IO InstalledFindResult -> IO InstalledFindResult
homeSearchCache HscEnv
hsc_env ModuleName
mod_name (IO InstalledFindResult -> IO InstalledFindResult)
-> IO InstalledFindResult -> IO InstalledFindResult
forall a b. (a -> b) -> a -> b
$
let
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
home_path :: [String]
home_path = DynFlags -> [String]
importPaths DynFlags
dflags
hisuf :: String
hisuf = DynFlags -> String
hiSuf DynFlags
dflags
mod :: InstalledModule
mod = DynFlags -> ModuleName -> InstalledModule
mkHomeInstalledModule DynFlags
dflags ModuleName
mod_name
source_exts :: [(String, String -> String -> IO ModLocation)]
source_exts =
[ ("hs", DynFlags
-> ModuleName -> String -> String -> String -> IO ModLocation
mkHomeModLocationSearched DynFlags
dflags ModuleName
mod_name "hs")
, ("lhs", DynFlags
-> ModuleName -> String -> String -> String -> IO ModLocation
mkHomeModLocationSearched DynFlags
dflags ModuleName
mod_name "lhs")
, ("hsig", DynFlags
-> ModuleName -> String -> String -> String -> IO ModLocation
mkHomeModLocationSearched DynFlags
dflags ModuleName
mod_name "hsig")
, ("lhsig", DynFlags
-> ModuleName -> String -> String -> String -> IO ModLocation
mkHomeModLocationSearched DynFlags
dflags ModuleName
mod_name "lhsig")
]
hi_exts :: [(String, String -> String -> IO ModLocation)]
hi_exts = [ (String
hisuf, DynFlags -> String -> String -> String -> IO ModLocation
mkHiOnlyModLocation DynFlags
dflags String
hisuf)
, (String -> String
addBootSuffix String
hisuf, DynFlags -> String -> String -> String -> IO ModLocation
mkHiOnlyModLocation DynFlags
dflags String
hisuf)
]
exts :: [(String, String -> String -> IO ModLocation)]
exts | GhcMode -> Bool
isOneShot (DynFlags -> GhcMode
ghcMode DynFlags
dflags) = [(String, String -> String -> IO ModLocation)]
hi_exts
| Bool
otherwise = [(String, String -> String -> IO ModLocation)]
source_exts
in
if InstalledModule
mod InstalledModule -> Module -> Bool
`installedModuleEq` Module
gHC_PRIM
then InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (ModLocation -> InstalledModule -> InstalledFindResult
InstalledFound (String -> ModLocation
forall a. HasCallStack => String -> a
error "GHC.Prim ModLocation") InstalledModule
mod)
else [String]
-> InstalledModule
-> [(String, String -> String -> IO ModLocation)]
-> IO InstalledFindResult
searchPathExts [String]
home_path InstalledModule
mod [(String, String -> String -> IO ModLocation)]
exts
findPackageModule :: HscEnv -> InstalledModule -> IO InstalledFindResult
findPackageModule :: HscEnv -> InstalledModule -> IO InstalledFindResult
findPackageModule hsc_env :: HscEnv
hsc_env mod :: InstalledModule
mod = do
let
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
pkg_id :: InstalledUnitId
pkg_id = InstalledModule -> InstalledUnitId
installedModuleUnitId InstalledModule
mod
case DynFlags -> InstalledUnitId -> Maybe PackageConfig
lookupInstalledPackage DynFlags
dflags InstalledUnitId
pkg_id of
Nothing -> InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (InstalledUnitId -> InstalledFindResult
InstalledNoPackage InstalledUnitId
pkg_id)
Just pkg_conf :: PackageConfig
pkg_conf -> HscEnv
-> InstalledModule -> PackageConfig -> IO InstalledFindResult
findPackageModule_ HscEnv
hsc_env InstalledModule
mod PackageConfig
pkg_conf
findPackageModule_ :: HscEnv -> InstalledModule -> PackageConfig -> IO InstalledFindResult
findPackageModule_ :: HscEnv
-> InstalledModule -> PackageConfig -> IO InstalledFindResult
findPackageModule_ hsc_env :: HscEnv
hsc_env mod :: InstalledModule
mod pkg_conf :: PackageConfig
pkg_conf =
ASSERT2( installedModuleUnitId mod == installedPackageConfigId pkg_conf, ppr (installedModuleUnitId mod) <+> ppr (installedPackageConfigId pkg_conf) )
HscEnv
-> InstalledModule
-> IO InstalledFindResult
-> IO InstalledFindResult
modLocationCache HscEnv
hsc_env InstalledModule
mod (IO InstalledFindResult -> IO InstalledFindResult)
-> IO InstalledFindResult -> IO InstalledFindResult
forall a b. (a -> b) -> a -> b
$
if InstalledModule
mod InstalledModule -> Module -> Bool
`installedModuleEq` Module
gHC_PRIM
then InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (ModLocation -> InstalledModule -> InstalledFindResult
InstalledFound (String -> ModLocation
forall a. HasCallStack => String -> a
error "GHC.Prim ModLocation") InstalledModule
mod)
else
let
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
tag :: String
tag = DynFlags -> String
buildTag DynFlags
dflags
package_hisuf :: String
package_hisuf | String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
tag = "hi"
| Bool
otherwise = String
tag String -> String -> String
forall a. [a] -> [a] -> [a]
++ "_hi"
mk_hi_loc :: String -> String -> IO ModLocation
mk_hi_loc = DynFlags -> String -> String -> String -> IO ModLocation
mkHiOnlyModLocation DynFlags
dflags String
package_hisuf
import_dirs :: [String]
import_dirs = PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
importDirs PackageConfig
pkg_conf
in
case [String]
import_dirs of
[one :: String
one] | GhcMode
MkDepend <- DynFlags -> GhcMode
ghcMode DynFlags
dflags -> do
let basename :: String
basename = ModuleName -> String
moduleNameSlashes (InstalledModule -> ModuleName
installedModuleName InstalledModule
mod)
ModLocation
loc <- String -> String -> IO ModLocation
mk_hi_loc String
one String
basename
InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (ModLocation -> InstalledModule -> InstalledFindResult
InstalledFound ModLocation
loc InstalledModule
mod)
_otherwise :: [String]
_otherwise ->
[String]
-> InstalledModule
-> [(String, String -> String -> IO ModLocation)]
-> IO InstalledFindResult
searchPathExts [String]
import_dirs InstalledModule
mod [(String
package_hisuf, String -> String -> IO ModLocation
mk_hi_loc)]
searchPathExts
:: [FilePath]
-> InstalledModule
-> [ (
FileExt,
FilePath -> BaseName -> IO ModLocation
)
]
-> IO InstalledFindResult
searchPathExts :: [String]
-> InstalledModule
-> [(String, String -> String -> IO ModLocation)]
-> IO InstalledFindResult
searchPathExts paths :: [String]
paths mod :: InstalledModule
mod exts :: [(String, String -> String -> IO ModLocation)]
exts
= do InstalledFindResult
result <- [(String, IO ModLocation)] -> IO InstalledFindResult
search [(String, IO ModLocation)]
to_search
InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return InstalledFindResult
result
where
basename :: String
basename = ModuleName -> String
moduleNameSlashes (InstalledModule -> ModuleName
installedModuleName InstalledModule
mod)
to_search :: [(FilePath, IO ModLocation)]
to_search :: [(String, IO ModLocation)]
to_search = [ (String
file, String -> String -> IO ModLocation
fn String
path String
basename)
| String
path <- [String]
paths,
(ext :: String
ext,fn :: String -> String -> IO ModLocation
fn) <- [(String, String -> String -> IO ModLocation)]
exts,
let base :: String
base | String
path String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "." = String
basename
| Bool
otherwise = String
path String -> String -> String
</> String
basename
file :: String
file = String
base String -> String -> String
<.> String
ext
]
search :: [(String, IO ModLocation)] -> IO InstalledFindResult
search [] = InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return ([String] -> Maybe InstalledUnitId -> InstalledFindResult
InstalledNotFound (((String, IO ModLocation) -> String)
-> [(String, IO ModLocation)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, IO ModLocation) -> String
forall a b. (a, b) -> a
fst [(String, IO ModLocation)]
to_search) (InstalledUnitId -> Maybe InstalledUnitId
forall a. a -> Maybe a
Just (InstalledModule -> InstalledUnitId
installedModuleUnitId InstalledModule
mod)))
search ((file :: String
file, mk_result :: IO ModLocation
mk_result) : rest :: [(String, IO ModLocation)]
rest) = do
Bool
b <- String -> IO Bool
doesFileExist String
file
if Bool
b
then do { ModLocation
loc <- IO ModLocation
mk_result; InstalledFindResult -> IO InstalledFindResult
forall (m :: * -> *) a. Monad m => a -> m a
return (ModLocation -> InstalledModule -> InstalledFindResult
InstalledFound ModLocation
loc InstalledModule
mod) }
else [(String, IO ModLocation)] -> IO InstalledFindResult
search [(String, IO ModLocation)]
rest
mkHomeModLocationSearched :: DynFlags -> ModuleName -> FileExt
-> FilePath -> BaseName -> IO ModLocation
mkHomeModLocationSearched :: DynFlags
-> ModuleName -> String -> String -> String -> IO ModLocation
mkHomeModLocationSearched dflags :: DynFlags
dflags mod :: ModuleName
mod suff :: String
suff path :: String
path basename :: String
basename = do
DynFlags -> ModuleName -> String -> String -> IO ModLocation
mkHomeModLocation2 DynFlags
dflags ModuleName
mod (String
path String -> String -> String
</> String
basename) String
suff
mkHomeModLocation :: DynFlags -> ModuleName -> FilePath -> IO ModLocation
mkHomeModLocation :: DynFlags -> ModuleName -> String -> IO ModLocation
mkHomeModLocation dflags :: DynFlags
dflags mod :: ModuleName
mod src_filename :: String
src_filename = do
let (basename :: String
basename,extension :: String
extension) = String -> (String, String)
splitExtension String
src_filename
DynFlags -> ModuleName -> String -> String -> IO ModLocation
mkHomeModLocation2 DynFlags
dflags ModuleName
mod String
basename String
extension
mkHomeModLocation2 :: DynFlags
-> ModuleName
-> FilePath
-> String
-> IO ModLocation
mkHomeModLocation2 :: DynFlags -> ModuleName -> String -> String -> IO ModLocation
mkHomeModLocation2 dflags :: DynFlags
dflags mod :: ModuleName
mod src_basename :: String
src_basename ext :: String
ext = do
let mod_basename :: String
mod_basename = ModuleName -> String
moduleNameSlashes ModuleName
mod
obj_fn :: String
obj_fn = DynFlags -> String -> String -> String
mkObjPath DynFlags
dflags String
src_basename String
mod_basename
hi_fn :: String
hi_fn = DynFlags -> String -> String -> String
mkHiPath DynFlags
dflags String
src_basename String
mod_basename
hie_fn :: String
hie_fn = DynFlags -> String -> String -> String
mkHiePath DynFlags
dflags String
src_basename String
mod_basename
ModLocation -> IO ModLocation
forall (m :: * -> *) a. Monad m => a -> m a
return (ModLocation :: Maybe String -> String -> String -> String -> ModLocation
ModLocation{ ml_hs_file :: Maybe String
ml_hs_file = String -> Maybe String
forall a. a -> Maybe a
Just (String
src_basename String -> String -> String
<.> String
ext),
ml_hi_file :: String
ml_hi_file = String
hi_fn,
ml_obj_file :: String
ml_obj_file = String
obj_fn,
ml_hie_file :: String
ml_hie_file = String
hie_fn })
mkHiOnlyModLocation :: DynFlags -> Suffix -> FilePath -> String
-> IO ModLocation
mkHiOnlyModLocation :: DynFlags -> String -> String -> String -> IO ModLocation
mkHiOnlyModLocation dflags :: DynFlags
dflags hisuf :: String
hisuf path :: String
path basename :: String
basename
= do let full_basename :: String
full_basename = String
path String -> String -> String
</> String
basename
obj_fn :: String
obj_fn = DynFlags -> String -> String -> String
mkObjPath DynFlags
dflags String
full_basename String
basename
hie_fn :: String
hie_fn = DynFlags -> String -> String -> String
mkHiePath DynFlags
dflags String
full_basename String
basename
ModLocation -> IO ModLocation
forall (m :: * -> *) a. Monad m => a -> m a
return ModLocation :: Maybe String -> String -> String -> String -> ModLocation
ModLocation{ ml_hs_file :: Maybe String
ml_hs_file = Maybe String
forall a. Maybe a
Nothing,
ml_hi_file :: String
ml_hi_file = String
full_basename String -> String -> String
<.> String
hisuf,
ml_obj_file :: String
ml_obj_file = String
obj_fn,
ml_hie_file :: String
ml_hie_file = String
hie_fn
}
mkObjPath
:: DynFlags
-> FilePath
-> String
-> FilePath
mkObjPath :: DynFlags -> String -> String -> String
mkObjPath dflags :: DynFlags
dflags basename :: String
basename mod_basename :: String
mod_basename = String
obj_basename String -> String -> String
<.> String
osuf
where
odir :: Maybe String
odir = DynFlags -> Maybe String
objectDir DynFlags
dflags
osuf :: String
osuf = DynFlags -> String
objectSuf DynFlags
dflags
obj_basename :: String
obj_basename | Just dir :: String
dir <- Maybe String
odir = String
dir String -> String -> String
</> String
mod_basename
| Bool
otherwise = String
basename
mkHiPath
:: DynFlags
-> FilePath
-> String
-> FilePath
mkHiPath :: DynFlags -> String -> String -> String
mkHiPath dflags :: DynFlags
dflags basename :: String
basename mod_basename :: String
mod_basename = String
hi_basename String -> String -> String
<.> String
hisuf
where
hidir :: Maybe String
hidir = DynFlags -> Maybe String
hiDir DynFlags
dflags
hisuf :: String
hisuf = DynFlags -> String
hiSuf DynFlags
dflags
hi_basename :: String
hi_basename | Just dir :: String
dir <- Maybe String
hidir = String
dir String -> String -> String
</> String
mod_basename
| Bool
otherwise = String
basename
mkHiePath
:: DynFlags
-> FilePath
-> String
-> FilePath
mkHiePath :: DynFlags -> String -> String -> String
mkHiePath dflags :: DynFlags
dflags basename :: String
basename mod_basename :: String
mod_basename = String
hie_basename String -> String -> String
<.> String
hiesuf
where
hiedir :: Maybe String
hiedir = DynFlags -> Maybe String
hieDir DynFlags
dflags
hiesuf :: String
hiesuf = DynFlags -> String
hieSuf DynFlags
dflags
hie_basename :: String
hie_basename | Just dir :: String
dir <- Maybe String
hiedir = String
dir String -> String -> String
</> String
mod_basename
| Bool
otherwise = String
basename
mkStubPaths
:: DynFlags
-> ModuleName
-> ModLocation
-> FilePath
mkStubPaths :: DynFlags -> ModuleName -> ModLocation -> String
mkStubPaths dflags :: DynFlags
dflags mod :: ModuleName
mod location :: ModLocation
location
= let
stubdir :: Maybe String
stubdir = DynFlags -> Maybe String
stubDir DynFlags
dflags
mod_basename :: String
mod_basename = ModuleName -> String
moduleNameSlashes ModuleName
mod
src_basename :: String
src_basename = String -> String
dropExtension (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String -> Maybe String -> String
forall a. HasCallStack => String -> Maybe a -> a
expectJust "mkStubPaths"
(ModLocation -> Maybe String
ml_hs_file ModLocation
location)
stub_basename0 :: String
stub_basename0
| Just dir :: String
dir <- Maybe String
stubdir = String
dir String -> String -> String
</> String
mod_basename
| Bool
otherwise = String
src_basename
stub_basename :: String
stub_basename = String
stub_basename0 String -> String -> String
forall a. [a] -> [a] -> [a]
++ "_stub"
in
String
stub_basename String -> String -> String
<.> "h"
findObjectLinkableMaybe :: Module -> ModLocation -> IO (Maybe Linkable)
findObjectLinkableMaybe :: Module -> ModLocation -> IO (Maybe Linkable)
findObjectLinkableMaybe mod :: Module
mod locn :: ModLocation
locn
= do let obj_fn :: String
obj_fn = ModLocation -> String
ml_obj_file ModLocation
locn
Maybe UTCTime
maybe_obj_time <- String -> IO (Maybe UTCTime)
modificationTimeIfExists String
obj_fn
case Maybe UTCTime
maybe_obj_time of
Nothing -> Maybe Linkable -> IO (Maybe Linkable)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Linkable
forall a. Maybe a
Nothing
Just obj_time :: UTCTime
obj_time -> (Linkable -> Maybe Linkable) -> IO Linkable -> IO (Maybe Linkable)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Linkable -> Maybe Linkable
forall a. a -> Maybe a
Just (Module -> String -> UTCTime -> IO Linkable
findObjectLinkable Module
mod String
obj_fn UTCTime
obj_time)
findObjectLinkable :: Module -> FilePath -> UTCTime -> IO Linkable
findObjectLinkable :: Module -> String -> UTCTime -> IO Linkable
findObjectLinkable mod :: Module
mod obj_fn :: String
obj_fn obj_time :: UTCTime
obj_time = Linkable -> IO Linkable
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> Module -> [Unlinked] -> Linkable
LM UTCTime
obj_time Module
mod [String -> Unlinked
DotO String
obj_fn])
cannotFindModule :: DynFlags -> ModuleName -> FindResult -> SDoc
cannotFindModule :: DynFlags -> ModuleName -> FindResult -> SDoc
cannotFindModule flags :: DynFlags
flags mod :: ModuleName
mod res :: FindResult
res =
PtrString
-> PtrString -> DynFlags -> ModuleName -> FindResult -> SDoc
cantFindErr (String -> PtrString
sLit String
cannotFindMsg)
(String -> PtrString
sLit "Ambiguous module name")
DynFlags
flags ModuleName
mod FindResult
res
where
cannotFindMsg :: String
cannotFindMsg =
case FindResult
res of
NotFound { fr_mods_hidden :: FindResult -> [UnitId]
fr_mods_hidden = [UnitId]
hidden_mods
, fr_pkgs_hidden :: FindResult -> [UnitId]
fr_pkgs_hidden = [UnitId]
hidden_pkgs
, fr_unusables :: FindResult -> [(UnitId, UnusablePackageReason)]
fr_unusables = [(UnitId, UnusablePackageReason)]
unusables }
| Bool -> Bool
not ([UnitId] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [UnitId]
hidden_mods Bool -> Bool -> Bool
&& [UnitId] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [UnitId]
hidden_pkgs Bool -> Bool -> Bool
&& [(UnitId, UnusablePackageReason)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(UnitId, UnusablePackageReason)]
unusables)
-> "Could not load module"
_ -> "Could not find module"
cannotFindInterface :: DynFlags -> ModuleName -> InstalledFindResult -> SDoc
cannotFindInterface :: DynFlags -> ModuleName -> InstalledFindResult -> SDoc
cannotFindInterface = PtrString
-> PtrString
-> DynFlags
-> ModuleName
-> InstalledFindResult
-> SDoc
cantFindInstalledErr (String -> PtrString
sLit "Failed to load interface for")
(String -> PtrString
sLit "Ambiguous interface for")
cantFindErr :: PtrString -> PtrString -> DynFlags -> ModuleName -> FindResult
-> SDoc
cantFindErr :: PtrString
-> PtrString -> DynFlags -> ModuleName -> FindResult -> SDoc
cantFindErr _ multiple_found :: PtrString
multiple_found _ mod_name :: ModuleName
mod_name (FoundMultiple mods :: [(Module, ModuleOrigin)]
mods)
| Just pkgs :: [UnitId]
pkgs <- Maybe [UnitId]
unambiguousPackages
= SDoc -> Int -> SDoc -> SDoc
hang (PtrString -> SDoc
ptext PtrString
multiple_found SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod_name) SDoc -> SDoc -> SDoc
<> SDoc
colon) 2 (
[SDoc] -> SDoc
sep [String -> SDoc
text "it was found in multiple packages:",
[SDoc] -> SDoc
hsep ((UnitId -> SDoc) -> [UnitId] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr [UnitId]
pkgs) ]
)
| Bool
otherwise
= SDoc -> Int -> SDoc -> SDoc
hang (PtrString -> SDoc
ptext PtrString
multiple_found SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod_name) SDoc -> SDoc -> SDoc
<> SDoc
colon) 2 (
[SDoc] -> SDoc
vcat (((Module, ModuleOrigin) -> SDoc)
-> [(Module, ModuleOrigin)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (Module, ModuleOrigin) -> SDoc
pprMod [(Module, ModuleOrigin)]
mods)
)
where
unambiguousPackages :: Maybe [UnitId]
unambiguousPackages = (Maybe [UnitId] -> (Module, ModuleOrigin) -> Maybe [UnitId])
-> Maybe [UnitId] -> [(Module, ModuleOrigin)] -> Maybe [UnitId]
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Maybe [UnitId] -> (Module, ModuleOrigin) -> Maybe [UnitId]
unambiguousPackage ([UnitId] -> Maybe [UnitId]
forall a. a -> Maybe a
Just []) [(Module, ModuleOrigin)]
mods
unambiguousPackage :: Maybe [UnitId] -> (Module, ModuleOrigin) -> Maybe [UnitId]
unambiguousPackage (Just xs :: [UnitId]
xs) (m :: Module
m, ModOrigin (Just _) _ _ _)
= [UnitId] -> Maybe [UnitId]
forall a. a -> Maybe a
Just (Module -> UnitId
moduleUnitId Module
m UnitId -> [UnitId] -> [UnitId]
forall a. a -> [a] -> [a]
: [UnitId]
xs)
unambiguousPackage _ _ = Maybe [UnitId]
forall a. Maybe a
Nothing
pprMod :: (Module, ModuleOrigin) -> SDoc
pprMod (m :: Module
m, o :: ModuleOrigin
o) = String -> SDoc
text "it is bound as" SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
m SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "by" SDoc -> SDoc -> SDoc
<+> Module -> ModuleOrigin -> SDoc
pprOrigin Module
m ModuleOrigin
o
pprOrigin :: Module -> ModuleOrigin -> SDoc
pprOrigin _ ModHidden = String -> SDoc
forall a. String -> a
panic "cantFindErr: bound by mod hidden"
pprOrigin _ (ModUnusable _) = String -> SDoc
forall a. String -> a
panic "cantFindErr: bound by mod unusable"
pprOrigin m :: Module
m (ModOrigin e :: Maybe Bool
e res :: [PackageConfig]
res _ f :: Bool
f) = [SDoc] -> SDoc
sep ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ SDoc -> [SDoc] -> [SDoc]
punctuate SDoc
comma (
if Maybe Bool
e Maybe Bool -> Maybe Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
True
then [String -> SDoc
text "package" SDoc -> SDoc -> SDoc
<+> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> UnitId
moduleUnitId Module
m)]
else [] [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++
(PackageConfig -> SDoc) -> [PackageConfig] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ((String -> SDoc
text "a reexport in package" SDoc -> SDoc -> SDoc
<+>)
(SDoc -> SDoc) -> (PackageConfig -> SDoc) -> PackageConfig -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr(UnitId -> SDoc)
-> (PackageConfig -> UnitId) -> PackageConfig -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
.PackageConfig -> UnitId
packageConfigId) [PackageConfig]
res [SDoc] -> [SDoc] -> [SDoc]
forall a. [a] -> [a] -> [a]
++
if Bool
f then [String -> SDoc
text "a package flag"] else []
)
cantFindErr cannot_find :: PtrString
cannot_find _ dflags :: DynFlags
dflags mod_name :: ModuleName
mod_name find_result :: FindResult
find_result
= PtrString -> SDoc
ptext PtrString
cannot_find SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod_name)
SDoc -> SDoc -> SDoc
$$ SDoc
more_info
where
more_info :: SDoc
more_info
= case FindResult
find_result of
NoPackage pkg :: UnitId
pkg
-> String -> SDoc
text "no unit id matching" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
pkg) SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "was found"
NotFound { fr_paths :: FindResult -> [String]
fr_paths = [String]
files, fr_pkg :: FindResult -> Maybe UnitId
fr_pkg = Maybe UnitId
mb_pkg
, fr_mods_hidden :: FindResult -> [UnitId]
fr_mods_hidden = [UnitId]
mod_hiddens, fr_pkgs_hidden :: FindResult -> [UnitId]
fr_pkgs_hidden = [UnitId]
pkg_hiddens
, fr_unusables :: FindResult -> [(UnitId, UnusablePackageReason)]
fr_unusables = [(UnitId, UnusablePackageReason)]
unusables, fr_suggestions :: FindResult -> [ModuleSuggestion]
fr_suggestions = [ModuleSuggestion]
suggest }
| Just pkg :: UnitId
pkg <- Maybe UnitId
mb_pkg, UnitId
pkg UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
/= DynFlags -> UnitId
thisPackage DynFlags
dflags
-> UnitId -> [String] -> SDoc
forall a. Outputable a => a -> [String] -> SDoc
not_found_in_package UnitId
pkg [String]
files
| Bool -> Bool
not ([ModuleSuggestion] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ModuleSuggestion]
suggest)
-> [ModuleSuggestion] -> SDoc
pp_suggestions [ModuleSuggestion]
suggest SDoc -> SDoc -> SDoc
$$ [String] -> DynFlags -> SDoc
tried_these [String]
files DynFlags
dflags
| [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
files Bool -> Bool -> Bool
&& [UnitId] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [UnitId]
mod_hiddens Bool -> Bool -> Bool
&&
[UnitId] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [UnitId]
pkg_hiddens Bool -> Bool -> Bool
&& [(UnitId, UnusablePackageReason)] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(UnitId, UnusablePackageReason)]
unusables
-> String -> SDoc
text "It is not a module in the current program, or in any known package."
| Bool
otherwise
-> [SDoc] -> SDoc
vcat ((UnitId -> SDoc) -> [UnitId] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map UnitId -> SDoc
pkg_hidden [UnitId]
pkg_hiddens) SDoc -> SDoc -> SDoc
$$
[SDoc] -> SDoc
vcat ((UnitId -> SDoc) -> [UnitId] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map UnitId -> SDoc
forall a. Outputable a => a -> SDoc
mod_hidden [UnitId]
mod_hiddens) SDoc -> SDoc -> SDoc
$$
[SDoc] -> SDoc
vcat (((UnitId, UnusablePackageReason) -> SDoc)
-> [(UnitId, UnusablePackageReason)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (UnitId, UnusablePackageReason) -> SDoc
forall a. Outputable a => (a, UnusablePackageReason) -> SDoc
unusable [(UnitId, UnusablePackageReason)]
unusables) SDoc -> SDoc -> SDoc
$$
[String] -> DynFlags -> SDoc
tried_these [String]
files DynFlags
dflags
_ -> String -> SDoc
forall a. String -> a
panic "cantFindErr"
build_tag :: String
build_tag = DynFlags -> String
buildTag DynFlags
dflags
not_found_in_package :: a -> [String] -> SDoc
not_found_in_package pkg :: a
pkg files :: [String]
files
| String
build_tag String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= ""
= let
build :: String
build = if String
build_tag String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "p" then "profiling"
else "\"" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
build_tag String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\""
in
String -> SDoc
text "Perhaps you haven't installed the " SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
build SDoc -> SDoc -> SDoc
<>
String -> SDoc
text " libraries for package " SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
quotes (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
pkg) SDoc -> SDoc -> SDoc
<> Char -> SDoc
char '?' SDoc -> SDoc -> SDoc
$$
[String] -> DynFlags -> SDoc
tried_these [String]
files DynFlags
dflags
| Bool
otherwise
= String -> SDoc
text "There are files missing in the " SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
quotes (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
pkg) SDoc -> SDoc -> SDoc
<>
String -> SDoc
text " package," SDoc -> SDoc -> SDoc
$$
String -> SDoc
text "try running 'ghc-pkg check'." SDoc -> SDoc -> SDoc
$$
[String] -> DynFlags -> SDoc
tried_these [String]
files DynFlags
dflags
pkg_hidden :: UnitId -> SDoc
pkg_hidden :: UnitId -> SDoc
pkg_hidden pkgid :: UnitId
pkgid =
String -> SDoc
text "It is a member of the hidden package"
SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr UnitId
pkgid)
SDoc -> SDoc -> SDoc
<> SDoc
dot SDoc -> SDoc -> SDoc
$$ UnitId -> SDoc
pkg_hidden_hint UnitId
pkgid
pkg_hidden_hint :: UnitId -> SDoc
pkg_hidden_hint pkgid :: UnitId
pkgid
| GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_BuildingCabalPackage DynFlags
dflags
= let pkg :: PackageConfig
pkg = String -> Maybe PackageConfig -> PackageConfig
forall a. HasCallStack => String -> Maybe a -> a
expectJust "pkg_hidden" (DynFlags -> UnitId -> Maybe PackageConfig
lookupPackage DynFlags
dflags UnitId
pkgid)
in String -> SDoc
text "Perhaps you need to add" SDoc -> SDoc -> SDoc
<+>
SDoc -> SDoc
quotes (PackageName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PackageConfig -> PackageName
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> srcpkgname
packageName PackageConfig
pkg)) SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "to the build-depends in your .cabal file."
| Just pkg :: PackageConfig
pkg <- DynFlags -> UnitId -> Maybe PackageConfig
lookupPackage DynFlags
dflags UnitId
pkgid
= String -> SDoc
text "You can run" SDoc -> SDoc -> SDoc
<+>
SDoc -> SDoc
quotes (String -> SDoc
text ":set -package " SDoc -> SDoc -> SDoc
<> PackageName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PackageConfig -> PackageName
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> srcpkgname
packageName PackageConfig
pkg)) SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "to expose it." SDoc -> SDoc -> SDoc
$$
String -> SDoc
text "(Note: this unloads all the modules in the current scope.)"
| Bool
otherwise = SDoc
Outputable.empty
mod_hidden :: a -> SDoc
mod_hidden pkg :: a
pkg =
String -> SDoc
text "it is a hidden module in the package" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
pkg)
unusable :: (a, UnusablePackageReason) -> SDoc
unusable (pkg :: a
pkg, reason :: UnusablePackageReason
reason)
= String -> SDoc
text "It is a member of the package"
SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
pkg)
SDoc -> SDoc -> SDoc
$$ SDoc -> UnusablePackageReason -> SDoc
pprReason (String -> SDoc
text "which is") UnusablePackageReason
reason
pp_suggestions :: [ModuleSuggestion] -> SDoc
pp_suggestions :: [ModuleSuggestion] -> SDoc
pp_suggestions sugs :: [ModuleSuggestion]
sugs
| [ModuleSuggestion] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ModuleSuggestion]
sugs = SDoc
Outputable.empty
| Bool
otherwise = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Perhaps you meant")
2 ([SDoc] -> SDoc
vcat ((ModuleSuggestion -> SDoc) -> [ModuleSuggestion] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map ModuleSuggestion -> SDoc
pp_sugg [ModuleSuggestion]
sugs))
pp_sugg :: ModuleSuggestion -> SDoc
pp_sugg (SuggestVisible m :: ModuleName
m mod :: Module
mod o :: ModuleOrigin
o) = ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
m SDoc -> SDoc -> SDoc
<+> ModuleOrigin -> SDoc
provenance ModuleOrigin
o
where provenance :: ModuleOrigin -> SDoc
provenance ModHidden = SDoc
Outputable.empty
provenance (ModUnusable _) = SDoc
Outputable.empty
provenance (ModOrigin{ fromOrigPackage :: ModuleOrigin -> Maybe Bool
fromOrigPackage = Maybe Bool
e,
fromExposedReexport :: ModuleOrigin -> [PackageConfig]
fromExposedReexport = [PackageConfig]
res,
fromPackageFlag :: ModuleOrigin -> Bool
fromPackageFlag = Bool
f })
| Just True <- Maybe Bool
e
= SDoc -> SDoc
parens (String -> SDoc
text "from" SDoc -> SDoc -> SDoc
<+> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> UnitId
moduleUnitId Module
mod))
| Bool
f Bool -> Bool -> Bool
&& Module -> ModuleName
moduleName Module
mod ModuleName -> ModuleName -> Bool
forall a. Eq a => a -> a -> Bool
== ModuleName
m
= SDoc -> SDoc
parens (String -> SDoc
text "from" SDoc -> SDoc -> SDoc
<+> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> UnitId
moduleUnitId Module
mod))
| (pkg :: PackageConfig
pkg:_) <- [PackageConfig]
res
= SDoc -> SDoc
parens (String -> SDoc
text "from" SDoc -> SDoc -> SDoc
<+> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PackageConfig -> UnitId
packageConfigId PackageConfig
pkg)
SDoc -> SDoc -> SDoc
<> SDoc
comma SDoc -> SDoc -> SDoc
<+> String -> SDoc
text "reexporting" SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
| Bool
f
= SDoc -> SDoc
parens (String -> SDoc
text "defined via package flags to be"
SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
| Bool
otherwise = SDoc
Outputable.empty
pp_sugg (SuggestHidden m :: ModuleName
m mod :: Module
mod o :: ModuleOrigin
o) = ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
m SDoc -> SDoc -> SDoc
<+> ModuleOrigin -> SDoc
provenance ModuleOrigin
o
where provenance :: ModuleOrigin -> SDoc
provenance ModHidden = SDoc
Outputable.empty
provenance (ModUnusable _) = SDoc
Outputable.empty
provenance (ModOrigin{ fromOrigPackage :: ModuleOrigin -> Maybe Bool
fromOrigPackage = Maybe Bool
e,
fromHiddenReexport :: ModuleOrigin -> [PackageConfig]
fromHiddenReexport = [PackageConfig]
rhs })
| Just False <- Maybe Bool
e
= SDoc -> SDoc
parens (String -> SDoc
text "needs flag -package-key"
SDoc -> SDoc -> SDoc
<+> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> UnitId
moduleUnitId Module
mod))
| (pkg :: PackageConfig
pkg:_) <- [PackageConfig]
rhs
= SDoc -> SDoc
parens (String -> SDoc
text "needs flag -package-id"
SDoc -> SDoc -> SDoc
<+> UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PackageConfig -> UnitId
packageConfigId PackageConfig
pkg))
| Bool
otherwise = SDoc
Outputable.empty
cantFindInstalledErr :: PtrString -> PtrString -> DynFlags -> ModuleName
-> InstalledFindResult -> SDoc
cantFindInstalledErr :: PtrString
-> PtrString
-> DynFlags
-> ModuleName
-> InstalledFindResult
-> SDoc
cantFindInstalledErr cannot_find :: PtrString
cannot_find _ dflags :: DynFlags
dflags mod_name :: ModuleName
mod_name find_result :: InstalledFindResult
find_result
= PtrString -> SDoc
ptext PtrString
cannot_find SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr ModuleName
mod_name)
SDoc -> SDoc -> SDoc
$$ SDoc
more_info
where
more_info :: SDoc
more_info
= case InstalledFindResult
find_result of
InstalledNoPackage pkg :: InstalledUnitId
pkg
-> String -> SDoc
text "no unit id matching" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (InstalledUnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr InstalledUnitId
pkg) SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "was found" SDoc -> SDoc -> SDoc
$$ InstalledUnitId -> SDoc
looks_like_srcpkgid InstalledUnitId
pkg
InstalledNotFound files :: [String]
files mb_pkg :: Maybe InstalledUnitId
mb_pkg
| Just pkg :: InstalledUnitId
pkg <- Maybe InstalledUnitId
mb_pkg, Bool -> Bool
not (InstalledUnitId
pkg InstalledUnitId -> UnitId -> Bool
`installedUnitIdEq` DynFlags -> UnitId
thisPackage DynFlags
dflags)
-> InstalledUnitId -> [String] -> SDoc
forall a. Outputable a => a -> [String] -> SDoc
not_found_in_package InstalledUnitId
pkg [String]
files
| [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
files
-> String -> SDoc
text "It is not a module in the current program, or in any known package."
| Bool
otherwise
-> [String] -> DynFlags -> SDoc
tried_these [String]
files DynFlags
dflags
_ -> String -> SDoc
forall a. String -> a
panic "cantFindInstalledErr"
build_tag :: String
build_tag = DynFlags -> String
buildTag DynFlags
dflags
looks_like_srcpkgid :: InstalledUnitId -> SDoc
looks_like_srcpkgid :: InstalledUnitId -> SDoc
looks_like_srcpkgid pk :: InstalledUnitId
pk
| (pkg :: PackageConfig
pkg:pkgs :: [PackageConfig]
pkgs) <- DynFlags -> SourcePackageId -> [PackageConfig]
searchPackageId DynFlags
dflags (FastString -> SourcePackageId
SourcePackageId (InstalledUnitId -> FastString
installedUnitIdFS InstalledUnitId
pk))
= SDoc -> SDoc
parens (String -> SDoc
text "This unit ID looks like the source package ID;" SDoc -> SDoc -> SDoc
$$
String -> SDoc
text "the real unit ID is" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (FastString -> SDoc
ftext (InstalledUnitId -> FastString
installedUnitIdFS (PackageConfig -> InstalledUnitId
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> instunitid
unitId PackageConfig
pkg))) SDoc -> SDoc -> SDoc
$$
(if [PackageConfig] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [PackageConfig]
pkgs then SDoc
Outputable.empty
else String -> SDoc
text "and" SDoc -> SDoc -> SDoc
<+> Int -> SDoc
int ([PackageConfig] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [PackageConfig]
pkgs) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text "other candidates"))
| Bool
otherwise = SDoc
Outputable.empty
not_found_in_package :: a -> [String] -> SDoc
not_found_in_package pkg :: a
pkg files :: [String]
files
| String
build_tag String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/= ""
= let
build :: String
build = if String
build_tag String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== "p" then "profiling"
else "\"" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
build_tag String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\""
in
String -> SDoc
text "Perhaps you haven't installed the " SDoc -> SDoc -> SDoc
<> String -> SDoc
text String
build SDoc -> SDoc -> SDoc
<>
String -> SDoc
text " libraries for package " SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
quotes (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
pkg) SDoc -> SDoc -> SDoc
<> Char -> SDoc
char '?' SDoc -> SDoc -> SDoc
$$
[String] -> DynFlags -> SDoc
tried_these [String]
files DynFlags
dflags
| Bool
otherwise
= String -> SDoc
text "There are files missing in the " SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
quotes (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
pkg) SDoc -> SDoc -> SDoc
<>
String -> SDoc
text " package," SDoc -> SDoc -> SDoc
$$
String -> SDoc
text "try running 'ghc-pkg check'." SDoc -> SDoc -> SDoc
$$
[String] -> DynFlags -> SDoc
tried_these [String]
files DynFlags
dflags
tried_these :: [FilePath] -> DynFlags -> SDoc
tried_these :: [String] -> DynFlags -> SDoc
tried_these files :: [String]
files dflags :: DynFlags
dflags
| [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
files = SDoc
Outputable.empty
| DynFlags -> Int
verbosity DynFlags
dflags Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 3 =
String -> SDoc
text "Use -v (or `:set -v` in ghci) " SDoc -> SDoc -> SDoc
<>
String -> SDoc
text "to see a list of the files searched for."
| Bool
otherwise =
SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text "Locations searched:") 2 (SDoc -> SDoc) -> SDoc -> SDoc
forall a b. (a -> b) -> a -> b
$ [SDoc] -> SDoc
vcat ((String -> SDoc) -> [String] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map String -> SDoc
text [String]
files)