+ tc_extend_gtvs gtvs extra_global_tyvars `thenNF_Tc` \ gtvs' ->
+ tcSetEnv (TcEnv ue te ve' (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 gtvs) ->
+ returnNF_Tc (lookupWithDefaultUFM ve def name)
+ where
+ def = pprPanic "tcLookupValue:" (ppr name)
+
+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 gtvs) ->
+ returnNF_Tc (lookupUFM ve name)
+
+tcLookupValueByKey :: Unique -> NF_TcM s Id -- Panics if not found
+tcLookupValueByKey key
+ = tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve gtvs) ->
+ returnNF_Tc (explicitLookupValueByKey ve key)
+
+tcLookupValueByKeyMaybe :: Unique -> NF_TcM s (Maybe Id)
+tcLookupValueByKeyMaybe key
+ = tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve gtvs) ->
+ returnNF_Tc (lookupUFM_Directly ve key)
+
+tcGetValueEnv :: NF_TcM s ValueEnv
+tcGetValueEnv
+ = tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve gtvs) ->
+ returnNF_Tc ve
+
+tcSetValueEnv :: ValueEnv -> TcM s a -> TcM s a
+tcSetValueEnv ve scope
+ = tcGetEnv `thenNF_Tc` \ (TcEnv ue te _ gtvs) ->
+ tcSetEnv (TcEnv ue te ve 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 -> lookupUFM 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 = -- pprTrace "tcAdd" (ppr id) $
+ case explicitLookupValue unf_env (getName id) of
+ Nothing -> vanillaIdInfo
+ Just imported_id -> idInfo imported_id
+ -- ToDo: could check that types are the same