ghc-hotswap-0.1.0.0: Library for hot-swapping shared objects in GHC

Safe HaskellNone
LanguageHaskell2010

GHC.Hotswap

Description

A library for safely interacting with frequently updating shared objects within a haskell binary. See more documentation at https://github.com/fbsamples/ghc-hotswap/.

Assuming you have some structure of data called Foo.

In common types: ``` type FooExport = IO (StablePtr Foo) ```

In the shared object: ``` foreign export ccall "hs_mySOFunction" hsHandle :: FooExport

hsHandle :: FooExport hsHandle = newStablePtr Foo { ... } ```

In the main binary: ``` main = do myData <- registerHotswap "hs_mySOFunction" "pathto/lib.o" (withSO myData) $ Foo{..} -> do -- first version ...

(swapSO myData) "pathto/next_lib.o" (withSO myData) $ Foo{..} -> do -- next version ... ```

Synopsis

Documentation

data UpdatableSO a Source #

Access control for a shared object that return a type a from the shared object

swapSO :: UpdatableSO a -> FilePath -> IO () Source #

Loads and links the new object such that future calls to withSO will use the new objects. Existing calls in the old object will complete as normal and the old object will be unloaded when all references to it are dropped. The underlying work is not thread safe, so it's on the caller to appropriately serialize these calls to avoid accidentally skipping an update.

withSO :: UpdatableSO a -> forall b. (a -> IO b) -> IO b Source #

Accessor for information out of the shared object. Use this to run something with data from the latest shared object. You are guaranteed to access the latest object and the object will be retained until the call finishes. Always eventually return from calling this function, otherwise objects will not be dropped.

registerHotswap :: NFData a => String -> FilePath -> IO (UpdatableSO a) Source #

Loads a shared object, pulls out the particular symbol name, and returns a control structure for interacting with the data