Dynamically lookup up values from modules and loading them.
- forceLoadModuleInterfaces :: HscEnv -> SDoc -> [Module] -> IO ()
- forceLoadNameModuleInterface :: HscEnv -> SDoc -> Name -> IO ()
- forceLoadTyCon :: HscEnv -> Name -> IO TyCon
- lookupRdrNameInModule :: HscEnv -> ModuleName -> RdrName -> IO (Maybe Name)
- getValueSafely :: HscEnv -> Name -> Type -> IO (Maybe a)
- lessUnsafeCoerce :: DynFlags -> String -> a -> IO b
Force loading information
forceLoadModuleInterfaces :: HscEnv -> SDoc -> [Module] -> IO ()Source
Force the interfaces for the given modules to be loaded. The SDoc
parameter is used
for debugging (-ddump-if-trace
) only: it is shown as the reason why the module is being loaded.
forceLoadNameModuleInterface :: HscEnv -> SDoc -> Name -> IO ()Source
Force the interface for the module containing the name to be loaded. The SDoc
parameter is used
for debugging (-ddump-if-trace
) only: it is shown as the reason why the module is being loaded.
Finding names
lookupRdrNameInModule :: HscEnv -> ModuleName -> RdrName -> IO (Maybe Name)Source
Finds the Name
corresponding to the given RdrName
in the context of the ModuleName
. Returns Nothing
if no
such Name
could be found. Any other condition results in an exception:
- If the module could not be found * If we could not determine the imports of the module
Loading values
getValueSafely :: HscEnv -> Name -> Type -> IO (Maybe a)Source
Loads the value corresponding to a Name
if that value has the given Type
. This only provides limited safety
in that it is up to the user to ensure that that type corresponds to the type you try to use the return value at!
If the value found was not of the correct type, returns Nothing
. Any other condition results in an exception:
- If we could not load the names module * If the thing being loaded is not a value * If the Name does not exist in the module * If the link failed
lessUnsafeCoerce :: DynFlags -> String -> a -> IO bSource
Coerce a value as usual, but:
1) Evaluate it immediately to get a segfault early if the coercion was wrong
2) Wrap it in some debug messages at verbosity 3 or higher so we can see what happened if it does segfault