-tcExtendGlobalValEnv :: [Id] -> TcM s a -> TcM s a
-tcExtendGlobalValEnv ids scope
- = tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve ie gtvs) ->
- let
- ve' = addListToUFM_Directly ve [(getUnique id, id) | id <- ids]
- in
- tcSetEnv (TcEnv ue te ve' ie gtvs) scope
-
-tcExtendLocalValEnv :: [(Name,TcId)] -> TcM s a -> TcM s a
-tcExtendLocalValEnv names_w_ids scope
- = tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve ie (in_scope_tvs,gtvs)) ->
- tcReadMutVar gtvs `thenNF_Tc` \ global_tvs ->
- let
- ve' = extendNameEnvList ve names_w_ids
- extra_global_tyvars = tyVarsOfTypes (map (idType . snd) names_w_ids)
- in
- tc_extend_gtvs gtvs extra_global_tyvars `thenNF_Tc` \ gtvs' ->
- tcSetEnv (TcEnv ue te ve' ie (in_scope_tvs,gtvs')) scope
-\end{code}
-
-
-\begin{code}
-tcLookupValue :: Name -> NF_TcM s Id -- Panics if not found
-tcLookupValue name
- = case maybeWiredInIdName name of
- Just id -> returnNF_Tc id
- Nothing -> tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve ie gtvs) ->
- returnNF_Tc (lookupWithDefaultUFM ve def name)
- where
- wired_in = case maybeWiredInIdName name of
- Just id -> True
- Nothing -> False
- def = pprPanic "tcLookupValue:" (ppr name <+> ppr wired_in)
-
-tcLookupValueMaybe :: Name -> NF_TcM s (Maybe Id)
-tcLookupValueMaybe name
- = case maybeWiredInIdName name of
- Just id -> returnNF_Tc (Just id)
- Nothing -> tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve ie gtvs) ->
- returnNF_Tc (lookupNameEnv ve name)
-
-tcLookupValueByKey :: Unique -> NF_TcM s Id -- Panics if not found
-tcLookupValueByKey key
- = tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve ie gtvs) ->
- returnNF_Tc (explicitLookupValueByKey ve key)
-
-tcLookupValueByKeyMaybe :: Unique -> NF_TcM s (Maybe Id)
-tcLookupValueByKeyMaybe key
- = tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve ie gtvs) ->
- returnNF_Tc (lookupUFM_Directly ve key)
-
-tcGetValueEnv :: NF_TcM s ValueEnv
-tcGetValueEnv
- = tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve ie gtvs) ->
- returnNF_Tc ve
-
-
-tcSetValueEnv :: ValueEnv -> TcM s a -> TcM s a
-tcSetValueEnv ve scope
- = tcGetEnv `thenNF_Tc` \ (TcEnv ue te _ ie gtvs) ->
- tcSetEnv (TcEnv ue te ve ie gtvs) scope
-
--- Non-monadic version, environment given explicitly
-explicitLookupValueByKey :: ValueEnv -> Unique -> Id
-explicitLookupValueByKey ve key
- = lookupWithDefaultUFM_Directly ve def key
- where
- def = pprPanic "lookupValueByKey:" (pprUnique10 key)
-
-explicitLookupValue :: ValueEnv -> Name -> Maybe Id
-explicitLookupValue ve name
- = case maybeWiredInIdName name of
- Just id -> Just id
- Nothing -> lookupNameEnv ve name
-
- -- Extract the IdInfo from an IfaceSig imported from an interface file
-tcAddImportedIdInfo :: ValueEnv -> Id -> Id
-tcAddImportedIdInfo unf_env id
- | isLocallyDefined id -- Don't look up locally defined Ids, because they
- -- have explicit local definitions, so we get a black hole!
- = id
- | otherwise
- = id `lazySetIdInfo` new_info
- -- The Id must be returned without a data dependency on maybe_id
- where
- new_info = case explicitLookupValue unf_env (getName id) of
- Nothing -> vanillaIdInfo
- Just imported_id -> idInfo imported_id
- -- ToDo: could check that types are the same