{-# LANGUAGE CPP, NondecreasingIndentation, TupleSections, RecordWildCards #-}
{-# LANGUAGE BangPatterns #-}
{-# OPTIONS_GHC -fno-cse #-}
module Linker ( getHValue, showLinkerState,
linkExpr, linkDecls, unload, withExtendedLinkEnv,
extendLinkEnv, deleteFromLinkEnv,
extendLoadedPkgs,
linkPackages,initDynLinker,linkModule,
linkCmdLineLibs
) where
#include "HsVersions.h"
import GhcPrelude
import GHCi
import GHCi.RemoteTypes
import LoadIface
import ByteCodeLink
import ByteCodeAsm
import ByteCodeTypes
import TcRnMonad
import Packages
import DriverPhases
import Finder
import HscTypes
import Name
import NameEnv
import Module
import ListSetOps
import DynFlags
import BasicTypes
import Outputable
import Panic
import Util
import ErrUtils
import SrcLoc
import qualified Maybes
import UniqDSet
import FastString
import Platform
import SysTools
import FileCleanup
import Control.Monad
import Data.Char (isSpace)
import Data.IORef
import Data.List
import Data.Maybe
import Control.Concurrent.MVar
import System.FilePath
import System.Directory
import System.IO.Unsafe
import System.Environment (lookupEnv)
#if defined(mingw32_HOST_OS)
import System.Win32.Info (getSystemDirectory)
#endif
import Exception
#if STAGE >= 2
import Foreign (Ptr)
#endif
#if STAGE < 2
GLOBAL_VAR_M( v_PersistentLinkerState
, newMVar Nothing
, MVar (Maybe PersistentLinkerState))
#else
SHARED_GLOBAL_VAR_M( v_PersistentLinkerState
, getOrSetLibHSghcPersistentLinkerState
, "getOrSetLibHSghcPersistentLinkerState"
, newMVar Nothing
, MVar (Maybe PersistentLinkerState))
#endif
uninitialised :: a
uninitialised :: a
uninitialised = String -> a
forall a. String -> a
panic "Dynamic linker not initialised"
modifyPLS_ :: (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ :: (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ f :: PersistentLinkerState -> IO PersistentLinkerState
f = IORef (MVar (Maybe PersistentLinkerState))
-> IO (MVar (Maybe PersistentLinkerState))
forall a. IORef a -> IO a
readIORef IORef (MVar (Maybe PersistentLinkerState))
v_PersistentLinkerState
IO (MVar (Maybe PersistentLinkerState))
-> (MVar (Maybe PersistentLinkerState) -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (MVar (Maybe PersistentLinkerState)
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState))
-> IO ())
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState))
-> MVar (Maybe PersistentLinkerState)
-> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip MVar (Maybe PersistentLinkerState)
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState))
-> IO ()
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ ((PersistentLinkerState -> Maybe PersistentLinkerState)
-> IO PersistentLinkerState -> IO (Maybe PersistentLinkerState)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap PersistentLinkerState -> Maybe PersistentLinkerState
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IO PersistentLinkerState -> IO (Maybe PersistentLinkerState))
-> (Maybe PersistentLinkerState -> IO PersistentLinkerState)
-> Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PersistentLinkerState -> IO PersistentLinkerState
f (PersistentLinkerState -> IO PersistentLinkerState)
-> (Maybe PersistentLinkerState -> PersistentLinkerState)
-> Maybe PersistentLinkerState
-> IO PersistentLinkerState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PersistentLinkerState
-> Maybe PersistentLinkerState -> PersistentLinkerState
forall a. a -> Maybe a -> a
fromMaybe PersistentLinkerState
forall a. a
uninitialised)
modifyPLS :: (PersistentLinkerState -> IO (PersistentLinkerState, a)) -> IO a
modifyPLS :: (PersistentLinkerState -> IO (PersistentLinkerState, a)) -> IO a
modifyPLS f :: PersistentLinkerState -> IO (PersistentLinkerState, a)
f = IORef (MVar (Maybe PersistentLinkerState))
-> IO (MVar (Maybe PersistentLinkerState))
forall a. IORef a -> IO a
readIORef IORef (MVar (Maybe PersistentLinkerState))
v_PersistentLinkerState
IO (MVar (Maybe PersistentLinkerState))
-> (MVar (Maybe PersistentLinkerState) -> IO a) -> IO a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (MVar (Maybe PersistentLinkerState)
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState, a))
-> IO a)
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState, a))
-> MVar (Maybe PersistentLinkerState)
-> IO a
forall a b c. (a -> b -> c) -> b -> a -> c
flip MVar (Maybe PersistentLinkerState)
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState, a))
-> IO a
forall a b. MVar a -> (a -> IO (a, b)) -> IO b
modifyMVar ((PersistentLinkerState -> Maybe PersistentLinkerState)
-> IO (PersistentLinkerState, a)
-> IO (Maybe PersistentLinkerState, a)
forall (f :: * -> *) t a b.
Functor f =>
(t -> a) -> f (t, b) -> f (a, b)
fmapFst PersistentLinkerState -> Maybe PersistentLinkerState
forall (f :: * -> *) a. Applicative f => a -> f a
pure (IO (PersistentLinkerState, a)
-> IO (Maybe PersistentLinkerState, a))
-> (Maybe PersistentLinkerState -> IO (PersistentLinkerState, a))
-> Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PersistentLinkerState -> IO (PersistentLinkerState, a)
f (PersistentLinkerState -> IO (PersistentLinkerState, a))
-> (Maybe PersistentLinkerState -> PersistentLinkerState)
-> Maybe PersistentLinkerState
-> IO (PersistentLinkerState, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PersistentLinkerState
-> Maybe PersistentLinkerState -> PersistentLinkerState
forall a. a -> Maybe a -> a
fromMaybe PersistentLinkerState
forall a. a
uninitialised)
where fmapFst :: (t -> a) -> f (t, b) -> f (a, b)
fmapFst f :: t -> a
f = ((t, b) -> (a, b)) -> f (t, b) -> f (a, b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(x :: t
x, y :: b
y) -> (t -> a
f t
x, b
y))
readPLS :: IO PersistentLinkerState
readPLS :: IO PersistentLinkerState
readPLS = IORef (MVar (Maybe PersistentLinkerState))
-> IO (MVar (Maybe PersistentLinkerState))
forall a. IORef a -> IO a
readIORef IORef (MVar (Maybe PersistentLinkerState))
v_PersistentLinkerState
IO (MVar (Maybe PersistentLinkerState))
-> (MVar (Maybe PersistentLinkerState) -> IO PersistentLinkerState)
-> IO PersistentLinkerState
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe PersistentLinkerState -> PersistentLinkerState)
-> IO (Maybe PersistentLinkerState) -> IO PersistentLinkerState
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (PersistentLinkerState
-> Maybe PersistentLinkerState -> PersistentLinkerState
forall a. a -> Maybe a -> a
fromMaybe PersistentLinkerState
forall a. a
uninitialised) (IO (Maybe PersistentLinkerState) -> IO PersistentLinkerState)
-> (MVar (Maybe PersistentLinkerState)
-> IO (Maybe PersistentLinkerState))
-> MVar (Maybe PersistentLinkerState)
-> IO PersistentLinkerState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MVar (Maybe PersistentLinkerState)
-> IO (Maybe PersistentLinkerState)
forall a. MVar a -> IO a
readMVar
modifyMbPLS_
:: (Maybe PersistentLinkerState -> IO (Maybe PersistentLinkerState)) -> IO ()
modifyMbPLS_ :: (Maybe PersistentLinkerState -> IO (Maybe PersistentLinkerState))
-> IO ()
modifyMbPLS_ f :: Maybe PersistentLinkerState -> IO (Maybe PersistentLinkerState)
f = IORef (MVar (Maybe PersistentLinkerState))
-> IO (MVar (Maybe PersistentLinkerState))
forall a. IORef a -> IO a
readIORef IORef (MVar (Maybe PersistentLinkerState))
v_PersistentLinkerState IO (MVar (Maybe PersistentLinkerState))
-> (MVar (Maybe PersistentLinkerState) -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (MVar (Maybe PersistentLinkerState)
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState))
-> IO ())
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState))
-> MVar (Maybe PersistentLinkerState)
-> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip MVar (Maybe PersistentLinkerState)
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState))
-> IO ()
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ Maybe PersistentLinkerState -> IO (Maybe PersistentLinkerState)
f
data PersistentLinkerState
= PersistentLinkerState {
PersistentLinkerState -> ClosureEnv
closure_env :: ClosureEnv,
PersistentLinkerState -> ItblEnv
itbl_env :: !ItblEnv,
PersistentLinkerState -> [Linkable]
bcos_loaded :: ![Linkable],
PersistentLinkerState -> [Linkable]
objs_loaded :: ![Linkable],
PersistentLinkerState -> [LinkerUnitId]
pkgs_loaded :: ![LinkerUnitId],
PersistentLinkerState -> [(String, String)]
temp_sos :: ![(FilePath, String)] }
emptyPLS :: DynFlags -> PersistentLinkerState
emptyPLS :: DynFlags -> PersistentLinkerState
emptyPLS _ = $WPersistentLinkerState :: ClosureEnv
-> ItblEnv
-> [Linkable]
-> [Linkable]
-> [LinkerUnitId]
-> [(String, String)]
-> PersistentLinkerState
PersistentLinkerState {
closure_env :: ClosureEnv
closure_env = ClosureEnv
forall a. NameEnv a
emptyNameEnv,
itbl_env :: ItblEnv
itbl_env = ItblEnv
forall a. NameEnv a
emptyNameEnv,
pkgs_loaded :: [LinkerUnitId]
pkgs_loaded = [LinkerUnitId]
init_pkgs,
bcos_loaded :: [Linkable]
bcos_loaded = [],
objs_loaded :: [Linkable]
objs_loaded = [],
temp_sos :: [(String, String)]
temp_sos = [] }
where init_pkgs :: [LinkerUnitId]
init_pkgs = (UnitId -> LinkerUnitId) -> [UnitId] -> [LinkerUnitId]
forall a b. (a -> b) -> [a] -> [b]
map UnitId -> LinkerUnitId
toInstalledUnitId [UnitId
rtsUnitId]
extendLoadedPkgs :: [InstalledUnitId] -> IO ()
extendLoadedPkgs :: [LinkerUnitId] -> IO ()
extendLoadedPkgs pkgs :: [LinkerUnitId]
pkgs =
(PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ ((PersistentLinkerState -> IO PersistentLinkerState) -> IO ())
-> (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
forall a b. (a -> b) -> a -> b
$ \s :: PersistentLinkerState
s ->
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
s{ pkgs_loaded :: [LinkerUnitId]
pkgs_loaded = [LinkerUnitId]
pkgs [LinkerUnitId] -> [LinkerUnitId] -> [LinkerUnitId]
forall a. [a] -> [a] -> [a]
++ PersistentLinkerState -> [LinkerUnitId]
pkgs_loaded PersistentLinkerState
s }
extendLinkEnv :: [(Name,ForeignHValue)] -> IO ()
extendLinkEnv :: [(Name, ForeignHValue)] -> IO ()
extendLinkEnv new_bindings :: [(Name, ForeignHValue)]
new_bindings =
(PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ ((PersistentLinkerState -> IO PersistentLinkerState) -> IO ())
-> (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
forall a b. (a -> b) -> a -> b
$ \pls :: PersistentLinkerState
pls@PersistentLinkerState{..} -> do
let new_ce :: ClosureEnv
new_ce = ClosureEnv -> [(Name, ForeignHValue)] -> ClosureEnv
extendClosureEnv ClosureEnv
closure_env [(Name, ForeignHValue)]
new_bindings
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState -> IO PersistentLinkerState)
-> PersistentLinkerState -> IO PersistentLinkerState
forall a b. (a -> b) -> a -> b
$! PersistentLinkerState
pls{ closure_env :: ClosureEnv
closure_env = ClosureEnv
new_ce }
deleteFromLinkEnv :: [Name] -> IO ()
deleteFromLinkEnv :: [Name] -> IO ()
deleteFromLinkEnv to_remove :: [Name]
to_remove =
(PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ ((PersistentLinkerState -> IO PersistentLinkerState) -> IO ())
-> (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
forall a b. (a -> b) -> a -> b
$ \pls :: PersistentLinkerState
pls -> do
let ce :: ClosureEnv
ce = PersistentLinkerState -> ClosureEnv
closure_env PersistentLinkerState
pls
let new_ce :: ClosureEnv
new_ce = ClosureEnv -> [Name] -> ClosureEnv
forall a. NameEnv a -> [Name] -> NameEnv a
delListFromNameEnv ClosureEnv
ce [Name]
to_remove
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls{ closure_env :: ClosureEnv
closure_env = ClosureEnv
new_ce }
getHValue :: HscEnv -> Name -> IO ForeignHValue
getHValue :: HscEnv -> Name -> IO ForeignHValue
getHValue hsc_env :: HscEnv
hsc_env name :: Name
name = do
HscEnv -> IO ()
initDynLinker HscEnv
hsc_env
PersistentLinkerState
pls <- (PersistentLinkerState
-> IO (PersistentLinkerState, PersistentLinkerState))
-> IO PersistentLinkerState
forall a.
(PersistentLinkerState -> IO (PersistentLinkerState, a)) -> IO a
modifyPLS ((PersistentLinkerState
-> IO (PersistentLinkerState, PersistentLinkerState))
-> IO PersistentLinkerState)
-> (PersistentLinkerState
-> IO (PersistentLinkerState, PersistentLinkerState))
-> IO PersistentLinkerState
forall a b. (a -> b) -> a -> b
$ \pls :: PersistentLinkerState
pls -> do
if (Name -> Bool
isExternalName Name
name) then do
(pls' :: PersistentLinkerState
pls', ok :: SuccessFlag
ok) <- HscEnv
-> PersistentLinkerState
-> SrcSpan
-> [Module]
-> IO (PersistentLinkerState, SuccessFlag)
linkDependencies HscEnv
hsc_env PersistentLinkerState
pls SrcSpan
noSrcSpan
[HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
name]
if (SuccessFlag -> Bool
failed SuccessFlag
ok) then GhcException -> IO (PersistentLinkerState, PersistentLinkerState)
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
ProgramError "")
else (PersistentLinkerState, PersistentLinkerState)
-> IO (PersistentLinkerState, PersistentLinkerState)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls', PersistentLinkerState
pls')
else
(PersistentLinkerState, PersistentLinkerState)
-> IO (PersistentLinkerState, PersistentLinkerState)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls, PersistentLinkerState
pls)
case ClosureEnv -> Name -> Maybe (Name, ForeignHValue)
forall a. NameEnv a -> Name -> Maybe a
lookupNameEnv (PersistentLinkerState -> ClosureEnv
closure_env PersistentLinkerState
pls) Name
name of
Just (_,aa :: ForeignHValue
aa) -> ForeignHValue -> IO ForeignHValue
forall (m :: * -> *) a. Monad m => a -> m a
return ForeignHValue
aa
Nothing
-> ASSERT2(isExternalName name, ppr name)
do let sym_to_find :: FastString
sym_to_find = Name -> String -> FastString
nameToCLabel Name
name "closure"
Maybe HValueRef
m <- HscEnv -> String -> IO (Maybe HValueRef)
lookupClosure HscEnv
hsc_env (FastString -> String
unpackFS FastString
sym_to_find)
case Maybe HValueRef
m of
Just hvref :: HValueRef
hvref -> HscEnv -> HValueRef -> IO ForeignHValue
forall a. HscEnv -> RemoteRef a -> IO (ForeignRef a)
mkFinalizedHValue HscEnv
hsc_env HValueRef
hvref
Nothing -> String -> String -> IO ForeignHValue
forall a. String -> String -> IO a
linkFail "ByteCodeLink.lookupCE"
(FastString -> String
unpackFS FastString
sym_to_find)
linkDependencies :: HscEnv -> PersistentLinkerState
-> SrcSpan -> [Module]
-> IO (PersistentLinkerState, SuccessFlag)
linkDependencies :: HscEnv
-> PersistentLinkerState
-> SrcSpan
-> [Module]
-> IO (PersistentLinkerState, SuccessFlag)
linkDependencies hsc_env :: HscEnv
hsc_env pls :: PersistentLinkerState
pls span :: SrcSpan
span needed_mods :: [Module]
needed_mods = do
let hpt :: HomePackageTable
hpt = HscEnv -> HomePackageTable
hsc_HPT HscEnv
hsc_env
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
Maybe String
maybe_normal_osuf <- DynFlags -> SrcSpan -> IO (Maybe String)
checkNonStdWay DynFlags
dflags SrcSpan
span
(lnks :: [Linkable]
lnks, pkgs :: [LinkerUnitId]
pkgs) <- HscEnv
-> HomePackageTable
-> PersistentLinkerState
-> Maybe String
-> SrcSpan
-> [Module]
-> IO ([Linkable], [LinkerUnitId])
getLinkDeps HscEnv
hsc_env HomePackageTable
hpt PersistentLinkerState
pls
Maybe String
maybe_normal_osuf SrcSpan
span [Module]
needed_mods
PersistentLinkerState
pls1 <- HscEnv
-> [LinkerUnitId]
-> PersistentLinkerState
-> IO PersistentLinkerState
linkPackages' HscEnv
hsc_env [LinkerUnitId]
pkgs PersistentLinkerState
pls
HscEnv
-> PersistentLinkerState
-> [Linkable]
-> IO (PersistentLinkerState, SuccessFlag)
linkModules HscEnv
hsc_env PersistentLinkerState
pls1 [Linkable]
lnks
withExtendedLinkEnv :: (ExceptionMonad m) =>
[(Name,ForeignHValue)] -> m a -> m a
withExtendedLinkEnv :: [(Name, ForeignHValue)] -> m a -> m a
withExtendedLinkEnv new_env :: [(Name, ForeignHValue)]
new_env action :: m a
action
= m () -> (() -> m ()) -> (() -> m a) -> m a
forall (m :: * -> *) a b c.
ExceptionMonad m =>
m a -> (a -> m b) -> (a -> m c) -> m c
gbracket (IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ [(Name, ForeignHValue)] -> IO ()
extendLinkEnv [(Name, ForeignHValue)]
new_env)
(\_ -> m ()
reset_old_env)
(\_ -> m a
action)
where
reset_old_env :: m ()
reset_old_env = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
(PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ ((PersistentLinkerState -> IO PersistentLinkerState) -> IO ())
-> (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
forall a b. (a -> b) -> a -> b
$ \pls :: PersistentLinkerState
pls ->
let cur :: ClosureEnv
cur = PersistentLinkerState -> ClosureEnv
closure_env PersistentLinkerState
pls
new :: ClosureEnv
new = ClosureEnv -> [Name] -> ClosureEnv
forall a. NameEnv a -> [Name] -> NameEnv a
delListFromNameEnv ClosureEnv
cur (((Name, ForeignHValue) -> Name)
-> [(Name, ForeignHValue)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name, ForeignHValue) -> Name
forall a b. (a, b) -> a
fst [(Name, ForeignHValue)]
new_env)
in PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls{ closure_env :: ClosureEnv
closure_env = ClosureEnv
new }
showLinkerState :: DynFlags -> IO ()
showLinkerState :: DynFlags -> IO ()
showLinkerState dflags :: DynFlags
dflags
= do PersistentLinkerState
pls <- IO PersistentLinkerState
readPLS
DynFlags
-> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
putLogMsg DynFlags
dflags WarnReason
NoReason Severity
SevDump SrcSpan
noSrcSpan
(DynFlags -> PprStyle
defaultDumpStyle DynFlags
dflags)
([SDoc] -> SDoc
vcat [String -> SDoc
text "----- Linker state -----",
String -> SDoc
text "Pkgs:" SDoc -> SDoc -> SDoc
<+> [LinkerUnitId] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PersistentLinkerState -> [LinkerUnitId]
pkgs_loaded PersistentLinkerState
pls),
String -> SDoc
text "Objs:" SDoc -> SDoc -> SDoc
<+> [Linkable] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PersistentLinkerState -> [Linkable]
objs_loaded PersistentLinkerState
pls),
String -> SDoc
text "BCOs:" SDoc -> SDoc -> SDoc
<+> [Linkable] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PersistentLinkerState -> [Linkable]
bcos_loaded PersistentLinkerState
pls)])
initDynLinker :: HscEnv -> IO ()
initDynLinker :: HscEnv -> IO ()
initDynLinker hsc_env :: HscEnv
hsc_env =
(Maybe PersistentLinkerState -> IO (Maybe PersistentLinkerState))
-> IO ()
modifyMbPLS_ ((Maybe PersistentLinkerState -> IO (Maybe PersistentLinkerState))
-> IO ())
-> (Maybe PersistentLinkerState
-> IO (Maybe PersistentLinkerState))
-> IO ()
forall a b. (a -> b) -> a -> b
$ \pls :: Maybe PersistentLinkerState
pls -> do
case Maybe PersistentLinkerState
pls of
Just _ -> Maybe PersistentLinkerState -> IO (Maybe PersistentLinkerState)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe PersistentLinkerState
pls
Nothing -> PersistentLinkerState -> Maybe PersistentLinkerState
forall a. a -> Maybe a
Just (PersistentLinkerState -> Maybe PersistentLinkerState)
-> IO PersistentLinkerState -> IO (Maybe PersistentLinkerState)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HscEnv -> IO PersistentLinkerState
reallyInitDynLinker HscEnv
hsc_env
reallyInitDynLinker :: HscEnv -> IO PersistentLinkerState
reallyInitDynLinker :: HscEnv -> IO PersistentLinkerState
reallyInitDynLinker hsc_env :: HscEnv
hsc_env = do
let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
pls0 :: PersistentLinkerState
pls0 = DynFlags -> PersistentLinkerState
emptyPLS DynFlags
dflags
HscEnv -> IO ()
initObjLinker HscEnv
hsc_env
PersistentLinkerState
pls <- HscEnv
-> [LinkerUnitId]
-> PersistentLinkerState
-> IO PersistentLinkerState
linkPackages' HscEnv
hsc_env (PackageState -> [LinkerUnitId]
preloadPackages (DynFlags -> PackageState
pkgState DynFlags
dflags)) PersistentLinkerState
pls0
HscEnv -> PersistentLinkerState -> IO PersistentLinkerState
linkCmdLineLibs' HscEnv
hsc_env PersistentLinkerState
pls
linkCmdLineLibs :: HscEnv -> IO ()
linkCmdLineLibs :: HscEnv -> IO ()
linkCmdLineLibs hsc_env :: HscEnv
hsc_env = do
HscEnv -> IO ()
initDynLinker HscEnv
hsc_env
(PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ ((PersistentLinkerState -> IO PersistentLinkerState) -> IO ())
-> (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
forall a b. (a -> b) -> a -> b
$ \pls :: PersistentLinkerState
pls -> do
HscEnv -> PersistentLinkerState -> IO PersistentLinkerState
linkCmdLineLibs' HscEnv
hsc_env PersistentLinkerState
pls
linkCmdLineLibs' :: HscEnv -> PersistentLinkerState -> IO PersistentLinkerState
linkCmdLineLibs' :: HscEnv -> PersistentLinkerState -> IO PersistentLinkerState
linkCmdLineLibs' hsc_env :: HscEnv
hsc_env pls :: PersistentLinkerState
pls =
do
let dflags :: DynFlags
dflags@(DynFlags { ldInputs :: DynFlags -> [Option]
ldInputs = [Option]
cmdline_ld_inputs
, libraryPaths :: DynFlags -> [String]
libraryPaths = [String]
lib_paths_base})
= HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
let minus_ls_1 :: [String]
minus_ls_1 = [ String
lib | Option ('-':'l':lib :: String
lib) <- [Option]
cmdline_ld_inputs ]
let platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
os :: OS
os = Platform -> OS
platformOS Platform
platform
minus_ls :: [String]
minus_ls = case OS
os of
OSMinGW32 -> "pthread" String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
minus_ls_1
_ -> [String]
minus_ls_1
[String]
gcc_paths <- DynFlags -> OS -> IO [String]
getGCCPaths DynFlags
dflags OS
os
[String]
lib_paths_env <- String -> [String] -> IO [String]
addEnvPaths "LIBRARY_PATH" [String]
lib_paths_base
DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags "Search directories (user):"
DynFlags -> String -> IO ()
maybePutStr DynFlags
dflags ([String] -> String
unlines ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (" "String -> String -> String
forall a. [a] -> [a] -> [a]
++) [String]
lib_paths_env)
DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags "Search directories (gcc):"
DynFlags -> String -> IO ()
maybePutStr DynFlags
dflags ([String] -> String
unlines ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (" "String -> String -> String
forall a. [a] -> [a] -> [a]
++) [String]
gcc_paths)
[LibrarySpec]
libspecs
<- (String -> IO LibrarySpec) -> [String] -> IO [LibrarySpec]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (HscEnv -> Bool -> [String] -> [String] -> String -> IO LibrarySpec
locateLib HscEnv
hsc_env Bool
False [String]
lib_paths_env [String]
gcc_paths) [String]
minus_ls
[Maybe LibrarySpec]
classified_ld_inputs <- (String -> IO (Maybe LibrarySpec))
-> [String] -> IO [Maybe LibrarySpec]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (DynFlags -> String -> IO (Maybe LibrarySpec)
classifyLdInput DynFlags
dflags)
[ String
f | FileOption _ f :: String
f <- [Option]
cmdline_ld_inputs ]
let platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
let (framework_paths :: [String]
framework_paths, frameworks :: [String]
frameworks) =
if Platform -> Bool
platformUsesFrameworks Platform
platform
then (DynFlags -> [String]
frameworkPaths DynFlags
dflags, DynFlags -> [String]
cmdlineFrameworks DynFlags
dflags)
else ([],[])
let cmdline_lib_specs :: [LibrarySpec]
cmdline_lib_specs = [Maybe LibrarySpec] -> [LibrarySpec]
forall a. [Maybe a] -> [a]
catMaybes [Maybe LibrarySpec]
classified_ld_inputs
[LibrarySpec] -> [LibrarySpec] -> [LibrarySpec]
forall a. [a] -> [a] -> [a]
++ [LibrarySpec]
libspecs
[LibrarySpec] -> [LibrarySpec] -> [LibrarySpec]
forall a. [a] -> [a] -> [a]
++ (String -> LibrarySpec) -> [String] -> [LibrarySpec]
forall a b. (a -> b) -> [a] -> [b]
map String -> LibrarySpec
Framework [String]
frameworks
if [LibrarySpec] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [LibrarySpec]
cmdline_lib_specs then PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls
else do
let all_paths :: [String]
all_paths = let paths :: [String]
paths = String -> String
takeDirectory ((String, [Option]) -> String
forall a b. (a, b) -> a
fst ((String, [Option]) -> String) -> (String, [Option]) -> String
forall a b. (a -> b) -> a -> b
$ Settings -> (String, [Option])
sPgm_c (Settings -> (String, [Option])) -> Settings -> (String, [Option])
forall a b. (a -> b) -> a -> b
$ DynFlags -> Settings
settings DynFlags
dflags)
String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
framework_paths
[String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
lib_paths_base
[String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [ String -> String
takeDirectory String
dll | DLLPath dll :: String
dll <- [LibrarySpec]
libspecs ]
in [String] -> [String]
forall a. Eq a => [a] -> [a]
nub ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
normalise [String]
paths
let lib_paths :: [String]
lib_paths = [String] -> [String]
forall a. Eq a => [a] -> [a]
nub ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ [String]
lib_paths_base [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
gcc_paths
[String]
all_paths_env <- String -> [String] -> IO [String]
addEnvPaths "LD_LIBRARY_PATH" [String]
all_paths
[Ptr ()]
pathCache <- (String -> IO (Ptr ())) -> [String] -> IO [Ptr ()]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (HscEnv -> String -> IO (Ptr ())
addLibrarySearchPath HscEnv
hsc_env) [String]
all_paths_env
let merged_specs :: [LibrarySpec]
merged_specs = [LibrarySpec] -> [LibrarySpec]
mergeStaticObjects [LibrarySpec]
cmdline_lib_specs
PersistentLinkerState
pls1 <- (PersistentLinkerState -> LibrarySpec -> IO PersistentLinkerState)
-> PersistentLinkerState
-> [LibrarySpec]
-> IO PersistentLinkerState
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM (HscEnv
-> [String]
-> [String]
-> PersistentLinkerState
-> LibrarySpec
-> IO PersistentLinkerState
preloadLib HscEnv
hsc_env [String]
lib_paths [String]
framework_paths) PersistentLinkerState
pls
[LibrarySpec]
merged_specs
DynFlags -> String -> IO ()
maybePutStr DynFlags
dflags "final link ... "
SuccessFlag
ok <- HscEnv -> IO SuccessFlag
resolveObjs HscEnv
hsc_env
(Ptr () -> IO Bool) -> [Ptr ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> Ptr () -> IO Bool
removeLibrarySearchPath HscEnv
hsc_env) ([Ptr ()] -> IO ()) -> [Ptr ()] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Ptr ()] -> [Ptr ()]
forall a. [a] -> [a]
reverse [Ptr ()]
pathCache
if SuccessFlag -> Bool
succeeded SuccessFlag
ok then DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags "done"
else GhcException -> IO ()
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
ProgramError "linking extra libraries/objects failed")
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls1
mergeStaticObjects :: [LibrarySpec] -> [LibrarySpec]
mergeStaticObjects :: [LibrarySpec] -> [LibrarySpec]
mergeStaticObjects specs :: [LibrarySpec]
specs = [String] -> [LibrarySpec] -> [LibrarySpec]
go [] [LibrarySpec]
specs
where
go :: [FilePath] -> [LibrarySpec] -> [LibrarySpec]
go :: [String] -> [LibrarySpec] -> [LibrarySpec]
go accum :: [String]
accum (Objects objs :: [String]
objs : rest :: [LibrarySpec]
rest) = [String] -> [LibrarySpec] -> [LibrarySpec]
go ([String]
objs [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
accum) [LibrarySpec]
rest
go accum :: [String]
accum@(_:_) rest :: [LibrarySpec]
rest = [String] -> LibrarySpec
Objects ([String] -> [String]
forall a. [a] -> [a]
reverse [String]
accum) LibrarySpec -> [LibrarySpec] -> [LibrarySpec]
forall a. a -> [a] -> [a]
: [String] -> [LibrarySpec] -> [LibrarySpec]
go [] [LibrarySpec]
rest
go [] (spec :: LibrarySpec
spec:rest :: [LibrarySpec]
rest) = LibrarySpec
spec LibrarySpec -> [LibrarySpec] -> [LibrarySpec]
forall a. a -> [a] -> [a]
: [String] -> [LibrarySpec] -> [LibrarySpec]
go [] [LibrarySpec]
rest
go [] [] = []
classifyLdInput :: DynFlags -> FilePath -> IO (Maybe LibrarySpec)
classifyLdInput :: DynFlags -> String -> IO (Maybe LibrarySpec)
classifyLdInput dflags :: DynFlags
dflags f :: String
f
| Platform -> String -> Bool
isObjectFilename Platform
platform String
f = Maybe LibrarySpec -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a. Monad m => a -> m a
return (LibrarySpec -> Maybe LibrarySpec
forall a. a -> Maybe a
Just ([String] -> LibrarySpec
Objects [String
f]))
| Platform -> String -> Bool
isDynLibFilename Platform
platform String
f = Maybe LibrarySpec -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a. Monad m => a -> m a
return (LibrarySpec -> Maybe LibrarySpec
forall a. a -> Maybe a
Just (String -> LibrarySpec
DLLPath String
f))
| Bool
otherwise = do
DynFlags
-> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
putLogMsg DynFlags
dflags WarnReason
NoReason Severity
SevInfo SrcSpan
noSrcSpan
(DynFlags -> PprStyle
defaultUserStyle DynFlags
dflags)
(String -> SDoc
text ("Warning: ignoring unrecognised input `" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
f String -> String -> String
forall a. [a] -> [a] -> [a]
++ "'"))
Maybe LibrarySpec -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe LibrarySpec
forall a. Maybe a
Nothing
where platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
preloadLib
:: HscEnv -> [String] -> [String] -> PersistentLinkerState
-> LibrarySpec -> IO PersistentLinkerState
preloadLib :: HscEnv
-> [String]
-> [String]
-> PersistentLinkerState
-> LibrarySpec
-> IO PersistentLinkerState
preloadLib hsc_env :: HscEnv
hsc_env lib_paths :: [String]
lib_paths framework_paths :: [String]
framework_paths pls :: PersistentLinkerState
pls lib_spec :: LibrarySpec
lib_spec = do
DynFlags -> String -> IO ()
maybePutStr DynFlags
dflags ("Loading object " String -> String -> String
forall a. [a] -> [a] -> [a]
++ LibrarySpec -> String
showLS LibrarySpec
lib_spec String -> String -> String
forall a. [a] -> [a] -> [a]
++ " ... ")
case LibrarySpec
lib_spec of
Objects static_ishs :: [String]
static_ishs -> do
(b :: Bool
b, pls1 :: PersistentLinkerState
pls1) <- [String] -> [String] -> IO (Bool, PersistentLinkerState)
forall p. p -> [String] -> IO (Bool, PersistentLinkerState)
preload_statics [String]
lib_paths [String]
static_ishs
DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags (if Bool
b then "done" else "not found")
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls1
Archive static_ish :: String
static_ish -> do
Bool
b <- [String] -> String -> IO Bool
forall p. p -> String -> IO Bool
preload_static_archive [String]
lib_paths String
static_ish
DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags (if Bool
b then "done" else "not found")
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls
DLL dll_unadorned :: String
dll_unadorned -> do
Maybe String
maybe_errstr <- HscEnv -> String -> IO (Maybe String)
loadDLL HscEnv
hsc_env (Platform -> String -> String
mkSOName Platform
platform String
dll_unadorned)
case Maybe String
maybe_errstr of
Nothing -> DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags "done"
Just mm :: String
mm | Platform -> OS
platformOS Platform
platform OS -> OS -> Bool
forall a. Eq a => a -> a -> Bool
/= OS
OSDarwin ->
String -> [String] -> LibrarySpec -> IO ()
preloadFailed String
mm [String]
lib_paths LibrarySpec
lib_spec
Just mm :: String
mm | Bool
otherwise -> do
let libfile :: String
libfile = ("lib" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
dll_unadorned) String -> String -> String
<.> "so"
Maybe String
err2 <- HscEnv -> String -> IO (Maybe String)
loadDLL HscEnv
hsc_env String
libfile
case Maybe String
err2 of
Nothing -> DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags "done"
Just _ -> String -> [String] -> LibrarySpec -> IO ()
preloadFailed String
mm [String]
lib_paths LibrarySpec
lib_spec
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls
DLLPath dll_path :: String
dll_path -> do
do Maybe String
maybe_errstr <- HscEnv -> String -> IO (Maybe String)
loadDLL HscEnv
hsc_env String
dll_path
case Maybe String
maybe_errstr of
Nothing -> DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags "done"
Just mm :: String
mm -> String -> [String] -> LibrarySpec -> IO ()
preloadFailed String
mm [String]
lib_paths LibrarySpec
lib_spec
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls
Framework framework :: String
framework ->
if Platform -> Bool
platformUsesFrameworks (DynFlags -> Platform
targetPlatform DynFlags
dflags)
then do Maybe String
maybe_errstr <- HscEnv -> [String] -> String -> IO (Maybe String)
loadFramework HscEnv
hsc_env [String]
framework_paths String
framework
case Maybe String
maybe_errstr of
Nothing -> DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags "done"
Just mm :: String
mm -> String -> [String] -> LibrarySpec -> IO ()
preloadFailed String
mm [String]
framework_paths LibrarySpec
lib_spec
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls
else String -> IO PersistentLinkerState
forall a. String -> a
panic "preloadLib Framework"
where
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
preloadFailed :: String -> [String] -> LibrarySpec -> IO ()
preloadFailed :: String -> [String] -> LibrarySpec -> IO ()
preloadFailed sys_errmsg :: String
sys_errmsg paths :: [String]
paths spec :: LibrarySpec
spec
= do DynFlags -> String -> IO ()
maybePutStr DynFlags
dflags "failed.\n"
GhcException -> IO ()
forall a. GhcException -> IO a
throwGhcExceptionIO (GhcException -> IO ()) -> GhcException -> IO ()
forall a b. (a -> b) -> a -> b
$
String -> GhcException
CmdLineError (
"user specified .o/.so/.DLL could not be loaded ("
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
sys_errmsg String -> String -> String
forall a. [a] -> [a] -> [a]
++ ")\nWhilst trying to load: "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ LibrarySpec -> String
showLS LibrarySpec
spec String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\nAdditional directories searched:"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ (if [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
paths then " (none)" else
String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate "\n" ((String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (" "String -> String -> String
forall a. [a] -> [a] -> [a]
++) [String]
paths)))
preload_statics :: p -> [String] -> IO (Bool, PersistentLinkerState)
preload_statics _paths :: p
_paths names :: [String]
names
= do Bool
b <- [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
or ([Bool] -> Bool) -> IO [Bool] -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> IO Bool) -> [String] -> IO [Bool]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM String -> IO Bool
doesFileExist [String]
names
if Bool -> Bool
not Bool
b then (Bool, PersistentLinkerState) -> IO (Bool, PersistentLinkerState)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
False, PersistentLinkerState
pls)
else if Bool
dynamicGhc
then do PersistentLinkerState
pls1 <- HscEnv
-> PersistentLinkerState -> [String] -> IO PersistentLinkerState
dynLoadObjs HscEnv
hsc_env PersistentLinkerState
pls [String]
names
(Bool, PersistentLinkerState) -> IO (Bool, PersistentLinkerState)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
True, PersistentLinkerState
pls1)
else do (String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> String -> IO ()
loadObj HscEnv
hsc_env) [String]
names
(Bool, PersistentLinkerState) -> IO (Bool, PersistentLinkerState)
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
True, PersistentLinkerState
pls)
preload_static_archive :: p -> String -> IO Bool
preload_static_archive _paths :: p
_paths name :: String
name
= do Bool
b <- String -> IO Bool
doesFileExist String
name
if Bool -> Bool
not Bool
b then Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
else do if Bool
dynamicGhc
then GhcException -> IO ()
forall a. GhcException -> IO a
throwGhcExceptionIO (GhcException -> IO ()) -> GhcException -> IO ()
forall a b. (a -> b) -> a -> b
$
String -> GhcException
CmdLineError String
dynamic_msg
else HscEnv -> String -> IO ()
loadArchive HscEnv
hsc_env String
name
Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
where
dynamic_msg :: String
dynamic_msg = [String] -> String
unlines
[ "User-specified static library could not be loaded ("
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
name String -> String -> String
forall a. [a] -> [a] -> [a]
++ ")"
, "Loading static libraries is not supported in this configuration."
, "Try using a dynamic library instead."
]
linkExpr :: HscEnv -> SrcSpan -> UnlinkedBCO -> IO ForeignHValue
linkExpr :: HscEnv -> SrcSpan -> UnlinkedBCO -> IO ForeignHValue
linkExpr hsc_env :: HscEnv
hsc_env span :: SrcSpan
span root_ul_bco :: UnlinkedBCO
root_ul_bco
= do {
; HscEnv -> IO ()
initDynLinker HscEnv
hsc_env
; (PersistentLinkerState
-> IO (PersistentLinkerState, ForeignHValue))
-> IO ForeignHValue
forall a.
(PersistentLinkerState -> IO (PersistentLinkerState, a)) -> IO a
modifyPLS ((PersistentLinkerState
-> IO (PersistentLinkerState, ForeignHValue))
-> IO ForeignHValue)
-> (PersistentLinkerState
-> IO (PersistentLinkerState, ForeignHValue))
-> IO ForeignHValue
forall a b. (a -> b) -> a -> b
$ \pls0 :: PersistentLinkerState
pls0 -> do {
; (pls :: PersistentLinkerState
pls, ok :: SuccessFlag
ok) <- HscEnv
-> PersistentLinkerState
-> SrcSpan
-> [Module]
-> IO (PersistentLinkerState, SuccessFlag)
linkDependencies HscEnv
hsc_env PersistentLinkerState
pls0 SrcSpan
span [Module]
needed_mods
; if SuccessFlag -> Bool
failed SuccessFlag
ok then
GhcException -> IO (PersistentLinkerState, ForeignHValue)
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
ProgramError "")
else do {
let ie :: ItblEnv
ie = PersistentLinkerState -> ItblEnv
itbl_env PersistentLinkerState
pls
ce :: ClosureEnv
ce = PersistentLinkerState -> ClosureEnv
closure_env PersistentLinkerState
pls
; let nobreakarray :: a
nobreakarray = String -> a
forall a. HasCallStack => String -> a
error "no break array"
bco_ix :: NameEnv Int
bco_ix = [(Name, Int)] -> NameEnv Int
forall a. [(Name, a)] -> NameEnv a
mkNameEnv [(UnlinkedBCO -> Name
unlinkedBCOName UnlinkedBCO
root_ul_bco, 0)]
; ResolvedBCO
resolved <- HscEnv
-> ItblEnv
-> ClosureEnv
-> NameEnv Int
-> RemoteRef BreakArray
-> UnlinkedBCO
-> IO ResolvedBCO
linkBCO HscEnv
hsc_env ItblEnv
ie ClosureEnv
ce NameEnv Int
bco_ix RemoteRef BreakArray
forall a. a
nobreakarray UnlinkedBCO
root_ul_bco
; [root_hvref :: HValueRef
root_hvref] <- HscEnv -> [ResolvedBCO] -> IO [HValueRef]
createBCOs HscEnv
hsc_env [ResolvedBCO
resolved]
; ForeignHValue
fhv <- HscEnv -> HValueRef -> IO ForeignHValue
forall a. HscEnv -> RemoteRef a -> IO (ForeignRef a)
mkFinalizedHValue HscEnv
hsc_env HValueRef
root_hvref
; (PersistentLinkerState, ForeignHValue)
-> IO (PersistentLinkerState, ForeignHValue)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls, ForeignHValue
fhv)
}}}
where
free_names :: [Name]
free_names = UniqDSet Name -> [Name]
forall a. UniqDSet a -> [a]
uniqDSetToList (UnlinkedBCO -> UniqDSet Name
bcoFreeNames UnlinkedBCO
root_ul_bco)
needed_mods :: [Module]
needed_mods :: [Module]
needed_mods = [ HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
n | Name
n <- [Name]
free_names,
Name -> Bool
isExternalName Name
n,
Bool -> Bool
not (Name -> Bool
isWiredInName Name
n)
]
dieWith :: DynFlags -> SrcSpan -> MsgDoc -> IO a
dieWith :: DynFlags -> SrcSpan -> SDoc -> IO a
dieWith dflags :: DynFlags
dflags span :: SrcSpan
span msg :: SDoc
msg = GhcException -> IO a
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
ProgramError (DynFlags -> SDoc -> String
showSDoc DynFlags
dflags (Severity -> SrcSpan -> SDoc -> SDoc
mkLocMessage Severity
SevFatal SrcSpan
span SDoc
msg)))
checkNonStdWay :: DynFlags -> SrcSpan -> IO (Maybe FilePath)
checkNonStdWay :: DynFlags -> SrcSpan -> IO (Maybe String)
checkNonStdWay dflags :: DynFlags
dflags srcspan :: SrcSpan
srcspan
| GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_ExternalInterpreter DynFlags
dflags = Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
| [Way]
interpWays [Way] -> [Way] -> Bool
forall a. Eq a => a -> a -> Bool
== [Way]
haskellWays = Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
| DynFlags -> String
objectSuf DynFlags
dflags String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
normalObjectSuffix Bool -> Bool -> Bool
&& Bool -> Bool
not ([Way] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Way]
haskellWays)
= DynFlags -> SrcSpan -> IO (Maybe String)
failNonStd DynFlags
dflags SrcSpan
srcspan
| Bool
otherwise = Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Maybe String
forall a. a -> Maybe a
Just (String
interpTag String -> String -> String
forall a. [a] -> [a] -> [a]
++ "o"))
where
haskellWays :: [Way]
haskellWays = (Way -> Bool) -> [Way] -> [Way]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Way -> Bool) -> Way -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Way -> Bool
wayRTSOnly) (DynFlags -> [Way]
ways DynFlags
dflags)
interpTag :: String
interpTag = case [Way] -> String
mkBuildTag [Way]
interpWays of
"" -> ""
tag :: String
tag -> String
tag String -> String -> String
forall a. [a] -> [a] -> [a]
++ "_"
normalObjectSuffix :: String
normalObjectSuffix :: String
normalObjectSuffix = Phase -> String
phaseInputExt Phase
StopLn
failNonStd :: DynFlags -> SrcSpan -> IO (Maybe FilePath)
failNonStd :: DynFlags -> SrcSpan -> IO (Maybe String)
failNonStd dflags :: DynFlags
dflags srcspan :: SrcSpan
srcspan = DynFlags -> SrcSpan -> SDoc -> IO (Maybe String)
forall a. DynFlags -> SrcSpan -> SDoc -> IO a
dieWith DynFlags
dflags SrcSpan
srcspan (SDoc -> IO (Maybe String)) -> SDoc -> IO (Maybe String)
forall a b. (a -> b) -> a -> b
$
String -> SDoc
text "Cannot load" SDoc -> SDoc -> SDoc
<+> SDoc
compWay SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "objects when GHC is built" SDoc -> SDoc -> SDoc
<+> SDoc
ghciWay SDoc -> SDoc -> SDoc
$$
String -> SDoc
text "To fix this, either:" SDoc -> SDoc -> SDoc
$$
String -> SDoc
text " (1) Use -fexternal-interpreter, or" SDoc -> SDoc -> SDoc
$$
String -> SDoc
text " (2) Build the program twice: once" SDoc -> SDoc -> SDoc
<+>
SDoc
ghciWay SDoc -> SDoc -> SDoc
<> String -> SDoc
text ", and then" SDoc -> SDoc -> SDoc
$$
String -> SDoc
text " with" SDoc -> SDoc -> SDoc
<+> SDoc
compWay SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "using -osuf to set a different object file suffix."
where compWay :: SDoc
compWay
| Way
WayDyn Way -> [Way] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` DynFlags -> [Way]
ways DynFlags
dflags = String -> SDoc
text "-dynamic"
| Way
WayProf Way -> [Way] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` DynFlags -> [Way]
ways DynFlags
dflags = String -> SDoc
text "-prof"
| Bool
otherwise = String -> SDoc
text "normal"
ghciWay :: SDoc
ghciWay
| Bool
dynamicGhc = String -> SDoc
text "with -dynamic"
| Bool
rtsIsProfiled = String -> SDoc
text "with -prof"
| Bool
otherwise = String -> SDoc
text "the normal way"
getLinkDeps :: HscEnv -> HomePackageTable
-> PersistentLinkerState
-> Maybe FilePath
-> SrcSpan
-> [Module]
-> IO ([Linkable], [InstalledUnitId])
getLinkDeps :: HscEnv
-> HomePackageTable
-> PersistentLinkerState
-> Maybe String
-> SrcSpan
-> [Module]
-> IO ([Linkable], [LinkerUnitId])
getLinkDeps hsc_env :: HscEnv
hsc_env hpt :: HomePackageTable
hpt pls :: PersistentLinkerState
pls replace_osuf :: Maybe String
replace_osuf span :: SrcSpan
span mods :: [Module]
mods
= do {
; (mods_s :: [ModuleName]
mods_s, pkgs_s :: [LinkerUnitId]
pkgs_s) <- [Module]
-> UniqDSet ModuleName
-> UniqDSet LinkerUnitId
-> IO ([ModuleName], [LinkerUnitId])
follow_deps ((Module -> Bool) -> [Module] -> [Module]
forall a. (a -> Bool) -> [a] -> [a]
filterOut Module -> Bool
isInteractiveModule [Module]
mods)
UniqDSet ModuleName
forall a. UniqDSet a
emptyUniqDSet UniqDSet LinkerUnitId
forall a. UniqDSet a
emptyUniqDSet;
; let {
mods_needed :: [ModuleName]
mods_needed = [ModuleName]
mods_s [ModuleName] -> [ModuleName] -> [ModuleName]
forall a. Ord a => [a] -> [a] -> [a]
`minusList` [ModuleName]
linked_mods ;
pkgs_needed :: [LinkerUnitId]
pkgs_needed = [LinkerUnitId]
pkgs_s [LinkerUnitId] -> [LinkerUnitId] -> [LinkerUnitId]
forall a. Ord a => [a] -> [a] -> [a]
`minusList` PersistentLinkerState -> [LinkerUnitId]
pkgs_loaded PersistentLinkerState
pls ;
linked_mods :: [ModuleName]
linked_mods = (Linkable -> ModuleName) -> [Linkable] -> [ModuleName]
forall a b. (a -> b) -> [a] -> [b]
map (Module -> ModuleName
moduleName(Module -> ModuleName)
-> (Linkable -> Module) -> Linkable -> ModuleName
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Linkable -> Module
linkableModule)
(PersistentLinkerState -> [Linkable]
objs_loaded PersistentLinkerState
pls [Linkable] -> [Linkable] -> [Linkable]
forall a. [a] -> [a] -> [a]
++ PersistentLinkerState -> [Linkable]
bcos_loaded PersistentLinkerState
pls) }
; let { osuf :: String
osuf = DynFlags -> String
objectSuf DynFlags
dflags }
; [Linkable]
lnks_needed <- (ModuleName -> IO Linkable) -> [ModuleName] -> IO [Linkable]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (String -> ModuleName -> IO Linkable
get_linkable String
osuf) [ModuleName]
mods_needed
; ([Linkable], [LinkerUnitId]) -> IO ([Linkable], [LinkerUnitId])
forall (m :: * -> *) a. Monad m => a -> m a
return ([Linkable]
lnks_needed, [LinkerUnitId]
pkgs_needed) }
where
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
this_pkg :: UnitId
this_pkg = DynFlags -> UnitId
thisPackage DynFlags
dflags
follow_deps :: [Module]
-> UniqDSet ModuleName
-> UniqDSet InstalledUnitId
-> IO ([ModuleName], [InstalledUnitId])
follow_deps :: [Module]
-> UniqDSet ModuleName
-> UniqDSet LinkerUnitId
-> IO ([ModuleName], [LinkerUnitId])
follow_deps [] acc_mods :: UniqDSet ModuleName
acc_mods acc_pkgs :: UniqDSet LinkerUnitId
acc_pkgs
= ([ModuleName], [LinkerUnitId]) -> IO ([ModuleName], [LinkerUnitId])
forall (m :: * -> *) a. Monad m => a -> m a
return (UniqDSet ModuleName -> [ModuleName]
forall a. UniqDSet a -> [a]
uniqDSetToList UniqDSet ModuleName
acc_mods, UniqDSet LinkerUnitId -> [LinkerUnitId]
forall a. UniqDSet a -> [a]
uniqDSetToList UniqDSet LinkerUnitId
acc_pkgs)
follow_deps (mod :: Module
mod:mods :: [Module]
mods) acc_mods :: UniqDSet ModuleName
acc_mods acc_pkgs :: UniqDSet LinkerUnitId
acc_pkgs
= do
MaybeErr SDoc ModIface
mb_iface <- SDoc
-> HscEnv
-> IfG (MaybeErr SDoc ModIface)
-> IO (MaybeErr SDoc ModIface)
forall a. SDoc -> HscEnv -> IfG a -> IO a
initIfaceCheck (String -> SDoc
text "getLinkDeps") HscEnv
hsc_env (IfG (MaybeErr SDoc ModIface) -> IO (MaybeErr SDoc ModIface))
-> IfG (MaybeErr SDoc ModIface) -> IO (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
msg Module
mod (Bool -> WhereFrom
ImportByUser Bool
False)
ModIface
iface <- case MaybeErr SDoc ModIface
mb_iface of
Maybes.Failed err :: SDoc
err -> GhcException -> IO ModIface
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
ProgramError (DynFlags -> SDoc -> String
showSDoc DynFlags
dflags SDoc
err))
Maybes.Succeeded iface :: ModIface
iface -> ModIface -> IO ModIface
forall (m :: * -> *) a. Monad m => a -> m a
return ModIface
iface
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ModIface -> Bool
mi_boot ModIface
iface) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ Module -> IO ()
forall a a. Outputable a => a -> IO a
link_boot_mod_error Module
mod
let
pkg :: UnitId
pkg = Module -> UnitId
moduleUnitId Module
mod
deps :: Dependencies
deps = ModIface -> Dependencies
mi_deps ModIface
iface
pkg_deps :: [(LinkerUnitId, Bool)]
pkg_deps = Dependencies -> [(LinkerUnitId, Bool)]
dep_pkgs Dependencies
deps
(boot_deps :: [ModuleName]
boot_deps, mod_deps :: [ModuleName]
mod_deps) = ((ModuleName, Bool) -> Either ModuleName ModuleName)
-> [(ModuleName, Bool)] -> ([ModuleName], [ModuleName])
forall a b c. (a -> Either b c) -> [a] -> ([b], [c])
partitionWith (ModuleName, Bool) -> Either ModuleName ModuleName
forall b. (b, Bool) -> Either b b
is_boot (Dependencies -> [(ModuleName, Bool)]
dep_mods Dependencies
deps)
where is_boot :: (b, Bool) -> Either b b
is_boot (m :: b
m,True) = b -> Either b b
forall a b. a -> Either a b
Left b
m
is_boot (m :: b
m,False) = b -> Either b b
forall a b. b -> Either a b
Right b
m
boot_deps' :: [ModuleName]
boot_deps' = (ModuleName -> Bool) -> [ModuleName] -> [ModuleName]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (ModuleName -> Bool) -> ModuleName -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ModuleName -> UniqDSet ModuleName -> Bool
forall a. Uniquable a => a -> UniqDSet a -> Bool
`elementOfUniqDSet` UniqDSet ModuleName
acc_mods)) [ModuleName]
boot_deps
acc_mods' :: UniqDSet ModuleName
acc_mods' = UniqDSet ModuleName -> [ModuleName] -> UniqDSet ModuleName
forall a. Uniquable a => UniqDSet a -> [a] -> UniqDSet a
addListToUniqDSet UniqDSet ModuleName
acc_mods (Module -> ModuleName
moduleName Module
mod ModuleName -> [ModuleName] -> [ModuleName]
forall a. a -> [a] -> [a]
: [ModuleName]
mod_deps)
acc_pkgs' :: UniqDSet LinkerUnitId
acc_pkgs' = UniqDSet LinkerUnitId -> [LinkerUnitId] -> UniqDSet LinkerUnitId
forall a. Uniquable a => UniqDSet a -> [a] -> UniqDSet a
addListToUniqDSet UniqDSet LinkerUnitId
acc_pkgs ([LinkerUnitId] -> UniqDSet LinkerUnitId)
-> [LinkerUnitId] -> UniqDSet LinkerUnitId
forall a b. (a -> b) -> a -> b
$ ((LinkerUnitId, Bool) -> LinkerUnitId)
-> [(LinkerUnitId, Bool)] -> [LinkerUnitId]
forall a b. (a -> b) -> [a] -> [b]
map (LinkerUnitId, Bool) -> LinkerUnitId
forall a b. (a, b) -> a
fst [(LinkerUnitId, Bool)]
pkg_deps
if UnitId
pkg UnitId -> UnitId -> Bool
forall a. Eq a => a -> a -> Bool
/= UnitId
this_pkg
then [Module]
-> UniqDSet ModuleName
-> UniqDSet LinkerUnitId
-> IO ([ModuleName], [LinkerUnitId])
follow_deps [Module]
mods UniqDSet ModuleName
acc_mods (UniqDSet LinkerUnitId -> LinkerUnitId -> UniqDSet LinkerUnitId
forall a. Uniquable a => UniqDSet a -> a -> UniqDSet a
addOneToUniqDSet UniqDSet LinkerUnitId
acc_pkgs' (UnitId -> LinkerUnitId
toInstalledUnitId UnitId
pkg))
else [Module]
-> UniqDSet ModuleName
-> UniqDSet LinkerUnitId
-> IO ([ModuleName], [LinkerUnitId])
follow_deps ((ModuleName -> Module) -> [ModuleName] -> [Module]
forall a b. (a -> b) -> [a] -> [b]
map (UnitId -> ModuleName -> Module
mkModule UnitId
this_pkg) [ModuleName]
boot_deps' [Module] -> [Module] -> [Module]
forall a. [a] -> [a] -> [a]
++ [Module]
mods)
UniqDSet ModuleName
acc_mods' UniqDSet LinkerUnitId
acc_pkgs'
where
msg :: SDoc
msg = String -> SDoc
text "need to link module" SDoc -> SDoc -> SDoc
<+> Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "due to use of Template Haskell"
link_boot_mod_error :: a -> IO a
link_boot_mod_error mod :: a
mod =
GhcException -> IO a
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
ProgramError (DynFlags -> SDoc -> String
showSDoc DynFlags
dflags (
String -> SDoc
text "module" SDoc -> SDoc -> SDoc
<+> a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
mod SDoc -> SDoc -> SDoc
<+>
String -> SDoc
text "cannot be linked; it is only available as a boot module")))
no_obj :: Outputable a => a -> IO b
no_obj :: a -> IO b
no_obj mod :: a
mod = DynFlags -> SrcSpan -> SDoc -> IO b
forall a. DynFlags -> SrcSpan -> SDoc -> IO a
dieWith DynFlags
dflags SrcSpan
span (SDoc -> IO b) -> SDoc -> IO b
forall a b. (a -> b) -> a -> b
$
String -> SDoc
text "cannot find object file for module " SDoc -> SDoc -> SDoc
<>
SDoc -> SDoc
quotes (a -> SDoc
forall a. Outputable a => a -> SDoc
ppr a
mod) SDoc -> SDoc -> SDoc
$$
SDoc
while_linking_expr
while_linking_expr :: SDoc
while_linking_expr = String -> SDoc
text "while linking an interpreted expression"
get_linkable :: String -> ModuleName -> IO Linkable
get_linkable osuf :: String
osuf mod_name :: ModuleName
mod_name
| Just mod_info :: HomeModInfo
mod_info <- HomePackageTable -> ModuleName -> Maybe HomeModInfo
lookupHpt HomePackageTable
hpt ModuleName
mod_name
= Linkable -> IO Linkable
adjust_linkable (String -> Maybe Linkable -> Linkable
forall a. HasCallStack => String -> Maybe a -> a
Maybes.expectJust "getLinkDeps" (HomeModInfo -> Maybe Linkable
hm_linkable HomeModInfo
mod_info))
| Bool
otherwise
= do
FindResult
mb_stuff <- HscEnv -> ModuleName -> IO FindResult
findHomeModule HscEnv
hsc_env ModuleName
mod_name
case FindResult
mb_stuff of
Found loc :: ModLocation
loc mod :: Module
mod -> ModLocation -> Module -> IO Linkable
found ModLocation
loc Module
mod
_ -> ModuleName -> IO Linkable
forall a a. Outputable a => a -> IO a
no_obj ModuleName
mod_name
where
found :: ModLocation -> Module -> IO Linkable
found loc :: ModLocation
loc mod :: Module
mod = do {
Maybe Linkable
mb_lnk <- Module -> ModLocation -> IO (Maybe Linkable)
findObjectLinkableMaybe Module
mod ModLocation
loc ;
case Maybe Linkable
mb_lnk of {
Nothing -> Module -> IO Linkable
forall a a. Outputable a => a -> IO a
no_obj Module
mod ;
Just lnk :: Linkable
lnk -> Linkable -> IO Linkable
adjust_linkable Linkable
lnk
}}
adjust_linkable :: Linkable -> IO Linkable
adjust_linkable lnk :: Linkable
lnk
| Just new_osuf :: String
new_osuf <- Maybe String
replace_osuf = do
[Unlinked]
new_uls <- (Unlinked -> IO Unlinked) -> [Unlinked] -> IO [Unlinked]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (String -> Unlinked -> IO Unlinked
adjust_ul String
new_osuf)
(Linkable -> [Unlinked]
linkableUnlinked Linkable
lnk)
Linkable -> IO Linkable
forall (m :: * -> *) a. Monad m => a -> m a
return Linkable
lnk{ linkableUnlinked :: [Unlinked]
linkableUnlinked=[Unlinked]
new_uls }
| Bool
otherwise =
Linkable -> IO Linkable
forall (m :: * -> *) a. Monad m => a -> m a
return Linkable
lnk
adjust_ul :: String -> Unlinked -> IO Unlinked
adjust_ul new_osuf :: String
new_osuf (DotO file :: String
file) = do
MASSERT(osuf `isSuffixOf` file)
let file_base :: String
file_base = Maybe String -> String
forall a. HasCallStack => Maybe a -> a
fromJust (String -> String -> Maybe String
stripExtension String
osuf String
file)
new_file :: String
new_file = String
file_base String -> String -> String
<.> String
new_osuf
Bool
ok <- String -> IO Bool
doesFileExist String
new_file
if (Bool -> Bool
not Bool
ok)
then DynFlags -> SrcSpan -> SDoc -> IO Unlinked
forall a. DynFlags -> SrcSpan -> SDoc -> IO a
dieWith DynFlags
dflags SrcSpan
span (SDoc -> IO Unlinked) -> SDoc -> IO Unlinked
forall a b. (a -> b) -> a -> b
$
String -> SDoc
text "cannot find object file "
SDoc -> SDoc -> SDoc
<> SDoc -> SDoc
quotes (String -> SDoc
text String
new_file) SDoc -> SDoc -> SDoc
$$ SDoc
while_linking_expr
else Unlinked -> IO Unlinked
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Unlinked
DotO String
new_file)
adjust_ul _ (DotA fp :: String
fp) = String -> IO Unlinked
forall a. String -> a
panic ("adjust_ul DotA " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
fp)
adjust_ul _ (DotDLL fp :: String
fp) = String -> IO Unlinked
forall a. String -> a
panic ("adjust_ul DotDLL " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
fp)
adjust_ul _ l :: Unlinked
l@(BCOs {}) = Unlinked -> IO Unlinked
forall (m :: * -> *) a. Monad m => a -> m a
return Unlinked
l
linkDecls :: HscEnv -> SrcSpan -> CompiledByteCode -> IO ()
linkDecls :: HscEnv -> SrcSpan -> CompiledByteCode -> IO ()
linkDecls hsc_env :: HscEnv
hsc_env span :: SrcSpan
span cbc :: CompiledByteCode
cbc@CompiledByteCode{..} = do
HscEnv -> IO ()
initDynLinker HscEnv
hsc_env
(PersistentLinkerState -> IO (PersistentLinkerState, ())) -> IO ()
forall a.
(PersistentLinkerState -> IO (PersistentLinkerState, a)) -> IO a
modifyPLS ((PersistentLinkerState -> IO (PersistentLinkerState, ()))
-> IO ())
-> (PersistentLinkerState -> IO (PersistentLinkerState, ()))
-> IO ()
forall a b. (a -> b) -> a -> b
$ \pls0 :: PersistentLinkerState
pls0 -> do
(pls :: PersistentLinkerState
pls, ok :: SuccessFlag
ok) <- HscEnv
-> PersistentLinkerState
-> SrcSpan
-> [Module]
-> IO (PersistentLinkerState, SuccessFlag)
linkDependencies HscEnv
hsc_env PersistentLinkerState
pls0 SrcSpan
span [Module]
needed_mods
if SuccessFlag -> Bool
failed SuccessFlag
ok
then GhcException -> IO (PersistentLinkerState, ())
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
ProgramError "")
else do
let ie :: ItblEnv
ie = ItblEnv -> ItblEnv -> ItblEnv
forall a. NameEnv a -> NameEnv a -> NameEnv a
plusNameEnv (PersistentLinkerState -> ItblEnv
itbl_env PersistentLinkerState
pls) ItblEnv
bc_itbls
ce :: ClosureEnv
ce = PersistentLinkerState -> ClosureEnv
closure_env PersistentLinkerState
pls
[(Name, HValueRef)]
new_bindings <- HscEnv
-> ItblEnv
-> ClosureEnv
-> [CompiledByteCode]
-> IO [(Name, HValueRef)]
linkSomeBCOs HscEnv
hsc_env ItblEnv
ie ClosureEnv
ce [CompiledByteCode
cbc]
[(Name, ForeignHValue)]
nms_fhvs <- HscEnv -> [(Name, HValueRef)] -> IO [(Name, ForeignHValue)]
makeForeignNamedHValueRefs HscEnv
hsc_env [(Name, HValueRef)]
new_bindings
let pls2 :: PersistentLinkerState
pls2 = PersistentLinkerState
pls { closure_env :: ClosureEnv
closure_env = ClosureEnv -> [(Name, ForeignHValue)] -> ClosureEnv
extendClosureEnv ClosureEnv
ce [(Name, ForeignHValue)]
nms_fhvs
, itbl_env :: ItblEnv
itbl_env = ItblEnv
ie }
(PersistentLinkerState, ()) -> IO (PersistentLinkerState, ())
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls2, ())
where
free_names :: [Name]
free_names = UniqDSet Name -> [Name]
forall a. UniqDSet a -> [a]
uniqDSetToList (UniqDSet Name -> [Name]) -> UniqDSet Name -> [Name]
forall a b. (a -> b) -> a -> b
$
(UnlinkedBCO -> UniqDSet Name -> UniqDSet Name)
-> UniqDSet Name -> [UnlinkedBCO] -> UniqDSet Name
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (UniqDSet Name -> UniqDSet Name -> UniqDSet Name
forall a. UniqDSet a -> UniqDSet a -> UniqDSet a
unionUniqDSets (UniqDSet Name -> UniqDSet Name -> UniqDSet Name)
-> (UnlinkedBCO -> UniqDSet Name)
-> UnlinkedBCO
-> UniqDSet Name
-> UniqDSet Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnlinkedBCO -> UniqDSet Name
bcoFreeNames) UniqDSet Name
forall a. UniqDSet a
emptyUniqDSet [UnlinkedBCO]
bc_bcos
needed_mods :: [Module]
needed_mods :: [Module]
needed_mods = [ HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
n | Name
n <- [Name]
free_names,
Name -> Bool
isExternalName Name
n,
Bool -> Bool
not (Name -> Bool
isWiredInName Name
n)
]
linkModule :: HscEnv -> Module -> IO ()
linkModule :: HscEnv -> Module -> IO ()
linkModule hsc_env :: HscEnv
hsc_env mod :: Module
mod = do
HscEnv -> IO ()
initDynLinker HscEnv
hsc_env
(PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ ((PersistentLinkerState -> IO PersistentLinkerState) -> IO ())
-> (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
forall a b. (a -> b) -> a -> b
$ \pls :: PersistentLinkerState
pls -> do
(pls' :: PersistentLinkerState
pls', ok :: SuccessFlag
ok) <- HscEnv
-> PersistentLinkerState
-> SrcSpan
-> [Module]
-> IO (PersistentLinkerState, SuccessFlag)
linkDependencies HscEnv
hsc_env PersistentLinkerState
pls SrcSpan
noSrcSpan [Module
mod]
if (SuccessFlag -> Bool
failed SuccessFlag
ok) then GhcException -> IO PersistentLinkerState
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
ProgramError "could not link module")
else PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls'
linkModules :: HscEnv -> PersistentLinkerState -> [Linkable]
-> IO (PersistentLinkerState, SuccessFlag)
linkModules :: HscEnv
-> PersistentLinkerState
-> [Linkable]
-> IO (PersistentLinkerState, SuccessFlag)
linkModules hsc_env :: HscEnv
hsc_env pls :: PersistentLinkerState
pls linkables :: [Linkable]
linkables
= IO (PersistentLinkerState, SuccessFlag)
-> IO (PersistentLinkerState, SuccessFlag)
forall a. IO a -> IO a
mask_ (IO (PersistentLinkerState, SuccessFlag)
-> IO (PersistentLinkerState, SuccessFlag))
-> IO (PersistentLinkerState, SuccessFlag)
-> IO (PersistentLinkerState, SuccessFlag)
forall a b. (a -> b) -> a -> b
$ do
let (objs :: [Linkable]
objs, bcos :: [Linkable]
bcos) = (Linkable -> Bool) -> [Linkable] -> ([Linkable], [Linkable])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition Linkable -> Bool
isObjectLinkable
((Linkable -> [Linkable]) -> [Linkable] -> [Linkable]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Linkable -> [Linkable]
partitionLinkable [Linkable]
linkables)
(pls1 :: PersistentLinkerState
pls1, ok_flag :: SuccessFlag
ok_flag) <- HscEnv
-> PersistentLinkerState
-> [Linkable]
-> IO (PersistentLinkerState, SuccessFlag)
dynLinkObjs HscEnv
hsc_env PersistentLinkerState
pls [Linkable]
objs
if SuccessFlag -> Bool
failed SuccessFlag
ok_flag then
(PersistentLinkerState, SuccessFlag)
-> IO (PersistentLinkerState, SuccessFlag)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls1, SuccessFlag
Failed)
else do
PersistentLinkerState
pls2 <- HscEnv
-> PersistentLinkerState -> [Linkable] -> IO PersistentLinkerState
dynLinkBCOs HscEnv
hsc_env PersistentLinkerState
pls1 [Linkable]
bcos
(PersistentLinkerState, SuccessFlag)
-> IO (PersistentLinkerState, SuccessFlag)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls2, SuccessFlag
Succeeded)
partitionLinkable :: Linkable -> [Linkable]
partitionLinkable :: Linkable -> [Linkable]
partitionLinkable li :: Linkable
li
= let li_uls :: [Unlinked]
li_uls = Linkable -> [Unlinked]
linkableUnlinked Linkable
li
li_uls_obj :: [Unlinked]
li_uls_obj = (Unlinked -> Bool) -> [Unlinked] -> [Unlinked]
forall a. (a -> Bool) -> [a] -> [a]
filter Unlinked -> Bool
isObject [Unlinked]
li_uls
li_uls_bco :: [Unlinked]
li_uls_bco = (Unlinked -> Bool) -> [Unlinked] -> [Unlinked]
forall a. (a -> Bool) -> [a] -> [a]
filter Unlinked -> Bool
isInterpretable [Unlinked]
li_uls
in
case ([Unlinked]
li_uls_obj, [Unlinked]
li_uls_bco) of
(_:_, _:_) -> [Linkable
li {linkableUnlinked :: [Unlinked]
linkableUnlinked=[Unlinked]
li_uls_obj},
Linkable
li {linkableUnlinked :: [Unlinked]
linkableUnlinked=[Unlinked]
li_uls_bco}]
_ -> [Linkable
li]
findModuleLinkable_maybe :: [Linkable] -> Module -> Maybe Linkable
findModuleLinkable_maybe :: [Linkable] -> Module -> Maybe Linkable
findModuleLinkable_maybe lis :: [Linkable]
lis mod :: Module
mod
= case [UTCTime -> Module -> [Unlinked] -> Linkable
LM UTCTime
time Module
nm [Unlinked]
us | LM time :: UTCTime
time nm :: Module
nm us :: [Unlinked]
us <- [Linkable]
lis, Module
nm Module -> Module -> Bool
forall a. Eq a => a -> a -> Bool
== Module
mod] of
[] -> Maybe Linkable
forall a. Maybe a
Nothing
[li :: Linkable
li] -> Linkable -> Maybe Linkable
forall a. a -> Maybe a
Just Linkable
li
_ -> String -> SDoc -> Maybe Linkable
forall a. HasCallStack => String -> SDoc -> a
pprPanic "findModuleLinkable" (Module -> SDoc
forall a. Outputable a => a -> SDoc
ppr Module
mod)
linkableInSet :: Linkable -> [Linkable] -> Bool
linkableInSet :: Linkable -> [Linkable] -> Bool
linkableInSet l :: Linkable
l objs_loaded :: [Linkable]
objs_loaded =
case [Linkable] -> Module -> Maybe Linkable
findModuleLinkable_maybe [Linkable]
objs_loaded (Linkable -> Module
linkableModule Linkable
l) of
Nothing -> Bool
False
Just m :: Linkable
m -> Linkable -> UTCTime
linkableTime Linkable
l UTCTime -> UTCTime -> Bool
forall a. Eq a => a -> a -> Bool
== Linkable -> UTCTime
linkableTime Linkable
m
dynLinkObjs :: HscEnv -> PersistentLinkerState -> [Linkable]
-> IO (PersistentLinkerState, SuccessFlag)
dynLinkObjs :: HscEnv
-> PersistentLinkerState
-> [Linkable]
-> IO (PersistentLinkerState, SuccessFlag)
dynLinkObjs hsc_env :: HscEnv
hsc_env pls :: PersistentLinkerState
pls objs :: [Linkable]
objs = do
let (objs_loaded' :: [Linkable]
objs_loaded', new_objs :: [Linkable]
new_objs) = [Linkable] -> [Linkable] -> ([Linkable], [Linkable])
rmDupLinkables (PersistentLinkerState -> [Linkable]
objs_loaded PersistentLinkerState
pls) [Linkable]
objs
pls1 :: PersistentLinkerState
pls1 = PersistentLinkerState
pls { objs_loaded :: [Linkable]
objs_loaded = [Linkable]
objs_loaded' }
unlinkeds :: [Unlinked]
unlinkeds = (Linkable -> [Unlinked]) -> [Linkable] -> [Unlinked]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Linkable -> [Unlinked]
linkableUnlinked [Linkable]
new_objs
wanted_objs :: [String]
wanted_objs = (Unlinked -> String) -> [Unlinked] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Unlinked -> String
nameOfObject [Unlinked]
unlinkeds
if DynFlags -> Bool
interpreterDynamic (HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env)
then do PersistentLinkerState
pls2 <- HscEnv
-> PersistentLinkerState -> [String] -> IO PersistentLinkerState
dynLoadObjs HscEnv
hsc_env PersistentLinkerState
pls1 [String]
wanted_objs
(PersistentLinkerState, SuccessFlag)
-> IO (PersistentLinkerState, SuccessFlag)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls2, SuccessFlag
Succeeded)
else do (String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> String -> IO ()
loadObj HscEnv
hsc_env) [String]
wanted_objs
SuccessFlag
ok <- HscEnv -> IO SuccessFlag
resolveObjs HscEnv
hsc_env
if SuccessFlag -> Bool
succeeded SuccessFlag
ok then do
(PersistentLinkerState, SuccessFlag)
-> IO (PersistentLinkerState, SuccessFlag)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls1, SuccessFlag
Succeeded)
else do
PersistentLinkerState
pls2 <- HscEnv
-> [Linkable] -> PersistentLinkerState -> IO PersistentLinkerState
unload_wkr HscEnv
hsc_env [] PersistentLinkerState
pls1
(PersistentLinkerState, SuccessFlag)
-> IO (PersistentLinkerState, SuccessFlag)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls2, SuccessFlag
Failed)
dynLoadObjs :: HscEnv -> PersistentLinkerState -> [FilePath]
-> IO PersistentLinkerState
dynLoadObjs :: HscEnv
-> PersistentLinkerState -> [String] -> IO PersistentLinkerState
dynLoadObjs _ pls :: PersistentLinkerState
pls [] = PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls
dynLoadObjs hsc_env :: HscEnv
hsc_env pls :: PersistentLinkerState
pls objs :: [String]
objs = do
let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
let platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
let minus_ls :: [String]
minus_ls = [ String
lib | Option ('-':'l':lib :: String
lib) <- DynFlags -> [Option]
ldInputs DynFlags
dflags ]
let minus_big_ls :: [String]
minus_big_ls = [ String
lib | Option ('-':'L':lib :: String
lib) <- DynFlags -> [Option]
ldInputs DynFlags
dflags ]
(soFile :: String
soFile, libPath :: String
libPath , libName :: String
libName) <-
DynFlags
-> TempFileLifetime -> String -> IO (String, String, String)
newTempLibName DynFlags
dflags TempFileLifetime
TFL_CurrentModule (Platform -> String
soExt Platform
platform)
let
dflags2 :: DynFlags
dflags2 = DynFlags
dflags {
ldInputs :: [Option]
ldInputs =
(String -> [Option]) -> [String] -> [Option]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\l :: String
l -> [ String -> Option
Option ("-l" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
l) ])
([String] -> [String]
forall a. Eq a => [a] -> [a]
nub ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ (String, String) -> String
forall a b. (a, b) -> b
snd ((String, String) -> String) -> [(String, String)] -> [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PersistentLinkerState -> [(String, String)]
temp_sos PersistentLinkerState
pls)
[Option] -> [Option] -> [Option]
forall a. [a] -> [a] -> [a]
++ (String -> [Option]) -> [String] -> [Option]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\lp :: String
lp -> [ String -> Option
Option ("-L" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lp)
, String -> Option
Option "-Xlinker"
, String -> Option
Option "-rpath"
, String -> Option
Option "-Xlinker"
, String -> Option
Option String
lp ])
([String] -> [String]
forall a. Eq a => [a] -> [a]
nub ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ (String, String) -> String
forall a b. (a, b) -> a
fst ((String, String) -> String) -> [(String, String)] -> [String]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PersistentLinkerState -> [(String, String)]
temp_sos PersistentLinkerState
pls)
[Option] -> [Option] -> [Option]
forall a. [a] -> [a] -> [a]
++ (String -> [Option]) -> [String] -> [Option]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap
(\lp :: String
lp ->
[ String -> Option
Option ("-L" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lp)
, String -> Option
Option "-Xlinker"
, String -> Option
Option "-rpath"
, String -> Option
Option "-Xlinker"
, String -> Option
Option String
lp
])
[String]
minus_big_ls
[Option] -> [Option] -> [Option]
forall a. [a] -> [a] -> [a]
++ (String -> Option) -> [String] -> [Option]
forall a b. (a -> b) -> [a] -> [b]
map (\l :: String
l -> String -> Option
Option ("-l" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
l)) [String]
minus_ls,
ways :: [Way]
ways = [Way
WayDyn],
buildTag :: String
buildTag = [Way] -> String
mkBuildTag [Way
WayDyn],
outputFile :: Maybe String
outputFile = String -> Maybe String
forall a. a -> Maybe a
Just String
soFile
}
DynFlags -> [String] -> [LinkerUnitId] -> IO ()
linkDynLib DynFlags
dflags2 [String]
objs (PersistentLinkerState -> [LinkerUnitId]
pkgs_loaded PersistentLinkerState
pls)
DynFlags -> TempFileLifetime -> [String] -> IO ()
changeTempFilesLifetime DynFlags
dflags TempFileLifetime
TFL_GhcSession [String
soFile]
Maybe String
m <- HscEnv -> String -> IO (Maybe String)
loadDLL HscEnv
hsc_env String
soFile
case Maybe String
m of
Nothing -> PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls { temp_sos :: [(String, String)]
temp_sos = (String
libPath, String
libName) (String, String) -> [(String, String)] -> [(String, String)]
forall a. a -> [a] -> [a]
: PersistentLinkerState -> [(String, String)]
temp_sos PersistentLinkerState
pls }
Just err :: String
err -> String -> IO PersistentLinkerState
forall a. String -> a
panic ("Loading temp shared object failed: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err)
rmDupLinkables :: [Linkable]
-> [Linkable]
-> ([Linkable],
[Linkable])
rmDupLinkables :: [Linkable] -> [Linkable] -> ([Linkable], [Linkable])
rmDupLinkables already :: [Linkable]
already ls :: [Linkable]
ls
= [Linkable] -> [Linkable] -> [Linkable] -> ([Linkable], [Linkable])
go [Linkable]
already [] [Linkable]
ls
where
go :: [Linkable] -> [Linkable] -> [Linkable] -> ([Linkable], [Linkable])
go already :: [Linkable]
already extras :: [Linkable]
extras [] = ([Linkable]
already, [Linkable]
extras)
go already :: [Linkable]
already extras :: [Linkable]
extras (l :: Linkable
l:ls :: [Linkable]
ls)
| Linkable -> [Linkable] -> Bool
linkableInSet Linkable
l [Linkable]
already = [Linkable] -> [Linkable] -> [Linkable] -> ([Linkable], [Linkable])
go [Linkable]
already [Linkable]
extras [Linkable]
ls
| Bool
otherwise = [Linkable] -> [Linkable] -> [Linkable] -> ([Linkable], [Linkable])
go (Linkable
lLinkable -> [Linkable] -> [Linkable]
forall a. a -> [a] -> [a]
:[Linkable]
already) (Linkable
lLinkable -> [Linkable] -> [Linkable]
forall a. a -> [a] -> [a]
:[Linkable]
extras) [Linkable]
ls
dynLinkBCOs :: HscEnv -> PersistentLinkerState -> [Linkable]
-> IO PersistentLinkerState
dynLinkBCOs :: HscEnv
-> PersistentLinkerState -> [Linkable] -> IO PersistentLinkerState
dynLinkBCOs hsc_env :: HscEnv
hsc_env pls :: PersistentLinkerState
pls bcos :: [Linkable]
bcos = do
let (bcos_loaded' :: [Linkable]
bcos_loaded', new_bcos :: [Linkable]
new_bcos) = [Linkable] -> [Linkable] -> ([Linkable], [Linkable])
rmDupLinkables (PersistentLinkerState -> [Linkable]
bcos_loaded PersistentLinkerState
pls) [Linkable]
bcos
pls1 :: PersistentLinkerState
pls1 = PersistentLinkerState
pls { bcos_loaded :: [Linkable]
bcos_loaded = [Linkable]
bcos_loaded' }
unlinkeds :: [Unlinked]
unlinkeds :: [Unlinked]
unlinkeds = (Linkable -> [Unlinked]) -> [Linkable] -> [Unlinked]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Linkable -> [Unlinked]
linkableUnlinked [Linkable]
new_bcos
cbcs :: [CompiledByteCode]
cbcs :: [CompiledByteCode]
cbcs = (Unlinked -> CompiledByteCode) -> [Unlinked] -> [CompiledByteCode]
forall a b. (a -> b) -> [a] -> [b]
map Unlinked -> CompiledByteCode
byteCodeOfObject [Unlinked]
unlinkeds
ies :: [ItblEnv]
ies = (CompiledByteCode -> ItblEnv) -> [CompiledByteCode] -> [ItblEnv]
forall a b. (a -> b) -> [a] -> [b]
map CompiledByteCode -> ItblEnv
bc_itbls [CompiledByteCode]
cbcs
gce :: ClosureEnv
gce = PersistentLinkerState -> ClosureEnv
closure_env PersistentLinkerState
pls
final_ie :: ItblEnv
final_ie = (ItblEnv -> ItblEnv -> ItblEnv) -> ItblEnv -> [ItblEnv] -> ItblEnv
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ItblEnv -> ItblEnv -> ItblEnv
forall a. NameEnv a -> NameEnv a -> NameEnv a
plusNameEnv (PersistentLinkerState -> ItblEnv
itbl_env PersistentLinkerState
pls) [ItblEnv]
ies
[(Name, HValueRef)]
names_and_refs <- HscEnv
-> ItblEnv
-> ClosureEnv
-> [CompiledByteCode]
-> IO [(Name, HValueRef)]
linkSomeBCOs HscEnv
hsc_env ItblEnv
final_ie ClosureEnv
gce [CompiledByteCode]
cbcs
let (to_add :: [(Name, HValueRef)]
to_add, to_drop :: [(Name, HValueRef)]
to_drop) = ((Name, HValueRef) -> Bool)
-> [(Name, HValueRef)]
-> ([(Name, HValueRef)], [(Name, HValueRef)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (Name -> Bool
isExternalName(Name -> Bool)
-> ((Name, HValueRef) -> Name) -> (Name, HValueRef) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Name, HValueRef) -> Name
forall a b. (a, b) -> a
fst) [(Name, HValueRef)]
names_and_refs
HscEnv -> [HValueRef] -> IO ()
freeHValueRefs HscEnv
hsc_env (((Name, HValueRef) -> HValueRef)
-> [(Name, HValueRef)] -> [HValueRef]
forall a b. (a -> b) -> [a] -> [b]
map (Name, HValueRef) -> HValueRef
forall a b. (a, b) -> b
snd [(Name, HValueRef)]
to_drop)
[(Name, ForeignHValue)]
new_binds <- HscEnv -> [(Name, HValueRef)] -> IO [(Name, ForeignHValue)]
makeForeignNamedHValueRefs HscEnv
hsc_env [(Name, HValueRef)]
to_add
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
pls1 { closure_env :: ClosureEnv
closure_env = ClosureEnv -> [(Name, ForeignHValue)] -> ClosureEnv
extendClosureEnv ClosureEnv
gce [(Name, ForeignHValue)]
new_binds,
itbl_env :: ItblEnv
itbl_env = ItblEnv
final_ie }
linkSomeBCOs :: HscEnv
-> ItblEnv
-> ClosureEnv
-> [CompiledByteCode]
-> IO [(Name,HValueRef)]
linkSomeBCOs :: HscEnv
-> ItblEnv
-> ClosureEnv
-> [CompiledByteCode]
-> IO [(Name, HValueRef)]
linkSomeBCOs hsc_env :: HscEnv
hsc_env ie :: ItblEnv
ie ce :: ClosureEnv
ce mods :: [CompiledByteCode]
mods = (CompiledByteCode
-> ([(RemoteRef BreakArray, [UnlinkedBCO])]
-> IO [(Name, HValueRef)])
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
-> IO [(Name, HValueRef)])
-> ([(RemoteRef BreakArray, [UnlinkedBCO])]
-> IO [(Name, HValueRef)])
-> [CompiledByteCode]
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
-> IO [(Name, HValueRef)]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr CompiledByteCode
-> ([(RemoteRef BreakArray, [UnlinkedBCO])]
-> IO [(Name, HValueRef)])
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
-> IO [(Name, HValueRef)]
forall b.
CompiledByteCode
-> ([(RemoteRef BreakArray, [UnlinkedBCO])] -> IO b)
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
-> IO b
fun [(RemoteRef BreakArray, [UnlinkedBCO])] -> IO [(Name, HValueRef)]
do_link [CompiledByteCode]
mods []
where
fun :: CompiledByteCode
-> ([(RemoteRef BreakArray, [UnlinkedBCO])] -> IO b)
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
-> IO b
fun CompiledByteCode{..} inner :: [(RemoteRef BreakArray, [UnlinkedBCO])] -> IO b
inner accum :: [(RemoteRef BreakArray, [UnlinkedBCO])]
accum =
case Maybe ModBreaks
bc_breaks of
Nothing -> [(RemoteRef BreakArray, [UnlinkedBCO])] -> IO b
inner ((String -> RemoteRef BreakArray
forall a. String -> a
panic "linkSomeBCOs: no break array", [UnlinkedBCO]
bc_bcos) (RemoteRef BreakArray, [UnlinkedBCO])
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
forall a. a -> [a] -> [a]
: [(RemoteRef BreakArray, [UnlinkedBCO])]
accum)
Just mb :: ModBreaks
mb -> ForeignRef BreakArray -> (RemoteRef BreakArray -> IO b) -> IO b
forall a b. ForeignRef a -> (RemoteRef a -> IO b) -> IO b
withForeignRef (ModBreaks -> ForeignRef BreakArray
modBreaks_flags ModBreaks
mb) ((RemoteRef BreakArray -> IO b) -> IO b)
-> (RemoteRef BreakArray -> IO b) -> IO b
forall a b. (a -> b) -> a -> b
$ \breakarray :: RemoteRef BreakArray
breakarray ->
[(RemoteRef BreakArray, [UnlinkedBCO])] -> IO b
inner ((RemoteRef BreakArray
breakarray, [UnlinkedBCO]
bc_bcos) (RemoteRef BreakArray, [UnlinkedBCO])
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
-> [(RemoteRef BreakArray, [UnlinkedBCO])]
forall a. a -> [a] -> [a]
: [(RemoteRef BreakArray, [UnlinkedBCO])]
accum)
do_link :: [(RemoteRef BreakArray, [UnlinkedBCO])] -> IO [(Name, HValueRef)]
do_link [] = [(Name, HValueRef)] -> IO [(Name, HValueRef)]
forall (m :: * -> *) a. Monad m => a -> m a
return []
do_link mods :: [(RemoteRef BreakArray, [UnlinkedBCO])]
mods = do
let flat :: [(RemoteRef BreakArray, UnlinkedBCO)]
flat = [ (RemoteRef BreakArray
breakarray, UnlinkedBCO
bco) | (breakarray, bcos) <- [(RemoteRef BreakArray, [UnlinkedBCO])]
mods, UnlinkedBCO
bco <- [UnlinkedBCO]
bcos ]
names :: [Name]
names = ((RemoteRef BreakArray, UnlinkedBCO) -> Name)
-> [(RemoteRef BreakArray, UnlinkedBCO)] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (UnlinkedBCO -> Name
unlinkedBCOName (UnlinkedBCO -> Name)
-> ((RemoteRef BreakArray, UnlinkedBCO) -> UnlinkedBCO)
-> (RemoteRef BreakArray, UnlinkedBCO)
-> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RemoteRef BreakArray, UnlinkedBCO) -> UnlinkedBCO
forall a b. (a, b) -> b
snd) [(RemoteRef BreakArray, UnlinkedBCO)]
flat
bco_ix :: NameEnv Int
bco_ix = [(Name, Int)] -> NameEnv Int
forall a. [(Name, a)] -> NameEnv a
mkNameEnv ([Name] -> [Int] -> [(Name, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
names [0..])
[ResolvedBCO]
resolved <- [IO ResolvedBCO] -> IO [ResolvedBCO]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [ HscEnv
-> ItblEnv
-> ClosureEnv
-> NameEnv Int
-> RemoteRef BreakArray
-> UnlinkedBCO
-> IO ResolvedBCO
linkBCO HscEnv
hsc_env ItblEnv
ie ClosureEnv
ce NameEnv Int
bco_ix RemoteRef BreakArray
breakarray UnlinkedBCO
bco
| (breakarray :: RemoteRef BreakArray
breakarray, bco :: UnlinkedBCO
bco) <- [(RemoteRef BreakArray, UnlinkedBCO)]
flat ]
[HValueRef]
hvrefs <- HscEnv -> [ResolvedBCO] -> IO [HValueRef]
createBCOs HscEnv
hsc_env [ResolvedBCO]
resolved
[(Name, HValueRef)] -> IO [(Name, HValueRef)]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Name] -> [HValueRef] -> [(Name, HValueRef)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
names [HValueRef]
hvrefs)
makeForeignNamedHValueRefs
:: HscEnv -> [(Name,HValueRef)] -> IO [(Name,ForeignHValue)]
makeForeignNamedHValueRefs :: HscEnv -> [(Name, HValueRef)] -> IO [(Name, ForeignHValue)]
makeForeignNamedHValueRefs hsc_env :: HscEnv
hsc_env bindings :: [(Name, HValueRef)]
bindings =
((Name, HValueRef) -> IO (Name, ForeignHValue))
-> [(Name, HValueRef)] -> IO [(Name, ForeignHValue)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(n :: Name
n, hvref :: HValueRef
hvref) -> (Name
n,) (ForeignHValue -> (Name, ForeignHValue))
-> IO ForeignHValue -> IO (Name, ForeignHValue)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HscEnv -> HValueRef -> IO ForeignHValue
forall a. HscEnv -> RemoteRef a -> IO (ForeignRef a)
mkFinalizedHValue HscEnv
hsc_env HValueRef
hvref) [(Name, HValueRef)]
bindings
unload :: HscEnv
-> [Linkable]
-> IO ()
unload :: HscEnv -> [Linkable] -> IO ()
unload hsc_env :: HscEnv
hsc_env linkables :: [Linkable]
linkables
= IO () -> IO ()
forall a. IO a -> IO a
mask_ (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
HscEnv -> IO ()
initDynLinker HscEnv
hsc_env
PersistentLinkerState
new_pls
<- (PersistentLinkerState
-> IO (PersistentLinkerState, PersistentLinkerState))
-> IO PersistentLinkerState
forall a.
(PersistentLinkerState -> IO (PersistentLinkerState, a)) -> IO a
modifyPLS ((PersistentLinkerState
-> IO (PersistentLinkerState, PersistentLinkerState))
-> IO PersistentLinkerState)
-> (PersistentLinkerState
-> IO (PersistentLinkerState, PersistentLinkerState))
-> IO PersistentLinkerState
forall a b. (a -> b) -> a -> b
$ \pls :: PersistentLinkerState
pls -> do
PersistentLinkerState
pls1 <- HscEnv
-> [Linkable] -> PersistentLinkerState -> IO PersistentLinkerState
unload_wkr HscEnv
hsc_env [Linkable]
linkables PersistentLinkerState
pls
(PersistentLinkerState, PersistentLinkerState)
-> IO (PersistentLinkerState, PersistentLinkerState)
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState
pls1, PersistentLinkerState
pls1)
let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
DynFlags -> Int -> SDoc -> IO ()
debugTraceMsg DynFlags
dflags 3 (SDoc -> IO ()) -> SDoc -> IO ()
forall a b. (a -> b) -> a -> b
$
String -> SDoc
text "unload: retaining objs" SDoc -> SDoc -> SDoc
<+> [Linkable] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PersistentLinkerState -> [Linkable]
objs_loaded PersistentLinkerState
new_pls)
DynFlags -> Int -> SDoc -> IO ()
debugTraceMsg DynFlags
dflags 3 (SDoc -> IO ()) -> SDoc -> IO ()
forall a b. (a -> b) -> a -> b
$
String -> SDoc
text "unload: retaining bcos" SDoc -> SDoc -> SDoc
<+> [Linkable] -> SDoc
forall a. Outputable a => a -> SDoc
ppr (PersistentLinkerState -> [Linkable]
bcos_loaded PersistentLinkerState
new_pls)
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
unload_wkr :: HscEnv
-> [Linkable]
-> PersistentLinkerState
-> IO PersistentLinkerState
unload_wkr :: HscEnv
-> [Linkable] -> PersistentLinkerState -> IO PersistentLinkerState
unload_wkr hsc_env :: HscEnv
hsc_env keep_linkables :: [Linkable]
keep_linkables pls :: PersistentLinkerState
pls@PersistentLinkerState{..} = do
let (objs_to_keep :: [Linkable]
objs_to_keep, bcos_to_keep :: [Linkable]
bcos_to_keep) = (Linkable -> Bool) -> [Linkable] -> ([Linkable], [Linkable])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition Linkable -> Bool
isObjectLinkable [Linkable]
keep_linkables
discard :: [Linkable] -> Linkable -> Bool
discard keep :: [Linkable]
keep l :: Linkable
l = Bool -> Bool
not (Linkable -> [Linkable] -> Bool
linkableInSet Linkable
l [Linkable]
keep)
(objs_to_unload :: [Linkable]
objs_to_unload, remaining_objs_loaded :: [Linkable]
remaining_objs_loaded) =
(Linkable -> Bool) -> [Linkable] -> ([Linkable], [Linkable])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition ([Linkable] -> Linkable -> Bool
discard [Linkable]
objs_to_keep) [Linkable]
objs_loaded
(bcos_to_unload :: [Linkable]
bcos_to_unload, remaining_bcos_loaded :: [Linkable]
remaining_bcos_loaded) =
(Linkable -> Bool) -> [Linkable] -> ([Linkable], [Linkable])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition ([Linkable] -> Linkable -> Bool
discard [Linkable]
bcos_to_keep) [Linkable]
bcos_loaded
(Linkable -> IO ()) -> [Linkable] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Linkable -> IO ()
unloadObjs [Linkable]
objs_to_unload
(Linkable -> IO ()) -> [Linkable] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Linkable -> IO ()
unloadObjs [Linkable]
bcos_to_unload
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not ([Linkable] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([Linkable]
objs_to_unload [Linkable] -> [Linkable] -> [Linkable]
forall a. [a] -> [a] -> [a]
++
(Linkable -> Bool) -> [Linkable] -> [Linkable]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (Linkable -> Bool) -> Linkable -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null ([String] -> Bool) -> (Linkable -> [String]) -> Linkable -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Linkable -> [String]
linkableObjs) [Linkable]
bcos_to_unload))) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
HscEnv -> IO ()
purgeLookupSymbolCache HscEnv
hsc_env
let !bcos_retained :: ModuleSet
bcos_retained = [Module] -> ModuleSet
mkModuleSet ([Module] -> ModuleSet) -> [Module] -> ModuleSet
forall a b. (a -> b) -> a -> b
$ (Linkable -> Module) -> [Linkable] -> [Module]
forall a b. (a -> b) -> [a] -> [b]
map Linkable -> Module
linkableModule [Linkable]
remaining_bcos_loaded
keep_name :: (Name, b) -> Bool
keep_name (n :: Name
n,_) = Name -> Bool
isExternalName Name
n Bool -> Bool -> Bool
&&
HasDebugCallStack => Name -> Module
Name -> Module
nameModule Name
n Module -> ModuleSet -> Bool
`elemModuleSet` ModuleSet
bcos_retained
itbl_env' :: ItblEnv
itbl_env' = ((Name, ItblPtr) -> Bool) -> ItblEnv -> ItblEnv
forall elt. (elt -> Bool) -> NameEnv elt -> NameEnv elt
filterNameEnv (Name, ItblPtr) -> Bool
forall b. (Name, b) -> Bool
keep_name ItblEnv
itbl_env
closure_env' :: ClosureEnv
closure_env' = ((Name, ForeignHValue) -> Bool) -> ClosureEnv -> ClosureEnv
forall elt. (elt -> Bool) -> NameEnv elt -> NameEnv elt
filterNameEnv (Name, ForeignHValue) -> Bool
forall b. (Name, b) -> Bool
keep_name ClosureEnv
closure_env
!new_pls :: PersistentLinkerState
new_pls = PersistentLinkerState
pls { itbl_env :: ItblEnv
itbl_env = ItblEnv
itbl_env',
closure_env :: ClosureEnv
closure_env = ClosureEnv
closure_env',
bcos_loaded :: [Linkable]
bcos_loaded = [Linkable]
remaining_bcos_loaded,
objs_loaded :: [Linkable]
objs_loaded = [Linkable]
remaining_objs_loaded }
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return PersistentLinkerState
new_pls
where
unloadObjs :: Linkable -> IO ()
unloadObjs :: Linkable -> IO ()
unloadObjs lnk :: Linkable
lnk
| Bool
dynamicGhc = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise
= (String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> String -> IO ()
unloadObj HscEnv
hsc_env) [String
f | DotO f :: String
f <- Linkable -> [Unlinked]
linkableUnlinked Linkable
lnk]
data LibrarySpec
= Objects [FilePath]
| Archive FilePath
| DLL String
| DLLPath FilePath
| Framework String
partOfGHCi :: [PackageName]
partOfGHCi :: [PackageName]
partOfGHCi
| Bool
isWindowsHost Bool -> Bool -> Bool
|| Bool
isDarwinHost = []
| Bool
otherwise = (String -> PackageName) -> [String] -> [PackageName]
forall a b. (a -> b) -> [a] -> [b]
map (FastString -> PackageName
PackageName (FastString -> PackageName)
-> (String -> FastString) -> String -> PackageName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> FastString
mkFastString)
["base", "template-haskell", "editline"]
showLS :: LibrarySpec -> String
showLS :: LibrarySpec -> String
showLS (Objects nms :: [String]
nms) = "(static) [" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate ", " [String]
nms String -> String -> String
forall a. [a] -> [a] -> [a]
++ "]"
showLS (Archive nm :: String
nm) = "(static archive) " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
nm
showLS (DLL nm :: String
nm) = "(dynamic) " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
nm
showLS (DLLPath nm :: String
nm) = "(dynamic) " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
nm
showLS (Framework nm :: String
nm) = "(framework) " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
nm
type LinkerUnitId = InstalledUnitId
linkPackages :: HscEnv -> [LinkerUnitId] -> IO ()
linkPackages :: HscEnv -> [LinkerUnitId] -> IO ()
linkPackages hsc_env :: HscEnv
hsc_env new_pkgs :: [LinkerUnitId]
new_pkgs = do
HscEnv -> IO ()
initDynLinker HscEnv
hsc_env
(PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
modifyPLS_ ((PersistentLinkerState -> IO PersistentLinkerState) -> IO ())
-> (PersistentLinkerState -> IO PersistentLinkerState) -> IO ()
forall a b. (a -> b) -> a -> b
$ \pls :: PersistentLinkerState
pls -> do
HscEnv
-> [LinkerUnitId]
-> PersistentLinkerState
-> IO PersistentLinkerState
linkPackages' HscEnv
hsc_env [LinkerUnitId]
new_pkgs PersistentLinkerState
pls
linkPackages' :: HscEnv -> [LinkerUnitId] -> PersistentLinkerState
-> IO PersistentLinkerState
linkPackages' :: HscEnv
-> [LinkerUnitId]
-> PersistentLinkerState
-> IO PersistentLinkerState
linkPackages' hsc_env :: HscEnv
hsc_env new_pks :: [LinkerUnitId]
new_pks pls :: PersistentLinkerState
pls = do
[LinkerUnitId]
pkgs' <- [LinkerUnitId] -> [LinkerUnitId] -> IO [LinkerUnitId]
link (PersistentLinkerState -> [LinkerUnitId]
pkgs_loaded PersistentLinkerState
pls) [LinkerUnitId]
new_pks
PersistentLinkerState -> IO PersistentLinkerState
forall (m :: * -> *) a. Monad m => a -> m a
return (PersistentLinkerState -> IO PersistentLinkerState)
-> PersistentLinkerState -> IO PersistentLinkerState
forall a b. (a -> b) -> a -> b
$! PersistentLinkerState
pls { pkgs_loaded :: [LinkerUnitId]
pkgs_loaded = [LinkerUnitId]
pkgs' }
where
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
link :: [LinkerUnitId] -> [LinkerUnitId] -> IO [LinkerUnitId]
link :: [LinkerUnitId] -> [LinkerUnitId] -> IO [LinkerUnitId]
link pkgs :: [LinkerUnitId]
pkgs new_pkgs :: [LinkerUnitId]
new_pkgs =
([LinkerUnitId] -> LinkerUnitId -> IO [LinkerUnitId])
-> [LinkerUnitId] -> [LinkerUnitId] -> IO [LinkerUnitId]
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM [LinkerUnitId] -> LinkerUnitId -> IO [LinkerUnitId]
link_one [LinkerUnitId]
pkgs [LinkerUnitId]
new_pkgs
link_one :: [LinkerUnitId] -> LinkerUnitId -> IO [LinkerUnitId]
link_one pkgs :: [LinkerUnitId]
pkgs new_pkg :: LinkerUnitId
new_pkg
| LinkerUnitId
new_pkg LinkerUnitId -> [LinkerUnitId] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [LinkerUnitId]
pkgs
= [LinkerUnitId] -> IO [LinkerUnitId]
forall (m :: * -> *) a. Monad m => a -> m a
return [LinkerUnitId]
pkgs
| Just pkg_cfg :: PackageConfig
pkg_cfg <- DynFlags -> LinkerUnitId -> Maybe PackageConfig
lookupInstalledPackage DynFlags
dflags LinkerUnitId
new_pkg
= do {
[LinkerUnitId]
pkgs' <- [LinkerUnitId] -> [LinkerUnitId] -> IO [LinkerUnitId]
link [LinkerUnitId]
pkgs (PackageConfig -> [LinkerUnitId]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [instunitid]
depends PackageConfig
pkg_cfg)
; HscEnv -> PackageConfig -> IO ()
linkPackage HscEnv
hsc_env PackageConfig
pkg_cfg
; [LinkerUnitId] -> IO [LinkerUnitId]
forall (m :: * -> *) a. Monad m => a -> m a
return (LinkerUnitId
new_pkg LinkerUnitId -> [LinkerUnitId] -> [LinkerUnitId]
forall a. a -> [a] -> [a]
: [LinkerUnitId]
pkgs') }
| Bool
otherwise
= GhcException -> IO [LinkerUnitId]
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
CmdLineError ("unknown package: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ FastString -> String
unpackFS (LinkerUnitId -> FastString
installedUnitIdFS LinkerUnitId
new_pkg)))
linkPackage :: HscEnv -> PackageConfig -> IO ()
linkPackage :: HscEnv -> PackageConfig -> IO ()
linkPackage hsc_env :: HscEnv
hsc_env pkg :: PackageConfig
pkg
= do
let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
is_dyn :: Bool
is_dyn = DynFlags -> Bool
interpreterDynamic DynFlags
dflags
dirs :: [String]
dirs | Bool
is_dyn = PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.libraryDynDirs PackageConfig
pkg
| Bool
otherwise = PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.libraryDirs PackageConfig
pkg
let hs_libs :: [String]
hs_libs = PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.hsLibraries PackageConfig
pkg
hs_libs' :: [String]
hs_libs' = (String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter ("HSffi" String -> String -> Bool
forall a. Eq a => a -> a -> Bool
/=) [String]
hs_libs
extra_libs :: [String]
extra_libs =
(if [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.extraGHCiLibraries PackageConfig
pkg)
then PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.extraLibraries PackageConfig
pkg
else PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.extraGHCiLibraries PackageConfig
pkg)
[String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [ String
lib | '-':'l':lib :: String
lib <- PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.ldOptions PackageConfig
pkg ]
[String]
gcc_paths <- DynFlags -> OS -> IO [String]
getGCCPaths DynFlags
dflags (Platform -> OS
platformOS Platform
platform)
[String]
dirs_env <- String -> [String] -> IO [String]
addEnvPaths "LIBRARY_PATH" [String]
dirs
[LibrarySpec]
hs_classifieds
<- (String -> IO LibrarySpec) -> [String] -> IO [LibrarySpec]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (HscEnv -> Bool -> [String] -> [String] -> String -> IO LibrarySpec
locateLib HscEnv
hsc_env Bool
True [String]
dirs_env [String]
gcc_paths) [String]
hs_libs'
[LibrarySpec]
extra_classifieds
<- (String -> IO LibrarySpec) -> [String] -> IO [LibrarySpec]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (HscEnv -> Bool -> [String] -> [String] -> String -> IO LibrarySpec
locateLib HscEnv
hsc_env Bool
False [String]
dirs_env [String]
gcc_paths) [String]
extra_libs
let classifieds :: [LibrarySpec]
classifieds = [LibrarySpec]
hs_classifieds [LibrarySpec] -> [LibrarySpec] -> [LibrarySpec]
forall a. [a] -> [a] -> [a]
++ [LibrarySpec]
extra_classifieds
let known_dlls :: [String]
known_dlls = [ String
dll | DLLPath dll :: String
dll <- [LibrarySpec]
classifieds ]
dlls :: [String]
dlls = [ String
dll | DLL dll :: String
dll <- [LibrarySpec]
classifieds ]
objs :: [String]
objs = [ String
obj | Objects objs :: [String]
objs <- [LibrarySpec]
classifieds
, String
obj <- [String]
objs ]
archs :: [String]
archs = [ String
arch | Archive arch :: String
arch <- [LibrarySpec]
classifieds ]
let dll_paths :: [String]
dll_paths = (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
takeDirectory [String]
known_dlls
all_paths :: [String]
all_paths = [String] -> [String]
forall a. Eq a => [a] -> [a]
nub ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ (String -> String) -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map String -> String
normalise ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ [String]
dll_paths [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
dirs
[String]
all_paths_env <- String -> [String] -> IO [String]
addEnvPaths "LD_LIBRARY_PATH" [String]
all_paths
[Ptr ()]
pathCache <- (String -> IO (Ptr ())) -> [String] -> IO [Ptr ()]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (HscEnv -> String -> IO (Ptr ())
addLibrarySearchPath HscEnv
hsc_env) [String]
all_paths_env
DynFlags -> String -> IO ()
maybePutStr DynFlags
dflags
("Loading package " String -> String -> String
forall a. [a] -> [a] -> [a]
++ PackageConfig -> String
sourcePackageIdString PackageConfig
pkg String -> String -> String
forall a. [a] -> [a] -> [a]
++ " ... ")
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PackageConfig -> PackageName
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> srcpkgname
packageName PackageConfig
pkg PackageName -> [PackageName] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [PackageName]
partOfGHCi) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
HscEnv -> Platform -> PackageConfig -> IO ()
loadFrameworks HscEnv
hsc_env Platform
platform PackageConfig
pkg
(String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> Bool -> String -> IO ()
load_dyn HscEnv
hsc_env Bool
True) [String]
known_dlls
(String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> Bool -> String -> IO ()
load_dyn HscEnv
hsc_env (Bool -> Bool
not Bool
is_dyn) (String -> IO ()) -> (String -> String) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Platform -> String -> String
mkSOName Platform
platform) [String]
dlls
(String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> String -> IO ()
loadObj HscEnv
hsc_env) [String]
objs
(String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> String -> IO ()
loadArchive HscEnv
hsc_env) [String]
archs
DynFlags -> String -> IO ()
maybePutStr DynFlags
dflags "linking ... "
SuccessFlag
ok <- HscEnv -> IO SuccessFlag
resolveObjs HscEnv
hsc_env
(Ptr () -> IO Bool) -> [Ptr ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (HscEnv -> Ptr () -> IO Bool
removeLibrarySearchPath HscEnv
hsc_env) ([Ptr ()] -> IO ()) -> [Ptr ()] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Ptr ()] -> [Ptr ()]
forall a. [a] -> [a]
reverse [Ptr ()]
pathCache
if SuccessFlag -> Bool
succeeded SuccessFlag
ok
then DynFlags -> String -> IO ()
maybePutStrLn DynFlags
dflags "done."
else let errmsg :: String
errmsg = "unable to load package `"
String -> String -> String
forall a. [a] -> [a] -> [a]
++ PackageConfig -> String
sourcePackageIdString PackageConfig
pkg String -> String -> String
forall a. [a] -> [a] -> [a]
++ "'"
in GhcException -> IO ()
forall a. GhcException -> IO a
throwGhcExceptionIO (String -> GhcException
InstallationError String
errmsg)
load_dyn :: HscEnv -> Bool -> FilePath -> IO ()
load_dyn :: HscEnv -> Bool -> String -> IO ()
load_dyn hsc_env :: HscEnv
hsc_env crash_early :: Bool
crash_early dll :: String
dll = do
Maybe String
r <- HscEnv -> String -> IO (Maybe String)
loadDLL HscEnv
hsc_env String
dll
case Maybe String
r of
Nothing -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just err :: String
err ->
if Bool
crash_early
then String -> IO ()
forall a. String -> IO a
cmdLineErrorIO String
err
else let dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env in
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (WarningFlag -> DynFlags -> Bool
wopt WarningFlag
Opt_WarnMissedExtraSharedLib DynFlags
dflags)
(IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ DynFlags
-> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
putLogMsg DynFlags
dflags
(WarningFlag -> WarnReason
Reason WarningFlag
Opt_WarnMissedExtraSharedLib) Severity
SevWarning
SrcSpan
noSrcSpan (DynFlags -> PprStyle
defaultUserStyle DynFlags
dflags)(String -> SDoc
note String
err)
where
note :: String -> SDoc
note err :: String
err = [SDoc] -> SDoc
vcat ([SDoc] -> SDoc) -> [SDoc] -> SDoc
forall a b. (a -> b) -> a -> b
$ (String -> SDoc) -> [String] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map String -> SDoc
text
[ String
err
, "It's OK if you don't want to use symbols from it directly."
, "(the package DLL is loaded by the system linker"
, " which manages dependencies by itself)." ]
loadFrameworks :: HscEnv -> Platform -> PackageConfig -> IO ()
loadFrameworks :: HscEnv -> Platform -> PackageConfig -> IO ()
loadFrameworks hsc_env :: HscEnv
hsc_env platform :: Platform
platform pkg :: PackageConfig
pkg
= Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Platform -> Bool
platformUsesFrameworks Platform
platform) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ (String -> IO ()) -> [String] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ String -> IO ()
load [String]
frameworks
where
fw_dirs :: [String]
fw_dirs = PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.frameworkDirs PackageConfig
pkg
frameworks :: [String]
frameworks = PackageConfig -> [String]
forall compid srcpkgid srcpkgname instunitid unitid modulename mod.
InstalledPackageInfo
compid srcpkgid srcpkgname instunitid unitid modulename mod
-> [String]
Packages.frameworks PackageConfig
pkg
load :: String -> IO ()
load fw :: String
fw = do Maybe String
r <- HscEnv -> [String] -> String -> IO (Maybe String)
loadFramework HscEnv
hsc_env [String]
fw_dirs String
fw
case Maybe String
r of
Nothing -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just err :: String
err -> String -> IO ()
forall a. String -> IO a
cmdLineErrorIO ("can't load framework: "
String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
fw String -> String -> String
forall a. [a] -> [a] -> [a]
++ " (" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
err String -> String -> String
forall a. [a] -> [a] -> [a]
++ ")" )
locateLib :: HscEnv -> Bool -> [FilePath] -> [FilePath] -> String
-> IO LibrarySpec
locateLib :: HscEnv -> Bool -> [String] -> [String] -> String -> IO LibrarySpec
locateLib hsc_env :: HscEnv
hsc_env is_hs :: Bool
is_hs lib_dirs :: [String]
lib_dirs gcc_dirs :: [String]
gcc_dirs lib :: String
lib
| Bool -> Bool
not Bool
is_hs
= Bool -> IO (Maybe LibrarySpec)
findDll Bool
user IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
Bool -> IO (Maybe LibrarySpec)
tryImpLib Bool
user IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
Bool -> IO (Maybe LibrarySpec)
findDll Bool
gcc IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
IO (Maybe LibrarySpec)
findSysDll IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
Bool -> IO (Maybe LibrarySpec)
tryImpLib Bool
gcc IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
IO (Maybe LibrarySpec)
findArchive IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
IO (Maybe LibrarySpec)
tryGcc IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
IO LibrarySpec
assumeDll
| Bool
loading_dynamic_hs_libs
= IO (Maybe LibrarySpec)
findHSDll IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
IO (Maybe LibrarySpec)
findDynObject IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
IO LibrarySpec
assumeDll
| Bool
otherwise
= IO (Maybe LibrarySpec)
findObject IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
IO (Maybe LibrarySpec)
findArchive IO (Maybe LibrarySpec) -> IO LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
`orElse`
IO LibrarySpec
assumeDll
where
dflags :: DynFlags
dflags = HscEnv -> DynFlags
hsc_dflags HscEnv
hsc_env
dirs :: [String]
dirs = [String]
lib_dirs [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
gcc_dirs
gcc :: Bool
gcc = Bool
False
user :: Bool
user = Bool
True
obj_file :: String
obj_file
| Bool
is_hs Bool -> Bool -> Bool
&& Bool
loading_profiled_hs_libs = String
lib String -> String -> String
<.> "p_o"
| Bool
otherwise = String
lib String -> String -> String
<.> "o"
dyn_obj_file :: String
dyn_obj_file = String
lib String -> String -> String
<.> "dyn_o"
arch_files :: [String]
arch_files = [ "lib" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lib String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lib_tag String -> String -> String
<.> "a"
, String
lib String -> String -> String
<.> "a"
, "lib" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lib, String
lib
]
lib_tag :: String
lib_tag = if Bool
is_hs Bool -> Bool -> Bool
&& Bool
loading_profiled_hs_libs then "_p" else ""
loading_profiled_hs_libs :: Bool
loading_profiled_hs_libs = DynFlags -> Bool
interpreterProfiled DynFlags
dflags
loading_dynamic_hs_libs :: Bool
loading_dynamic_hs_libs = DynFlags -> Bool
interpreterDynamic DynFlags
dflags
import_libs :: [String]
import_libs = [ String
lib String -> String -> String
<.> "lib" , "lib" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lib String -> String -> String
<.> "lib"
, "lib" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lib String -> String -> String
<.> "dll.a", String
lib String -> String -> String
<.> "dll.a"
]
hs_dyn_lib_name :: String
hs_dyn_lib_name = String
lib String -> String -> String
forall a. [a] -> [a] -> [a]
++ '-'Char -> String -> String
forall a. a -> [a] -> [a]
:DynFlags -> String
programName DynFlags
dflags String -> String -> String
forall a. [a] -> [a] -> [a]
++ DynFlags -> String
projectVersion DynFlags
dflags
hs_dyn_lib_file :: String
hs_dyn_lib_file = Platform -> String -> String
mkHsSOName Platform
platform String
hs_dyn_lib_name
so_name :: String
so_name = Platform -> String -> String
mkSOName Platform
platform String
lib
lib_so_name :: String
lib_so_name = "lib" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
so_name
dyn_lib_file :: String
dyn_lib_file = case (Arch
arch, OS
os) of
(ArchX86_64, OSSolaris2) -> "64" String -> String -> String
</> String
so_name
_ -> String
so_name
findObject :: IO (Maybe LibrarySpec)
findObject = (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec)
-> (String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall a b. (a -> b) -> a -> b
$ [String] -> LibrarySpec
Objects ([String] -> LibrarySpec)
-> (String -> [String]) -> String -> LibrarySpec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> [String] -> [String]
forall a. a -> [a] -> [a]
:[])) (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ [String] -> String -> IO (Maybe String)
findFile [String]
dirs String
obj_file
findDynObject :: IO (Maybe LibrarySpec)
findDynObject = (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec)
-> (String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall a b. (a -> b) -> a -> b
$ [String] -> LibrarySpec
Objects ([String] -> LibrarySpec)
-> (String -> [String]) -> String -> LibrarySpec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> [String] -> [String]
forall a. a -> [a] -> [a]
:[])) (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ [String] -> String -> IO (Maybe String)
findFile [String]
dirs String
dyn_obj_file
findArchive :: IO (Maybe LibrarySpec)
findArchive = let local :: String -> IO (Maybe LibrarySpec)
local name :: String
name = (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> LibrarySpec
Archive) (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ [String] -> String -> IO (Maybe String)
findFile [String]
dirs String
name
in [IO (Maybe LibrarySpec)] -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a. Monad m => [m (Maybe a)] -> m (Maybe a)
apply ((String -> IO (Maybe LibrarySpec))
-> [String] -> [IO (Maybe LibrarySpec)]
forall a b. (a -> b) -> [a] -> [b]
map String -> IO (Maybe LibrarySpec)
local [String]
arch_files)
findHSDll :: IO (Maybe LibrarySpec)
findHSDll = (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> LibrarySpec
DLLPath) (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ [String] -> String -> IO (Maybe String)
findFile [String]
dirs String
hs_dyn_lib_file
findDll :: Bool -> IO (Maybe LibrarySpec)
findDll re :: Bool
re = let dirs' :: [String]
dirs' = if Bool
re Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
user then [String]
lib_dirs else [String]
gcc_dirs
in (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> LibrarySpec
DLLPath) (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ [String] -> String -> IO (Maybe String)
findFile [String]
dirs' String
dyn_lib_file
findSysDll :: IO (Maybe LibrarySpec)
findSysDll = (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec)
-> (String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall a b. (a -> b) -> a -> b
$ String -> LibrarySpec
DLL (String -> LibrarySpec)
-> (String -> String) -> String -> LibrarySpec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
dropExtension (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
takeFileName) (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$
HscEnv -> String -> IO (Maybe String)
findSystemLibrary HscEnv
hsc_env String
so_name
tryGcc :: IO (Maybe LibrarySpec)
tryGcc = let search :: String -> [String] -> IO (Maybe String)
search = DynFlags -> String -> [String] -> IO (Maybe String)
searchForLibUsingGcc DynFlags
dflags
dllpath :: IO (Maybe String) -> IO (Maybe LibrarySpec)
dllpath = (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> LibrarySpec
DLLPath)
short :: IO (Maybe LibrarySpec)
short = IO (Maybe String) -> IO (Maybe LibrarySpec)
dllpath (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ String -> [String] -> IO (Maybe String)
search String
so_name [String]
lib_dirs
full :: IO (Maybe LibrarySpec)
full = IO (Maybe String) -> IO (Maybe LibrarySpec)
dllpath (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ String -> [String] -> IO (Maybe String)
search String
lib_so_name [String]
lib_dirs
gcc :: String -> IO (Maybe LibrarySpec)
gcc name :: String
name = (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> LibrarySpec
Archive) (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ String -> [String] -> IO (Maybe String)
search String
name [String]
lib_dirs
files :: [String]
files = [String]
import_libs [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
arch_files
in [IO (Maybe LibrarySpec)] -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a. Monad m => [m (Maybe a)] -> m (Maybe a)
apply ([IO (Maybe LibrarySpec)] -> IO (Maybe LibrarySpec))
-> [IO (Maybe LibrarySpec)] -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$ IO (Maybe LibrarySpec)
short IO (Maybe LibrarySpec)
-> [IO (Maybe LibrarySpec)] -> [IO (Maybe LibrarySpec)]
forall a. a -> [a] -> [a]
: IO (Maybe LibrarySpec)
full IO (Maybe LibrarySpec)
-> [IO (Maybe LibrarySpec)] -> [IO (Maybe LibrarySpec)]
forall a. a -> [a] -> [a]
: (String -> IO (Maybe LibrarySpec))
-> [String] -> [IO (Maybe LibrarySpec)]
forall a b. (a -> b) -> [a] -> [b]
map String -> IO (Maybe LibrarySpec)
gcc [String]
files
tryImpLib :: Bool -> IO (Maybe LibrarySpec)
tryImpLib re :: Bool
re = case OS
os of
OSMinGW32 ->
let dirs' :: [String]
dirs' = if Bool
re Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
user then [String]
lib_dirs else [String]
gcc_dirs
implib :: String -> IO (Maybe LibrarySpec)
implib name :: String
name = (Maybe String -> Maybe LibrarySpec)
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM ((String -> LibrarySpec) -> Maybe String -> Maybe LibrarySpec
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> LibrarySpec
Archive) (IO (Maybe String) -> IO (Maybe LibrarySpec))
-> IO (Maybe String) -> IO (Maybe LibrarySpec)
forall a b. (a -> b) -> a -> b
$
[String] -> String -> IO (Maybe String)
findFile [String]
dirs' String
name
in [IO (Maybe LibrarySpec)] -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a. Monad m => [m (Maybe a)] -> m (Maybe a)
apply ((String -> IO (Maybe LibrarySpec))
-> [String] -> [IO (Maybe LibrarySpec)]
forall a b. (a -> b) -> [a] -> [b]
map String -> IO (Maybe LibrarySpec)
implib [String]
import_libs)
_ -> Maybe LibrarySpec -> IO (Maybe LibrarySpec)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe LibrarySpec
forall a. Maybe a
Nothing
assumeDll :: IO LibrarySpec
assumeDll = LibrarySpec -> IO LibrarySpec
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> LibrarySpec
DLL String
lib)
infixr `orElse`
f :: m (Maybe b)
f orElse :: m (Maybe b) -> m b -> m b
`orElse` g :: m b
g = m (Maybe b)
f m (Maybe b) -> (Maybe b -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= m b -> (b -> m b) -> Maybe b -> m b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe m b
g b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return
apply :: [m (Maybe a)] -> m (Maybe a)
apply [] = Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
apply (x :: m (Maybe a)
x:xs :: [m (Maybe a)]
xs) = do Maybe a
x' <- m (Maybe a)
x
if Maybe a -> Bool
forall a. Maybe a -> Bool
isJust Maybe a
x'
then Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
x'
else [m (Maybe a)] -> m (Maybe a)
apply [m (Maybe a)]
xs
platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
arch :: Arch
arch = Platform -> Arch
platformArch Platform
platform
os :: OS
os = Platform -> OS
platformOS Platform
platform
searchForLibUsingGcc :: DynFlags -> String -> [FilePath] -> IO (Maybe FilePath)
searchForLibUsingGcc :: DynFlags -> String -> [String] -> IO (Maybe String)
searchForLibUsingGcc dflags :: DynFlags
dflags so :: String
so dirs :: [String]
dirs = do
String
str <- DynFlags -> [Option] -> IO String
askLd DynFlags
dflags ((String -> Option) -> [String] -> [Option]
forall a b. (a -> b) -> [a] -> [b]
map (String -> String -> Option
FileOption "-B") [String]
dirs
[Option] -> [Option] -> [Option]
forall a. [a] -> [a] -> [a]
++ [String -> Option
Option "--print-file-name", String -> Option
Option String
so])
let file :: String
file = case String -> [String]
lines String
str of
[] -> ""
l :: String
l:_ -> String
l
if (String
file String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
so)
then Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe String
forall a. Maybe a
Nothing
else do Bool
b <- String -> IO Bool
doesFileExist String
file
Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
b then String -> Maybe String
forall a. a -> Maybe a
Just String
file else Maybe String
forall a. Maybe a
Nothing)
getGCCPaths :: DynFlags -> OS -> IO [FilePath]
getGCCPaths :: DynFlags -> OS -> IO [String]
getGCCPaths dflags :: DynFlags
dflags os :: OS
os
= case OS
os of
OSMinGW32 ->
do [String]
gcc_dirs <- DynFlags -> String -> IO [String]
getGccSearchDirectory DynFlags
dflags "libraries"
[String]
sys_dirs <- IO [String]
getSystemDirectories
[String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return ([String] -> IO [String]) -> [String] -> IO [String]
forall a b. (a -> b) -> a -> b
$ [String] -> [String]
forall a. Eq a => [a] -> [a]
nub ([String] -> [String]) -> [String] -> [String]
forall a b. (a -> b) -> a -> b
$ [String]
gcc_dirs [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
sys_dirs
_ -> [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return []
{-# NOINLINE gccSearchDirCache #-}
gccSearchDirCache :: IORef [(String, [String])]
gccSearchDirCache :: IORef [(String, [String])]
gccSearchDirCache = IO (IORef [(String, [String])]) -> IORef [(String, [String])]
forall a. IO a -> a
unsafePerformIO (IO (IORef [(String, [String])]) -> IORef [(String, [String])])
-> IO (IORef [(String, [String])]) -> IORef [(String, [String])]
forall a b. (a -> b) -> a -> b
$ [(String, [String])] -> IO (IORef [(String, [String])])
forall a. a -> IO (IORef a)
newIORef []
getGccSearchDirectory :: DynFlags -> String -> IO [FilePath]
getGccSearchDirectory :: DynFlags -> String -> IO [String]
getGccSearchDirectory dflags :: DynFlags
dflags key :: String
key = do
[(String, [String])]
cache <- IORef [(String, [String])] -> IO [(String, [String])]
forall a. IORef a -> IO a
readIORef IORef [(String, [String])]
gccSearchDirCache
case String -> [(String, [String])] -> Maybe [String]
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
key [(String, [String])]
cache of
Just x :: [String]
x -> [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return [String]
x
Nothing -> do
String
str <- DynFlags -> [Option] -> IO String
askLd DynFlags
dflags [String -> Option
Option "--print-search-dirs"]
let line :: String
line = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace String
str
name :: String
name = String
key String -> String -> String
forall a. [a] -> [a] -> [a]
++ ": ="
if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
line
then [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return []
else do let val :: [String]
val = String -> [String]
split (String -> [String]) -> String -> [String]
forall a b. (a -> b) -> a -> b
$ String -> String -> String
find String
name String
line
[String]
dirs <- (String -> IO Bool) -> [String] -> IO [String]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM String -> IO Bool
doesDirectoryExist [String]
val
IORef [(String, [String])]
-> ([(String, [String])] -> [(String, [String])]) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
modifyIORef' IORef [(String, [String])]
gccSearchDirCache ((String
key, [String]
dirs)(String, [String]) -> [(String, [String])] -> [(String, [String])]
forall a. a -> [a] -> [a]
:)
[String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return [String]
val
where split :: FilePath -> [FilePath]
split :: String -> [String]
split r :: String
r = case (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
==';') String
r of
(s :: String
s, [] ) -> [String
s]
(s :: String
s, (_:xs :: String
xs)) -> String
s String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String -> [String]
split String
xs
find :: String -> String -> String
find :: String -> String -> String
find r :: String
r x :: String
x = let lst :: [String]
lst = String -> [String]
lines String
x
val :: [String]
val = (String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter (String
r String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf`) [String]
lst
in if [String] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
val
then []
else case (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='=') ([String] -> String
forall a. [a] -> a
head [String]
val) of
(_ , []) -> []
(_, (_:xs :: String
xs)) -> String
xs
getSystemDirectories :: IO [FilePath]
#if defined(mingw32_HOST_OS)
getSystemDirectories = fmap (:[]) getSystemDirectory
#else
getSystemDirectories :: IO [String]
getSystemDirectories = [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return []
#endif
addEnvPaths :: String -> [String] -> IO [String]
addEnvPaths :: String -> [String] -> IO [String]
addEnvPaths name :: String
name list :: [String]
list
= do
String
working_dir <- IO String
getCurrentDirectory
Maybe String
values <- String -> IO (Maybe String)
lookupEnv String
name
case Maybe String
values of
Nothing -> [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return [String]
list
Just arr :: String
arr -> [String] -> IO [String]
forall (m :: * -> *) a. Monad m => a -> m a
return ([String] -> IO [String]) -> [String] -> IO [String]
forall a b. (a -> b) -> a -> b
$ [String]
list [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ String -> String -> [String]
splitEnv String
working_dir String
arr
where
splitEnv :: FilePath -> String -> [String]
splitEnv :: String -> String -> [String]
splitEnv working_dir :: String
working_dir value :: String
value =
case (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
envListSep) String
value of
(x :: String
x, [] ) ->
[if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
x then String
working_dir else String
x]
(x :: String
x, (_:xs :: String
xs)) ->
(if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
x then String
working_dir else String
x) String -> [String] -> [String]
forall a. a -> [a] -> [a]
: String -> String -> [String]
splitEnv String
working_dir String
xs
#if defined(mingw32_HOST_OS)
envListSep = ';'
#else
envListSep :: Char
envListSep = ':'
#endif
loadFramework :: HscEnv -> [FilePath] -> FilePath -> IO (Maybe String)
loadFramework :: HscEnv -> [String] -> String -> IO (Maybe String)
loadFramework hsc_env :: HscEnv
hsc_env extraPaths :: [String]
extraPaths rootname :: String
rootname
= do { Either IOException String
either_dir <- IO String -> IO (Either IOException String)
forall a. IO a -> IO (Either IOException a)
tryIO IO String
getHomeDirectory
; let homeFrameworkPath :: [String]
homeFrameworkPath = case Either IOException String
either_dir of
Left _ -> []
Right dir :: String
dir -> [String
dir String -> String -> String
</> "Library/Frameworks"]
ps :: [String]
ps = [String]
extraPaths [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
homeFrameworkPath [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
defaultFrameworkPaths
; Maybe String
mb_fwk <- [String] -> String -> IO (Maybe String)
findFile [String]
ps String
fwk_file
; case Maybe String
mb_fwk of
Just fwk_path :: String
fwk_path -> HscEnv -> String -> IO (Maybe String)
loadDLL HscEnv
hsc_env String
fwk_path
Nothing -> Maybe String -> IO (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> Maybe String
forall a. a -> Maybe a
Just "not found") }
where
fwk_file :: String
fwk_file = String
rootname String -> String -> String
<.> "framework" String -> String -> String
</> String
rootname
defaultFrameworkPaths :: [String]
defaultFrameworkPaths = ["/Library/Frameworks", "/System/Library/Frameworks"]
maybePutStr :: DynFlags -> String -> IO ()
maybePutStr :: DynFlags -> String -> IO ()
maybePutStr dflags :: DynFlags
dflags s :: String
s
= Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (DynFlags -> Int
verbosity DynFlags
dflags Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
DynFlags
-> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
putLogMsg DynFlags
dflags
WarnReason
NoReason
Severity
SevInteractive
SrcSpan
noSrcSpan
(DynFlags -> PprStyle
defaultUserStyle DynFlags
dflags)
(String -> SDoc
text String
s)
maybePutStrLn :: DynFlags -> String -> IO ()
maybePutStrLn :: DynFlags -> String -> IO ()
maybePutStrLn dflags :: DynFlags
dflags s :: String
s = DynFlags -> String -> IO ()
maybePutStr DynFlags
dflags (String
s String -> String -> String
forall a. [a] -> [a] -> [a]
++ "\n")