{-
(c) The University of Glasgow, 2000-2006
\section[Finder]{Module Finder}
-}{-# LANGUAGE CPP #-}moduleFinder(flushFinderCaches ,FindResult(..),findImportedModule ,findPluginModule ,findExactModule ,findHomeModule ,findExposedPackageModule ,mkHomeModLocation ,mkHomeModLocation2 ,mkHiOnlyModLocation ,mkHiPath ,mkObjPath ,addHomeModuleToFinder ,uncacheModule ,mkStubPaths ,findObjectLinkableMaybe ,findObjectLinkable ,cannotFindModule ,cannotFindInterface ,)where#include "HsVersions.h"
importGhcPreludeimportModuleimportHscTypesimportPackagesimportFastStringimportUtilimportPrelNames(gHC_PRIM)importDynFlagsimportOutputableimportMaybes(expectJust)importData.IORef(IORef,readIORef,atomicModifyIORef')importSystem.DirectoryimportSystem.FilePathimportControl.MonadimportData.TimetypeFileExt =String-- Filename extensiontypeBaseName =String-- Basename of file-- ------------------------------------------------------------------------------- The Finder-- The Finder provides a thin filesystem abstraction to the rest of-- the compiler. For a given module, it can tell you where the-- source, interface, and object files for that module live.-- It does *not* know which particular package a module lives in. Use-- Packages.lookupModuleInAllPackages for that.-- ------------------------------------------------------------------------------- The finder's cache-- remove all the home modules from the cache; package modules are-- assumed to not move around during a session.flushFinderCaches::HscEnv->IO()flushFinderCaches hsc_env =atomicModifyIORef'fc_ref $\fm ->(filterInstalledModuleEnvis_ext fm ,())wherethis_pkg =thisPackage(hsc_dflagshsc_env )fc_ref =hsc_FChsc_env is_ext mod _|not(installedModuleUnitIdmod `installedUnitIdEq`this_pkg )=True|otherwise=FalseaddToFinderCache::IORefFinderCache->InstalledModule->InstalledFindResult->IO()addToFinderCache ref key val =atomicModifyIORef'ref $\c ->(extendInstalledModuleEnvc key val ,())removeFromFinderCache::IORefFinderCache->InstalledModule->IO()removeFromFinderCache ref key =atomicModifyIORef'ref $\c ->(delInstalledModuleEnvc key ,())lookupFinderCache::IORefFinderCache->InstalledModule->IO(MaybeInstalledFindResult)lookupFinderCache ref key =doc <-readIORefref return$!lookupInstalledModuleEnvc key -- ------------------------------------------------------------------------------- The three external entry points-- | Locate a module that was imported by the user. We have the-- module's name, and possibly a package name. Without a package-- name, this function will use the search path and the known exposed-- packages to find the module, if a package is specified then only-- that package is searched for the module.findImportedModule::HscEnv->ModuleName->MaybeFastString->IOFindResultfindImportedModule hsc_env mod_name mb_pkg =casemb_pkg ofNothing->unqual_import Justpkg |pkg ==fsLit"this"->home_import -- "this" is special|otherwise->pkg_import wherehome_import =findHomeModule hsc_env mod_name pkg_import =findExposedPackageModule hsc_env mod_name mb_pkg unqual_import =home_import `orIfNotFound `findExposedPackageModule hsc_env mod_name Nothing-- | Locate a plugin module requested by the user, for a compiler-- plugin. This consults the same set of exposed packages as-- 'findImportedModule', unless @-hide-all-plugin-packages@ or-- @-plugin-package@ are specified.findPluginModule::HscEnv->ModuleName->IOFindResultfindPluginModule hsc_env mod_name =findHomeModule hsc_env mod_name `orIfNotFound `findExposedPluginPackageModule hsc_env mod_name -- | Locate a specific 'Module'. The purpose of this function is to-- create a 'ModLocation' for a given 'Module', that is to find out-- where the files associated with this module live. It is used when-- reading the interface for a module mentioned by another interface,-- for example (a "system import").findExactModule::HscEnv->InstalledModule->IOInstalledFindResultfindExactModule hsc_env mod =letdflags =hsc_dflagshsc_env inifinstalledModuleUnitIdmod `installedUnitIdEq`thisPackagedflags thenfindInstalledHomeModule hsc_env (installedModuleNamemod )elsefindPackageModule hsc_env mod -- ------------------------------------------------------------------------------- Helpers-- | Given a monadic actions @this@ and @or_this@, first execute-- @this@. If the returned 'FindResult' is successful, return-- it; otherwise, execute @or_this@. If both failed, this function-- also combines their failure messages in a reasonable way.orIfNotFound::Monadm =>m FindResult->m FindResult->m FindResultorIfNotFound this or_this =dores <-this caseres ofNotFound{fr_paths=paths1 ,fr_mods_hidden=mh1 ,fr_pkgs_hidden=ph1 ,fr_unusables=u1 ,fr_suggestions=s1 }->dores2 <-or_this caseres2 ofNotFound{fr_paths=paths2 ,fr_pkg=mb_pkg2 ,fr_mods_hidden=mh2 ,fr_pkgs_hidden=ph2 ,fr_unusables=u2 ,fr_suggestions=s2 }->return(NotFound{fr_paths=paths1 ++paths2 ,fr_pkg=mb_pkg2 -- snd arg is the package search,fr_mods_hidden=mh1 ++mh2 ,fr_pkgs_hidden=ph1 ++ph2 ,fr_unusables=u1 ++u2 ,fr_suggestions=s1 ++s2 })_other ->returnres2 _other ->returnres -- | Helper function for 'findHomeModule': this function wraps an IO action-- which would look up @mod_name@ in the file system (the home package),-- and first consults the 'hsc_FC' cache to see if the lookup has already-- been done. Otherwise, do the lookup (with the IO action) and save-- the result in the finder cache and the module location cache (if it-- was successful.)homeSearchCache::HscEnv->ModuleName->IOInstalledFindResult->IOInstalledFindResulthomeSearchCache hsc_env mod_name do_this =doletmod =mkHomeInstalledModule (hsc_dflagshsc_env )mod_name modLocationCache hsc_env mod do_this findExposedPackageModule::HscEnv->ModuleName->MaybeFastString->IOFindResultfindExposedPackageModule hsc_env mod_name mb_pkg =findLookupResult hsc_env $lookupModuleWithSuggestions(hsc_dflagshsc_env )mod_name mb_pkg findExposedPluginPackageModule::HscEnv->ModuleName->IOFindResultfindExposedPluginPackageModule hsc_env mod_name =findLookupResult hsc_env $lookupPluginModuleWithSuggestions(hsc_dflagshsc_env )mod_name NothingfindLookupResult::HscEnv->LookupResult->IOFindResultfindLookupResult hsc_env r =caser ofLookupFoundm pkg_conf ->doletim =fst(splitModuleInstsm )r' <-findPackageModule_ hsc_env im pkg_conf caser' of-- TODO: ghc -M is unlikely to do the right thing-- with just the location of the thing that was-- instantiated; you probably also need all of the-- implicit locations from the instancesInstalledFoundloc _->return(Foundloc m )InstalledNoPackage_->return(NoPackage(moduleUnitIdm ))InstalledNotFoundfp _->return(NotFound{fr_paths=fp ,fr_pkg=Just(moduleUnitIdm ),fr_pkgs_hidden=[],fr_mods_hidden=[],fr_unusables=[],fr_suggestions=[]})LookupMultiplers ->return(FoundMultiplers )LookupHiddenpkg_hiddens mod_hiddens ->return(NotFound{fr_paths=[],fr_pkg=Nothing,fr_pkgs_hidden=map(moduleUnitId.fst)pkg_hiddens ,fr_mods_hidden=map(moduleUnitId.fst)mod_hiddens ,fr_unusables=[],fr_suggestions=[]})LookupUnusableunusable ->letunusables' =mapget_unusable unusable get_unusable (m ,ModUnusabler )=(moduleUnitIdm ,r )get_unusable(_,r )=pprPanic"findLookupResult: unexpected origin"(pprr )inreturn(NotFound{fr_paths=[],fr_pkg=Nothing,fr_pkgs_hidden=[],fr_mods_hidden=[],fr_unusables=unusables' ,fr_suggestions=[]})LookupNotFoundsuggest ->return(NotFound{fr_paths=[],fr_pkg=Nothing,fr_pkgs_hidden=[],fr_mods_hidden=[],fr_unusables=[],fr_suggestions=suggest })modLocationCache::HscEnv->InstalledModule->IOInstalledFindResult->IOInstalledFindResultmodLocationCache hsc_env mod do_this =dom <-lookupFinderCache (hsc_FChsc_env )mod casem ofJustresult ->returnresult Nothing->doresult <-do_this addToFinderCache (hsc_FChsc_env )mod result returnresult mkHomeInstalledModule::DynFlags->ModuleName->InstalledModulemkHomeInstalledModule dflags mod_name =letiuid =fst(splitUnitIdInsts(thisPackagedflags ))inInstalledModuleiuid mod_name -- This returns a module because it's more convenient for usersaddHomeModuleToFinder::HscEnv->ModuleName->ModLocation->IOModuleaddHomeModuleToFinder hsc_env mod_name loc =doletmod =mkHomeInstalledModule (hsc_dflagshsc_env )mod_name addToFinderCache (hsc_FChsc_env )mod (InstalledFoundloc mod )return(mkModule(thisPackage(hsc_dflagshsc_env ))mod_name )uncacheModule::HscEnv->ModuleName->IO()uncacheModule hsc_env mod_name =doletmod =mkHomeInstalledModule (hsc_dflagshsc_env )mod_name removeFromFinderCache (hsc_FChsc_env )mod -- ------------------------------------------------------------------------------- The internal workersfindHomeModule::HscEnv->ModuleName->IOFindResultfindHomeModule hsc_env mod_name =dor <-findInstalledHomeModule hsc_env mod_name return$caser ofInstalledFoundloc _->Foundloc (mkModuleuid mod_name )InstalledNoPackage_->NoPackageuid -- impossibleInstalledNotFoundfps _->NotFound{fr_paths=fps ,fr_pkg=Justuid ,fr_mods_hidden=[],fr_pkgs_hidden=[],fr_unusables=[],fr_suggestions=[]}wheredflags =hsc_dflagshsc_env uid =thisPackagedflags -- | Implements the search for a module name in the home package only. Calling-- this function directly is usually *not* what you want; currently, it's used-- as a building block for the following operations:---- 1. When you do a normal package lookup, we first check if the module-- is available in the home module, before looking it up in the package-- database.---- 2. When you have a package qualified import with package name "this",-- we shortcut to the home module.---- 3. When we look up an exact 'Module', if the unit id associated with-- the module is the current home module do a look up in the home module.---- 4. Some special-case code in GHCi (ToDo: Figure out why that needs to-- call this.)findInstalledHomeModule::HscEnv->ModuleName->IOInstalledFindResultfindInstalledHomeModule hsc_env mod_name =homeSearchCache hsc_env mod_name $letdflags =hsc_dflagshsc_env home_path =importPathsdflags hisuf =hiSufdflags mod =mkHomeInstalledModule dflags mod_name source_exts =[("hs",mkHomeModLocationSearched dflags mod_name "hs"),("lhs",mkHomeModLocationSearched dflags mod_name "lhs"),("hsig",mkHomeModLocationSearched dflags mod_name "hsig"),("lhsig",mkHomeModLocationSearched dflags mod_name "lhsig")]-- we use mkHomeModHiOnlyLocation instead of mkHiOnlyModLocation so that-- when hiDir field is set in dflags, we know to look there (see #16500)hi_exts =[(hisuf ,mkHomeModHiOnlyLocation dflags mod_name ),(addBootSuffixhisuf ,mkHomeModHiOnlyLocation dflags mod_name )]-- In compilation manager modes, we look for source files in the home-- package because we can compile these automatically. In one-shot-- compilation mode we look for .hi and .hi-boot files only.exts |isOneShot(ghcModedflags )=hi_exts |otherwise=source_exts in-- special case for GHC.Prim; we won't find it in the filesystem.-- This is important only when compiling the base package (where GHC.Prim-- is a home module).ifmod `installedModuleEq`gHC_PRIMthenreturn(InstalledFound(error"GHC.Prim ModLocation")mod )elsesearchPathExts home_path mod exts -- | Search for a module in external packages only.findPackageModule::HscEnv->InstalledModule->IOInstalledFindResultfindPackageModule hsc_env mod =doletdflags =hsc_dflagshsc_env pkg_id =installedModuleUnitIdmod --caselookupInstalledPackagedflags pkg_id ofNothing->return(InstalledNoPackagepkg_id )Justpkg_conf ->findPackageModule_ hsc_env mod pkg_conf -- | Look up the interface file associated with module @mod@. This function-- requires a few invariants to be upheld: (1) the 'Module' in question must-- be the module identifier of the *original* implementation of a module,-- not a reexport (this invariant is upheld by @Packages.hs@) and (2)-- the 'PackageConfig' must be consistent with the unit id in the 'Module'.-- The redundancy is to avoid an extra lookup in the package state-- for the appropriate config.findPackageModule_::HscEnv->InstalledModule->PackageConfig->IOInstalledFindResultfindPackageModule_ hsc_env mod pkg_conf =ASSERT2(installedModuleUnitIdmod==installedPackageConfigIdpkg_conf,ppr(installedModuleUnitIdmod)<+>ppr(installedPackageConfigIdpkg_conf))modLocationCache hsc_env mod $-- special case for GHC.Prim; we won't find it in the filesystem.ifmod `installedModuleEq`gHC_PRIMthenreturn(InstalledFound(error"GHC.Prim ModLocation")mod )elseletdflags =hsc_dflagshsc_env tag =buildTagdflags -- hi-suffix for packages depends on the build tag.package_hisuf |nulltag ="hi"|otherwise=tag ++"_hi"mk_hi_loc =mkHiOnlyModLocation dflags package_hisuf import_dirs =importDirspkg_conf -- we never look for a .hi-boot file in an external package;-- .hi-boot files only make sense for the home package.incaseimport_dirs of[one ]|MkDepend<-ghcModedflags ->do-- there's only one place that this .hi file can be, so-- don't bother looking for it.letbasename =moduleNameSlashes(installedModuleNamemod )loc <-mk_hi_loc one basename return(InstalledFoundloc mod )_otherwise ->searchPathExts import_dirs mod [(package_hisuf ,mk_hi_loc )]-- ------------------------------------------------------------------------------- General path searchingsearchPathExts::[FilePath]-- paths to search->InstalledModule-- module name->[(FileExt ,-- suffixFilePath->BaseName ->IOModLocation-- action)]->IOInstalledFindResultsearchPathExts paths mod exts =doresult <-search to_search {-
 hPutStrLn stderr (showSDoc $
 vcat [text "Search" <+> ppr mod <+> sep (map (text. fst) exts)
 , nest 2 (vcat (map text paths))
 , case result of
 Succeeded (loc, p) -> text "Found" <+> ppr loc
 Failed fs -> text "not found"])
-}returnresult wherebasename =moduleNameSlashes(installedModuleNamemod )to_search::[(FilePath,IOModLocation)]to_search =[(file ,fn path basename )|path <-paths ,(ext ,fn )<-exts ,letbase |path =="."=basename |otherwise=path </>basename file =base <.>ext ]search []=return(InstalledNotFound(mapfstto_search )(Just(installedModuleUnitIdmod )))search((file ,mk_result ):rest )=dob <-doesFileExistfile ifb thendo{loc <-mk_result ;return(InstalledFoundloc mod )}elsesearch rest mkHomeModLocationSearched::DynFlags->ModuleName->FileExt ->FilePath->BaseName ->IOModLocationmkHomeModLocationSearched dflags mod suff path basename =domkHomeModLocation2 dflags mod (path </>basename )suff -- ------------------------------------------------------------------------------- Constructing a home module location-- This is where we construct the ModLocation for a module in the home-- package, for which we have a source file. It is called from three-- places:---- (a) Here in the finder, when we are searching for a module to import,-- using the search path (-i option).---- (b) The compilation manager, when constructing the ModLocation for-- a "root" module (a source file named explicitly on the command line-- or in a :load command in GHCi).---- (c) The driver in one-shot mode, when we need to construct a-- ModLocation for a source file named on the command-line.---- Parameters are:---- mod-- The name of the module---- path-- (a): The search path component where the source file was found.-- (b) and (c): "."---- src_basename-- (a): (moduleNameSlashes mod)-- (b) and (c): The filename of the source file, minus its extension---- ext-- The filename extension of the source file (usually "hs" or "lhs").mkHomeModLocation::DynFlags->ModuleName->FilePath->IOModLocationmkHomeModLocation dflags mod src_filename =dolet(basename ,extension )=splitExtensionsrc_filename mkHomeModLocation2 dflags mod basename extension mkHomeModLocation2::DynFlags->ModuleName->FilePath-- Of source module, without suffix->String-- Suffix->IOModLocationmkHomeModLocation2 dflags mod src_basename ext =doletmod_basename =moduleNameSlashesmod obj_fn =mkObjPath dflags src_basename mod_basename hi_fn =mkHiPath dflags src_basename mod_basename hie_fn =mkHiePath dflags src_basename mod_basename return(ModLocation{ml_hs_file=Just(src_basename <.>ext ),ml_hi_file=hi_fn ,ml_obj_file=obj_fn ,ml_hie_file=hie_fn })mkHomeModHiOnlyLocation::DynFlags->ModuleName->FilePath->BaseName ->IOModLocationmkHomeModHiOnlyLocation dflags mod path basename =doloc <-mkHomeModLocation2 dflags mod (path </>basename )""returnloc {ml_hs_file=Nothing}mkHiOnlyModLocation::DynFlags->Suffix->FilePath->String->IOModLocationmkHiOnlyModLocation dflags hisuf path basename =doletfull_basename =path </>basename obj_fn =mkObjPath dflags full_basename basename hie_fn =mkHiePath dflags full_basename basename returnModLocation{ml_hs_file=Nothing,ml_hi_file=full_basename <.>hisuf ,-- Remove the .hi-boot suffix from-- hi_file, if it had one. We always-- want the name of the real .hi file-- in the ml_hi_file field.ml_obj_file=obj_fn ,ml_hie_file=hie_fn }-- | Constructs the filename of a .o file for a given source file.-- Does /not/ check whether the .o file existsmkObjPath::DynFlags->FilePath-- the filename of the source file, minus the extension->String-- the module name with dots replaced by slashes->FilePathmkObjPath dflags basename mod_basename =obj_basename <.>osuf whereodir =objectDirdflags osuf =objectSufdflags obj_basename |Justdir <-odir =dir </>mod_basename |otherwise=basename -- | Constructs the filename of a .hi file for a given source file.-- Does /not/ check whether the .hi file existsmkHiPath::DynFlags->FilePath-- the filename of the source file, minus the extension->String-- the module name with dots replaced by slashes->FilePathmkHiPath dflags basename mod_basename =hi_basename <.>hisuf wherehidir =hiDirdflags hisuf =hiSufdflags hi_basename |Justdir <-hidir =dir </>mod_basename |otherwise=basename -- | Constructs the filename of a .hie file for a given source file.-- Does /not/ check whether the .hie file existsmkHiePath::DynFlags->FilePath-- the filename of the source file, minus the extension->String-- the module name with dots replaced by slashes->FilePathmkHiePath dflags basename mod_basename =hie_basename <.>hiesuf wherehiedir =hieDirdflags hiesuf =hieSufdflags hie_basename |Justdir <-hiedir =dir </>mod_basename |otherwise=basename -- ------------------------------------------------------------------------------- Filenames of the stub files-- We don't have to store these in ModLocations, because they can be derived-- from other available information, and they're only rarely needed.mkStubPaths::DynFlags->ModuleName->ModLocation->FilePathmkStubPaths dflags mod location =letstubdir =stubDirdflags mod_basename =moduleNameSlashesmod src_basename =dropExtension$expectJust"mkStubPaths"(ml_hs_filelocation )stub_basename0 |Justdir <-stubdir =dir </>mod_basename |otherwise=src_basename stub_basename =stub_basename0 ++"_stub"instub_basename <.>"h"-- ------------------------------------------------------------------------------- findLinkable isn't related to the other stuff in here,-- but there's no other obvious place for itfindObjectLinkableMaybe::Module->ModLocation->IO(MaybeLinkable)findObjectLinkableMaybe mod locn =doletobj_fn =ml_obj_filelocn maybe_obj_time <-modificationTimeIfExistsobj_fn casemaybe_obj_time ofNothing->returnNothingJustobj_time ->liftMJust(findObjectLinkable mod obj_fn obj_time )-- Make an object linkable when we know the object file exists, and we know-- its modification time.findObjectLinkable::Module->FilePath->UTCTime->IOLinkablefindObjectLinkable mod obj_fn obj_time =return(LMobj_time mod [DotOobj_fn ])-- We used to look for _stub.o files here, but that was a bug (#706)-- Now GHC merges the stub.o into the main .o (#3687)-- ------------------------------------------------------------------------------- Error messagescannotFindModule::DynFlags->ModuleName->FindResult->SDoccannotFindModule flags mod res =cantFindErr (sLitcannotFindMsg )(sLit"Ambiguous module name")flags mod res wherecannotFindMsg =caseres ofNotFound{fr_mods_hidden=hidden_mods ,fr_pkgs_hidden=hidden_pkgs ,fr_unusables=unusables }|not(nullhidden_mods &&nullhidden_pkgs &&nullunusables )->"Could not load module"_->"Could not find module"cannotFindInterface::DynFlags->ModuleName->InstalledFindResult->SDoccannotFindInterface =cantFindInstalledErr (sLit"Failed to load interface for")(sLit"Ambiguous interface for")cantFindErr::PtrString->PtrString->DynFlags->ModuleName->FindResult->SDoccantFindErr _multiple_found _mod_name (FoundMultiplemods )|Justpkgs <-unambiguousPackages =hang(ptextmultiple_found <+>quotes(pprmod_name )<>colon)2(sep[text"it was found in multiple packages:",hsep(mappprpkgs )])|otherwise=hang(ptextmultiple_found <+>quotes(pprmod_name )<>colon)2(vcat(mappprMod mods ))whereunambiguousPackages =foldl'unambiguousPackage (Just[])mods unambiguousPackage (Justxs )(m ,ModOrigin(Just_)___)=Just(moduleUnitIdm :xs )unambiguousPackage__=NothingpprMod (m ,o )=text"it is bound as"<+>pprm <+>text"by"<+>pprOrigin m o pprOrigin _ModHidden=panic"cantFindErr: bound by mod hidden"pprOrigin_(ModUnusable_)=panic"cantFindErr: bound by mod unusable"pprOriginm (ModOrigine res _f )=sep$punctuatecomma(ife ==JustTruethen[text"package"<+>ppr(moduleUnitIdm )]else[]++map((text"a reexport in package"<+>).ppr.packageConfigId)res ++iff then[text"a package flag"]else[])cantFindErrcannot_find _dflags mod_name find_result =ptextcannot_find <+>quotes(pprmod_name )$$more_info wheremore_info =casefind_result ofNoPackagepkg ->text"no unit id matching"<+>quotes(pprpkg )<+>text"was found"NotFound{fr_paths=files ,fr_pkg=mb_pkg ,fr_mods_hidden=mod_hiddens ,fr_pkgs_hidden=pkg_hiddens ,fr_unusables=unusables ,fr_suggestions=suggest }|Justpkg <-mb_pkg ,pkg /=thisPackagedflags ->not_found_in_package pkg files |not(nullsuggest )->pp_suggestions suggest $$tried_these files dflags |nullfiles &&nullmod_hiddens &&nullpkg_hiddens &&nullunusables ->text"It is not a module in the current program, or in any known package."|otherwise->vcat(mappkg_hidden pkg_hiddens )$$vcat(mapmod_hidden mod_hiddens )$$vcat(mapunusable unusables )$$tried_these files dflags _->panic"cantFindErr"build_tag =buildTagdflags not_found_in_package pkg files |build_tag /=""=letbuild =ifbuild_tag =="p"then"profiling"else"\""++build_tag ++"\""intext"Perhaps you haven't installed the "<>textbuild <>text" libraries for package "<>quotes(pprpkg )<>char'?'$$tried_these files dflags |otherwise=text"There are files missing in the "<>quotes(pprpkg )<>text" package,"$$text"try running 'ghc-pkg check'."$$tried_these files dflags pkg_hidden::UnitId->SDocpkg_hidden pkgid =text"It is a member of the hidden package"<+>quotes(pprpkgid )--FIXME: we don't really want to show the unit id here we should-- show the source package id or installed package id if it's ambiguous<>dot$$pkg_hidden_hint pkgid pkg_hidden_hint pkgid |goptOpt_BuildingCabalPackagedflags =letpkg =expectJust"pkg_hidden"(lookupPackagedflags pkgid )intext"Perhaps you need to add"<+>quotes(ppr(packageNamepkg ))<+>text"to the build-depends in your .cabal file."|Justpkg <-lookupPackagedflags pkgid =text"You can run"<+>quotes(text":set -package "<>ppr(packageNamepkg ))<+>text"to expose it."$$text"(Note: this unloads all the modules in the current scope.)"|otherwise=Outputable.emptymod_hidden pkg =text"it is a hidden module in the package"<+>quotes(pprpkg )unusable (pkg ,reason )=text"It is a member of the package"<+>quotes(pprpkg )$$pprReason(text"which is")reason pp_suggestions::[ModuleSuggestion]->SDocpp_suggestions sugs |nullsugs =Outputable.empty|otherwise=hang(text"Perhaps you meant")2(vcat(mappp_sugg sugs ))-- NB: Prefer the *original* location, and then reexports, and then-- package flags when making suggestions. ToDo: if the original package-- also has a reexport, prefer that onepp_sugg (SuggestVisiblem mod o )=pprm <+>provenance o whereprovenance ModHidden=Outputable.emptyprovenance(ModUnusable_)=Outputable.emptyprovenance(ModOrigin{fromOrigPackage=e ,fromExposedReexport=res ,fromPackageFlag=f })|JustTrue<-e =parens(text"from"<+>ppr(moduleUnitIdmod ))|f &&moduleNamemod ==m =parens(text"from"<+>ppr(moduleUnitIdmod ))|(pkg :_)<-res =parens(text"from"<+>ppr(packageConfigIdpkg )<>comma<+>text"reexporting"<+>pprmod )|f =parens(text"defined via package flags to be"<+>pprmod )|otherwise=Outputable.emptypp_sugg(SuggestHiddenm mod o )=pprm <+>provenance o whereprovenance ModHidden=Outputable.emptyprovenance(ModUnusable_)=Outputable.emptyprovenance(ModOrigin{fromOrigPackage=e ,fromHiddenReexport=rhs })|JustFalse<-e =parens(text"needs flag -package-key"<+>ppr(moduleUnitIdmod ))|(pkg :_)<-rhs =parens(text"needs flag -package-id"<+>ppr(packageConfigIdpkg ))|otherwise=Outputable.emptycantFindInstalledErr::PtrString->PtrString->DynFlags->ModuleName->InstalledFindResult->SDoccantFindInstalledErr cannot_find _dflags mod_name find_result =ptextcannot_find <+>quotes(pprmod_name )$$more_info wheremore_info =casefind_result ofInstalledNoPackagepkg ->text"no unit id matching"<+>quotes(pprpkg )<+>text"was found"$$looks_like_srcpkgid pkg InstalledNotFoundfiles mb_pkg |Justpkg <-mb_pkg ,not(pkg `installedUnitIdEq`thisPackagedflags )->not_found_in_package pkg files |nullfiles ->text"It is not a module in the current program, or in any known package."|otherwise->tried_these files dflags _->panic"cantFindInstalledErr"build_tag =buildTagdflags looks_like_srcpkgid::InstalledUnitId->SDoclooks_like_srcpkgid pk -- Unsafely coerce a unit id FastString into a source package ID-- FastString and see if it means anything.|(pkg :pkgs )<-searchPackageIddflags (SourcePackageId(installedUnitIdFSpk ))=parens(text"This unit ID looks like the source package ID;"$$text"the real unit ID is"<+>quotes(ftext(installedUnitIdFS(unitIdpkg )))$$(ifnullpkgs thenOutputable.emptyelsetext"and"<+>int(lengthpkgs )<+>text"other candidates"))-- Todo: also check if it looks like a package name!|otherwise=Outputable.emptynot_found_in_package pkg files |build_tag /=""=letbuild =ifbuild_tag =="p"then"profiling"else"\""++build_tag ++"\""intext"Perhaps you haven't installed the "<>textbuild <>text" libraries for package "<>quotes(pprpkg )<>char'?'$$tried_these files dflags |otherwise=text"There are files missing in the "<>quotes(pprpkg )<>text" package,"$$text"try running 'ghc-pkg check'."$$tried_these files dflags tried_these::[FilePath]->DynFlags->SDoctried_these files dflags |nullfiles =Outputable.empty|verbositydflags <3=text"Use -v (or `:set -v` in ghci) "<>text"to see a list of the files searched for."|otherwise=hang(text"Locations searched:")2$vcat(maptextfiles )

AltStyle によって変換されたページ (->オリジナル) /