- tcLEnv :: NameEnv TcTyThing, -- The local type environment: Ids and TyVars
- -- defined in this module
-
- tcTyVars :: TcRef TcTyVarSet -- The "global tyvars"
- -- Namely, the in-scope TyVars bound in tcLEnv, plus the tyvars
- -- mentioned in the types of Ids bound in tcLEnv
- -- Why mutable? see notes with tcGetGlobalTyVars
- }
-
-\end{code}
-
-The Global-Env/Local-Env story
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-During type checking, we keep in the GlobalEnv
- * All types and classes
- * All Ids derived from types and classes (constructors, selectors)
- * Imported Ids
-
-At the end of type checking, we zonk the local bindings,
-and as we do so we add to the GlobalEnv
- * Locally defined top-level Ids
-
-Why? Because they are now Ids not TcIds. This final GlobalEnv is
-used thus:
- a) fed back (via the knot) to typechecking the
- unfoldings of interface signatures
-
- b) used to augment the GlobalSymbolTable
-
-
-\begin{code}
-data TcTyThing
- = AGlobal TyThing -- Used only in the return type of a lookup
- | ATcId TcId -- Ids defined in this module
- | ATyVar TyVar -- Type variables
- | AThing TcKind -- Used temporarily, during kind checking
--- Here's an example of how the AThing guy is used
--- Suppose we are checking (forall a. T a Int):
--- 1. We first bind (a -> AThink kv), where kv is a kind variable.
--- 2. Then we kind-check the (T a Int) part.
--- 3. Then we zonk the kind variable.
--- 4. Now we know the kind for 'a', and we add (a -> ATyVar a::K) to the environment
-
-initTcEnv :: PrelNames.SyntaxMap -> HomeSymbolTable -> PackageTypeEnv -> IO TcEnv
-initTcEnv syntax_map hst pte
- = do { gtv_var <- newIORef emptyVarSet ;
- return (TcEnv { tcSyntaxMap = syntax_map,
- tcGST = lookup,
- tcGEnv = emptyNameEnv,
- tcInsts = emptyInstEnv,
- tcLEnv = emptyNameEnv,
- tcTyVars = gtv_var
- })}
- where
- lookup name | isLocalName name = Nothing
- | 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)]
-tcEnvTyVars env = [tv | ATyVar tv <- nameEnvElts (tcLEnv env)]
-tcEnvTcIds env = [id | ATcId id <- nameEnvElts (tcLEnv env)]
-
-getTcGEnv (TcEnv { tcGEnv = genv }) = genv
-
--- This data type is used to help tie the knot
--- when type checking type and class declarations
-data TyThingDetails = SynTyDetails Type
- | DataTyDetails ClassContext [DataCon] [Id]
- | ClassDetails ClassContext [Id] [ClassOpItem] DataCon