GHC.Runtime.Interpreter.Types

ghc-lib-parser-9.14.1.20251220: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Runtime.Interpreter.Types

Contents

- InterpSymbolCache
- IServ
- JSInterp

Description

Types used by the runtime interpreter

Synopsis

- data Interp = Interp {
  - interpInstance :: !InterpInstance
  - interpLoader :: !Loader
  - interpSymbolCache :: !InterpSymbolCache
  }
- data InterpInstance = ExternalInterp !ExtInterp
- data InterpProcess = InterpProcess {
  - interpPipe :: !Pipe
  - interpHandle :: !ProcessHandle
  - interpLock :: !(MVar ())
  }
- data ExtInterp
  - = ExtIServ !IServ
  - | ExtJS !JSInterp
  - | ExtWasm !WasmInterp
- type ExtInterpStatusVar d = MVar (InterpStatus (ExtInterpInstance d))
- data ExtInterpInstance c = ExtInterpInstance {
  - instProcess :: !InterpProcess
  - instPendingFrees :: !(MVar [HValueRef])
  - instExtra :: !c
  }
- data ExtInterpState cfg details = ExtInterpState {
  - interpConfig :: !cfg
  - interpStatus :: !(ExtInterpStatusVar details)
  }
- data InterpStatus inst
  - = InterpPending
  - | InterpRunning !inst
- data InterpSymbolCache = InterpSymbolCache {
  - interpClosureCache :: MVar (SymbolCache "closure")
  - interpConInfoCache :: MVar (SymbolCache "con_info")
  - interpStaticInfoCache :: MVar (SymbolCache "static_info")
  - interpBytesCache :: MVar (SymbolCache "bytes")
  - interpFaststringCache :: MVar (UniqFM FastString (Ptr ()))
  }
- mkInterpSymbolCache :: IO InterpSymbolCache
- lookupInterpSymbolCache :: forall (s :: SuffixOrInterpreted). InterpSymbol s -> InterpSymbolCache -> IO (Maybe (Ptr ()))
- updateInterpSymbolCache :: forall (s :: SuffixOrInterpreted). InterpSymbol s -> InterpSymbolCache -> Ptr () -> IO ()
- purgeInterpSymbolCache :: InterpSymbolCache -> IO ()
- data InterpSymbol (s :: SuffixOrInterpreted) where
  - IClosureSymbol :: Name -> InterpSymbol ('Suffix "closure")
  - IConInfoSymbol :: Name -> InterpSymbol ('Suffix "con_info")
  - IStaticInfoSymbol :: Name -> InterpSymbol ('Suffix "static_info")
  - IBytesSymbol :: Name -> InterpSymbol ('Suffix "bytes")
  - IFaststringSymbol :: FastString -> InterpSymbol 'Interpreted
- data SuffixOrInterpreted
  - = Suffix Symbol
  - | Interpreted
- interpSymbolName :: forall (s :: Symbol). InterpSymbol ('Suffix s) -> Name
- interpSymbolSuffix :: forall (s :: Symbol). InterpSymbol ('Suffix s) -> String
- eliminateInterpSymbol :: forall (s :: SuffixOrInterpreted) r. InterpSymbol s -> (InterpSymbol 'Interpreted -> r) -> (forall (x :: Symbol). InterpSymbol ('Suffix x) -> r) -> r
- interpretedInterpSymbol :: InterpSymbol 'Interpreted -> FastString
- interpreterProfiled :: Interp -> Bool
- interpreterDynamic :: Interp -> Bool
- type IServ = ExtInterpState IServConfig ()
- data IServConfig = IServConfig {
  - iservConfProgram :: !String
  - iservConfOpts :: ![String]
  - iservConfProfiled :: !Bool
  - iservConfDynamic :: !Bool
  - iservConfHook :: !(Maybe (CreateProcess -> IO ProcessHandle))
  - iservConfTrace :: IO ()
  }
- type JSInterp = ExtInterpState JSInterpConfig JSInterpExtra
- data JSInterpExtra = JSInterpExtra {
  - instStdIn :: !Handle
  - instFinderCache :: !FinderCache
  - instFinderOpts :: !FinderOpts
  - instJSState :: !(MVar JSState)
  - instGhciUnitId :: !UnitId
  }
- data JSInterpConfig = JSInterpConfig {
  - jsInterpNodeConfig :: !NodeJsSettings
  - jsInterpScript :: !FilePath
  - jsInterpTmpFs :: !TmpFs
  - jsInterpTmpDir :: !TempDir
  - jsInterpLogger :: !Logger
  - jsInterpCodegenCfg :: !StgToJSConfig
  - jsInterpUnitEnv :: !UnitEnv
  - jsInterpFinderOpts :: !FinderOpts
  - jsInterpFinderCache :: !FinderCache
  }
- data JSState = JSState {
  - jsLinkState :: !LinkPlan
  - jsServerStarted :: !Bool
  }
- data NodeJsSettings = NodeJsSettings {
  - nodeProgram :: FilePath
  - nodePath :: Maybe FilePath
  - nodeExtraArgs :: [String]
  - nodeKeepAliveMaxMem :: Integer
  }
- defaultNodeJsSettings :: NodeJsSettings
- type WasmInterp = ExtInterpState WasmInterpConfig ()
- data WasmInterpConfig = WasmInterpConfig {
  - wasmInterpDyLD :: !FilePath
  - wasmInterpLibDir :: FilePath
  - wasmInterpOpts :: ![String]
  - wasmInterpBrowser :: !Bool
  - wasmInterpBrowserHost :: !String
  - wasmInterpBrowserPort :: !Int
  - wasmInterpBrowserRedirectWasiConsole :: !Bool
  - wasmInterpBrowserPuppeteerLaunchOpts :: !(Maybe String)
  - wasmInterpBrowserPlaywrightBrowserType :: !(Maybe String)
  - wasmInterpBrowserPlaywrightLaunchOpts :: !(Maybe String)
  - wasmInterpTargetPlatform :: !Platform
  - wasmInterpProfiled :: !Bool
  - wasmInterpHsSoSuffix :: !String
  - wasmInterpUnitState :: !UnitState
  }

# Documentation

data Interp #

Interpreter

Constructors

Interp |
Fields interpInstance :: !InterpInstance Interpreter instance (internal, external) interpLoader :: !Loader Interpreter loader interpSymbolCache :: !InterpSymbolCache LookupSymbol cache

data InterpInstance #

Constructors

ExternalInterp !ExtInterp | External interpreter

data InterpProcess #

Constructors

InterpProcess |
Fields interpPipe :: !Pipe Pipe to communicate with the server interpHandle :: !ProcessHandle Process handle of the server interpLock :: !(MVar ()) Lock to prevent concurrent access to the stream

data ExtInterp #

Constructors

ExtIServ !IServ |
ExtJS !JSInterp |
ExtWasm !WasmInterp |

type ExtInterpStatusVar d = MVar (InterpStatus (ExtInterpInstance d)) #

data ExtInterpInstance c #

Common field between native external interpreter and the JS one

Constructors

ExtInterpInstance |
Fields instProcess :: !InterpProcess External interpreter process and its pipe (communication channel) instPendingFrees :: !(MVar [HValueRef]) Values that need to be freed before the next command is sent. Finalizers for ForeignRefs can append values to this list asynchronously. instExtra :: !c Instance specific extra fields

data ExtInterpState cfg details #

External interpreter

The external interpreter is spawned lazily (on first use) to avoid slowing down sessions that don't require it. The contents of the MVar reflects the state of the interpreter (running or not).

Constructors

ExtInterpState |
Fields interpConfig :: !cfg interpStatus :: !(ExtInterpStatusVar details)

data InterpStatus inst #

Status of an external interpreter

Constructors

InterpPending | Not spawned yet
InterpRunning !inst | Running

# InterpSymbolCache

data InterpSymbolCache #

Constructors

InterpSymbolCache |
Fields interpClosureCache :: MVar (SymbolCache "closure") interpConInfoCache :: MVar (SymbolCache "con_info") interpStaticInfoCache :: MVar (SymbolCache "static_info") interpBytesCache :: MVar (SymbolCache "bytes") interpFaststringCache :: MVar (UniqFM FastString (Ptr ()))

mkInterpSymbolCache :: IO InterpSymbolCache #

lookupInterpSymbolCache :: forall (s :: SuffixOrInterpreted). InterpSymbol s -> InterpSymbolCache -> IO (Maybe (Ptr ())) #

updateInterpSymbolCache :: forall (s :: SuffixOrInterpreted). InterpSymbol s -> InterpSymbolCache -> Ptr () -> IO () #

purgeInterpSymbolCache :: InterpSymbolCache -> IO () #

Clear all symbol caches.

data InterpSymbol (s :: SuffixOrInterpreted) where #

Constructors

IClosureSymbol :: Name -> InterpSymbol ('Suffix "closure") |
IConInfoSymbol :: Name -> InterpSymbol ('Suffix "con_info") |
IStaticInfoSymbol :: Name -> InterpSymbol ('Suffix "static_info") |
IBytesSymbol :: Name -> InterpSymbol ('Suffix "bytes") |
IFaststringSymbol :: FastString -> InterpSymbol 'Interpreted |

#### Instances

Instances details

Outputable (InterpSymbol s) # |
Instance details Defined in GHC.Runtime.Interpreter.Types.SymbolCache Methods ppr :: InterpSymbol s -> SDoc #

data SuffixOrInterpreted #

Constructors

Suffix Symbol |
Interpreted |

interpSymbolName :: forall (s :: Symbol). InterpSymbol ('Suffix s) -> Name #

interpSymbolSuffix :: forall (s :: Symbol). InterpSymbol ('Suffix s) -> String #

eliminateInterpSymbol :: forall (s :: SuffixOrInterpreted) r. InterpSymbol s -> (InterpSymbol 'Interpreted -> r) -> (forall (x :: Symbol). InterpSymbol ('Suffix x) -> r) -> r #

interpretedInterpSymbol :: InterpSymbol 'Interpreted -> FastString #

interpreterProfiled :: Interp -> Bool #

Interpreter uses Profiling way

interpreterDynamic :: Interp -> Bool #

Interpreter uses Dynamic way

# IServ

type IServ = ExtInterpState IServConfig () #

data IServConfig #

Configuration needed to spawn an external interpreter

Constructors

IServConfig |
Fields iservConfProgram :: !String External program to run iservConfOpts :: ![String] Command-line options iservConfProfiled :: !Bool Use Profiling way iservConfDynamic :: !Bool Use Dynamic way iservConfHook :: !(Maybe (CreateProcess -> IO ProcessHandle)) Hook iservConfTrace :: IO () Trace action executed after spawn

# JSInterp

type JSInterp = ExtInterpState JSInterpConfig JSInterpExtra #

data JSInterpExtra #

Constructors

JSInterpExtra |
Fields instStdIn :: !Handle Stdin for the process instFinderCache :: !FinderCache instFinderOpts :: !FinderOpts instJSState :: !(MVar JSState) Mutable state instGhciUnitId :: !UnitId GHCi unit-id

data JSInterpConfig #

Constructors

JSInterpConfig |
Fields jsInterpNodeConfig :: !NodeJsSettings NodeJS settings jsInterpScript :: !FilePath Path to "ghc-interp.js" script jsInterpTmpFs :: !TmpFs jsInterpTmpDir :: !TempDir jsInterpLogger :: !Logger jsInterpCodegenCfg :: !StgToJSConfig jsInterpUnitEnv :: !UnitEnv jsInterpFinderOpts :: !FinderOpts jsInterpFinderCache :: !FinderCache

data JSState #

Constructors

JSState |
Fields jsLinkState :: !LinkPlan Linker state of the interpreter jsServerStarted :: !Bool Is the Haskell server started?

data NodeJsSettings #

NodeJs configuration

Constructors

NodeJsSettings |
Fields nodeProgram :: FilePath location of node.js program nodePath :: Maybe FilePath value of NODE_PATH environment variable (search path for Node modules; GHCJS used to provide some) nodeExtraArgs :: [String] extra arguments to pass to node.js nodeKeepAliveMaxMem :: Integer keep node.js (TH, GHCJSi) processes alive if they don't use more than this

defaultNodeJsSettings :: NodeJsSettings #

type WasmInterp = ExtInterpState WasmInterpConfig () #

data WasmInterpConfig #

Constructors

WasmInterpConfig |
Fields wasmInterpDyLD :: !FilePath Location of dyld.mjs script wasmInterpLibDir :: FilePath wasi-sdk sysroot libdir containing libc.so, etc wasmInterpOpts :: ![String] Additional command line arguments for iserv wasmInterpBrowser :: !Bool wasmInterpBrowserHost :: !String wasmInterpBrowserPort :: !Int wasmInterpBrowserRedirectWasiConsole :: !Bool wasmInterpBrowserPuppeteerLaunchOpts :: !(Maybe String) wasmInterpBrowserPlaywrightBrowserType :: !(Maybe String) wasmInterpBrowserPlaywrightLaunchOpts :: !(Maybe String) wasmInterpTargetPlatform :: !Platform wasmInterpProfiled :: !Bool Are we profiling yet? wasmInterpHsSoSuffix :: !String Shared lib filename common suffix sans .so, e.g. p-ghc9.13.20241001 wasmInterpUnitState :: !UnitState