simpleInstInfoTy, simpleInstInfoTyCon,
-- Global environment
- tcExtendGlobalEnv, tcExtendGlobalValEnv,
+ tcExtendGlobalEnv, tcExtendGlobalValEnv, tcExtendGlobalTypeEnv,
tcLookupTyCon, tcLookupClass, tcLookupGlobalId, tcLookupDataCon,
tcLookupGlobal_maybe, tcLookupGlobal, tcLookupSyntaxId, tcLookupSyntaxName,
-- Local environment
tcExtendKindEnv, tcLookupLocalIds,
tcExtendTyVarEnv, tcExtendTyVarEnvForMeths,
- tcExtendLocalValEnv, tcLookup, tcLookup_maybe,
+ tcExtendLocalValEnv, tcLookup, tcLookup_maybe, tcLookupId,
-- Global type variables
tcGetGlobalTyVars, tcExtendGlobalTyVars,
import TyCon ( TyCon )
import Class ( Class, ClassOpItem, ClassContext )
import Name ( Name, OccName, NamedThing(..),
- nameOccName, getSrcLoc, mkLocalName,
- isLocalName, nameModule_maybe
+ nameOccName, getSrcLoc, mkLocalName, isLocalName,
+ nameIsLocalOrFrom
)
-import Name ( NameEnv, lookupNameEnv, nameEnvElts, extendNameEnvList, emptyNameEnv )
+import Name ( NameEnv, lookupNameEnv, nameEnvElts,
+ extendNameEnvList, emptyNameEnv, plusNameEnv )
import OccName ( mkDFunOcc, occNameString )
-import HscTypes ( DFunId, TypeEnv, HomeSymbolTable, PackageTypeEnv )
+import HscTypes ( DFunId,
+ PackageTypeEnv, TypeEnv,
+ extendTypeEnvList, extendTypeEnvWithIds,
+ typeEnvTyCons, typeEnvClasses, typeEnvIds,
+ HomeSymbolTable
+ )
import Module ( Module )
import InstEnv ( InstEnv, emptyInstEnv )
import HscTypes ( lookupType, TyThing(..) )
{- NameEnv TyThing-} -- compiling this module:
-- types and classes (both imported and local)
-- imported Ids
- -- (Ids defined in this module are in the local envt)
+ -- (Ids defined in this module start in the local envt,
+ -- though they move to the global envt during zonking)
tcLEnv :: NameEnv TcTyThing, -- The local type environment: Ids and TyVars
-- defined in this module
| otherwise = lookupType hst pte name
-tcEnvClasses env = [cl | AClass cl <- nameEnvElts (tcGEnv env)]
-tcEnvTyCons env = [tc | ATyCon tc <- nameEnvElts (tcGEnv env)]
-tcEnvIds env = [id | AnId id <- nameEnvElts (tcGEnv env)]
+tcEnvClasses env = typeEnvClasses (tcGEnv env)
+tcEnvTyCons env = typeEnvTyCons (tcGEnv env)
+tcEnvIds env = typeEnvIds (tcGEnv env)
tcEnvTyVars env = [tv | ATyVar tv <- nameEnvElts (tcLEnv env)]
tcEnvTcIds env = [id | ATcId id <- nameEnvElts (tcLEnv env)]
\begin{code}
isLocalThing :: NamedThing a => Module -> a -> Bool
- -- True if the thing has a Local name,
- -- or a Global name from the specified module
-isLocalThing mod thing = case nameModule_maybe (getName thing) of
- Nothing -> True -- A local name
- Just m -> m == mod -- A global thing
+isLocalThing mod thing = nameIsLocalOrFrom mod (getName thing)
\end{code}
%************************************************************************
tcExtendGlobalEnv things thing_inside
= tcGetEnv `thenNF_Tc` \ env ->
let
- ge' = extendNameEnvList (tcGEnv env) [(getName thing, thing) | thing <- things]
+ ge' = extendTypeEnvList (tcGEnv env) things
+ in
+ tcSetEnv (env {tcGEnv = ge'}) thing_inside
+
+
+tcExtendGlobalTypeEnv :: TypeEnv -> TcM r -> TcM r
+tcExtendGlobalTypeEnv extra_env thing_inside
+ = tcGetEnv `thenNF_Tc` \ env ->
+ let
+ ge' = tcGEnv env `plusNameEnv` extra_env
in
tcSetEnv (env {tcGEnv = ge'}) thing_inside
tcExtendGlobalValEnv ids thing_inside
= tcGetEnv `thenNF_Tc` \ env ->
let
- ge' = extendNameEnvList (tcGEnv env) [(getName id, AnId id) | id <- ids]
+ ge' = extendTypeEnvWithIds (tcGEnv env) ids
in
tcSetEnv (env {tcGEnv = ge'}) thing_inside
\end{code}
Just (ATyCon tc) -> returnNF_Tc tc
other -> notFound "tcLookupTyCon" name
+tcLookupId :: Name -> NF_TcM Id
+tcLookupId name
+ = tcLookup name `thenNF_Tc` \ thing ->
+ case thing of
+ ATcId tc_id -> returnNF_Tc tc_id
+ AGlobal (AnId id) -> returnNF_Tc id
+ other -> pprPanic "tcLookupId" (ppr name)
+
tcLookupLocalIds :: [Name] -> NF_TcM [TcId]
tcLookupLocalIds ns
= tcGetEnv `thenNF_Tc` \ env ->
tcLookupSyntaxId :: Name -> NF_TcM Id
-- Lookup a name like PrelNum.fromInt, and return the corresponding Id,
-- after mapping through the SyntaxMap. This may give us the Id for
--- (say) MyPrelude.fromInt
+-- (say) MyPrelude.fromInteger
tcLookupSyntaxId name
= tcGetEnv `thenNF_Tc` \ env ->
returnNF_Tc (case lookup_global env (tcSyntaxMap env name) of
\begin{code}
data InstInfo
= InstInfo {
- iLocal :: Bool, -- True <=> it's defined in this module
iDFunId :: DFunId, -- The dfun id
iBinds :: RenamedMonoBinds, -- Bindings, b
iPrags :: [RenamedSig] -- User pragmas recorded for generating specialised instances