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

Safe Haskell | Ignore
Language | GHC2021

GHC.Driver.Env

Synopsis

- newtype Hsc a = Hsc (HscEnv -> Messages GhcMessage -> IO (a, Messages GhcMessage))
- data HscEnv = HscEnv {
  - hsc_dflags :: DynFlags
  - hsc_targets :: [Target]
  - hsc_mod_graph :: ModuleGraph
  - hsc_IC :: InteractiveContext
  - hsc_NC :: !NameCache
  - hsc_FC :: !FinderCache
  - hsc_type_env_vars :: KnotVars (IORef TypeEnv)
  - hsc_interp :: Maybe Interp
  - hsc_plugins :: !Plugins
  - hsc_unit_env :: UnitEnv
  - hsc_logger :: !Logger
  - hsc_hooks :: !Hooks
  - hsc_tmpfs :: !TmpFs
  - hsc_llvm_config :: !LlvmConfigCache
  }
- hscUpdateFlags :: (DynFlags -> DynFlags) -> HscEnv -> HscEnv
- hscSetFlags :: HasDebugCallStack => DynFlags -> HscEnv -> HscEnv
- hsc_home_unit :: HscEnv -> HomeUnit
- hsc_home_unit_maybe :: HscEnv -> Maybe HomeUnit
- hsc_units :: HasDebugCallStack => HscEnv -> UnitState
- hsc_HPT :: HscEnv -> HomePackageTable
- hsc_HUE :: HscEnv -> HomeUnitEnv
- hsc_HUG :: HscEnv -> HomeUnitGraph
- hsc_all_home_unit_ids :: HscEnv -> Set UnitId
- hscUpdateLoggerFlags :: HscEnv -> HscEnv
- hscUpdateHUG :: (HomeUnitGraph -> HomeUnitGraph) -> HscEnv -> HscEnv
- hscUpdateHPT_lazy :: (HomePackageTable -> HomePackageTable) -> HscEnv -> HscEnv
- hscUpdateHPT :: (HomePackageTable -> HomePackageTable) -> HscEnv -> HscEnv
- hscSetActiveHomeUnit :: HasDebugCallStack => HomeUnit -> HscEnv -> HscEnv
- hscSetActiveUnitId :: HasDebugCallStack => UnitId -> HscEnv -> HscEnv
- hscActiveUnitId :: HscEnv -> UnitId
- runHsc :: HscEnv -> Hsc a -> IO a
- runHsc' :: HscEnv -> Hsc a -> IO (a, Messages GhcMessage)
- mkInteractiveHscEnv :: HscEnv -> HscEnv
- runInteractiveHsc :: HscEnv -> Hsc a -> IO a
- hscEPS :: HscEnv -> IO ExternalPackageState
- hscInterp :: HscEnv -> Interp
- hptCompleteSigs :: HscEnv -> [CompleteMatch]
- hptAllInstances :: HscEnv -> (InstEnv, [FamInst])
- hptInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> (InstEnv, [FamInst])
- hptAnns :: HscEnv -> Maybe (UnitId, ModuleNameWithIsBoot) -> [Annotation]
- hptAllThings :: (HomeModInfo -> [a]) -> HscEnv -> [a]
- hptSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> [a]
- hptRules :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> [CoreRule]
- prepareAnnotations :: HscEnv -> Maybe ModGuts -> IO AnnEnv
- discardIC :: HscEnv -> HscEnv
- lookupType :: HscEnv -> Name -> IO (Maybe TyThing)
- lookupIfaceByModule :: HomeUnitGraph -> PackageIfaceTable -> Module -> Maybe ModIface
- mainModIs :: HomeUnitEnv -> Module

# Documentation

newtype Hsc a #

The Hsc monad: Passing an environment and diagnostic state

Constructors

Hsc (HscEnv -> Messages GhcMessage -> IO (a, Messages GhcMessage)) |

#### Instances

Instances details

MonadIO Hsc # |
Instance details Defined in GHC.Driver.Env.Types Methods liftIO :: IO a -> Hsc a #
Applicative Hsc # |
Instance details Defined in GHC.Driver.Env.Types Methods pure :: a -> Hsc a # (<*>) :: Hsc (a -> b) -> Hsc a -> Hsc b # liftA2 :: (a -> b -> c) -> Hsc a -> Hsc b -> Hsc c # (*>) :: Hsc a -> Hsc b -> Hsc b # (<*) :: Hsc a -> Hsc b -> Hsc a #
Functor Hsc # |
Instance details Defined in GHC.Driver.Env.Types Methods fmap :: (a -> b) -> Hsc a -> Hsc b # (<$) :: a -> Hsc b -> Hsc a #
Monad Hsc # |
Instance details Defined in GHC.Driver.Env.Types Methods (>>=) :: Hsc a -> (a -> Hsc b) -> Hsc b # (>>) :: Hsc a -> Hsc b -> Hsc b # return :: a -> Hsc a #
HasDynFlags Hsc # |
Instance details Defined in GHC.Driver.Env.Types Methods getDynFlags :: Hsc DynFlags #
HasLogger Hsc # |
Instance details Defined in GHC.Driver.Env.Types Methods getLogger :: Hsc Logger #

data HscEnv #

HscEnv is like `Session`, except that some of the fields are immutable. An HscEnv is used to compile a single module from plain Haskell source code (after preprocessing) to either C, assembly or C--. It's also used to store the dynamic linker state to allow for multiple linkers in the same address space. Things like the module graph don't change during a single compilation.

Historical note: "hsc" used to be the name of the compiler binary, when there was a separate driver and compiler. To compile a single module, the driver would invoke hsc on the source code... so nowadays we think of hsc as the layer of the compiler that deals with compiling a single module.

Constructors

HscEnv |

Fields

- hsc_dflags :: DynFlags

  The dynamic flag settings

- hsc_targets :: [Target]

  The targets (or roots) of the current session

- hsc_mod_graph :: ModuleGraph

  The module graph of the current session

- hsc_IC :: InteractiveContext

  The context for evaluating interactive statements

- hsc_NC :: !NameCache

  Global Name cache so that each Name gets a single Unique. Also track the origin of the Names.

- hsc_FC :: !FinderCache

  The cached result of performing finding in the file system

- hsc_type_env_vars :: KnotVars (IORef TypeEnv)

  Used for one-shot compilation only, to initialise the `IfGblEnv`. See `tcg_type_env_var` for `TcGblEnv`. See also Note [hsc_type_env_var hack]

- hsc_interp :: Maybe Interp

  target code interpreter (if any) to use for TH and GHCi. See Note [Target code interpreter]

- hsc_plugins :: !Plugins

  Plugins

- hsc_unit_env :: UnitEnv

  Unit environment (unit state, home unit, etc.).

  Initialized from the databases cached in `hsc_unit_dbs` and from the DynFlags.

- hsc_logger :: !Logger

  Logger with its flags.

  Don't forget to update the logger flags if the logging related DynFlags change. Or better, use hscSetFlags setter which does it.

- hsc_hooks :: !Hooks

  Hooks

- hsc_tmpfs :: !TmpFs

  Temporary files

- hsc_llvm_config :: !LlvmConfigCache

  LLVM configuration cache.

#### Instances

Instances details

ContainsDynFlags HscEnv # |
Instance details Defined in GHC.Driver.Env.Types Methods extractDynFlags :: HscEnv -> DynFlags #

hscUpdateFlags :: (DynFlags -> DynFlags) -> HscEnv -> HscEnv #

Update Flags

hscSetFlags :: HasDebugCallStack => DynFlags -> HscEnv -> HscEnv #

Set Flags

hsc_home_unit :: HscEnv -> HomeUnit #

hsc_home_unit_maybe :: HscEnv -> Maybe HomeUnit #

hsc_units :: HasDebugCallStack => HscEnv -> UnitState #

hsc_HPT :: HscEnv -> HomePackageTable #

hsc_HUE :: HscEnv -> HomeUnitEnv #

hsc_HUG :: HscEnv -> HomeUnitGraph #

hsc_all_home_unit_ids :: HscEnv -> Set UnitId #

hscUpdateLoggerFlags :: HscEnv -> HscEnv #

Update the LogFlags of the Log in hsc_logger from the DynFlags in hsc_dflags. You need to call this when DynFlags are modified.

hscUpdateHUG :: (HomeUnitGraph -> HomeUnitGraph) -> HscEnv -> HscEnv #

hscUpdateHPT_lazy :: (HomePackageTable -> HomePackageTable) -> HscEnv -> HscEnv #

hscUpdateHPT :: (HomePackageTable -> HomePackageTable) -> HscEnv -> HscEnv #

hscSetActiveHomeUnit :: HasDebugCallStack => HomeUnit -> HscEnv -> HscEnv #

hscSetActiveUnitId :: HasDebugCallStack => UnitId -> HscEnv -> HscEnv #

hscActiveUnitId :: HscEnv -> UnitId #

runHsc :: HscEnv -> Hsc a -> IO a #

runHsc' :: HscEnv -> Hsc a -> IO (a, Messages GhcMessage) #

mkInteractiveHscEnv :: HscEnv -> HscEnv #

Switches in the DynFlags and Plugins from the InteractiveContext

runInteractiveHsc :: HscEnv -> Hsc a -> IO a #

A variant of runHsc that switches in the DynFlags and Plugins from the InteractiveContext before running the Hsc computation.

hscEPS :: HscEnv -> IO ExternalPackageState #

Retrieve the ExternalPackageState cache.

hscInterp :: HscEnv -> Interp #

Retrieve the target code interpreter

Fails if no target code interpreter is available

hptCompleteSigs :: HscEnv -> [CompleteMatch] #

hptAllInstances :: HscEnv -> (InstEnv, [FamInst]) #

Find all the instance declarations (of classes and families) from the Home Package Table filtered by the provided predicate function. Used in `tcRnImports`, to select the instances that are in the transitive closure of imports from the currently compiled module.

hptInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> (InstEnv, [FamInst]) #

Find instances visible from the given set of imports

hptAnns :: HscEnv -> Maybe (UnitId, ModuleNameWithIsBoot) -> [Annotation] #

Get annotations from modules "below" this one (in the dependency sense)

hptAllThings :: (HomeModInfo -> [a]) -> HscEnv -> [a] #

hptSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> [a] #

Get things from modules "below" this one (in the dependency sense) C.f Inst.hptInstances

hptRules :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> [CoreRule] #

Get rules from modules "below" this one (in the dependency sense)

prepareAnnotations :: HscEnv -> Maybe ModGuts -> IO AnnEnv #

Deal with gathering annotations in from all possible places and combining them into a single `AnnEnv`

discardIC :: HscEnv -> HscEnv #

Discard the contents of the InteractiveContext, but keep the DynFlags and the loaded plugins. It will also keep ic_int_print and ic_monad if their names are from external packages.

lookupType :: HscEnv -> Name -> IO (Maybe TyThing) #

Find the `TyThing` for the given `Name` by using all the resources at our disposal: the compiled modules in the `HomePackageTable` and the compiled modules in other packages that live in `PackageTypeEnv`. Note that this does NOT look up the `TyThing` in the module being compiled: you have to do that yourself, if desired

lookupIfaceByModule :: HomeUnitGraph -> PackageIfaceTable -> Module -> Maybe ModIface #

Find the `ModIface` for a `Module`, searching in both the loaded home and external package module information

mainModIs :: HomeUnitEnv -> Module #