{-# 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.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 <- TcRnIf TcGblEnv TcLclEnv HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
; Maybe TyThing
mb_thing <- IO (Maybe TyThing) -> IOEnv (Env TcGblEnv TcLclEnv) (Maybe TyThing)
forall a. IO a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 -> MaybeErr SDoc TyThing -> TcM (MaybeErr SDoc TyThing)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TyThing -> MaybeErr SDoc TyThing
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 { Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (TyThing -> Bool
needWiredInHomeIface TyThing
thing)
(IfG () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. IfG a -> TcRn a
initIfaceTcRn (Name -> IfG ()
forall lcl. Name -> IfM lcl ()
loadWiredInHomeIface Name
name))
; MaybeErr SDoc TyThing -> TcM (MaybeErr SDoc TyThing)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (TyThing -> MaybeErr SDoc TyThing
forall err val. val -> MaybeErr err val
Succeeded TyThing
thing) }
| Bool
otherwise
= IfG (MaybeErr SDoc TyThing) -> TcM (MaybeErr SDoc TyThing)
forall a. IfG a -> TcRn a
initIfaceTcRn (Name -> IfG (MaybeErr SDoc TyThing)
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
= Bool
-> IfM lcl (MaybeErr SDoc TyThing)
-> IfM lcl (MaybeErr SDoc TyThing)
forall a. HasCallStack => Bool -> a -> a
assert (Bool -> Bool
not (Name -> Bool
isWiredInName Name
name)) (IfM lcl (MaybeErr SDoc TyThing)
-> IfM lcl (MaybeErr SDoc TyThing))
-> IfM lcl (MaybeErr SDoc TyThing)
-> IfM lcl (MaybeErr SDoc TyThing)
forall a b. (a -> b) -> a -> b
$
do { Logger
logger <- IOEnv (Env IfGblEnv lcl) Logger
forall (m :: * -> *). HasLogger m => m Logger
getLogger
; IO () -> IOEnv (Env IfGblEnv lcl) ()
forall a. IO a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> IOEnv (Env IfGblEnv lcl) ())
-> IO () -> IOEnv (Env IfGblEnv lcl) ()
forall a b. (a -> b) -> a -> b
$ Logger -> SDoc -> IO ()
trace_if Logger
logger SDoc
nd_doc
; MaybeErr SDoc ModIface
mb_iface <- Bool
-> SDoc
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface)
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface)
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Name -> Bool
isExternalName Name
name) (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) (IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface)
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface))
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface)
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface)
forall a b. (a -> b) -> a -> b
$
SDoc
-> Module
-> WhereFrom
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface)
forall lcl.
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
loadInterface SDoc
nd_doc ((() :: Constraint) => Name -> Module
Name -> Module
nameModule Name
name) WhereFrom
ImportBySystem
; case MaybeErr SDoc ModIface
mb_iface of {
Failed SDoc
err_msg -> MaybeErr SDoc TyThing -> IfM lcl (MaybeErr SDoc TyThing)
forall a. a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc TyThing
forall err val. err -> MaybeErr err val
Failed SDoc
err_msg) ;
Succeeded ModIface
_ -> do
{ ExternalPackageState
eps <- TcRnIf IfGblEnv lcl ExternalPackageState
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 -> MaybeErr SDoc TyThing -> IfM lcl (MaybeErr SDoc TyThing)
forall a. a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (MaybeErr SDoc TyThing -> IfM lcl (MaybeErr SDoc TyThing))
-> MaybeErr SDoc TyThing -> IfM lcl (MaybeErr SDoc TyThing)
forall a b. (a -> b) -> a -> b
$ TyThing -> MaybeErr SDoc TyThing
forall err val. val -> MaybeErr err val
Succeeded TyThing
thing
Maybe TyThing
Nothing -> let doc :: SDoc
doc = SDoc -> SDoc
forall doc. IsOutput doc => doc -> doc
whenPprDebug (ExternalPackageState -> SDoc
found_things_msg ExternalPackageState
eps SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
forall doc. IsOutput doc => doc
empty)
SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
not_found_msg
in MaybeErr SDoc TyThing -> IfM lcl (MaybeErr SDoc TyThing)
forall a. a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (MaybeErr SDoc TyThing -> IfM lcl (MaybeErr SDoc TyThing))
-> MaybeErr SDoc TyThing -> IfM lcl (MaybeErr SDoc TyThing)
forall a b. (a -> b) -> a -> b
$ SDoc -> MaybeErr SDoc TyThing
forall err val. err -> MaybeErr err val
Failed SDoc
doc
}}}
where
nd_doc :: SDoc
nd_doc = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Need decl for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name
not_found_msg :: SDoc
not_found_msg = SDoc -> Int -> SDoc -> SDoc
hang (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Can't find interface-file declaration for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
NameSpace -> SDoc
pprNameSpace (Name -> NameSpace
nameNameSpace Name
name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name)
Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Probable cause: bug in .hi-boot file, or inconsistent .hi file",
String -> SDoc
forall doc. IsLine doc => String -> doc
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
forall doc. IsLine doc => String -> doc
text String
"Found the following declarations in" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr ((() :: Constraint) => Name -> Module
Name -> Module
nameModule Name
name) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
colon)
Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((TyThing -> SDoc) -> [TyThing] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map TyThing -> SDoc
forall a. Outputable a => a -> SDoc
ppr ([TyThing] -> [SDoc]) -> [TyThing] -> [SDoc]
forall a b. (a -> b) -> a -> b
$ (TyThing -> Bool) -> [TyThing] -> [TyThing]
forall a. (a -> Bool) -> [a] -> [a]
filter TyThing -> Bool
is_interesting ([TyThing] -> [TyThing]) -> [TyThing] -> [TyThing]
forall a b. (a -> b) -> a -> b
$ TypeEnv -> [TyThing]
forall a. NameEnv a -> [a]
nonDetNameEnvElts (TypeEnv -> [TyThing]) -> TypeEnv -> [TyThing]
forall a b. (a -> b) -> a -> b
$ ExternalPackageState -> TypeEnv
eps_PTE ExternalPackageState
eps))
where
is_interesting :: TyThing -> Bool
is_interesting TyThing
thing = (() :: Constraint) => Name -> Module
Name -> Module
nameModule Name
name Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== (() :: Constraint) => Name -> Module
Name -> Module
nameModule (TyThing -> Name
forall a. NamedThing a => a -> Name
getName TyThing
thing)
checkWiredInTyCon :: TyCon -> TcM ()
checkWiredInTyCon :: TyCon -> IOEnv (Env TcGblEnv TcLclEnv) ()
checkWiredInTyCon TyCon
tc
| Bool -> Bool
not (Name -> Bool
isWiredInName Name
tc_name)
= () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= do { Module
mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; Logger
logger <- IOEnv (Env TcGblEnv TcLclEnv) Logger
forall (m :: * -> *). HasLogger m => m Logger
getLogger
; IO () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. IO a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IO () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ Logger -> SDoc -> IO ()
trace_if Logger
logger (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"checkWiredInTyCon" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
tc_name SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
; Bool
-> (Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. HasCallStack => Bool -> a -> a
assert (Name -> Bool
isExternalName Name
tc_name )
Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Module
mod Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
/= (() :: Constraint) => Name -> Module
Name -> Module
nameModule Name
tc_name)
(IfG () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. IfG a -> TcRn a
initIfaceTcRn (Name -> IfG ()
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 = TyThing -> Name
forall a. NamedThing a => a -> Name
getName TyThing
thing
; Bool -> SDoc -> IfL () -> IfL ()
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Name -> Bool
isExternalName Name
name) (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) (IfL () -> IfL ()) -> IfL () -> IfL ()
forall a b. (a -> b) -> a -> b
$
Bool -> IfL () -> IfL ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (TyThing -> Bool
needWiredInHomeIface TyThing
thing Bool -> Bool -> Bool
&& Module
mod Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
/= (() :: Constraint) => Name -> Module
Name -> Module
nameModule Name
name)
(Name -> IfL ()
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 -> TcRnMessage -> RnM ModIface
forall a. TcRnMessage -> TcM a
failWithTc (DiagnosticMessage -> TcRnMessage
forall a.
(Diagnostic a, Typeable a, DiagnosticOpts a ~ NoDiagnosticOpts) =>
a -> TcRnMessage
mkTcRnUnknownMessage (DiagnosticMessage -> TcRnMessage)
-> DiagnosticMessage -> TcRnMessage
forall a b. (a -> b) -> a -> b
$ [GhcHint] -> SDoc -> DiagnosticMessage
mkPlainError [GhcHint]
noHints SDoc
err)
Succeeded ModIface
iface -> ModIface -> RnM ModIface
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
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 <- TcRnIf TcGblEnv TcLclEnv HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
FindResult
res <- IO FindResult -> IOEnv (Env TcGblEnv TcLclEnv) FindResult
forall a. IO a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO FindResult -> IOEnv (Env TcGblEnv TcLclEnv) FindResult)
-> IO FindResult -> IOEnv (Env TcGblEnv TcLclEnv) FindResult
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 -> IfG (MaybeErr SDoc ModIface) -> RnM (MaybeErr SDoc ModIface)
forall a. IfG a -> TcRn a
initIfaceTcRn (IfG (MaybeErr SDoc ModIface) -> RnM (MaybeErr SDoc ModIface))
-> IfG (MaybeErr SDoc ModIface) -> RnM (MaybeErr SDoc ModIface)
forall a b. (a -> b) -> a -> b
$ SDoc -> Module -> WhereFrom -> IfG (MaybeErr SDoc ModIface)
forall lcl.
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
loadInterface SDoc
doc Module
mod (IsBootInterface -> WhereFrom
ImportByUser IsBootInterface
want_boot)
FindResult
err -> MaybeErr SDoc ModIface -> RnM (MaybeErr SDoc ModIface)
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc ModIface
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 = IfG ModIface -> RnM ModIface
forall a. IfG a -> TcRn a
initIfaceTcRn (SDoc -> Module -> IfG ModIface
forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface SDoc
doc Module
mod)
loadModuleInterfaces :: SDoc -> [Module] -> TcM ()
loadModuleInterfaces :: SDoc -> [Module] -> IOEnv (Env TcGblEnv TcLclEnv) ()
loadModuleInterfaces SDoc
doc [Module]
mods
| [Module] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Module]
mods = () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. a -> IOEnv (Env TcGblEnv TcLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = IfG () -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a. IfG a -> TcRn a
initIfaceTcRn ((Module -> IfG ModIface) -> [Module] -> IfG ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Module -> IfG ModIface
load [Module]
mods)
where
load :: Module -> IfG ModIface
load Module
mod = SDoc -> Module -> IfG ModIface
forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface (SDoc
doc SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens (Module -> SDoc
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 { Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugIsOn (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$
do { Module
this_mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
; Bool -> SDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr (Bool -> Bool
not (Module -> Name -> Bool
nameIsLocalOrFrom Module
this_mod Name
name)) (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens SDoc
doc) }
; Bool -> SDoc -> RnM ModIface -> RnM ModIface
forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (Name -> Bool
isExternalName Name
name) (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
name) (RnM ModIface -> RnM ModIface) -> RnM ModIface -> RnM ModIface
forall a b. (a -> b) -> a -> b
$
IfG ModIface -> RnM ModIface
forall a. IfG a -> TcRn a
initIfaceTcRn (IfG ModIface -> RnM ModIface) -> IfG ModIface -> RnM ModIface
forall a b. (a -> b) -> a -> b
$ SDoc -> Module -> IfG ModIface
forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface SDoc
doc ((() :: Constraint) => Name -> Module
Name -> Module
nameModule Name
name) }
loadInterfaceForModule :: SDoc -> Module -> TcRn ModIface
loadInterfaceForModule :: SDoc -> Module -> RnM ModIface
loadInterfaceForModule SDoc
doc Module
m
= do
Bool
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debugIsOn (IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ())
-> IOEnv (Env TcGblEnv TcLclEnv) ()
-> IOEnv (Env TcGblEnv TcLclEnv) ()
forall a b. (a -> b) -> a -> b
$ do
Module
this_mod <- IOEnv (Env TcGblEnv TcLclEnv) Module
forall (m :: * -> *). HasModule m => m Module
getModule
Bool -> SDoc -> IOEnv (Env TcGblEnv TcLclEnv) ()
forall (m :: * -> *).
(HasCallStack, Applicative m) =>
Bool -> SDoc -> m ()
massertPpr (Module
this_mod Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
/= Module
m) (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
m SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
parens SDoc
doc)
IfG ModIface -> RnM ModIface
forall a. IfG a -> TcRn a
initIfaceTcRn (IfG ModIface -> RnM ModIface) -> IfG ModIface -> RnM ModIface
forall a b. (a -> b) -> a -> b
$ SDoc -> Module -> IfG ModIface
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
= Bool -> IfM lcl () -> IfM lcl ()
forall a. HasCallStack => Bool -> a -> a
assert (Name -> Bool
isWiredInName Name
name) (IfM lcl () -> IfM lcl ()) -> IfM lcl () -> IfM lcl ()
forall a b. (a -> b) -> a -> b
$
do ModIface
_ <- SDoc -> Module -> IfM lcl ModIface
forall lcl. SDoc -> Module -> IfM lcl ModIface
loadSysInterface SDoc
doc ((() :: Constraint) => Name -> Module
Name -> Module
nameModule Name
name); () -> IfM lcl ()
forall a. a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
doc :: SDoc
doc = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Need home interface for wired-in thing" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Name -> 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 = SDoc -> Module -> WhereFrom -> IfM lcl ModIface
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
= SDoc -> Module -> WhereFrom -> IfM lcl ModIface
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
= SDoc -> Module -> WhereFrom -> IfM lcl ModIface
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 <- IOEnv (Env IfGblEnv lcl) DynFlags
forall (m :: * -> *). HasDynFlags m => m DynFlags
getDynFlags
let ctx :: SDocContext
ctx = DynFlags -> PprStyle -> SDocContext
initSDocContext DynFlags
dflags PprStyle
defaultUserStyle
SDocContext
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface)
-> IfM lcl ModIface
forall (m :: * -> *) a.
MonadIO m =>
SDocContext -> m (MaybeErr SDoc a) -> m a
withException SDocContext
ctx (SDoc
-> Module
-> WhereFrom
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc ModIface)
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
| Module -> Bool
forall u. GenModule (GenUnit u) -> Bool
isHoleModule Module
mod
= do HscEnv
hsc_env <- TcRnIf IfGblEnv lcl HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
let home_unit :: HomeUnit
home_unit = HscEnv -> HomeUnit
hsc_home_unit HscEnv
hsc_env
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
forall lcl.
SDoc -> Module -> WhereFrom -> IfM lcl (MaybeErr SDoc ModIface)
loadInterface SDoc
doc_str (HomeUnit -> ModuleName -> Module
mkHomeModule HomeUnit
home_unit (Module -> ModuleName
forall unit. GenModule unit -> ModuleName
moduleName Module
mod)) WhereFrom
from
| Bool
otherwise
= do
Logger
logger <- IOEnv (Env IfGblEnv lcl) Logger
forall (m :: * -> *). HasLogger m => m Logger
getLogger
Logger
-> SDoc
-> (MaybeErr SDoc ModIface -> ())
-> IfM lcl (MaybeErr SDoc ModIface)
-> IfM lcl (MaybeErr SDoc ModIface)
forall (m :: * -> *) a.
MonadIO m =>
Logger -> SDoc -> (a -> ()) -> m a -> m a
withTimingSilent Logger
logger (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"loading interface") (() -> MaybeErr SDoc ModIface -> ()
forall a. a -> MaybeErr SDoc ModIface -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) (IfM lcl (MaybeErr SDoc ModIface)
-> IfM lcl (MaybeErr SDoc ModIface))
-> IfM lcl (MaybeErr SDoc ModIface)
-> IfM lcl (MaybeErr SDoc ModIface)
forall a b. (a -> b) -> a -> b
$ do
{
(ExternalPackageState
eps,HomeUnitGraph
hug) <- TcRnIf IfGblEnv lcl (ExternalPackageState, HomeUnitGraph)
forall gbl lcl.
TcRnIf gbl lcl (ExternalPackageState, HomeUnitGraph)
getEpsAndHug
; IfGblEnv
gbl_env <- TcRnIf IfGblEnv lcl IfGblEnv
forall gbl lcl. TcRnIf gbl lcl gbl
getGblEnv
; IO () -> IOEnv (Env IfGblEnv lcl) ()
forall a. IO a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> IOEnv (Env IfGblEnv lcl) ())
-> IO () -> IOEnv (Env IfGblEnv lcl) ()
forall a b. (a -> b) -> a -> b
$ Logger -> SDoc -> IO ()
trace_if Logger
logger (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Considering whether to load" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WhereFrom -> SDoc
forall a. Outputable a => a -> SDoc
ppr WhereFrom
from)
; HscEnv
hsc_env <- TcRnIf IfGblEnv lcl HscEnv
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
-> MaybeErr SDoc ModIface -> IfM lcl (MaybeErr SDoc ModIface)
forall a. a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ModIface -> MaybeErr SDoc ModIface
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 -> MaybeErr SDoc (ModIface, String)
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc (ModIface, String))
forall a. a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc (ModIface, String)
forall err val. err -> MaybeErr err val
Failed SDoc
err)
Succeeded IsBootInterface
hi_boot_file -> do
HscEnv
hsc_env <- TcRnIf IfGblEnv lcl HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
IO (MaybeErr SDoc (ModIface, String))
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc (ModIface, String))
forall a. IO a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (MaybeErr SDoc (ModIface, String))
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc (ModIface, String)))
-> IO (MaybeErr SDoc (ModIface, String))
-> IOEnv (Env IfGblEnv lcl) (MaybeErr SDoc (ModIface, String))
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
; (ExternalPackageState -> ExternalPackageState)
-> IOEnv (Env IfGblEnv lcl) ()
forall gbl lcl.
(ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl ()
updateEps_ ((ExternalPackageState -> ExternalPackageState)
-> IOEnv (Env IfGblEnv lcl) ())
-> (ExternalPackageState -> ExternalPackageState)
-> IOEnv (Env IfGblEnv lcl) ()
forall a b. (a -> b) -> a -> b
$ \ExternalPackageState
eps ->
ExternalPackageState
eps { eps_PIT = extendModuleEnv (eps_PIT eps) (mi_module fake_iface) fake_iface }
; MaybeErr SDoc ModIface -> IfM lcl (MaybeErr SDoc ModIface)
forall a. a -> IOEnv (Env IfGblEnv lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc ModIface
forall err val. err -> MaybeErr err val
Failed SDoc
err) } ;
Succeeded (ModIface
iface, String
loc) ->
let
loc_doc :: SDoc
loc_doc = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
loc
in
Module
-> SDoc
-> IsBootInterface
-> IfL (MaybeErr SDoc ModIface)
-> IfM lcl (MaybeErr SDoc ModIface)
forall a lcl.
Module -> SDoc -> IsBootInterface -> IfL a -> IfM lcl a
initIfaceLcl (ModIface -> Module
forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_semantic_module ModIface
iface) SDoc
loc_doc (ModIface -> IsBootInterface
mi_boot ModIface
iface) (IfL (MaybeErr SDoc ModIface) -> IfM lcl (MaybeErr SDoc ModIface))
-> IfL (MaybeErr SDoc ModIface) -> IfM lcl (MaybeErr SDoc ModIface)
forall a b. (a -> b) -> a -> b
$
IfL (MaybeErr SDoc ModIface) -> IfL (MaybeErr SDoc ModIface)
forall a. IfL a -> IfL a
dontLeakTheHUG (IfL (MaybeErr SDoc ModIface) -> IfL (MaybeErr SDoc ModIface))
-> IfL (MaybeErr SDoc ModIface) -> IfL (MaybeErr SDoc ModIface)
forall a b. (a -> b) -> a -> b
$ do
; Bool -> SDoc -> IfL ()
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 UnitId -> Set UnitId -> Bool
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 Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== Module
gHC_PRIM)
(String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Attempting to load home package interface into the EPS" SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ HomeUnitGraph -> SDoc
forall a. Outputable a => a -> SDoc
ppr HomeUnitGraph
hug SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
doc_str SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> UnitId
moduleUnitId Module
mod))
; Bool
ignore_prags <- GeneralFlag -> TcRnIf IfGblEnv IfLclEnv Bool
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 (ModIface -> [IfaceDeclExts 'ModIfaceFinal]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls ModIface
iface)
; [ClsInst]
new_eps_insts <- (IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst)
-> [IfaceClsInst] -> IOEnv (Env IfGblEnv IfLclEnv) [ClsInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM IfaceClsInst -> IOEnv (Env IfGblEnv IfLclEnv) ClsInst
tcIfaceInst (ModIface -> [IfaceClsInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceClsInst]
mi_insts ModIface
iface)
; [FamInst]
new_eps_fam_insts <- (IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst)
-> [IfaceFamInst] -> IOEnv (Env IfGblEnv IfLclEnv) [FamInst]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM IfaceFamInst -> IOEnv (Env IfGblEnv IfLclEnv) FamInst
tcIfaceFamInst (ModIface -> [IfaceFamInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceFamInst]
mi_fam_insts ModIface
iface)
; [CoreRule]
new_eps_rules <- Bool -> [IfaceRule] -> IfL [CoreRule]
tcIfaceRules Bool
ignore_prags (ModIface -> [IfaceRule]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceRule]
mi_rules ModIface
iface)
; [Annotation]
new_eps_anns <- [IfaceAnnotation] -> IfL [Annotation]
tcIfaceAnnotations (ModIface -> [IfaceAnnotation]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceAnnotation]
mi_anns ModIface
iface)
; [CompleteMatch]
new_eps_complete_matches <- [IfaceCompleteMatch] -> IfL [CompleteMatch]
tcIfaceCompleteMatches (ModIface -> [IfaceCompleteMatch]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceCompleteMatch]
mi_complete_matches ModIface
iface)
; let { final_iface :: ModIface
final_iface = ModIface
iface {
mi_decls = panic "No mi_decls in PIT",
mi_insts = panic "No mi_insts in PIT",
mi_fam_insts = panic "No mi_fam_insts in PIT",
mi_rules = panic "No mi_rules in PIT",
mi_anns = panic "No mi_anns in PIT"
}
}
; let bad_boot :: Bool
bad_boot = ModIface -> IsBootInterface
mi_boot ModIface
iface IsBootInterface -> IsBootInterface -> Bool
forall a. Eq a => a -> a -> Bool
== IsBootInterface
IsBoot
Bool -> Bool -> Bool
&& Maybe (IfG TypeEnv) -> Bool
forall a. Maybe a -> Bool
isJust (KnotVars (IfG TypeEnv) -> Module -> Maybe (IfG TypeEnv)
forall a. KnotVars a -> Module -> Maybe a
lookupKnotVars (IfGblEnv -> KnotVars (IfG TypeEnv)
if_rec_types IfGblEnv
gbl_env) Module
mod)
; Bool -> String -> SDoc -> IfL () -> IfL ()
forall a. HasCallStack => Bool -> String -> SDoc -> a -> a
warnPprTrace Bool
bad_boot String
"loadInterface" (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod) (IfL () -> IfL ()) -> IfL () -> IfL ()
forall a b. (a -> b) -> a -> b
$
(ExternalPackageState -> ExternalPackageState) -> IfL ()
forall gbl lcl.
(ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl ()
updateEps_ ((ExternalPackageState -> ExternalPackageState) -> IfL ())
-> (ExternalPackageState -> ExternalPackageState) -> IfL ()
forall a b. (a -> b) -> a -> b
$ \ ExternalPackageState
eps ->
if Module -> PackageIfaceTable -> Bool
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 = addDeclsToPTE (eps_PTE eps) new_eps_decls }
else
ExternalPackageState
eps {
eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
eps_rule_base = extendRuleBaseList (eps_rule_base eps)
new_eps_rules,
eps_complete_matches
= eps_complete_matches eps ++ new_eps_complete_matches,
eps_inst_env = extendInstEnvList (eps_inst_env eps)
new_eps_insts,
eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
new_eps_fam_insts,
eps_ann_env = extendAnnEnvList (eps_ann_env eps)
new_eps_anns,
eps_mod_fam_inst_env
= let
fam_inst_env =
FamInstEnv -> [FamInst] -> FamInstEnv
extendFamInstEnvList FamInstEnv
emptyFamInstEnv
[FamInst]
new_eps_fam_insts
in
extendModuleEnv (eps_mod_fam_inst_env eps)
mod
fam_inst_env,
eps_stats = addEpsInStats (eps_stats eps)
(length new_eps_decls)
(length new_eps_insts)
(length new_eps_rules) }
;
ModIface
res <- Plugins
-> PluginOperation (IOEnv (Env IfGblEnv IfLclEnv)) ModIface
-> ModIface
-> IOEnv (Env IfGblEnv IfLclEnv) ModIface
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
; MaybeErr SDoc ModIface -> IfL (MaybeErr SDoc ModIface)
forall a. a -> IOEnv (Env IfGblEnv IfLclEnv) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ModIface -> MaybeErr SDoc ModIface
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 <- TcRnIf IfGblEnv IfLclEnv HscEnv
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 = emptyKnotVars }
cleanTopEnv :: HscEnv -> HscEnv
cleanTopEnv HscEnv
hsc_env =
let
!maybe_type_vars :: Maybe (KnotVars (IORef TypeEnv))
maybe_type_vars | Bool
inOneShot = KnotVars (IORef TypeEnv) -> Maybe (KnotVars (IORef TypeEnv))
forall a. a -> Maybe a
Just (HscEnv -> KnotVars (IORef TypeEnv)
hsc_type_env_vars HscEnv
env)
| Bool
otherwise = Maybe (KnotVars (IORef TypeEnv))
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
| Module -> Bool
forall u. GenModule (GenUnit u) -> Bool
isHoleModule (ModIface -> Module
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 = emptyHomePackageTable }
!unit_env :: UnitEnv
unit_env
= UnitEnv
old_unit_env
{ ue_home_unit_graph = if anyHpt keepFor20509 (ue_hpt old_unit_env) then ue_home_unit_graph old_unit_env
else unitEnv_map pruneHomeUnitEnv (ue_home_unit_graph old_unit_env)
}
in
HscEnv
hsc_env { hsc_targets = panic "cleanTopEnv: hsc_targets"
, hsc_mod_graph = panic "cleanTopEnv: hsc_mod_graph"
, hsc_IC = panic "cleanTopEnv: hsc_IC"
, hsc_type_env_vars = case maybe_type_vars of
Just KnotVars (IORef TypeEnv)
vars -> KnotVars (IORef TypeEnv)
vars
Maybe (KnotVars (IORef TypeEnv))
Nothing -> String -> KnotVars (IORef TypeEnv)
forall a. HasCallStack => String -> a
panic String
"cleanTopEnv: hsc_type_env_vars"
, hsc_unit_env = unit_env
}
(HscEnv -> HscEnv) -> IfL a -> IfL a
forall gbl lcl a.
(HscEnv -> HscEnv) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updTopEnv HscEnv -> HscEnv
cleanTopEnv (IfL a -> IfL a) -> IfL a -> IfL a
forall a b. (a -> b) -> a -> b
$ (IfGblEnv -> IfGblEnv) -> IfL a -> IfL a
forall gbl lcl a.
(gbl -> gbl) -> TcRnIf gbl lcl a -> TcRnIf gbl lcl a
updGblEnv IfGblEnv -> IfGblEnv
cleanGblEnv (IfL a -> IfL a) -> IfL a -> IfL a
forall a b. (a -> b) -> a -> b
$ do
!HscEnv
_ <- TcRnIf IfGblEnv IfLclEnv HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
!IfGblEnv
_ <- TcRnIf IfGblEnv IfLclEnv 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 =
ModIface -> Module
forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_semantic_module ModIface
iface Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
/= ModIface -> Module
forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface Bool -> Bool -> Bool
&&
Maybe HomeUnit -> Module -> Bool
notHomeModuleMaybe Maybe HomeUnit
mhome_unit (ModIface -> Module
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
Bool -> IO ()
forall (m :: * -> *). (HasCallStack, Applicative m) => Bool -> m ()
massert (Bool -> Bool
not (Module -> Bool
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
, HomeUnit -> Bool
forall u. GenHomeUnit u -> Bool
isHomeUnitIndefinite HomeUnit
home_unit ->
GenModule UnitId -> IO (MaybeErr SDoc (ModIface, String))
find_iface GenModule UnitId
imod IO (MaybeErr SDoc (ModIface, String))
-> (MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String)))
-> IO (MaybeErr SDoc (ModIface, String))
forall a b. IO a -> (a -> IO b) -> IO b
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 (GenInstantiatedUnit UnitId -> [(ModuleName, Module)]
forall unit. GenInstantiatedUnit unit -> GenInstantiations unit
instUnitInsts (InstantiatedModule -> GenInstantiatedUnit UnitId
forall unit. GenModule unit -> unit
moduleUnit InstantiatedModule
indef)) Maybe NameShape
forall a. Maybe a
Nothing ModIface
iface0 IO (Either (Messages TcRnMessage) ModIface)
-> (Either (Messages TcRnMessage) ModIface
-> IO (MaybeErr SDoc (ModIface, String)))
-> IO (MaybeErr SDoc (ModIface, String))
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right ModIface
x -> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((ModIface, String) -> MaybeErr SDoc (ModIface, String)
forall err val. val -> MaybeErr err val
Succeeded (ModIface
x, String
path))
Left Messages TcRnMessage
errs -> Messages GhcMessage -> IO (MaybeErr SDoc (ModIface, String))
forall (io :: * -> *) a. MonadIO io => Messages GhcMessage -> io a
throwErrors (TcRnMessage -> GhcMessage
GhcTcRnMessage (TcRnMessage -> GhcMessage)
-> Messages TcRnMessage -> Messages GhcMessage
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Messages TcRnMessage
errs)
Failed SDoc
err -> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc (ModIface, String)
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 = MaybeErr SDoc (UniqDSet ModuleName)
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (UniqDSet ModuleName))
forall a. a -> IOEnv (Env gbl lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (UniqDSet ModuleName -> MaybeErr SDoc (UniqDSet ModuleName)
forall err val. val -> MaybeErr err val
Succeeded UniqDSet ModuleName
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 <- IOEnv (Env gbl lcl) Logger
forall (m :: * -> *). HasLogger m => m Logger
getLogger
let insts :: [(ModuleName, Module)]
insts = GenInstantiatedUnit UnitId -> [(ModuleName, Module)]
forall unit. GenInstantiatedUnit unit -> GenInstantiations unit
instUnitInsts (InstantiatedModule -> GenInstantiatedUnit UnitId
forall unit. GenModule unit -> unit
moduleUnit InstantiatedModule
indef)
IO () -> IOEnv (Env gbl lcl) ()
forall a. IO a -> IOEnv (Env gbl lcl) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> IOEnv (Env gbl lcl) ())
-> IO () -> IOEnv (Env gbl lcl) ()
forall a b. (a -> b) -> a -> b
$ Logger -> SDoc -> IO ()
trace_if Logger
logger (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Considering whether to load" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+>
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"to compute precise free module holes")
(ExternalPackageState
eps, HomeUnitGraph
hpt) <- TcRnIf gbl lcl (ExternalPackageState, HomeUnitGraph)
forall gbl lcl.
TcRnIf gbl lcl (ExternalPackageState, HomeUnitGraph)
getEpsAndHug
case ExternalPackageState
-> HomeUnitGraph -> Maybe (UniqDSet ModuleName)
tryEpsAndHpt ExternalPackageState
eps HomeUnitGraph
hpt Maybe (UniqDSet ModuleName)
-> Maybe (UniqDSet ModuleName) -> Maybe (UniqDSet ModuleName)
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 -> MaybeErr SDoc (UniqDSet ModuleName)
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (UniqDSet ModuleName))
forall a. a -> IOEnv (Env gbl lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (UniqDSet ModuleName -> MaybeErr SDoc (UniqDSet ModuleName)
forall err val. val -> MaybeErr err val
Succeeded UniqDSet ModuleName
r)
Maybe (UniqDSet ModuleName)
Nothing -> GenModule UnitId
-> [(ModuleName, Module)]
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (UniqDSet ModuleName))
readAndCache GenModule UnitId
imod [(ModuleName, Module)]
insts
(GenModule UnitId
_, Maybe InstantiatedModule
Nothing) -> MaybeErr SDoc (UniqDSet ModuleName)
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (UniqDSet ModuleName))
forall a. a -> IOEnv (Env gbl lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (UniqDSet ModuleName -> MaybeErr SDoc (UniqDSet ModuleName)
forall err val. val -> MaybeErr err val
Succeeded UniqDSet ModuleName
forall a. UniqDSet a
emptyUniqDSet)
where
tryEpsAndHpt :: ExternalPackageState
-> HomeUnitGraph -> Maybe (UniqDSet ModuleName)
tryEpsAndHpt ExternalPackageState
eps HomeUnitGraph
hpt =
(ModIface -> UniqDSet ModuleName)
-> Maybe ModIface -> Maybe (UniqDSet ModuleName)
forall a b. (a -> b) -> Maybe a -> Maybe b
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 InstalledModuleEnv (UniqDSet ModuleName)
-> GenModule UnitId -> Maybe (UniqDSet ModuleName)
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 -> UniqDSet ModuleName -> Maybe (UniqDSet ModuleName)
forall a. a -> Maybe a
Just (UniqDSet ModuleName
-> [(ModuleName, Module)] -> UniqDSet ModuleName
renameFreeHoles UniqDSet ModuleName
ifhs [(ModuleName, Module)]
insts)
Maybe (UniqDSet ModuleName)
_otherwise -> Maybe (UniqDSet ModuleName)
forall a. Maybe a
Nothing
readAndCache :: GenModule UnitId
-> [(ModuleName, Module)]
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (UniqDSet ModuleName))
readAndCache GenModule UnitId
imod [(ModuleName, Module)]
insts = do
HscEnv
hsc_env <- TcRnIf gbl lcl HscEnv
forall gbl lcl. TcRnIf gbl lcl HscEnv
getTopEnv
MaybeErr SDoc (ModIface, String)
mb_iface <- IO (MaybeErr SDoc (ModIface, String))
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (ModIface, String))
forall a. IO a -> IOEnv (Env gbl lcl) a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (MaybeErr SDoc (ModIface, String))
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (ModIface, String)))
-> IO (MaybeErr SDoc (ModIface, String))
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (ModIface, String))
forall a b. (a -> b) -> a -> b
$ HscEnv
-> SDoc
-> GenModule UnitId
-> Module
-> IsBootInterface
-> IO (MaybeErr SDoc (ModIface, String))
findAndReadIface HscEnv
hsc_env
(String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"moduleFreeHolesPrecise" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> 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
(ExternalPackageState -> ExternalPackageState)
-> IOEnv (Env gbl lcl) ()
forall gbl lcl.
(ExternalPackageState -> ExternalPackageState) -> TcRnIf gbl lcl ()
updateEps_ (\ExternalPackageState
eps ->
ExternalPackageState
eps { eps_free_holes = extendInstalledModuleEnv (eps_free_holes eps) imod ifhs })
MaybeErr SDoc (UniqDSet ModuleName)
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (UniqDSet ModuleName))
forall a. a -> IOEnv (Env gbl lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (UniqDSet ModuleName -> MaybeErr SDoc (UniqDSet ModuleName)
forall err val. val -> MaybeErr err val
Succeeded (UniqDSet ModuleName
-> [(ModuleName, Module)] -> UniqDSet ModuleName
renameFreeHoles UniqDSet ModuleName
ifhs [(ModuleName, Module)]
insts))
Failed SDoc
err -> MaybeErr SDoc (UniqDSet ModuleName)
-> IOEnv (Env gbl lcl) (MaybeErr SDoc (UniqDSet ModuleName))
forall a. a -> IOEnv (Env gbl lcl) a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc (UniqDSet ModuleName)
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 IsBootInterface -> IsBootInterface -> Bool
forall a. Eq a => a -> a -> Bool
== IsBootInterface
IsBoot Bool -> Bool -> Bool
&& Maybe HomeUnit -> Module -> Bool
notHomeModuleMaybe Maybe HomeUnit
mhome_unit Module
mod
-> SDoc -> MaybeErr SDoc IsBootInterface
forall err val. err -> MaybeErr err val
Failed (Module -> SDoc
badSourceImport Module
mod)
| Bool
otherwise -> IsBootInterface -> MaybeErr SDoc IsBootInterface
forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
usr_boot
WhereFrom
ImportByPlugin
-> IsBootInterface -> MaybeErr SDoc IsBootInterface
forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
NotBoot
WhereFrom
ImportBySystem
| Maybe HomeUnit -> Module -> Bool
notHomeModuleMaybe Maybe HomeUnit
mhome_unit Module
mod
-> IsBootInterface -> MaybeErr SDoc IsBootInterface
forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
NotBoot
| Bool
otherwise
-> case InstalledModuleEnv ModuleNameWithIsBoot
-> GenModule UnitId -> Maybe ModuleNameWithIsBoot
forall a. InstalledModuleEnv a -> GenModule UnitId -> Maybe a
lookupInstalledModuleEnv (ExternalPackageState -> InstalledModuleEnv ModuleNameWithIsBoot
eps_is_boot ExternalPackageState
eps) (Unit -> UnitId
toUnitId (Unit -> UnitId) -> Module -> GenModule UnitId
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 }) ->
IsBootInterface -> MaybeErr SDoc IsBootInterface
forall err val. val -> MaybeErr err val
Succeeded IsBootInterface
is_boot
Maybe ModuleNameWithIsBoot
Nothing ->
IsBootInterface -> MaybeErr SDoc IsBootInterface
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
forall doc. IsLine doc => String -> doc
text String
"You cannot {-# SOURCE #-} import a module from another package")
Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"but" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"is from package"
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Unit -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Module -> Unit
forall unit. GenModule unit -> unit
moduleUnit Module
mod)))
addDeclsToPTE :: PackageTypeEnv -> [(Name,TyThing)] -> PackageTypeEnv
addDeclsToPTE :: TypeEnv -> [(Name, TyThing)] -> TypeEnv
addDeclsToPTE TypeEnv
pte [(Name, TyThing)]
things = TypeEnv -> [(Name, TyThing)] -> TypeEnv
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 = (() :: Constraint) => HscEnv -> UnitState
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 (DynFlags -> FinderOpts)
-> (HomeUnitEnv -> DynFlags) -> HomeUnitEnv -> FinderOpts
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HomeUnitEnv -> DynFlags
homeUnitEnv_dflags (HomeUnitEnv -> FinderOpts)
-> HomeUnitGraph -> UnitEnvGraph FinderOpts
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
forall doc. IsLine doc => [doc] -> doc
sep [[SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Reading",
if IsBootInterface
hi_boot_file IsBootInterface -> IsBootInterface -> Bool
forall a. Eq a => a -> a -> Bool
== IsBootInterface
IsBoot
then String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"[boot]"
else SDoc
forall doc. IsOutput doc => doc
Outputable.empty,
String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"interface for",
GenModule UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr GenModule UnitId
mod SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
semi],
Int -> SDoc -> SDoc
nest Int
4 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"reason:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> 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
MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((ModIface, String) -> MaybeErr SDoc (ModIface, String)
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 <- IO InstalledFindResult -> IO InstalledFindResult
forall a. IO a -> IO a
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
| HomeUnit -> GenModule UnitId -> Bool
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))
-> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc (ModIface, String)
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
_
-> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
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 -> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc (ModIface, String)
forall err val. err -> MaybeErr err val
Failed SDoc
sdoc)
Succeeded {} -> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
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
forall doc. IsLine doc => String -> doc
text String
"...not found")
MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String)))
-> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a b. (a -> b) -> a -> b
$ SDoc -> MaybeErr SDoc (ModIface, String)
forall err val. err -> MaybeErr err val
Failed (SDoc -> MaybeErr SDoc (ModIface, String))
-> SDoc -> MaybeErr SDoc (ModIface, String)
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)
(GenModule UnitId -> ModuleName
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 (ModIface -> Module
forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface)) = MaybeErr SDoc () -> IO (MaybeErr SDoc ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (() -> MaybeErr SDoc ()
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 = MaybeErr SDoc () -> IO (MaybeErr SDoc ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (() -> MaybeErr SDoc ()
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) IO (MaybeErr SDoc (ModIface, String))
-> (MaybeErr SDoc (ModIface, String) -> IO (MaybeErr SDoc ()))
-> IO (MaybeErr SDoc ())
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Succeeded (ModIface
dynIface, String
_)
| ModIfaceBackend -> Fingerprint
mi_mod_hash (ModIface -> IfaceBackendExts 'ModIfaceFinal
forall (phase :: ModIfacePhase).
ModIface_ phase -> IfaceBackendExts phase
mi_final_exts ModIface
iface) Fingerprint -> Fingerprint -> Bool
forall a. Eq a => a -> a -> Bool
== ModIfaceBackend -> Fingerprint
mi_mod_hash (ModIface -> IfaceBackendExts 'ModIfaceFinal
forall (phase :: ModIfacePhase).
ModIface_ phase -> IfaceBackendExts phase
mi_final_exts ModIface
dynIface)
-> MaybeErr SDoc () -> IO (MaybeErr SDoc ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (() -> MaybeErr SDoc ()
forall err val. val -> MaybeErr err val
Succeeded ())
| Bool
otherwise ->
do MaybeErr SDoc () -> IO (MaybeErr SDoc ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (MaybeErr SDoc () -> IO (MaybeErr SDoc ()))
-> MaybeErr SDoc () -> IO (MaybeErr SDoc ())
forall a b. (a -> b) -> a -> b
$ (SDoc -> MaybeErr SDoc ()
forall err val. err -> MaybeErr err val
Failed (SDoc -> MaybeErr SDoc ()) -> SDoc -> MaybeErr SDoc ()
forall a b. (a -> b) -> a -> b
$ Module -> ModLocation -> SDoc
dynamicHashMismatchError Module
wanted_mod ModLocation
loc)
Failed SDoc
err ->
do MaybeErr SDoc () -> IO (MaybeErr SDoc ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (MaybeErr SDoc () -> IO (MaybeErr SDoc ()))
-> MaybeErr SDoc () -> IO (MaybeErr SDoc ())
forall a b. (a -> b) -> a -> b
$ (SDoc -> MaybeErr SDoc ()
forall err val. err -> MaybeErr err val
Failed (SDoc -> MaybeErr SDoc ()) -> SDoc -> MaybeErr SDoc ()
forall a b. (a -> b) -> a -> b
$ ((String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Failed to load dynamic interface file for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
wanted_mod SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
forall doc. IsLine doc => doc
colon) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
err))
dynamicHashMismatchError :: Module -> ModLocation -> SDoc
dynamicHashMismatchError :: Module -> ModLocation -> SDoc
dynamicHashMismatchError Module
wanted_mod ModLocation
loc =
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Dynamic hash doesn't match for" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
wanted_mod)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Normal interface file from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text (ModLocation -> String
ml_hi_file ModLocation
loc)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Dynamic interface file from" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text (ModLocation -> String
ml_dyn_hi_file ModLocation
loc)
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"You probably need to recompile" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc -> SDoc
quotes (Module -> SDoc
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
forall doc. IsLine doc => String -> doc
text String
"readIFace" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
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 -> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc (ModIface, String)
forall err val. err -> MaybeErr err val
Failed (String -> SDoc -> SDoc
badIfaceFile String
file_path SDoc
err))
Succeeded ModIface
iface -> MaybeErr SDoc (ModIface, String)
-> IO (MaybeErr SDoc (ModIface, String))
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((ModIface, String) -> MaybeErr SDoc (ModIface, String)
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 <- IO ModIface -> IO (Either SomeException ModIface)
forall a. IO a -> IO (Either SomeException a)
tryMost (IO ModIface -> IO (Either SomeException ModIface))
-> IO ModIface -> IO (Either SomeException ModIface)
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 Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== Module
actual_mod
-> MaybeErr SDoc ModIface -> IO (MaybeErr SDoc ModIface)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ModIface -> MaybeErr SDoc ModIface
forall err val. val -> MaybeErr err val
Succeeded ModIface
iface)
| Bool
otherwise -> MaybeErr SDoc ModIface -> IO (MaybeErr SDoc ModIface)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc ModIface
forall err val. err -> MaybeErr err val
Failed SDoc
err)
where
actual_mod :: Module
actual_mod = ModIface -> Module
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 -> MaybeErr SDoc ModIface -> IO (MaybeErr SDoc ModIface)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (SDoc -> MaybeErr SDoc ModIface
forall err val. err -> MaybeErr err val
Failed (String -> SDoc
forall doc. IsLine doc => String -> doc
text (SomeException -> String
forall e. Exception e => e -> String
showException SomeException
exn)))
ghcPrimIface :: ModIface
ghcPrimIface :: ModIface
ghcPrimIface
= ModIface
empty_iface {
mi_exports = ghcPrimExports,
mi_decls = [],
mi_fixities = fixities,
mi_final_exts = (mi_final_exts empty_iface){ mi_fix_fn = mkIfaceFixCache fixities },
mi_docs = Just ghcPrimDeclDocs
}
where
empty_iface :: ModIface
empty_iface = Module -> ModIface
emptyFullModIface Module
gHC_PRIM
fixities :: [(OccName, Fixity)]
fixities = (Id -> OccName
forall a. NamedThing a => a -> OccName
getOccName Id
seqId, SourceText -> Int -> FixityDirection -> Fixity
Fixity SourceText
NoSourceText Int
0 FixityDirection
InfixR)
(OccName, Fixity) -> [(OccName, Fixity)] -> [(OccName, Fixity)]
forall a. a -> [a] -> [a]
: (PrimOp -> Maybe (OccName, Fixity))
-> [PrimOp] -> [(OccName, Fixity)]
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) (Fixity -> (OccName, Fixity))
-> Maybe Fixity -> Maybe (OccName, Fixity)
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
forall doc. IsLine doc => [doc] -> doc
hcat [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Renamer stats: ", SDoc
msg]
where
stats :: EpsStats
stats = ExternalPackageState -> EpsStats
eps_stats ExternalPackageState
eps
msg :: SDoc
msg = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat
[Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (EpsStats -> Int
n_ifaces_in EpsStats
stats) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"interfaces read",
[SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (EpsStats -> Int
n_decls_out EpsStats
stats), String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"type/class/variable imported, out of",
Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (EpsStats -> Int
n_decls_in EpsStats
stats), String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"read"],
[SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (EpsStats -> Int
n_insts_out EpsStats
stats), String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"instance decls imported, out of",
Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (EpsStats -> Int
n_insts_in EpsStats
stats), String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"read"],
[SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [ Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (EpsStats -> Int
n_rules_out EpsStats
stats), String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"rule decls imported, out of",
Int -> SDoc
forall doc. IsLine doc => Int -> doc
int (EpsStats -> Int
n_rules_in EpsStats
stats), String -> SDoc
forall doc. IsLine doc => String -> doc
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 (SDoc -> IO ()) -> (SDoc -> SDoc) -> SDoc -> IO ()
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 Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== ModIface -> Module
forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface = QualifyName
NameUnqual
| Bool
otherwise = QualifyName
NameNotInScope1
name_ppr_ctx :: NamePprCtx
name_ppr_ctx = (Module -> OccName -> QualifyName)
-> (Module -> Bool)
-> QueryQualifyPackage
-> QueryPromotionTick
-> NamePprCtx
QueryQualify Module -> OccName -> QualifyName
qualifyImportedNames
Module -> Bool
neverQualifyModules
QueryQualifyPackage
neverQualifyPackages
QueryPromotionTick
alwaysPrintPromTick
Logger -> MessageClass -> SrcSpan -> SDoc -> IO ()
logMsg Logger
logger MessageClass
MCDump SrcSpan
noSrcSpan
(SDoc -> IO ()) -> SDoc -> IO ()
forall a b. (a -> b) -> a -> b
$ PprStyle -> SDoc -> SDoc
withPprStyle (NamePprCtx -> PprStyle
mkDumpStyle NamePprCtx
name_ppr_ctx)
(SDoc -> SDoc) -> SDoc -> SDoc
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 =
Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> Module
forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface)
SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ UnitState -> Dependencies -> SDoc
pprDeps UnitState
unit_state (ModIface -> Dependencies
forall (phase :: ModIfacePhase). ModIface_ phase -> Dependencies
mi_deps ModIface
iface)
SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((IfaceExport -> SDoc) -> [IfaceExport] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map IfaceExport -> SDoc
pprExport (ModIface -> [IfaceExport]
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
forall doc. IsDoc doc => [doc] -> doc
vcat [ String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"interface"
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> Module
forall (phase :: ModIfacePhase). ModIface_ phase -> Module
mi_module ModIface
iface) SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> HscSource -> SDoc
forall {doc}. IsLine doc => HscSource -> doc
pp_hsc_src (ModIface -> HscSource
forall (phase :: ModIfacePhase). ModIface_ phase -> HscSource
mi_hsc_src ModIface
iface)
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> (if ModIfaceBackend -> Bool
mi_orphan IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts then String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"[orphan module]" else SDoc
forall doc. IsOutput doc => doc
Outputable.empty)
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> (if ModIfaceBackend -> Bool
mi_finsts IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts then String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"[family instance module]" else SDoc
forall doc. IsOutput doc => doc
Outputable.empty)
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> (if ModIface -> Bool
forall (phase :: ModIfacePhase). ModIface_ phase -> Bool
mi_hpc ModIface
iface then String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"[hpc]" else SDoc
forall doc. IsOutput doc => doc
Outputable.empty)
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Integer -> SDoc
forall doc. IsLine doc => Integer -> doc
integer Integer
hiVersion
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"interface hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_iface_hash IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"ABI hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_mod_hash IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"export-list hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_exp_hash IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"orphan hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_orphan_hash IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"flag hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_flag_hash IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"opt_hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_opt_hash IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"hpc_hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_hpc_hash IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"plugin_hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIfaceBackend -> Fingerprint
mi_plugin_hash IfaceBackendExts 'ModIfaceFinal
ModIfaceBackend
exts))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"src_hash:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> Fingerprint
forall (phase :: ModIfacePhase). ModIface_ phase -> Fingerprint
mi_src_hash ModIface
iface))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"sig of:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Maybe Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> Maybe Module
forall (phase :: ModIfacePhase). ModIface_ phase -> Maybe Module
mi_sig_of ModIface
iface))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"used TH splices:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> Bool
forall (phase :: ModIfacePhase). ModIface_ phase -> Bool
mi_used_th ModIface
iface))
, Int -> SDoc -> SDoc
nest Int
2 (String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"where")
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"exports:"
, Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((IfaceExport -> SDoc) -> [IfaceExport] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map IfaceExport -> SDoc
pprExport (ModIface -> [IfaceExport]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceExport]
mi_exports ModIface
iface)))
, UnitState -> Dependencies -> SDoc
pprDeps UnitState
unit_state (ModIface -> Dependencies
forall (phase :: ModIfacePhase). ModIface_ phase -> Dependencies
mi_deps ModIface
iface)
, [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((Usage -> SDoc) -> [Usage] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map Usage -> SDoc
pprUsage (ModIface -> [Usage]
forall (phase :: ModIfacePhase). ModIface_ phase -> [Usage]
mi_usages ModIface
iface))
, [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((IfaceAnnotation -> SDoc) -> [IfaceAnnotation] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map IfaceAnnotation -> SDoc
pprIfaceAnnotation (ModIface -> [IfaceAnnotation]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceAnnotation]
mi_anns ModIface
iface))
, [(OccName, Fixity)] -> SDoc
pprFixities (ModIface -> [(OccName, Fixity)]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [(OccName, Fixity)]
mi_fixities ModIface
iface)
, [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr Fingerprint
ver SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Int -> SDoc -> SDoc
nest Int
2 (IfaceDecl -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfaceDecl
decl) | (Fingerprint
ver,IfaceDecl
decl) <- ModIface -> [IfaceDeclExts 'ModIfaceFinal]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceDeclExts phase]
mi_decls ModIface
iface]
, case ModIface -> Maybe [IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo]
forall (phase :: ModIfacePhase).
ModIface_ phase
-> Maybe [IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo]
mi_extra_decls ModIface
iface of
Maybe [IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo]
Nothing -> SDoc
forall doc. IsOutput doc => doc
empty
Just [IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo]
eds -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"extra decls:"
SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Int -> SDoc -> SDoc
nest Int
2 ([SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ([IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo
bs | IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo
bs <- [IfaceBindingX IfaceMaybeRhs IfaceTopBndrInfo]
eds]))
, [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((IfaceClsInst -> SDoc) -> [IfaceClsInst] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map IfaceClsInst -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> [IfaceClsInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceClsInst]
mi_insts ModIface
iface))
, [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((IfaceFamInst -> SDoc) -> [IfaceFamInst] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map IfaceFamInst -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> [IfaceFamInst]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceFamInst]
mi_fam_insts ModIface
iface))
, [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((IfaceRule -> SDoc) -> [IfaceRule] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map IfaceRule -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> [IfaceRule]
forall (phase :: ModIfacePhase). ModIface_ phase -> [IfaceRule]
mi_rules ModIface
iface))
, Warnings GhcRn -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> Warnings GhcRn
forall (phase :: ModIfacePhase). ModIface_ phase -> Warnings GhcRn
mi_warns ModIface
iface)
, IfaceTrustInfo -> SDoc
pprTrustInfo (ModIface -> IfaceTrustInfo
forall (phase :: ModIfacePhase). ModIface_ phase -> IfaceTrustInfo
mi_trust ModIface
iface)
, Bool -> SDoc
pprTrustPkg (ModIface -> Bool
forall (phase :: ModIfacePhase). ModIface_ phase -> Bool
mi_trust_pkg ModIface
iface)
, [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ((IfaceCompleteMatch -> SDoc) -> [IfaceCompleteMatch] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map IfaceCompleteMatch -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> [IfaceCompleteMatch]
forall (phase :: ModIfacePhase).
ModIface_ phase -> [IfaceCompleteMatch]
mi_complete_matches ModIface
iface))
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"docs:" SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Int -> SDoc -> SDoc
nest Int
2 (Maybe Docs -> SDoc
forall a. Outputable a => a -> SDoc
ppr (ModIface -> Maybe Docs
forall (phase :: ModIfacePhase). ModIface_ phase -> Maybe Docs
mi_docs ModIface
iface))
, String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"extensible fields:" SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$ Int -> SDoc -> SDoc
nest Int
2 (ExtensibleFields -> SDoc
pprExtensibleFields (ModIface -> ExtensibleFields
forall (phase :: ModIfacePhase).
ModIface_ phase -> ExtensibleFields
mi_ext_fields ModIface
iface))
]
where
pp_hsc_src :: HscSource -> doc
pp_hsc_src HscSource
HsBootFile = String -> doc
forall doc. IsLine doc => String -> doc
text String
"[boot]"
pp_hsc_src HscSource
HsigFile = String -> doc
forall doc. IsLine doc => String -> doc
text String
"[hsig]"
pp_hsc_src HscSource
HsSrcFile = doc
forall doc. IsOutput doc => doc
Outputable.empty
pprExport :: IfaceExport -> SDoc
pprExport :: IfaceExport -> SDoc
pprExport (Avail GreName
n) = GreName -> SDoc
forall a. Outputable a => a -> SDoc
ppr GreName
n
pprExport (AvailTC Name
_ []) = SDoc
forall doc. IsOutput doc => doc
Outputable.empty
pprExport avail :: IfaceExport
avail@(AvailTC Name
n [GreName]
_) =
Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr Name
n SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> SDoc
mark SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> [GreName] -> SDoc
forall {a}. Outputable a => [a] -> SDoc
pp_export (IfaceExport -> [GreName]
availSubordinateGreNames IfaceExport
avail)
where
mark :: SDoc
mark | IfaceExport -> Bool
availExportsDecl IfaceExport
avail = SDoc
forall doc. IsOutput doc => doc
Outputable.empty
| Bool
otherwise = SDoc
forall doc. IsLine doc => doc
vbar
pp_export :: [a] -> SDoc
pp_export [] = SDoc
forall doc. IsOutput doc => doc
Outputable.empty
pp_export [a]
names = SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
braces ([SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep ((a -> SDoc) -> [a] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map a -> SDoc
forall a. Outputable a => a -> SDoc
ppr [a]
names))
pprUsage :: Usage -> SDoc
pprUsage :: Usage -> SDoc
pprUsage usage :: Usage
usage@UsagePackageModule{}
= Usage -> (Usage -> Module) -> SDoc
forall a. Outputable a => Usage -> (Usage -> a) -> SDoc
pprUsageImport Usage
usage Usage -> Module
usg_mod
pprUsage usage :: Usage
usage@UsageHomeModule{}
= Usage -> (Usage -> GenModule UnitId) -> SDoc
forall a. Outputable a => Usage -> (Usage -> a) -> SDoc
pprUsageImport Usage
usage (\Usage
u -> UnitId -> ModuleName -> GenModule UnitId
forall u. u -> ModuleName -> GenModule u
mkModule (Usage -> UnitId
usg_unit_id Usage
u) (Usage -> ModuleName
usg_mod_name Usage
u)) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
Int -> SDoc -> SDoc
nest Int
2 (
SDoc -> (Fingerprint -> SDoc) -> Maybe Fingerprint -> SDoc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe SDoc
forall doc. IsOutput doc => doc
Outputable.empty (\Fingerprint
v -> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"exports: " SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<> Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr Fingerprint
v) (Usage -> Maybe Fingerprint
usg_exports Usage
usage) SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
[SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat [ OccName -> SDoc
forall a. Outputable a => a -> SDoc
ppr OccName
n SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Fingerprint -> 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
forall doc. IsLine doc => [doc] -> doc
hsep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"addDependentFile",
SDoc -> SDoc
forall doc. IsLine doc => doc -> doc
doubleQuotes (String -> SDoc
forall doc. IsLine doc => String -> doc
text (Usage -> String
usg_file_path Usage
usage)),
Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Usage -> Fingerprint
usg_file_hash Usage
usage)]
pprUsage usage :: Usage
usage@UsageMergedRequirement{}
= [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"merged", Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Usage -> Module
usg_mod Usage
usage), Fingerprint -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Usage -> Fingerprint
usg_mod_hash Usage
usage)]
pprUsage usage :: Usage
usage@UsageHomeModuleInterface{}
= [SDoc] -> SDoc
forall doc. IsLine doc => [doc] -> doc
hsep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"implementation", ModuleName -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Usage -> ModuleName
usg_mod_name Usage
usage)
, UnitId -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Usage -> UnitId
usg_unit_id Usage
usage)
, Fingerprint -> SDoc
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
forall doc. IsLine doc => [doc] -> doc
hsep [String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"import", SDoc
safe, a -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Usage -> a
usg_mod' Usage
usage),
Fingerprint -> SDoc
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
forall doc. IsLine doc => String -> doc
text String
"safe"
| Bool
otherwise = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
" -/ "
pprFixities :: [(OccName, Fixity)] -> SDoc
pprFixities :: [(OccName, Fixity)] -> SDoc
pprFixities [] = SDoc
forall doc. IsOutput doc => doc
Outputable.empty
pprFixities [(OccName, Fixity)]
fixes = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"fixities" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> ((OccName, Fixity) -> SDoc) -> [(OccName, Fixity)] -> SDoc
forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (OccName, Fixity) -> SDoc
forall {a} {a}. (Outputable a, Outputable a) => (a, a) -> SDoc
pprFix [(OccName, Fixity)]
fixes
where
pprFix :: (a, a) -> SDoc
pprFix (a
occ,a
fix) = a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
fix SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
occ
pprTrustInfo :: IfaceTrustInfo -> SDoc
pprTrustInfo :: IfaceTrustInfo -> SDoc
pprTrustInfo IfaceTrustInfo
trust = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"trusted:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> IfaceTrustInfo -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfaceTrustInfo
trust
pprTrustPkg :: Bool -> SDoc
pprTrustPkg :: Bool -> SDoc
pprTrustPkg Bool
tpkg = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"require own pkg trusted:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Bool -> SDoc
forall a. Outputable a => a -> SDoc
ppr Bool
tpkg
instance Outputable (Warnings pass) where
ppr :: Warnings pass -> SDoc
ppr = Warnings pass -> SDoc
forall pass. Warnings pass -> SDoc
pprWarns
pprWarns :: Warnings pass -> SDoc
pprWarns :: forall pass. Warnings pass -> SDoc
pprWarns Warnings pass
NoWarnings = SDoc
forall doc. IsOutput doc => doc
Outputable.empty
pprWarns (WarnAll WarningTxt pass
txt) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Warn all" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> WarningTxt pass -> SDoc
forall a. Outputable a => a -> SDoc
ppr WarningTxt pass
txt
pprWarns (WarnSome [(OccName, WarningTxt pass)]
prs) = String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"Warnings:"
SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat (((OccName, WarningTxt pass) -> SDoc)
-> [(OccName, WarningTxt pass)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (OccName, WarningTxt pass) -> SDoc
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) = a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> a -> 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 })
= IfaceAnnTarget -> SDoc
forall a. Outputable a => a -> SDoc
ppr IfaceAnnTarget
target SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"annotated by" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> AnnPayload -> SDoc
forall a. Outputable a => a -> SDoc
ppr AnnPayload
serialized
pprExtensibleFields :: ExtensibleFields -> SDoc
pprExtensibleFields :: ExtensibleFields -> SDoc
pprExtensibleFields (ExtensibleFields Map String BinData
fs) = [SDoc] -> SDoc
forall doc. IsDoc doc => [doc] -> doc
vcat ([SDoc] -> SDoc)
-> ([(String, BinData)] -> [SDoc]) -> [(String, BinData)] -> SDoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((String, BinData) -> SDoc) -> [(String, BinData)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String, BinData) -> SDoc
pprField ([(String, BinData)] -> SDoc) -> [(String, BinData)] -> SDoc
forall a b. (a -> b) -> a -> b
$ Map String BinData -> [(String, BinData)]
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
forall doc. IsLine doc => String -> doc
text String
name SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"-" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> Int -> SDoc
forall a. Outputable a => a -> SDoc
ppr Int
size SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
<+> String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"bytes"