-tcLookupGlobal_maybe :: Name -> TcRn m (Maybe TyThing)
--- This is a rather heavily-used function, so I've inlined a few things (e.g. getEps)
--- Notice that for imported things we read the current version from the EPS
--- mutable variable. This is important in situations like
--- ...$(e1)...$(e2)...
--- where the code that e1 expands to might import some defns that
--- also turn out to be needed by the code that e2 expands to.
-tcLookupGlobal_maybe name
- = do { env <- getGblEnv
- ; if nameIsLocalOrFrom (tcg_mod env) name then
- -- Defined in this module
- return (lookupNameEnv (tcg_type_env env) name)
- else
- do { env <- getTopEnv
- ; eps <- readMutVar (top_eps env)
- ; return (lookupType (top_hpt env) (eps_PTE eps) name) }}
-\end{code}
-
-A variety of global lookups, when we know what we are looking for.
-
-\begin{code}
-tcLookupGlobal :: Name -> TcM TyThing
-tcLookupGlobal name
- = tcLookupGlobal_maybe name `thenM` \ maybe_thing ->
- case maybe_thing of
- Just thing -> returnM thing
- other -> notFound "tcLookupGlobal" name
-
-tcLookupGlobalId :: Name -> TcM Id
--- Never used for Haskell-source DataCons, hence no ADataCon case
-tcLookupGlobalId name
- = tcLookupGlobal_maybe name `thenM` \ maybe_thing ->
- case maybe_thing of
- Just (AnId id) -> returnM id
- other -> notFound "tcLookupGlobal (id)" name
-
-tcLookupDataCon :: Name -> TcM DataCon
-tcLookupDataCon con_name
- = tcLookupGlobal_maybe con_name `thenM` \ maybe_thing ->
- case maybe_thing of
- Just (ADataCon data_con) -> returnM data_con
- other -> notFound "tcLookupDataCon" con_name
-
-tcLookupClass :: Name -> TcM Class
-tcLookupClass name
- = tcLookupGlobal_maybe name `thenM` \ maybe_clas ->
- case maybe_clas of
- Just (AClass clas) -> returnM clas
- other -> notFound "tcLookupClass" name
-
-tcLookupTyCon :: Name -> TcM TyCon
-tcLookupTyCon name
- = tcLookupGlobal_maybe name `thenM` \ maybe_tc ->
- case maybe_tc of
- Just (ATyCon tc) -> returnM tc
- other -> notFound "tcLookupTyCon" name
-
-
-getInGlobalScope :: TcRn m (Name -> Bool)
--- Get all things in the global environment; used for deciding what
--- rules to suck in. Anything defined in this module (nameIsLocalOrFrom)
--- is certainly in the envt, so we don't bother to look.
-getInGlobalScope
- = do { mod <- getModule
- ; eps <- getEps
- ; hpt <- getHpt
- ; return (\n -> nameIsLocalOrFrom mod n ||
- isJust (lookupType hpt (eps_PTE eps) n)) }