-\begin{code}
------------------------
--- findGlobals looks at the value environment and finds values
--- whose types mention the offending type variable. It has to be
--- careful to zonk the Id's type first, so it has to be in the monad.
--- We must be careful to pass it a zonked type variable, too.
-
-findGlobals :: TcTyVarSet
- -> TidyEnv
- -> TcM (TidyEnv, [SDoc])
-
-findGlobals tvs tidy_env = do
- lcl_env <- getLclEnv
- go tidy_env [] (lclEnvElts lcl_env)
- where
- go tidy_env acc [] = return (tidy_env, acc)
- go tidy_env acc (thing : things) = do
- (tidy_env1, maybe_doc) <- find_thing ignore_it tidy_env thing
- case maybe_doc of
- Just d -> go tidy_env1 (d:acc) things
- Nothing -> go tidy_env1 acc things
-
- ignore_it ty = tvs `disjointVarSet` tyVarsOfType ty
-
------------------------
-find_thing :: (TcType -> Bool) -> TidyEnv -> TcTyThing
- -> TcM (TidyEnv, Maybe SDoc)
-find_thing ignore_it tidy_env (ATcId { tct_id = id }) = do
- id_ty <- zonkTcType (idType id)
- if ignore_it id_ty then
- return (tidy_env, Nothing)
- else let
- (tidy_env', tidy_ty) = tidyOpenType tidy_env id_ty
- msg = sep [ppr id <+> dcolon <+> ppr tidy_ty,
- nest 2 (parens (ptext (sLit "bound at") <+>
- ppr (getSrcLoc id)))]
- in
- return (tidy_env', Just msg)
-
-find_thing ignore_it tidy_env (ATyVar tv ty) = do
- tv_ty <- zonkTcType ty
- if ignore_it tv_ty then
- return (tidy_env, Nothing)
- else let
- -- The name tv is scoped, so we don't need to tidy it
- (tidy_env1, tidy_ty) = tidyOpenType tidy_env tv_ty
- msg = sep [ptext (sLit "Scoped type variable") <+> quotes (ppr tv) <+> eq_stuff, nest 2 bound_at]
-
- eq_stuff | Just tv' <- Type.getTyVar_maybe tv_ty,
- getOccName tv == getOccName tv' = empty
- | otherwise = equals <+> ppr tidy_ty
- -- It's ok to use Type.getTyVar_maybe because ty is zonked by now
- bound_at = parens $ ptext (sLit "bound at:") <+> ppr (getSrcLoc tv)
- in
- return (tidy_env1, Just msg)
-
-find_thing _ _ thing = pprPanic "find_thing" (ppr thing)
-\end{code}
-
-%************************************************************************
-%* *
-\subsection{The global tyvars}
-%* *
-%************************************************************************
-
-\begin{code}
-tc_extend_gtvs :: IORef VarSet -> VarSet -> TcM (IORef VarSet)
-tc_extend_gtvs gtvs extra_global_tvs = do
- global_tvs <- readMutVar gtvs
- newMutVar (global_tvs `unionVarSet` extra_global_tvs)
-\end{code}
-
-@tcGetGlobalTyVars@ returns a fully-zonked set of tyvars free in the environment.
-To improve subsequent calls to the same function it writes the zonked set back into
-the environment.
-
-\begin{code}
-tcGetGlobalTyVars :: TcM TcTyVarSet
-tcGetGlobalTyVars = do
- (TcLclEnv {tcl_tyvars = gtv_var}) <- getLclEnv
- gbl_tvs <- readMutVar gtv_var
- gbl_tvs' <- zonkTcTyVarsAndFV (varSetElems gbl_tvs)
- writeMutVar gtv_var gbl_tvs'
- return gbl_tvs'