Linker

ghc-8.2.2: The GHC API

Safe Haskell | None
Language | Haskell2010

Linker

Description

The dynamic linker for GHCi.

This module deals with the top-level issues of dynamic linking, calling the object-code linker and the byte-code linker where necessary.

Synopsis

- getHValue :: HscEnv -> Name -> IO ForeignHValue
- showLinkerState :: DynFlags -> IO ()
- linkExpr :: HscEnv -> SrcSpan -> UnlinkedBCO -> IO ForeignHValue
- linkDecls :: HscEnv -> SrcSpan -> CompiledByteCode -> IO ()
- unload :: HscEnv -> [Linkable] -> IO ()
- withExtendedLinkEnv :: ExceptionMonad m => [(Name, ForeignHValue)] -> m a -> m a
- extendLinkEnv :: [(Name, ForeignHValue)] -> IO ()
- deleteFromLinkEnv :: [Name] -> IO ()
- extendLoadedPkgs :: [InstalledUnitId] -> IO ()
- linkPackages :: HscEnv -> [LinkerUnitId] -> IO ()
- initDynLinker :: HscEnv -> IO ()
- linkModule :: HscEnv -> Module -> IO ()
- linkCmdLineLibs :: HscEnv -> IO ()

# Documentation

getHValue :: HscEnv -> Name -> IO ForeignHValue Source #

Get the `HValue` associated with the given name.

May cause loading the module that contains the name.

Throws a `ProgramError` if loading fails or the name cannot be found.

showLinkerState :: DynFlags -> IO () Source #

Display the persistent linker state.

linkExpr :: HscEnv -> SrcSpan -> UnlinkedBCO -> IO ForeignHValue Source #

Link a single expression, including first linking packages and modules that this expression depends on.

Raises an IO exception (`ProgramError`) if it can't find a compiled version of the dependents to link.

linkDecls :: HscEnv -> SrcSpan -> CompiledByteCode -> IO () Source #

unload Source #

Arguments

:: HscEnv |
-> [Linkable] | The linkables to *keep*.
-> IO () |

Unloading old objects ready for a new compilation sweep.

The compilation manager provides us with a list of linkables that it considers "stable", i.e. won't be recompiled this time around. For each of the modules current linked in memory,

- if the linkable is stable (and it's the same one -- the user may have recompiled the module on the side), we keep it,
- otherwise, we unload it.
- we also implicitly unload all temporary bindings at this point.

withExtendedLinkEnv :: ExceptionMonad m => [(Name, ForeignHValue)] -> m a -> m a Source #

Temporarily extend the linker state.

extendLinkEnv :: [(Name, ForeignHValue)] -> IO () Source #

deleteFromLinkEnv :: [Name] -> IO () Source #

extendLoadedPkgs :: [InstalledUnitId] -> IO () Source #

linkPackages :: HscEnv -> [LinkerUnitId] -> IO () Source #

Link exactly the specified packages, and their dependents (unless of course they are already linked). The dependents are linked automatically, and it doesn't matter what order you specify the input packages.

initDynLinker :: HscEnv -> IO () Source #

Initialise the dynamic linker. This entails

a) Calling the C initialisation procedure,

b) Loading any packages specified on the command line,

c) Loading any packages specified on the command line, now held in the `-l` options in `v_Opt_l`,

d) Loading any `.o/.dll` files specified on the command line, now held in `ldInputs`,

e) Loading any MacOS frameworks.

NOTE: This function is idempotent; if called more than once, it does nothing. This is useful in Template Haskell, where we call it before trying to link.

linkModule :: HscEnv -> Module -> IO () Source #

linkCmdLineLibs :: HscEnv -> IO () Source #