Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ulysses4ever
Last active March 10, 2018 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulysses4ever/2b1f3eb7bf0e2779cb1cd30249ec735c to your computer and use it in GitHub Desktop.
Save ulysses4ever/2b1f3eb7bf0e2779cb1cd30249ec735c to your computer and use it in GitHub Desktop.
GHC: Tc-less version of lookupGlobal
lookupGlobal :: HscEnv -> Name -> IO TyThing
-- This may look up an Id that one one has previously looked up.
-- If so, we are going to read its interface file, and add its bindings
-- to the ExternalPackageTable.
lookupGlobal hsc_env name
= do { -- Try local envt
let mod = icInteractiveModule (hsc_IC hsc_env)
dflags = hsc_dflags hsc_env
tcg_semantic_mod =
if thisPackage dflags == moduleUnitId mod
then canonicalizeHomeModule dflags (moduleName mod)
else mod
; if nameIsLocalOrFrom tcg_semantic_mod name
then pprPanic "lookupGlobal" (ppr name)
-- Internal names can happen in GHCi
else
-- Try home package table and external package table
do { mb_thing <- lookupImported_maybe hsc_env name
; case mb_thing of
Succeeded thing -> return thing
Failed msg -> pprPanic "lookupGlobal" msg
}}
lookupImported_maybe :: HscEnv -> Name -> IO (MaybeErr MsgDoc TyThing)
-- Returns (Failed err) if we can't find the interface file for the thing
lookupImported_maybe hsc_env name
= do { mb_thing <- lookupTypeHscEnv hsc_env name
; case mb_thing of
Just thing -> return (Succeeded thing)
Nothing -> importDecl_maybe hsc_env name }
importDecl_maybe :: HscEnv -> Name -> IO (MaybeErr MsgDoc TyThing)
importDecl_maybe hsc_env name
| Just thing <- wiredInNameTyThing_maybe name
= do { when (needWiredInHomeIface thing)
(initIfaceLoad hsc_env (loadWiredInHomeIface name))
-- See Note [Loading instances for wired-in things]
; return (Succeeded thing) }
| otherwise
= initIfaceLoad hsc_env (importDecl name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment