{-# LANGUAGE BangPatterns, NondecreasingIndentation #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE ViewPatterns #-}
module GHC.Iface.Load (
tcLookupImported_maybe, importDecl,
checkWiredInTyCon, ifCheckWiredInThing,
loadModuleInterface, loadModuleInterfaces,
loadSrcInterface, loadSrcInterface_maybe,
loadInterfaceForName, loadInterfaceForModule,
loadInterface,
loadSysInterface, loadUserInterface, loadPluginInterface,
findAndReadIface, readIface, writeIface,
moduleFreeHolesPrecise,
needWiredInHomeIface, loadWiredInHomeIface,
pprModIfaceSimple,
ifaceStats, pprModIface, showIface,
module Iface_Errors
) where
import GHC.Prelude
import GHC.Platform.Profile
import {-# SOURCE #-} GHC.IfaceToCore
( tcIfaceDecls, tcIfaceRules, tcIfaceInst, tcIfaceFamInst
, tcIfaceAnnotations, tcIfaceCompleteMatches )
import GHC.Driver.Config.Finder
import GHC.Driver.Env
import GHC.Driver.Errors.Types
import GHC.Driver.Session
import GHC.Driver.Hooks
import GHC.Driver.Plugins
import GHC.Iface.Syntax
import GHC.Iface.Ext.Fields
import GHC.Iface.Binary
import GHC.Iface.Rename
import GHC.Iface.Env
import GHC.Iface.Errors as Iface_Errors
import GHC.Tc.Errors.Types
import GHC.Tc.Utils.Monad
import GHC.Utils.Binary ( BinData(..) )
import GHC.Utils.Error
import GHC.Utils.Outputable as Outputable
import GHC.Utils.Panic
import GHC.Utils.Panic.Plain
import GHC.Utils.Constants (debugIsOn)
import GHC.Utils.Logger
import GHC.Utils.Trace
import GHC.Settings.Constants
import GHC.Builtin.Names
import GHC.Builtin.Utils
import GHC.Builtin.PrimOps ( allThePrimOps, primOpFixity, primOpOcc )
import GHC.Core.Rules
import GHC.Core.TyCon
import GHC.Core.InstEnv
import GHC.Core.FamInstEnv
import GHC.Types.Id.Make ( seqId )
import GHC.Types.Annotations
import GHC.Types.Name
import GHC.Types.Name.Cache
import GHC.Types.Name.Env
import GHC.Types.Avail
import GHC.Types.Fixity
import GHC.Types.Fixity.Env
import GHC.Types.SourceError
import GHC.Types.SourceText
import GHC.Types.SourceFile
import GHC.Types.SafeHaskell
import GHC.Types.TypeEnv
import GHC.Types.Unique.DSet
import GHC.Types.SrcLoc
import GHC.Types.TyThing
import GHC.Types.PkgQual
import GHC.Unit.External
import GHC.Unit.Module
import GHC.Unit.Module.Warnings
import GHC.Unit.Module.ModIface
import GHC.Unit.Module.Deps
import GHC.Unit.State
import GHC.Unit.Home
import GHC.Unit.Home.ModInfo
import GHC.Unit.Finder
import GHC.Unit.Env
import GHC.Data.Maybe
import Control.Monad
import Data.Map ( toList )
import System.FilePath
import System.Directory
import GHC.Driver.Env.KnotVars
tcLookupImported_maybe :: Name -> TcM (MaybeErr SDoc TyThing)
tcLookupImported_maybe :: Name -> TcM (MaybeErr SDoc TyThing)
tcLookupImported_maybe Name
name
= do { HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
; Maybe TyThing
mb_thing <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (HscEnv -> Name -> IO (Maybe TyThing)
lookupType HscEnv
hsc_env Name
name)
; case Maybe TyThing
mb_thing of
Just TyThing
thing -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded TyThing
thing)
Maybe TyThing
Nothing -> Name -> TcM (MaybeErr SDoc TyThing)
tcImportDecl_maybe Name
name }
tcImportDecl_maybe :: Name -> TcM (MaybeErr SDoc TyThing)
tcImportDecl_maybe :: Name -> TcM (MaybeErr SDoc TyThing)
tcImportDecl_maybe Name
name
| Just TyThing
thing <- Name -> Maybe TyThing
wiredInNameTyThing_maybe Name
name
= do { forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (TyThing -> Bool
needWiredInHomeIface TyThing
thing)
(forall a. IfG a -> TcRn a
initIfaceTcRn (forall lcl. Name -> IfM lcl ()
loadWiredInHomeIface Name
name))
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded TyThing
thing) }
| Bool
otherwise
= forall a. IfG a -> TcRn a
initIfaceTcRn (forall lcl. Name -> IfM lcl (MaybeErr SDoc TyThing)
importDecl Name
name)
importDecl :: Name -> IfM lcl (MaybeErr SDoc TyThing)
importDecl :: forall lcl. Name -> IfM lcl (MaybeErr SDoc TyThing)
importDecl Name
name
= forall a. HasCallStack => Bool -> a -> a
assert (Bool -> Bool
not (Name -> Bool
isWiredInName Name
name)) forall a b. (a -> b) -> a -> b
$
do { Logger
logger <- forall (m :: * -> *). HasLogger m => m Logger
getLogger
; forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Logger -> SDoc -> IO ()
trace_if Logger
logger SDoc
nd_doc
; MaybeErr SDoc ModIface
mb_iface <- forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Name -> Bool
isExternalName Name
name) (forall a. Outputable a => a -> SDoc
ppr Name
name) forall a b. (a -> b) -> a -> b
$
forall lcl.
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
loadInterface SDoc
nd_doc (HasDebugCallStack => Name -> Module
nameModule Name
name) WhereFrom
ImportBySystem
; case MaybeErr SDoc ModIface
mb_iface of {
Failed SDoc
err_msg -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed SDoc
err_msg) ;
Succeeded ModIface
_ -> do
{ ExternalPackageState
eps <- forall gbl lcl. TcRnIf gbl lcl ExternalPackageState
getEps
; case TypeEnv -> Name -> Maybe TyThing
lookupTypeEnv (ExternalPackageState -> TypeEnv
eps_PTE ExternalPackageState
eps) Name
name of
Just TyThing
thing -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall err val. val -> MaybeErr err val
Succeeded TyThing
thing
Maybe TyThing
Nothing -> let doc :: SDoc
doc = SDoc -> SDoc
whenPprDebug (ExternalPackageState -> SDoc
found_things_msg ExternalPackageState
eps SDoc -> SDoc -> SDoc
$$ SDoc
empty)
SDoc -> SDoc -> SDoc
$$ SDoc
not_found_msg
in forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall err val. err -> MaybeErr err val
Failed SDoc
doc
}}}
where
nd_doc :: SDoc
nd_doc = String -> SDoc
text String
"Need decl for" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Name
name
not_found_msg :: SDoc
not_found_msg = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Can't find interface-file declaration for" SDoc -> SDoc -> SDoc
<+>
NameSpace -> SDoc
pprNameSpace (Name -> NameSpace
nameNameSpace Name
name) SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Name
name)
Int
2 ([SDoc] -> SDoc
vcat [String -> SDoc
text String
"Probable cause: bug in .hi-boot file, or inconsistent .hi file",
String -> SDoc
text String
"Use -ddump-if-trace to get an idea of which file caused the error"])
found_things_msg :: ExternalPackageState -> SDoc
found_things_msg ExternalPackageState
eps =
SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"Found the following declarations in" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (HasDebugCallStack => Name -> Module
nameModule Name
name) SDoc -> SDoc -> SDoc
<> SDoc
colon)
Int
2 ([SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter TyThing -> Bool
is_interesting forall a b. (a -> b) -> a -> b
$ forall a. NameEnv a -> [a]
nonDetNameEnvElts forall a b. (a -> b) -> a -> b
$ ExternalPackageState -> TypeEnv
eps_PTE ExternalPackageState
eps))
where
is_interesting :: TyThing -> Bool
is_interesting TyThing
thing = HasDebugCallStack => Name -> Module
nameModule Name
name forall a. Eq a => a -> a -> Bool
== HasDebugCallStack => Name -> Module
nameModule (forall a. NamedThing a => a -> Name
getName TyThing
thing)
checkWiredInTyCon :: TyCon -> TcM ()
checkWiredInTyCon :: TyCon -> TcM ()
checkWiredInTyCon TyCon
tc
| Bool -> Bool
not (Name -> Bool
isWiredInName Name
tc_name)
= forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { Module
mod <- forall (m :: * -> *). HasModule m => m Module
getModule
; Logger
logger <- forall (m :: * -> *). HasLogger m => m Logger
getLogger
; forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Logger -> SDoc -> IO ()
trace_if Logger
logger (String -> SDoc
text String
"checkWiredInTyCon" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Name
tc_name SDoc -> SDoc -> SDoc
$$ forall a. Outputable a => a -> SDoc
ppr Module
mod)
; forall a. HasCallStack => Bool -> a -> a
assert (Name -> Bool
isExternalName Name
tc_name )
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Module
mod forall a. Eq a => a -> a -> Bool
/= HasDebugCallStack => Name -> Module
nameModule Name
tc_name)
(forall a. IfG a -> TcRn a
initIfaceTcRn (forall lcl. Name -> IfM lcl ()
loadWiredInHomeIface Name
tc_name))
}
where
tc_name :: Name
tc_name = TyCon -> Name
tyConName TyCon
tc
ifCheckWiredInThing :: TyThing -> IfL ()
ifCheckWiredInThing :: TyThing -> IfL ()
ifCheckWiredInThing TyThing
thing
= do { Module
mod <- IfL Module
getIfModule
; let name :: Name
name = forall a. NamedThing a => a -> Name
getName TyThing
thing
; forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Name -> Bool
isExternalName Name
name) (forall a. Outputable a => a -> SDoc
ppr Name
name) forall a b. (a -> b) -> a -> b
$
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (TyThing -> Bool
needWiredInHomeIface TyThing
thing Bool -> Bool -> Bool
&& Module
mod forall a. Eq a => a -> a -> Bool
/= HasDebugCallStack => Name -> Module
nameModule Name
name)
(forall lcl. Name -> IfM lcl ()
loadWiredInHomeIface Name
name) }
needWiredInHomeIface :: TyThing -> Bool
needWiredInHomeIface :: TyThing -> Bool
needWiredInHomeIface (ATyCon {}) = Bool
True
needWiredInHomeIface TyThing
_ = Bool
False
loadSrcInterface :: SDoc
-> ModuleName
-> IsBootInterface
-> PkgQual
-> RnM ModIface
loadSrcInterface :: SDoc -> ModuleName -> IsBootInterface -> PkgQual -> RnM ModIface
loadSrcInterface SDoc
doc ModuleName
mod IsBootInterface
want_boot PkgQual
maybe_pkg
= do { MaybeErr SDoc ModIface
res <- SDoc
-> ModuleName
-> IsBootInterface
-> PkgQual
-> RnM (MaybeErr SDoc ModIface)
loadSrcInterface_maybe SDoc
doc ModuleName
mod IsBootInterface
want_boot PkgQual
maybe_pkg
; case MaybeErr SDoc ModIface
res of
Failed SDoc
err -> forall a. TcRnMessage -> TcM a
failWithTc (forall a. (Diagnostic a, Typeable a) => a -> TcRnMessage
TcRnUnknownMessage forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints SDoc
err)
Succeeded ModIface
iface -> forall (m :: * -> *) a. Monad m => a -> m a
return ModIface
iface }
loadSrcInterface_maybe :: SDoc
-> ModuleName
-> IsBootInterface
-> PkgQual
-> RnM (MaybeErr SDoc ModIface)
loadSrcInterface_maybe :: SDoc
-> ModuleName
-> IsBootInterface
-> PkgQual
-> RnM (MaybeErr SDoc ModIface)
loadSrcInterface_maybe SDoc
doc ModuleName
mod IsBootInterface
want_boot PkgQual
maybe_pkg
= do HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
FindResult
res <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ HscEnv -> ModuleName -> PkgQual -> IO FindResult
findImportedModule HscEnv
hsc_env ModuleName
mod PkgQual
maybe_pkg
case FindResult
res of
Found ModLocation
_ Module
mod -> forall a. IfG a -> TcRn a
initIfaceTcRn forall a b. (a -> b) -> a -> b
$ forall lcl.
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
loadInterface SDoc
doc Module
mod (IsBootInterface -> WhereFrom
ImportByUser IsBootInterface
want_boot)
FindResult
err -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed (HscEnv -> ModuleName -> FindResult -> SDoc
cannotFindModule HscEnv
hsc_env ModuleName
mod FindResult
err))
loadModuleInterface :: SDoc -> Module -> TcM ModIface
loadModuleInterface :: SDoc -> Module -> RnM ModIface
loadModuleInterface SDoc
doc Module
mod = forall a. IfG a -> TcRn a
initIfaceTcRn (forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface SDoc
doc Module
mod)
loadModuleInterfaces :: SDoc -> [Module] -> TcM ()
loadModuleInterfaces :: SDoc -> [Module] -> TcM ()
loadModuleInterfaces SDoc
doc [Module]
mods
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Module]
mods = forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = forall a. IfG a -> TcRn a
initIfaceTcRn (forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Module -> IfM () ModIface
load [Module]
mods)
where
load :: Module -> IfM () ModIface
load Module
mod = forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface (SDoc
doc SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens (forall a. Outputable a => a -> SDoc
ppr Module
mod)) Module
mod
loadInterfaceForName :: SDoc -> Name -> TcRn ModIface
loadInterfaceForName :: SDoc -> Name -> RnM ModIface
loadInterfaceForName SDoc
doc Name
name
= do { forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugIsOn forall a b. (a -> b) -> a -> b
$
do { Module
this_mod <- forall (m :: * -> *). HasModule m => m Module
getModule
; forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr (Bool -> Bool
not (Module -> Name -> Bool
nameIsLocalOrFrom Module
this_mod Name
name)) (forall a. Outputable a => a -> SDoc
ppr Name
name SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens SDoc
doc) }
; forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Name -> Bool
isExternalName Name
name) (forall a. Outputable a => a -> SDoc
ppr Name
name) forall a b. (a -> b) -> a -> b
$
forall a. IfG a -> TcRn a
initIfaceTcRn forall a b. (a -> b) -> a -> b
$ forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface SDoc
doc (HasDebugCallStack => Name -> Module
nameModule Name
name) }
loadInterfaceForModule :: SDoc -> Module -> TcRn ModIface
loadInterfaceForModule :: SDoc -> Module -> RnM ModIface
loadInterfaceForModule SDoc
doc Module
m
= do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugIsOn forall a b. (a -> b) -> a -> b
$ do
Module
this_mod <- forall (m :: * -> *). HasModule m => m Module
getModule
forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr (Module
this_mod forall a. Eq a => a -> a -> Bool
/= Module
m) (forall a. Outputable a => a -> SDoc
ppr Module
m SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
parens SDoc
doc)
forall a. IfG a -> TcRn a
initIfaceTcRn forall a b. (a -> b) -> a -> b
$ forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface SDoc
doc Module
m
loadWiredInHomeIface :: Name -> IfM lcl ()
loadWiredInHomeIface :: forall lcl. Name -> IfM lcl ()
loadWiredInHomeIface Name
name
= forall a. HasCallStack => Bool -> a -> a
assert (Name -> Bool
isWiredInName Name
name) forall a b. (a -> b) -> a -> b
$
do ModIface
_ <- forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface SDoc
doc (HasDebugCallStack => Name -> Module
nameModule Name
name); forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
doc :: SDoc
doc = String -> SDoc
text String
"Need home interface for wired-in thing" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Name
name
loadSysInterface :: SDoc -> Module -> IfM lcl ModIface
loadSysInterface :: forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface SDoc
doc Module
mod_name = forall lcl. SDoc -> Module -> WhereFrom -> IfM lcl ModIface
loadInterfaceWithException SDoc
doc Module
mod_name WhereFrom
ImportBySystem
loadUserInterface :: IsBootInterface -> SDoc -> Module -> IfM lcl ModIface
loadUserInterface :: forall lcl. IsBootInterface -> SDoc -> Module -> IfM lcl ModIface
loadUserInterface IsBootInterface
is_boot SDoc
doc Module
mod_name
= forall lcl. SDoc -> Module -> WhereFrom -> IfM lcl ModIface
loadInterfaceWithException SDoc
doc Module
mod_name (IsBootInterface -> WhereFrom
ImportByUser IsBootInterface
is_boot)
loadPluginInterface :: SDoc -> Module -> IfM lcl ModIface
loadPluginInterface :: forall lcl. SDoc -> Module -> IfM lcl ModIface
loadPluginInterface SDoc
doc Module
mod_name
= forall lcl. SDoc -> Module -> WhereFrom -> IfM lcl ModIface
loadInterfaceWithException SDoc
doc Module
mod_name WhereFrom
ImportByPlugin
loadInterfaceWithException :: SDoc -> Module -> WhereFrom -> IfM lcl ModIface
loadInterfaceWithException :: forall lcl. SDoc -> Module -> WhereFrom -> IfM lcl ModIface
loadInterfaceWithException SDoc
doc Module
mod_name WhereFrom
where_from
= do
DynFlags
dflags <- forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
let ctx :: SDocContext
ctx = DynFlags -> PprStyle -> SDocContext
initSDocContext DynFlags
dflags PprStyle
defaultUserStyle
forall (m :: * -> *) a.
MonadIO m =>
SDocContext -> m (MaybeErr SDoc a) -> m a
withException SDocContext
ctx (forall lcl.
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
loadInterface SDoc
doc Module
mod_name WhereFrom
where_from)
loadInterface :: SDoc -> Module -> WhereFrom
-> IfM lcl (MaybeErr SDoc ModIface)
loadInterface :: forall lcl.
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
loadInterface SDoc
doc_str Module
mod WhereFrom
from
| forall u. GenModule (GenUnit u) -> Bool
isHoleModule Module
mod
= do HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
let home_unit :: HomeUnit
home_unit = HscEnv -> HomeUnit
hsc_home_unit HscEnv
hsc_env
forall lcl.
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
loadInterface SDoc
doc_str (HomeUnit -> ModuleName -> Module
mkHomeModule HomeUnit
home_unit (forall unit. GenModule unit -> ModuleName
moduleName Module
mod)) WhereFrom
from
| Bool
otherwise
= do
Logger
logger <- forall (m :: * -> *). HasLogger m => m Logger
getLogger
forall (m :: * -> *) a.
MonadIO m =>
Logger -> SDoc -> (a -> ()) -> m a -> m a
withTimingSilent Logger
logger (String -> SDoc
text String
"loading interface") (forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) forall a b. (a -> b) -> a -> b
$ do
{
(ExternalPackageState
eps,HomeUnitGraph
hug) <- forall gbl lcl.
TcRnIf gbl lcl (ExternalPackageState, HomeUnitGraph)
getEpsAndHug
; IfGblEnv
gbl_env <- forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Logger -> SDoc -> IO ()
trace_if Logger
logger (String -> SDoc
text String
"Considering whether to load" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr WhereFrom
from)
; HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
; let mhome_unit :: Maybe HomeUnit
mhome_unit = UnitEnv -> Maybe HomeUnit
ue_homeUnit (HscEnv -> UnitEnv
hsc_unit_env HscEnv
hsc_env)
; case HomeUnitGraph -> PackageIfaceTable -> Module -> Maybe ModIface
lookupIfaceByModule HomeUnitGraph
hug (ExternalPackageState -> PackageIfaceTable
eps_PIT ExternalPackageState
eps) Module
mod of {
Just ModIface
iface
-> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded ModIface
iface) ;
Maybe ModIface
_ -> do {
; MaybeErr SDoc (ModIface, String)
read_result <- case Maybe HomeUnit
-> ExternalPackageState
-> Module
-> WhereFrom
-> MaybeErr SDoc IsBootInterface
wantHiBootFile Maybe HomeUnit
mhome_unit ExternalPackageState
eps Module
mod WhereFrom
from of
Failed SDoc
err -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed SDoc
err)
Succeeded IsBootInterface
hi_boot_file -> do
HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ HscEnv
-> SDoc
-> IsBootInterface
-> Module
-> IO (MaybeErr SDoc (ModIface, String))
computeInterface HscEnv
hsc_env SDoc
doc_str IsBootInterface
hi_boot_file Module
mod
; case MaybeErr SDoc (ModIface, String)
read_result of {
Failed SDoc
err -> do
{ let fake_iface :: ModIface
fake_iface = Module -> ModIface
emptyFullModIface Module
mod
; forall gbl lcl.
(ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl ()
updateEps_ forall a b. (a -> b) -> a -> b
$ \ExternalPackageState
eps ->
ExternalPackageState
eps { eps_PIT :: PackageIfaceTable
eps_PIT = forall a. ModuleEnv a -> Module -> a -> ModuleEnv a
extendModuleEnv (ExternalPackageState -> PackageIfaceTable
eps_PIT ExternalPackageState
eps) (forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
fake_iface) ModIface
fake_iface }
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed SDoc
err) } ;
Succeeded (ModIface
iface, String
loc) ->
let
loc_doc :: SDoc
loc_doc = String -> SDoc
text String
loc
in
forall a lcl.
Module -> SDoc -> IsBootInterface -> IfL a -> IfM lcl a
initIfaceLcl (forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_semantic_module ModIface
iface) SDoc
loc_doc (ModIface -> IsBootInterface
mi_boot ModIface
iface) forall a b. (a -> b) -> a -> b
$
forall a. IfL a -> IfL a
dontLeakTheHUG forall a b. (a -> b) -> a -> b
$ do
; forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr
((GhcMode -> Bool
isOneShot (DynFlags -> GhcMode
ghcMode (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env)))
Bool -> Bool -> Bool
|| Module -> UnitId
moduleUnitId Module
mod forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` HscEnv -> Set UnitId
hsc_all_home_unit_ids HscEnv
hsc_env
Bool -> Bool -> Bool
|| Module
mod forall a. Eq a => a -> a -> Bool
== Module
gHC_PRIM)
(String -> SDoc
text String
"Attempting to load home package interface into the EPS" SDoc -> SDoc -> SDoc
$$ forall a. Outputable a => a -> SDoc
ppr HomeUnitGraph
hug SDoc -> SDoc -> SDoc
$$ SDoc
doc_str SDoc -> SDoc -> SDoc
$$ forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
$$ forall a. Outputable a => a -> SDoc
ppr (Module -> UnitId
moduleUnitId Module
mod))
; Bool
ignore_prags <- forall gbl lcl. GeneralFlag -> TcRnIf gbl lcl Bool
goptM GeneralFlag
Opt_IgnoreInterfacePragmas
; [(Name, TyThing)]
new_eps_decls <- Bool -> [(Fingerprint, IfaceDecl)] -> IfL [(Name, TyThing)]
tcIfaceDecls Bool
ignore_prags (forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls ModIface
iface)
; [ClsInst]
new_eps_insts <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceClsInst -> IfL ClsInst
tcIfaceInst (forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceClsInst]
mi_insts ModIface
iface)
; [FamInst]
new_eps_fam_insts <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM IfaceFamInst -> IfL FamInst
tcIfaceFamInst (forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceFamInst]
mi_fam_insts ModIface
iface)
; [CoreRule]
new_eps_rules <- Bool -> [IfaceRule] -> IfL [CoreRule]
tcIfaceRules Bool
ignore_prags (forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceRule]
mi_rules ModIface
iface)
; [Annotation]
new_eps_anns <- [IfaceAnnotation] -> IfL [Annotation]
tcIfaceAnnotations (forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceAnnotation]
mi_anns ModIface
iface)
; [CompleteMatch]
new_eps_complete_matches <- [IfaceCompleteMatch] -> IfL [CompleteMatch]
tcIfaceCompleteMatches (forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceCompleteMatch]
mi_complete_matches ModIface
iface)
; let { final_iface :: ModIface
final_iface = ModIface
iface {
mi_decls :: [IfaceDeclExts 'ModIfaceFinal]
mi_decls = forall a. String -> a
panic String
"No mi_decls in PIT",
mi_insts :: [IfaceClsInst]
mi_insts = forall a. String -> a
panic String
"No mi_insts in PIT",
mi_fam_insts :: [IfaceFamInst]
mi_fam_insts = forall a. String -> a
panic String
"No mi_fam_insts in PIT",
mi_rules :: [IfaceRule]
mi_rules = forall a. String -> a
panic String
"No mi_rules in PIT",
mi_anns :: [IfaceAnnotation]
mi_anns = forall a. String -> a
panic String
"No mi_anns in PIT"
}
}
; let bad_boot :: Bool
bad_boot = ModIface -> IsBootInterface
mi_boot ModIface
iface forall a. Eq a => a -> a -> Bool
== IsBootInterface
IsBoot
Bool -> Bool -> Bool
&& forall a. Maybe a -> Bool
isJust (forall a. KnotVars a -> Module -> Maybe a
lookupKnotVars (IfGblEnv -> KnotVars (IfG TypeEnv)
if_rec_types IfGblEnv
gbl_env) Module
mod)
; forall a. HasCallStack => Bool -> String -> SDoc -> a -> a
warnPprTrace Bool
bad_boot String
"loadInterface" (forall a. Outputable a => a -> SDoc
ppr Module
mod) forall a b. (a -> b) -> a -> b
$
forall gbl lcl.
(ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl ()
updateEps_ forall a b. (a -> b) -> a -> b
$ \ ExternalPackageState
eps ->
if forall a. Module -> ModuleEnv a -> Bool
elemModuleEnv Module
mod (ExternalPackageState -> PackageIfaceTable
eps_PIT ExternalPackageState
eps) Bool -> Bool -> Bool
|| Maybe HomeUnit -> ModIface -> Bool
is_external_sig Maybe HomeUnit
mhome_unit ModIface
iface
then ExternalPackageState
eps
else if Bool
bad_boot
then ExternalPackageState
eps { eps_PTE :: TypeEnv
eps_PTE = TypeEnv -> [(Name, TyThing)] -> TypeEnv
addDeclsToPTE (ExternalPackageState -> TypeEnv
eps_PTE ExternalPackageState
eps) [(Name, TyThing)]
new_eps_decls }
else
ExternalPackageState
eps {
eps_PIT :: PackageIfaceTable
eps_PIT = forall a. ModuleEnv a -> Module -> a -> ModuleEnv a
extendModuleEnv (ExternalPackageState -> PackageIfaceTable
eps_PIT ExternalPackageState
eps) Module
mod ModIface
final_iface,
eps_PTE :: TypeEnv
eps_PTE = TypeEnv -> [(Name, TyThing)] -> TypeEnv
addDeclsToPTE (ExternalPackageState -> TypeEnv
eps_PTE ExternalPackageState
eps) [(Name, TyThing)]
new_eps_decls,
eps_rule_base :: PackageRuleBase
eps_rule_base = PackageRuleBase -> [CoreRule] -> PackageRuleBase
extendRuleBaseList (ExternalPackageState -> PackageRuleBase
eps_rule_base ExternalPackageState
eps)
[CoreRule]
new_eps_rules,
eps_complete_matches :: [CompleteMatch]
eps_complete_matches
= ExternalPackageState -> [CompleteMatch]
eps_complete_matches ExternalPackageState
eps forall a. [a] -> [a] -> [a]
++ [CompleteMatch]
new_eps_complete_matches,
eps_inst_env :: PackageInstEnv
eps_inst_env = PackageInstEnv -> [ClsInst] -> PackageInstEnv
extendInstEnvList (ExternalPackageState -> PackageInstEnv
eps_inst_env ExternalPackageState
eps)
[ClsInst]
new_eps_insts,
eps_fam_inst_env :: PackageFamInstEnv
eps_fam_inst_env = PackageFamInstEnv -> [FamInst] -> PackageFamInstEnv
extendFamInstEnvList (ExternalPackageState -> PackageFamInstEnv
eps_fam_inst_env ExternalPackageState
eps)
[FamInst]
new_eps_fam_insts,
eps_ann_env :: PackageAnnEnv
eps_ann_env = PackageAnnEnv -> [Annotation] -> PackageAnnEnv
extendAnnEnvList (ExternalPackageState -> PackageAnnEnv
eps_ann_env ExternalPackageState
eps)
[Annotation]
new_eps_anns,
eps_mod_fam_inst_env :: ModuleEnv PackageFamInstEnv
eps_mod_fam_inst_env
= let
fam_inst_env :: PackageFamInstEnv
fam_inst_env =
PackageFamInstEnv -> [FamInst] -> PackageFamInstEnv
extendFamInstEnvList PackageFamInstEnv
emptyFamInstEnv
[FamInst]
new_eps_fam_insts
in
forall a. ModuleEnv a -> Module -> a -> ModuleEnv a
extendModuleEnv (ExternalPackageState -> ModuleEnv PackageFamInstEnv
eps_mod_fam_inst_env ExternalPackageState
eps)
Module
mod
PackageFamInstEnv
fam_inst_env,
eps_stats :: EpsStats
eps_stats = EpsStats -> Int -> Int -> Int -> EpsStats
addEpsInStats (ExternalPackageState -> EpsStats
eps_stats ExternalPackageState
eps)
(forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Name, TyThing)]
new_eps_decls)
(forall (t :: * -> *) a. Foldable t => t a -> Int
length [ClsInst]
new_eps_insts)
(forall (t :: * -> *) a. Foldable t => t a -> Int
length [CoreRule]
new_eps_rules) }
;
ModIface
res <- forall (m :: * -> *) a.
Monad m =>
Plugins -> PluginOperation m a -> a -> m a
withPlugins (HscEnv -> Plugins
hsc_plugins HscEnv
hsc_env) (\Plugin
p -> Plugin -> forall lcl. [String] -> ModIface -> IfM lcl ModIface
interfaceLoadAction Plugin
p) ModIface
iface
; forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded ModIface
res)
}}}}
dontLeakTheHUG :: IfL a -> IfL a
dontLeakTheHUG :: forall a. IfL a -> IfL a
dontLeakTheHUG IfL a
thing_inside = do
HscEnv
env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
let
inOneShot :: Bool
inOneShot =
GhcMode -> Bool
isOneShot (DynFlags -> GhcMode
ghcMode (HscEnv -> DynFlags
hsc_dflags HscEnv
env))
cleanGblEnv :: IfGblEnv -> IfGblEnv
cleanGblEnv IfGblEnv
gbl_env
| Bool
inOneShot = IfGblEnv
gbl_env
| Bool
otherwise = IfGblEnv
gbl_env { if_rec_types :: KnotVars (IfG TypeEnv)
if_rec_types = forall a. KnotVars a
emptyKnotVars }
cleanTopEnv :: HscEnv -> HscEnv
cleanTopEnv HscEnv
hsc_env =
let
!maybe_type_vars :: Maybe (KnotVars (IORef TypeEnv))
maybe_type_vars | Bool
inOneShot = forall a. a -> Maybe a
Just (HscEnv -> KnotVars (IORef TypeEnv)
hsc_type_env_vars HscEnv
env)
| Bool
otherwise = forall a. Maybe a
Nothing
old_unit_env :: UnitEnv
old_unit_env = HscEnv -> UnitEnv
hsc_unit_env HscEnv
hsc_env
keepFor20509 :: HomeModInfo -> Bool
keepFor20509 HomeModInfo
hmi
| forall u. GenModule (GenUnit u) -> Bool
isHoleModule (forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_semantic_module (HomeModInfo -> ModIface
hm_iface HomeModInfo
hmi)) = Bool
True
| Bool
otherwise = Bool
False
pruneHomeUnitEnv :: HomeUnitEnv -> HomeUnitEnv
pruneHomeUnitEnv HomeUnitEnv
hme = HomeUnitEnv
hme { homeUnitEnv_hpt :: HomePackageTable
homeUnitEnv_hpt = HomePackageTable
emptyHomePackageTable }
!unit_env :: UnitEnv
unit_env
= UnitEnv
old_unit_env
{ ue_home_unit_graph :: HomeUnitGraph
ue_home_unit_graph = if (HomeModInfo -> Bool) -> HomePackageTable -> Bool
anyHpt HomeModInfo -> Bool
keepFor20509 (HasDebugCallStack => UnitEnv -> HomePackageTable
ue_hpt UnitEnv
old_unit_env) then UnitEnv -> HomeUnitGraph
ue_home_unit_graph UnitEnv
old_unit_env
else forall v. (v -> v) -> UnitEnvGraph v -> UnitEnvGraph v
unitEnv_map HomeUnitEnv -> HomeUnitEnv
pruneHomeUnitEnv (UnitEnv -> HomeUnitGraph
ue_home_unit_graph UnitEnv
old_unit_env)
}
in
HscEnv
hsc_env { hsc_targets :: [Target]
hsc_targets = forall a. String -> a
panic String
"cleanTopEnv: hsc_targets"
, hsc_mod_graph :: ModuleGraph
hsc_mod_graph = forall a. String -> a
panic String
"cleanTopEnv: hsc_mod_graph"
, hsc_IC :: InteractiveContext
hsc_IC = forall a. String -> a
panic String
"cleanTopEnv: hsc_IC"
, hsc_type_env_vars :: KnotVars (IORef TypeEnv)
hsc_type_env_vars = case Maybe (KnotVars (IORef TypeEnv))
maybe_type_vars of
Just KnotVars (IORef TypeEnv)
vars -> KnotVars (IORef TypeEnv)
vars
Maybe (KnotVars (IORef TypeEnv))
Nothing -> forall a. String -> a
panic String
"cleanTopEnv: hsc_type_env_vars"
, hsc_unit_env :: UnitEnv
hsc_unit_env = UnitEnv
unit_env
}
forall gbl lcl a.
(HscEnv -> HscEnv) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updTopEnv HscEnv -> HscEnv
cleanTopEnv forall a b. (a -> b) -> a -> b
$ forall gbl lcl a.
(gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updGblEnv IfGblEnv -> IfGblEnv
cleanGblEnv forall a b. (a -> b) -> a -> b
$ do
!HscEnv
_ <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
!IfGblEnv
_ <- forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
IfL a
thing_inside
is_external_sig :: Maybe HomeUnit -> ModIface -> Bool
is_external_sig :: Maybe HomeUnit -> ModIface -> Bool
is_external_sig Maybe HomeUnit
mhome_unit ModIface
iface =
forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_semantic_module ModIface
iface forall a. Eq a => a -> a -> Bool
/= forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface Bool -> Bool -> Bool
&&
Maybe HomeUnit -> Module -> Bool
notHomeModuleMaybe Maybe HomeUnit
mhome_unit (forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface)
computeInterface
:: HscEnv
-> SDoc
-> IsBootInterface
-> Module
-> IO (MaybeErr SDoc (ModIface, FilePath))
computeInterface :: HscEnv
-> SDoc
-> IsBootInterface
-> Module
-> IO (MaybeErr SDoc (ModIface, String))
computeInterface HscEnv
hsc_env SDoc
doc_str IsBootInterface
hi_boot_file Module
mod0 = do
forall (m :: * -> *). (HasCallStack, Applicative m) => Bool -> m ()
massert (Bool -> Bool
not (forall u. GenModule (GenUnit u) -> Bool
isHoleModule Module
mod0))
let mhome_unit :: Maybe HomeUnit
mhome_unit = HscEnv -> Maybe HomeUnit
hsc_home_unit_maybe HscEnv
hsc_env
let find_iface :: GenModule UnitId -> IO (MaybeErr SDoc (ModIface, String))
find_iface GenModule UnitId
m = HscEnv
-> SDoc
-> GenModule UnitId
-> Module
-> IsBootInterface
-> IO (MaybeErr SDoc (ModIface, String))
findAndReadIface HscEnv
hsc_env SDoc
doc_str
GenModule UnitId
m Module
mod0 IsBootInterface
hi_boot_file
case Module -> (GenModule UnitId, Maybe InstantiatedModule)
getModuleInstantiation Module
mod0 of
(GenModule UnitId
imod, Just InstantiatedModule
indef)
| Just HomeUnit
home_unit <- Maybe HomeUnit
mhome_unit
, forall u. GenHomeUnit u -> Bool
isHomeUnitIndefinite HomeUnit
home_unit ->
GenModule UnitId -> IO (MaybeErr SDoc (ModIface, String))
find_iface GenModule UnitId
imod forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Succeeded (ModIface
iface0, String
path) ->
HscEnv
-> [(ModuleName, Module)]
-> Maybe NameShape
-> ModIface
-> IO (Either (Messages TcRnMessage) ModIface)
rnModIface HscEnv
hsc_env (forall unit. GenInstantiatedUnit unit -> GenInstantiations unit
instUnitInsts (forall unit. GenModule unit -> unit
moduleUnit InstantiatedModule
indef)) forall a. Maybe a
Nothing ModIface
iface0 forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right ModIface
x -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded (ModIface
x, String
path))
Left Messages TcRnMessage
errs -> forall (io :: * -> *) a. MonadIO io => Messages GhcMessage -> io a
throwErrors (TcRnMessage -> GhcMessage
GhcTcRnMessage forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Messages TcRnMessage
errs)
Failed SDoc
err -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed SDoc
err)
(GenModule UnitId
mod, Maybe InstantiatedModule
_) -> GenModule UnitId -> IO (MaybeErr SDoc (ModIface, String))
find_iface GenModule UnitId
mod
moduleFreeHolesPrecise
:: SDoc -> Module
-> TcRnIf gbl lcl (MaybeErr SDoc (UniqDSet ModuleName))
moduleFreeHolesPrecise :: forall gbl lcl.
SDoc
-> Module -> TcRnIf gbl lcl (MaybeErr SDoc (UniqDSet ModuleName))
moduleFreeHolesPrecise SDoc
doc_str Module
mod
| Module -> Bool
moduleIsDefinite Module
mod = forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded forall a. UniqDSet a
emptyUniqDSet)
| Bool
otherwise =
case Module -> (GenModule UnitId, Maybe InstantiatedModule)
getModuleInstantiation Module
mod of
(GenModule UnitId
imod, Just InstantiatedModule
indef) -> do
Logger
logger <- forall (m :: * -> *). HasLogger m => m Logger
getLogger
let insts :: [(ModuleName, Module)]
insts = forall unit. GenInstantiatedUnit unit -> GenInstantiations unit
instUnitInsts (forall unit. GenModule unit -> unit
moduleUnit InstantiatedModule
indef)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Logger -> SDoc -> IO ()
trace_if Logger
logger (String -> SDoc
text String
"Considering whether to load" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text String
"to compute precise free module holes")
(ExternalPackageState
eps, HomeUnitGraph
hpt) <- forall gbl lcl.
TcRnIf gbl lcl (ExternalPackageState, HomeUnitGraph)
getEpsAndHug
case ExternalPackageState
-> HomeUnitGraph -> Maybe (UniqDSet ModuleName)
tryEpsAndHpt ExternalPackageState
eps HomeUnitGraph
hpt forall a. Maybe a -> Maybe a -> Maybe a
`firstJust` ExternalPackageState
-> GenModule UnitId
-> [(ModuleName, Module)]
-> Maybe (UniqDSet ModuleName)
tryDepsCache ExternalPackageState
eps GenModule UnitId
imod [(ModuleName, Module)]
insts of
Just UniqDSet ModuleName
r -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded UniqDSet ModuleName
r)
Maybe (UniqDSet ModuleName)
Nothing -> GenModule UnitId
-> [(ModuleName, Module)]
-> TcRnIf gbl lcl (MaybeErr SDoc (UniqDSet ModuleName))
readAndCache GenModule UnitId
imod [(ModuleName, Module)]
insts
(GenModule UnitId
_, Maybe InstantiatedModule
Nothing) -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded forall a. UniqDSet a
emptyUniqDSet)
where
tryEpsAndHpt :: ExternalPackageState
-> HomeUnitGraph -> Maybe (UniqDSet ModuleName)
tryEpsAndHpt ExternalPackageState
eps HomeUnitGraph
hpt =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ModIface -> UniqDSet ModuleName
mi_free_holes (HomeUnitGraph -> PackageIfaceTable -> Module -> Maybe ModIface
lookupIfaceByModule HomeUnitGraph
hpt (ExternalPackageState -> PackageIfaceTable
eps_PIT ExternalPackageState
eps) Module
mod)
tryDepsCache :: ExternalPackageState
-> GenModule UnitId
-> [(ModuleName, Module)]
-> Maybe (UniqDSet ModuleName)
tryDepsCache ExternalPackageState
eps GenModule UnitId
imod [(ModuleName, Module)]
insts =
case forall a. InstalledModuleEnv a -> GenModule UnitId -> Maybe a
lookupInstalledModuleEnv (ExternalPackageState -> InstalledModuleEnv (UniqDSet ModuleName)
eps_free_holes ExternalPackageState
eps) GenModule UnitId
imod of
Just UniqDSet ModuleName
ifhs -> forall a. a -> Maybe a
Just (UniqDSet ModuleName
-> [(ModuleName, Module)] -> UniqDSet ModuleName
renameFreeHoles UniqDSet ModuleName
ifhs [(ModuleName, Module)]
insts)
Maybe (UniqDSet ModuleName)
_otherwise -> forall a. Maybe a
Nothing
readAndCache :: GenModule UnitId
-> [(ModuleName, Module)]
-> TcRnIf gbl lcl (MaybeErr SDoc (UniqDSet ModuleName))
readAndCache GenModule UnitId
imod [(ModuleName, Module)]
insts = do
HscEnv
hsc_env <- forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
MaybeErr SDoc (ModIface, String)
mb_iface <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ HscEnv
-> SDoc
-> GenModule UnitId
-> Module
-> IsBootInterface
-> IO (MaybeErr SDoc (ModIface, String))
findAndReadIface HscEnv
hsc_env
(String -> SDoc
text String
"moduleFreeHolesPrecise" SDoc -> SDoc -> SDoc
<+> SDoc
doc_str)
GenModule UnitId
imod Module
mod IsBootInterface
NotBoot
case MaybeErr SDoc (ModIface, String)
mb_iface of
Succeeded (ModIface
iface, String
_) -> do
let ifhs :: UniqDSet ModuleName
ifhs = ModIface -> UniqDSet ModuleName
mi_free_holes ModIface
iface
forall gbl lcl.
(ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl ()
updateEps_ (\ExternalPackageState
eps ->
ExternalPackageState
eps { eps_free_holes :: InstalledModuleEnv (UniqDSet ModuleName)
eps_free_holes = forall a.
InstalledModuleEnv a
-> GenModule UnitId -> a -> InstalledModuleEnv a
extendInstalledModuleEnv (ExternalPackageState -> InstalledModuleEnv (UniqDSet ModuleName)
eps_free_holes ExternalPackageState
eps) GenModule UnitId
imod UniqDSet ModuleName
ifhs })
forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded (UniqDSet ModuleName
-> [(ModuleName, Module)] -> UniqDSet ModuleName
renameFreeHoles UniqDSet ModuleName
ifhs [(ModuleName, Module)]
insts))
Failed SDoc
err -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed SDoc
err)
wantHiBootFile :: Maybe HomeUnit -> ExternalPackageState -> Module -> WhereFrom
-> MaybeErr SDoc IsBootInterface
wantHiBootFile :: Maybe HomeUnit
-> ExternalPackageState
-> Module
-> WhereFrom
-> MaybeErr SDoc IsBootInterface
wantHiBootFile Maybe HomeUnit
mhome_unit ExternalPackageState
eps Module
mod WhereFrom
from
= case WhereFrom
from of
ImportByUser IsBootInterface
usr_boot
| IsBootInterface
usr_boot forall a. Eq a => a -> a -> Bool
== IsBootInterface
IsBoot Bool -> Bool -> Bool
&& Maybe HomeUnit -> Module -> Bool
notHomeModuleMaybe Maybe HomeUnit
mhome_unit Module
mod
-> forall err val. err -> MaybeErr err val
Failed (Module -> SDoc
badSourceImport Module
mod)
| Bool
otherwise -> forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
usr_boot
WhereFrom
ImportByPlugin
-> forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
NotBoot
WhereFrom
ImportBySystem
| Maybe HomeUnit -> Module -> Bool
notHomeModuleMaybe Maybe HomeUnit
mhome_unit Module
mod
-> forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
NotBoot
| Bool
otherwise
-> case forall a. InstalledModuleEnv a -> GenModule UnitId -> Maybe a
lookupInstalledModuleEnv (ExternalPackageState -> InstalledModuleEnv ModuleNameWithIsBoot
eps_is_boot ExternalPackageState
eps) (Unit -> UnitId
toUnitId forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Module
mod) of
Just (GWIB { gwib_isBoot :: forall mod. GenWithIsBoot mod -> IsBootInterface
gwib_isBoot = IsBootInterface
is_boot }) ->
forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
is_boot
Maybe ModuleNameWithIsBoot
Nothing ->
forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
NotBoot
badSourceImport :: Module -> SDoc
badSourceImport :: Module -> SDoc
badSourceImport Module
mod
= SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
text String
"You cannot {-# SOURCE #-} import a module from another package")
Int
2 (String -> SDoc
text String
"but" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"is from package"
SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr (forall unit. GenModule unit -> unit
moduleUnit Module
mod)))
addDeclsToPTE :: PackageTypeEnv -> [(Name,TyThing)] -> PackageTypeEnv
addDeclsToPTE :: TypeEnv -> [(Name, TyThing)] -> TypeEnv
addDeclsToPTE TypeEnv
pte [(Name, TyThing)]
things = forall a. NameEnv a -> [(Name, a)] -> NameEnv a
extendNameEnvList TypeEnv
pte [(Name, TyThing)]
things
findAndReadIface
:: HscEnv
-> SDoc
-> InstalledModule
-> Module
-> IsBootInterface
-> IO (MaybeErr SDoc (ModIface, FilePath))
findAndReadIface :: HscEnv
-> SDoc
-> GenModule UnitId
-> Module
-> IsBootInterface
-> IO (MaybeErr SDoc (ModIface, String))
findAndReadIface HscEnv
hsc_env SDoc
doc_str GenModule UnitId
mod Module
wanted_mod IsBootInterface
hi_boot_file = do
let profile :: Profile
profile = DynFlags -> Profile
targetProfile DynFlags
dflags
unit_state :: UnitState
unit_state = HasDebugCallStack => HscEnv -> UnitState
hsc_units HscEnv
hsc_env
fc :: FinderCache
fc = HscEnv -> FinderCache
hsc_FC HscEnv
hsc_env
name_cache :: NameCache
name_cache = HscEnv -> NameCache
hsc_NC HscEnv
hsc_env
mhome_unit :: Maybe HomeUnit
mhome_unit = HscEnv -> Maybe HomeUnit
hsc_home_unit_maybe HscEnv
hsc_env
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
logger :: Logger
logger = HscEnv -> Logger
hsc_logger HscEnv
hsc_env
hooks :: Hooks
hooks = HscEnv -> Hooks
hsc_hooks HscEnv
hsc_env
other_fopts :: UnitEnvGraph FinderOpts
other_fopts = DynFlags -> FinderOpts
initFinderOpts forall b c a. (b -> c) -> (a -> b) -> a -> c
. HomeUnitEnv -> DynFlags
homeUnitEnv_dflags forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (HscEnv -> HomeUnitGraph
hsc_HUG HscEnv
hsc_env)
Logger -> SDoc -> IO ()
trace_if Logger
logger ([SDoc] -> SDoc
sep [[SDoc] -> SDoc
hsep [String -> SDoc
text String
"Reading",
if IsBootInterface
hi_boot_file forall a. Eq a => a -> a -> Bool
== IsBootInterface
IsBoot
then String -> SDoc
text String
"[boot]"
else SDoc
Outputable.empty,
String -> SDoc
text String
"interface for",
forall a. Outputable a => a -> SDoc
ppr GenModule UnitId
mod SDoc -> SDoc -> SDoc
<> SDoc
semi],
Int -> SDoc -> SDoc
nest Int
4 (String -> SDoc
text String
"reason:" SDoc -> SDoc -> SDoc
<+> SDoc
doc_str)])
if GenModule UnitId
mod GenModule UnitId -> Module -> Bool
`installedModuleEq` Module
gHC_PRIM
then do
let iface :: ModIface
iface = case Hooks -> Maybe ModIface
ghcPrimIfaceHook Hooks
hooks of
Maybe ModIface
Nothing -> ModIface
ghcPrimIface
Just ModIface
h -> ModIface
h
forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded (ModIface
iface, String
"<built in interface for GHC.Prim>"))
else do
let fopts :: FinderOpts
fopts = DynFlags -> FinderOpts
initFinderOpts DynFlags
dflags
InstalledFindResult
mb_found <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (FinderCache
-> FinderOpts
-> UnitEnvGraph FinderOpts
-> UnitState
-> Maybe HomeUnit
-> GenModule UnitId
-> IO InstalledFindResult
findExactModule FinderCache
fc FinderOpts
fopts UnitEnvGraph FinderOpts
other_fopts UnitState
unit_state Maybe HomeUnit
mhome_unit GenModule UnitId
mod)
case InstalledFindResult
mb_found of
InstalledFound (IsBootInterface -> ModLocation -> ModLocation
addBootSuffixLocn_maybe IsBootInterface
hi_boot_file -> ModLocation
loc) GenModule UnitId
mod -> do
case Maybe HomeUnit
mhome_unit of
Just HomeUnit
home_unit
| forall u. GenHomeUnit u -> GenModule UnitId -> Bool
isHomeInstalledModule HomeUnit
home_unit GenModule UnitId
mod
, Bool -> Bool
not (GhcMode -> Bool
isOneShot (DynFlags -> GhcMode
ghcMode DynFlags
dflags))
-> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed (GenModule UnitId -> ModLocation -> SDoc
homeModError GenModule UnitId
mod ModLocation
loc))
Maybe HomeUnit
_ -> do
MaybeErr SDoc (ModIface, String)
r <- Logger
-> NameCache
-> UnitState
-> DynFlags
-> Module
-> String
-> IO (MaybeErr SDoc (ModIface, String))
read_file Logger
logger NameCache
name_cache UnitState
unit_state DynFlags
dflags Module
wanted_mod (ModLocation -> String
ml_hi_file ModLocation
loc)
case MaybeErr SDoc (ModIface, String)
r of
Failed SDoc
_
-> forall (m :: * -> *) a. Monad m => a -> m a
return MaybeErr SDoc (ModIface, String)
r
Succeeded (ModIface
iface,String
_fp)
-> do
MaybeErr SDoc ()
r2 <- Logger
-> NameCache
-> UnitState
-> DynFlags
-> Module
-> ModIface
-> ModLocation
-> IO (MaybeErr SDoc ())
load_dynamic_too_maybe Logger
logger NameCache
name_cache UnitState
unit_state
(DynFlags -> DynFlags
setDynamicNow DynFlags
dflags) Module
wanted_mod
ModIface
iface ModLocation
loc
case MaybeErr SDoc ()
r2 of
Failed SDoc
sdoc -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed SDoc
sdoc)
Succeeded {} -> forall (m :: * -> *) a. Monad m => a -> m a
return MaybeErr SDoc (ModIface, String)
r
InstalledFindResult
err -> do
Logger -> SDoc -> IO ()
trace_if Logger
logger (String -> SDoc
text String
"...not found")
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall err val. err -> MaybeErr err val
Failed forall a b. (a -> b) -> a -> b
$ UnitState
-> Maybe HomeUnit
-> Profile
-> ([String] -> SDoc)
-> ModuleName
-> InstalledFindResult
-> SDoc
cannotFindInterface
UnitState
unit_state
Maybe HomeUnit
mhome_unit
Profile
profile
(DynFlags -> [String] -> SDoc
Iface_Errors.mayShowLocations DynFlags
dflags)
(forall unit. GenModule unit -> ModuleName
moduleName GenModule UnitId
mod)
InstalledFindResult
err
load_dynamic_too_maybe :: Logger -> NameCache -> UnitState -> DynFlags -> Module -> ModIface -> ModLocation -> IO (MaybeErr SDoc ())
load_dynamic_too_maybe :: Logger
-> NameCache
-> UnitState
-> DynFlags
-> Module
-> ModIface
-> ModLocation
-> IO (MaybeErr SDoc ())
load_dynamic_too_maybe Logger
logger NameCache
name_cache UnitState
unit_state DynFlags
dflags Module
wanted_mod ModIface
iface ModLocation
loc
| Bool -> Bool
not (Module -> Bool
moduleIsDefinite (forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface)) = forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded ())
| GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_BuildDynamicToo DynFlags
dflags = Logger
-> NameCache
-> UnitState
-> DynFlags
-> Module
-> ModIface
-> ModLocation
-> IO (MaybeErr SDoc ())
load_dynamic_too Logger
logger NameCache
name_cache UnitState
unit_state DynFlags
dflags Module
wanted_mod ModIface
iface ModLocation
loc
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded ())
load_dynamic_too :: Logger -> NameCache -> UnitState -> DynFlags -> Module -> ModIface -> ModLocation -> IO (MaybeErr SDoc ())
load_dynamic_too :: Logger
-> NameCache
-> UnitState
-> DynFlags
-> Module
-> ModIface
-> ModLocation
-> IO (MaybeErr SDoc ())
load_dynamic_too Logger
logger NameCache
name_cache UnitState
unit_state DynFlags
dflags Module
wanted_mod ModIface
iface ModLocation
loc = do
Logger
-> NameCache
-> UnitState
-> DynFlags
-> Module
-> String
-> IO (MaybeErr SDoc (ModIface, String))
read_file Logger
logger NameCache
name_cache UnitState
unit_state DynFlags
dflags Module
wanted_mod (ModLocation -> String
ml_dyn_hi_file ModLocation
loc) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Succeeded (ModIface
dynIface, String
_)
| ModIfaceBackend -> Fingerprint
mi_mod_hash (forall (phase :: ModIfacePhase).
ModIface_ phase -> IfaceBackendExts phase
mi_final_exts ModIface
iface) forall a. Eq a => a -> a -> Bool
== ModIfaceBackend -> Fingerprint
mi_mod_hash (forall (phase :: ModIfacePhase).
ModIface_ phase -> IfaceBackendExts phase
mi_final_exts ModIface
dynIface)
-> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded ())
| Bool
otherwise ->
do forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (forall err val. err -> MaybeErr err val
Failed forall a b. (a -> b) -> a -> b
$ Module -> ModLocation -> SDoc
dynamicHashMismatchError Module
wanted_mod ModLocation
loc)
Failed SDoc
err ->
do forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (forall err val. err -> MaybeErr err val
Failed forall a b. (a -> b) -> a -> b
$ ((String -> SDoc
text String
"Failed to load dynamic interface file for" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Module
wanted_mod SDoc -> SDoc -> SDoc
<> SDoc
colon) SDoc -> SDoc -> SDoc
$$ SDoc
err))
dynamicHashMismatchError :: Module -> ModLocation -> SDoc
dynamicHashMismatchError :: Module -> ModLocation -> SDoc
dynamicHashMismatchError Module
wanted_mod ModLocation
loc =
[SDoc] -> SDoc
vcat [ String -> SDoc
text String
"Dynamic hash doesn't match for" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
wanted_mod)
, String -> SDoc
text String
"Normal interface file from" SDoc -> SDoc -> SDoc
<+> String -> SDoc
text (ModLocation -> String
ml_hi_file ModLocation
loc)
, String -> SDoc
text String
"Dynamic interface file from" SDoc -> SDoc -> SDoc
<+> String -> SDoc
text (ModLocation -> String
ml_dyn_hi_file ModLocation
loc)
, String -> SDoc
text String
"You probably need to recompile" SDoc -> SDoc -> SDoc
<+> SDoc -> SDoc
quotes (forall a. Outputable a => a -> SDoc
ppr Module
wanted_mod) ]
read_file :: Logger -> NameCache -> UnitState -> DynFlags -> Module -> FilePath -> IO (MaybeErr SDoc (ModIface, FilePath))
read_file :: Logger
-> NameCache
-> UnitState
-> DynFlags
-> Module
-> String
-> IO (MaybeErr SDoc (ModIface, String))
read_file Logger
logger NameCache
name_cache UnitState
unit_state DynFlags
dflags Module
wanted_mod String
file_path = do
Logger -> SDoc -> IO ()
trace_if Logger
logger (String -> SDoc
text String
"readIFace" SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
file_path)
let wanted_mod' :: Module
wanted_mod' =
case Module -> (GenModule UnitId, Maybe InstantiatedModule)
getModuleInstantiation Module
wanted_mod of
(GenModule UnitId
_, Maybe InstantiatedModule
Nothing) -> Module
wanted_mod
(GenModule UnitId
_, Just InstantiatedModule
indef_mod) ->
UnitState -> InstantiatedModule -> Module
instModuleToModule UnitState
unit_state
(InstantiatedModule -> InstantiatedModule
uninstantiateInstantiatedModule InstantiatedModule
indef_mod)
MaybeErr SDoc ModIface
read_result <- DynFlags
-> NameCache -> Module -> String -> IO (MaybeErr SDoc ModIface)
readIface DynFlags
dflags NameCache
name_cache Module
wanted_mod' String
file_path
case MaybeErr SDoc ModIface
read_result of
Failed SDoc
err -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed (String -> SDoc -> SDoc
badIfaceFile String
file_path SDoc
err))
Succeeded ModIface
iface -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded (ModIface
iface, String
file_path))
writeIface :: Logger -> Profile -> FilePath -> ModIface -> IO ()
writeIface :: Logger -> Profile -> String -> ModIface -> IO ()
writeIface Logger
logger Profile
profile String
hi_file_path ModIface
new_iface
= do Bool -> String -> IO ()
createDirectoryIfMissing Bool
True (String -> String
takeDirectory String
hi_file_path)
let printer :: TraceBinIFace
printer = (SDoc -> IO ()) -> TraceBinIFace
TraceBinIFace (Logger -> Int -> SDoc -> IO ()
debugTraceMsg Logger
logger Int
3)
Profile -> TraceBinIFace -> String -> ModIface -> IO ()
writeBinIface Profile
profile TraceBinIFace
printer String
hi_file_path ModIface
new_iface
readIface
:: DynFlags
-> NameCache
-> Module
-> FilePath
-> IO (MaybeErr SDoc ModIface)
readIface :: DynFlags
-> NameCache -> Module -> String -> IO (MaybeErr SDoc ModIface)
readIface DynFlags
dflags NameCache
name_cache Module
wanted_mod String
file_path = do
let profile :: Profile
profile = DynFlags -> Profile
targetProfile DynFlags
dflags
Either SomeException ModIface
res <- forall a. IO a -> IO (Either SomeException a)
tryMost forall a b. (a -> b) -> a -> b
$ Profile
-> NameCache
-> CheckHiWay
-> TraceBinIFace
-> String
-> IO ModIface
readBinIface Profile
profile NameCache
name_cache CheckHiWay
CheckHiWay TraceBinIFace
QuietBinIFace String
file_path
case Either SomeException ModIface
res of
Right ModIface
iface
| Module
wanted_mod forall a. Eq a => a -> a -> Bool
== Module
actual_mod
-> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. val -> MaybeErr err val
Succeeded ModIface
iface)
| Bool
otherwise -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed SDoc
err)
where
actual_mod :: Module
actual_mod = forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface
err :: SDoc
err = Module -> Module -> SDoc
hiModuleNameMismatchWarn Module
wanted_mod Module
actual_mod
Left SomeException
exn -> forall (m :: * -> *) a. Monad m => a -> m a
return (forall err val. err -> MaybeErr err val
Failed (String -> SDoc
text (forall e. Exception e => e -> String
showException SomeException
exn)))
ghcPrimIface :: ModIface
ghcPrimIface :: ModIface
ghcPrimIface
= ModIface
empty_iface {
mi_exports :: [IfaceExport]
mi_exports = [IfaceExport]
ghcPrimExports,
mi_decls :: [IfaceDeclExts 'ModIfaceFinal]
mi_decls = [],
mi_fixities :: [(OccName, Fixity)]
mi_fixities = [(OccName, Fixity)]
fixities,
mi_final_exts :: IfaceBackendExts 'ModIfaceFinal
mi_final_exts = (forall (phase :: ModIfacePhase).
ModIface_ phase -> IfaceBackendExts phase
mi_final_exts ModIface
empty_iface){ mi_fix_fn :: OccName -> Maybe Fixity
mi_fix_fn = [(OccName, Fixity)] -> OccName -> Maybe Fixity
mkIfaceFixCache [(OccName, Fixity)]
fixities },
mi_docs :: Maybe Docs
mi_docs = forall a. a -> Maybe a
Just Docs
ghcPrimDeclDocs
}
where
empty_iface :: ModIface
empty_iface = Module -> ModIface
emptyFullModIface Module
gHC_PRIM
fixities :: [(OccName, Fixity)]
fixities = (forall a. NamedThing a => a -> OccName
getOccName Id
seqId, SourceText -> Int -> FixityDirection -> Fixity
Fixity SourceText
NoSourceText Int
0 FixityDirection
InfixR)
forall a. a -> [a] -> [a]
: forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe PrimOp -> Maybe (OccName, Fixity)
mkFixity [PrimOp]
allThePrimOps
mkFixity :: PrimOp -> Maybe (OccName, Fixity)
mkFixity PrimOp
op = (,) (PrimOp -> OccName
primOpOcc PrimOp
op) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PrimOp -> Maybe Fixity
primOpFixity PrimOp
op
ifaceStats :: ExternalPackageState -> SDoc
ifaceStats :: ExternalPackageState -> SDoc
ifaceStats ExternalPackageState
eps
= [SDoc] -> SDoc
hcat [String -> SDoc
text String
"Renamer stats: ", SDoc
msg]
where
stats :: EpsStats
stats = ExternalPackageState -> EpsStats
eps_stats ExternalPackageState
eps
msg :: SDoc
msg = [SDoc] -> SDoc
vcat
[Int -> SDoc
int (EpsStats -> Int
n_ifaces_in EpsStats
stats) SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"interfaces read",
[SDoc] -> SDoc
hsep [ Int -> SDoc
int (EpsStats -> Int
n_decls_out EpsStats
stats), String -> SDoc
text String
"type/class/variable imported, out of",
Int -> SDoc
int (EpsStats -> Int
n_decls_in EpsStats
stats), String -> SDoc
text String
"read"],
[SDoc] -> SDoc
hsep [ Int -> SDoc
int (EpsStats -> Int
n_insts_out EpsStats
stats), String -> SDoc
text String
"instance decls imported, out of",
Int -> SDoc
int (EpsStats -> Int
n_insts_in EpsStats
stats), String -> SDoc
text String
"read"],
[SDoc] -> SDoc
hsep [ Int -> SDoc
int (EpsStats -> Int
n_rules_out EpsStats
stats), String -> SDoc
text String
"rule decls imported, out of",
Int -> SDoc
int (EpsStats -> Int
n_rules_in EpsStats
stats), String -> SDoc
text String
"read"]
]
showIface :: Logger -> DynFlags -> UnitState -> NameCache -> FilePath -> IO ()
showIface :: Logger -> DynFlags -> UnitState -> NameCache -> String -> IO ()
showIface Logger
logger DynFlags
dflags UnitState
unit_state NameCache
name_cache String
filename = do
let profile :: Profile
profile = DynFlags -> Profile
targetProfile DynFlags
dflags
printer :: SDoc -> IO ()
printer = Logger -> MessageClass -> SrcSpan -> SDoc -> IO ()
logMsg Logger
logger MessageClass
MCOutput SrcSpan
noSrcSpan forall b c a. (b -> c) -> (a -> b) -> a -> c
. PprStyle -> SDoc -> SDoc
withPprStyle PprStyle
defaultDumpStyle
ModIface
iface <- Profile
-> NameCache
-> CheckHiWay
-> TraceBinIFace
-> String
-> IO ModIface
readBinIface Profile
profile NameCache
name_cache CheckHiWay
IgnoreHiWay ((SDoc -> IO ()) -> TraceBinIFace
TraceBinIFace SDoc -> IO ()
printer) String
filename
let
qualifyImportedNames :: Module -> OccName -> QualifyName
qualifyImportedNames Module
mod OccName
_
| Module
mod forall a. Eq a => a -> a -> Bool
== forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface = QualifyName
NameUnqual
| Bool
otherwise = QualifyName
NameNotInScope1
print_unqual :: PrintUnqualified
print_unqual = (Module -> OccName -> QualifyName)
-> (Module -> Bool) -> QueryQualifyPackage -> PrintUnqualified
QueryQualify Module -> OccName -> QualifyName
qualifyImportedNames
Module -> Bool
neverQualifyModules
QueryQualifyPackage
neverQualifyPackages
Logger -> MessageClass -> SrcSpan -> SDoc -> IO ()
logMsg Logger
logger MessageClass
MCDump SrcSpan
noSrcSpan
forall a b. (a -> b) -> a -> b
$ PprStyle -> SDoc -> SDoc
withPprStyle (PrintUnqualified -> PprStyle
mkDumpStyle PrintUnqualified
print_unqual)
forall a b. (a -> b) -> a -> b
$ UnitState -> ModIface -> SDoc
pprModIface UnitState
unit_state ModIface
iface
pprModIfaceSimple :: UnitState -> ModIface -> SDoc
pprModIfaceSimple :: UnitState -> ModIface -> SDoc
pprModIfaceSimple UnitState
unit_state ModIface
iface =
forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface)
SDoc -> SDoc -> SDoc
$$ UnitState -> Dependencies -> SDoc
pprDeps UnitState
unit_state (forall (phase :: ModIfacePhase). ModIface_ phase -> Dependencies
mi_deps ModIface
iface)
SDoc -> SDoc -> SDoc
$$ Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map IfaceExport -> SDoc
pprExport (forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceExport]
mi_exports ModIface
iface)))
pprModIface :: UnitState -> ModIface -> SDoc
pprModIface :: UnitState -> ModIface -> SDoc
pprModIface UnitState
unit_state iface :: ModIface
iface@ModIface{ mi_final_exts :: forall (phase :: ModIfacePhase).
ModIface_ phase -> IfaceBackendExts phase
mi_final_exts = IfaceBackendExts 'ModIfaceFinal
exts }
= [SDoc] -> SDoc
vcat [ String -> SDoc
text String
"interface"
SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface) SDoc -> SDoc -> SDoc
<+> HscSource -> SDoc
pp_hsc_src (forall (phase :: ModIfacePhase). ModIface_ phase -> HscSource
mi_hsc_src ModIface
iface)
SDoc -> SDoc -> SDoc
<+> (if ModIfaceBackend -> Bool
mi_orphan IfaceBackendExts 'ModIfaceFinal
exts then String -> SDoc
text String
"[orphan module]" else SDoc
Outputable.empty)
SDoc -> SDoc -> SDoc
<+> (if ModIfaceBackend -> Bool
mi_finsts IfaceBackendExts 'ModIfaceFinal
exts then String -> SDoc
text String
"[family instance module]" else SDoc
Outputable.empty)
SDoc -> SDoc -> SDoc
<+> (if forall (phase :: ModIfacePhase). ModIface_ phase -> Bool
mi_hpc ModIface
iface then String -> SDoc
text String
"[hpc]" else SDoc
Outputable.empty)
SDoc -> SDoc -> SDoc
<+> Integer -> SDoc
integer Integer
hiVersion
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"interface hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_iface_hash IfaceBackendExts 'ModIfaceFinal
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"ABI hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_mod_hash IfaceBackendExts 'ModIfaceFinal
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"export-list hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_exp_hash IfaceBackendExts 'ModIfaceFinal
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"orphan hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_orphan_hash IfaceBackendExts 'ModIfaceFinal
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"flag hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_flag_hash IfaceBackendExts 'ModIfaceFinal
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"opt_hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_opt_hash IfaceBackendExts 'ModIfaceFinal
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"hpc_hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_hpc_hash IfaceBackendExts 'ModIfaceFinal
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"plugin_hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_plugin_hash IfaceBackendExts 'ModIfaceFinal
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"src_hash:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> Fingerprint
mi_src_hash ModIface
iface))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"sig of:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> Maybe Module
mi_sig_of ModIface
iface))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"used TH splices:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> Bool
mi_used_th ModIface
iface))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
text String
"where")
, String -> SDoc
text String
"exports:"
, Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map IfaceExport -> SDoc
pprExport (forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceExport]
mi_exports ModIface
iface)))
, UnitState -> Dependencies -> SDoc
pprDeps UnitState
unit_state (forall (phase :: ModIfacePhase). ModIface_ phase -> Dependencies
mi_deps ModIface
iface)
, [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map Usage -> SDoc
pprUsage (forall (phase :: ModIfacePhase). ModIface_ phase -> [Usage]
mi_usages ModIface
iface))
, [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map IfaceAnnotation -> SDoc
pprIfaceAnnotation (forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceAnnotation]
mi_anns ModIface
iface))
, [(OccName, Fixity)] -> SDoc
pprFixities (forall (phase :: ModIfacePhase).
ModIface_ phase -> [(OccName, Fixity)]
mi_fixities ModIface
iface)
, [SDoc] -> SDoc
vcat [forall a. Outputable a => a -> SDoc
ppr Fingerprint
ver SDoc -> SDoc -> SDoc
$$ Int -> SDoc -> SDoc
nest Int
2 (forall a. Outputable a => a -> SDoc
ppr IfaceDecl
decl) | (Fingerprint
ver,IfaceDecl
decl) <- forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls ModIface
iface]
, [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceClsInst]
mi_insts ModIface
iface))
, [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceFamInst]
mi_fam_insts ModIface
iface))
, [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceRule]
mi_rules ModIface
iface))
, forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> Warnings GhcRn
mi_warns ModIface
iface)
, IfaceTrustInfo -> SDoc
pprTrustInfo (forall (phase :: ModIfacePhase). ModIface_ phase -> IfaceTrustInfo
mi_trust ModIface
iface)
, Bool -> SDoc
pprTrustPkg (forall (phase :: ModIfacePhase). ModIface_ phase -> Bool
mi_trust_pkg ModIface
iface)
, [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceCompleteMatch]
mi_complete_matches ModIface
iface))
, String -> SDoc
text String
"docs:" SDoc -> SDoc -> SDoc
$$ Int -> SDoc -> SDoc
nest Int
2 (forall a. Outputable a => a -> SDoc
ppr (forall (phase :: ModIfacePhase). ModIface_ phase -> Maybe Docs
mi_docs ModIface
iface))
, String -> SDoc
text String
"extensible fields:" SDoc -> SDoc -> SDoc
$$ Int -> SDoc -> SDoc
nest Int
2 (ExtensibleFields -> SDoc
pprExtensibleFields (forall (phase :: ModIfacePhase).
ModIface_ phase -> ExtensibleFields
mi_ext_fields ModIface
iface))
]
where
pp_hsc_src :: HscSource -> SDoc
pp_hsc_src HscSource
HsBootFile = String -> SDoc
text String
"[boot]"
pp_hsc_src HscSource
HsigFile = String -> SDoc
text String
"[hsig]"
pp_hsc_src HscSource
HsSrcFile = SDoc
Outputable.empty
pprExport :: IfaceExport -> SDoc
pprExport :: IfaceExport -> SDoc
pprExport (Avail GreName
n) = forall a. Outputable a => a -> SDoc
ppr GreName
n
pprExport (AvailTC Name
_ []) = SDoc
Outputable.empty
pprExport avail :: IfaceExport
avail@(AvailTC Name
n [GreName]
_) =
forall a. Outputable a => a -> SDoc
ppr Name
n SDoc -> SDoc -> SDoc
<> SDoc
mark SDoc -> SDoc -> SDoc
<> forall {a}. Outputable a => [a] -> SDoc
pp_export (IfaceExport -> [GreName]
availSubordinateGreNames IfaceExport
avail)
where
mark :: SDoc
mark | IfaceExport -> Bool
availExportsDecl IfaceExport
avail = SDoc
Outputable.empty
| Bool
otherwise = SDoc
vbar
pp_export :: [a] -> SDoc
pp_export [] = SDoc
Outputable.empty
pp_export [a]
names = SDoc -> SDoc
braces ([SDoc] -> SDoc
hsep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [a]
names))
pprUsage :: Usage -> SDoc
pprUsage :: Usage -> SDoc
pprUsage usage :: Usage
usage@UsagePackageModule{}
= forall a. Outputable a => Usage -> (Usage -> a) -> SDoc
pprUsageImport Usage
usage Usage -> Module
usg_mod
pprUsage usage :: Usage
usage@UsageHomeModule{}
= forall a. Outputable a => Usage -> (Usage -> a) -> SDoc
pprUsageImport Usage
usage (\Usage
u -> forall u. u -> ModuleName -> GenModule u
mkModule (Usage -> UnitId
usg_unit_id Usage
u) (Usage -> ModuleName
usg_mod_name Usage
u)) SDoc -> SDoc -> SDoc
$$
Int -> SDoc -> SDoc
nest Int
2 (
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SDoc
Outputable.empty (\Fingerprint
v -> String -> SDoc
text String
"exports: " SDoc -> SDoc -> SDoc
<> forall a. Outputable a => a -> SDoc
ppr Fingerprint
v) (Usage -> Maybe Fingerprint
usg_exports Usage
usage) SDoc -> SDoc -> SDoc
$$
[SDoc] -> SDoc
vcat [ forall a. Outputable a => a -> SDoc
ppr OccName
n SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Fingerprint
v | (OccName
n,Fingerprint
v) <- Usage -> [(OccName, Fingerprint)]
usg_entities Usage
usage ]
)
pprUsage usage :: Usage
usage@UsageFile{}
= [SDoc] -> SDoc
hsep [String -> SDoc
text String
"addDependentFile",
SDoc -> SDoc
doubleQuotes (String -> SDoc
text (Usage -> String
usg_file_path Usage
usage)),
forall a. Outputable a => a -> SDoc
ppr (Usage -> Fingerprint
usg_file_hash Usage
usage)]
pprUsage usage :: Usage
usage@UsageMergedRequirement{}
= [SDoc] -> SDoc
hsep [String -> SDoc
text String
"merged", forall a. Outputable a => a -> SDoc
ppr (Usage -> Module
usg_mod Usage
usage), forall a. Outputable a => a -> SDoc
ppr (Usage -> Fingerprint
usg_mod_hash Usage
usage)]
pprUsage usage :: Usage
usage@UsageHomeModuleInterface{}
= [SDoc] -> SDoc
hsep [String -> SDoc
text String
"implementation", forall a. Outputable a => a -> SDoc
ppr (Usage -> ModuleName
usg_mod_name Usage
usage)
, forall a. Outputable a => a -> SDoc
ppr (Usage -> UnitId
usg_unit_id Usage
usage)
, forall a. Outputable a => a -> SDoc
ppr (Usage -> Fingerprint
usg_iface_hash Usage
usage)]
pprUsageImport :: Outputable a => Usage -> (Usage -> a) -> SDoc
pprUsageImport :: forall a. Outputable a => Usage -> (Usage -> a) -> SDoc
pprUsageImport Usage
usage Usage -> a
usg_mod'
= [SDoc] -> SDoc
hsep [String -> SDoc
text String
"import", SDoc
safe, forall a. Outputable a => a -> SDoc
ppr (Usage -> a
usg_mod' Usage
usage),
forall a. Outputable a => a -> SDoc
ppr (Usage -> Fingerprint
usg_mod_hash Usage
usage)]
where
safe :: SDoc
safe | Usage -> Bool
usg_safe Usage
usage = String -> SDoc
text String
"safe"
| Bool
otherwise = String -> SDoc
text String
" -/ "
pprFixities :: [(OccName, Fixity)] -> SDoc
pprFixities :: [(OccName, Fixity)] -> SDoc
pprFixities [] = SDoc
Outputable.empty
pprFixities [(OccName, Fixity)]
fixes = String -> SDoc
text String
"fixities" SDoc -> SDoc -> SDoc
<+> forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas forall {a} {a}. (Outputable a, Outputable a) => (a, a) -> SDoc
pprFix [(OccName, Fixity)]
fixes
where
pprFix :: (a, a) -> SDoc
pprFix (a
occ,a
fix) = forall a. Outputable a => a -> SDoc
ppr a
fix SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr a
occ
pprTrustInfo :: IfaceTrustInfo -> SDoc
pprTrustInfo :: IfaceTrustInfo -> SDoc
pprTrustInfo IfaceTrustInfo
trust = String -> SDoc
text String
"trusted:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceTrustInfo
trust
pprTrustPkg :: Bool -> SDoc
pprTrustPkg :: Bool -> SDoc
pprTrustPkg Bool
tpkg = String -> SDoc
text String
"require own pkg trusted:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Bool
tpkg
instance Outputable (Warnings pass) where
ppr :: Warnings pass -> SDoc
ppr = forall pass. Warnings pass -> SDoc
pprWarns
pprWarns :: Warnings pass -> SDoc
pprWarns :: forall pass. Warnings pass -> SDoc
pprWarns Warnings pass
NoWarnings = SDoc
Outputable.empty
pprWarns (WarnAll WarningTxt pass
txt) = String -> SDoc
text String
"Warn all" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr WarningTxt pass
txt
pprWarns (WarnSome [(OccName, WarningTxt pass)]
prs) = String -> SDoc
text String
"Warnings:"
SDoc -> SDoc -> SDoc
<+> [SDoc] -> SDoc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall {a} {a}. (Outputable a, Outputable a) => (a, a) -> SDoc
pprWarning [(OccName, WarningTxt pass)]
prs)
where pprWarning :: (a, a) -> SDoc
pprWarning (a
name, a
txt) = forall a. Outputable a => a -> SDoc
ppr a
name SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr a
txt
pprIfaceAnnotation :: IfaceAnnotation -> SDoc
pprIfaceAnnotation :: IfaceAnnotation -> SDoc
pprIfaceAnnotation (IfaceAnnotation { ifAnnotatedTarget :: IfaceAnnotation -> IfaceAnnTarget
ifAnnotatedTarget = IfaceAnnTarget
target, ifAnnotatedValue :: IfaceAnnotation -> AnnPayload
ifAnnotatedValue = AnnPayload
serialized })
= forall a. Outputable a => a -> SDoc
ppr IfaceAnnTarget
target SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"annotated by" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr AnnPayload
serialized
pprExtensibleFields :: ExtensibleFields -> SDoc
pprExtensibleFields :: ExtensibleFields -> SDoc
pprExtensibleFields (ExtensibleFields Map String BinData
fs) = [SDoc] -> SDoc
vcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (String, BinData) -> SDoc
pprField forall a b. (a -> b) -> a -> b
$ forall k a. Map k a -> [(k, a)]
toList Map String BinData
fs
where
pprField :: (String, BinData) -> SDoc
pprField (String
name, (BinData Int
size BinArray
_data)) = String -> SDoc
text String
name SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"-" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Int
size SDoc -> SDoc -> SDoc
<+> String -> SDoc
text String
"bytes"