tcExtendGlobalValEnv, tcExtendLocalValEnv,
tcLookupLocalValue, tcLookupLocalValueOK, tcLookupLocalValueByKey,
tcLookupGlobalValue, tcLookupGlobalValueByKey, tcLookupGlobalValueMaybe,
- tcAddImportedIdInfo,
+ tcAddImportedIdInfo, tcExplicitLookupGlobal,
tcLookupGlobalValueByKeyMaybe,
newMonoIds, newLocalIds, newLocalId,
IMP_Ubiq()
+#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 201
IMPORT_DELOOPER(TcMLoop) -- for paranoia checking
+#endif
import HsTypes ( HsTyVar(..) )
import Id ( SYN_IE(Id), GenId, idType, mkUserLocal, mkUserId, replaceIdInfo, getIdInfo )
import PragmaInfo ( PragmaInfo(..) )
-import TcHsSyn ( SYN_IE(TcIdBndr), TcIdOcc(..) )
import TcKind ( TcKind, newKindVars, newKindVar, tcDefaultKind, kindToTcKind, Kind )
-import TcType ( SYN_IE(TcType), TcMaybe, SYN_IE(TcTyVar), SYN_IE(TcTyVarSet),
+import TcType ( SYN_IE(TcIdBndr), TcIdOcc(..),
+ SYN_IE(TcType), TcMaybe, SYN_IE(TcTyVar), SYN_IE(TcTyVarSet),
newTyVarTys, tcInstTyVars, zonkTcTyVars
)
import TyVar ( unionTyVarSets, emptyTyVarSet, tyVarSetToList, SYN_IE(TyVar) )
import PprType ( GenTyVar )
import Type ( tyVarsOfTypes, splitForAllTy )
-import TyCon ( TyCon, tyConKind, synTyConArity, SYN_IE(Arity) )
-import Class ( SYN_IE(Class), GenClass, classSig )
+import TyCon ( TyCon, tyConKind, tyConArity, isSynTyCon, SYN_IE(Arity) )
+import Class ( SYN_IE(Class), GenClass )
import TcMonad
import IdInfo ( noIdInfo )
import Name ( Name, OccName(..), getSrcLoc, occNameString,
- maybeWiredInTyConName, maybeWiredInIdName,
+ maybeWiredInTyConName, maybeWiredInIdName, isLocallyDefined,
NamedThing(..)
)
import Pretty
-import Unique ( pprUnique10{-, pprUnique ToDo:rm-}, Unique )
+import Unique ( pprUnique10{-, pprUnique ToDo:rm-}, Unique, Uniquable(..) )
import UniqFM
import Util ( zipEqual, zipWithEqual, zipWith3Equal, zipLazy,
panic, pprPanic, pprTrace
)
+import Maybes ( maybeToBool )
import Outputable
\end{code}
tcLookupTyCon name
- = case maybeWiredInTyConName name of
- Just tc -> returnTc (kindToTcKind (tyConKind tc), synTyConArity tc, tc)
- Nothing -> tcGetEnv `thenNF_Tc` \ (TcEnv tve tce ce gve lve gtvs) ->
- case lookupUFM tce name of
- Just stuff -> returnTc stuff
- Nothing -> -- Could be that he's using a class name as a type constructor
- case lookupUFM ce name of
- Just _ -> failTc (classAsTyConErr name)
- Nothing -> pprPanic "tcLookupTyCon:" (ppr PprDebug name)
+ = -- Try for a wired-in tycon
+ case maybeWiredInTyConName name of {
+ Just tc | isSynTyCon tc -> returnTc (kind, Just (tyConArity tc), tc)
+ | otherwise -> returnTc (kind, Nothing, tc)
+ where {
+ kind = kindToTcKind (tyConKind tc)
+ };
+
+ Nothing ->
+
+ -- Try in the environment
+ tcGetEnv `thenNF_Tc` \ (TcEnv tve tce ce gve lve gtvs) ->
+ case lookupUFM tce name of {
+ Just stuff -> returnTc stuff;
+
+ Nothing ->
+
+ -- Could be that he's using a class name as a type constructor
+ case lookupUFM ce name of
+ Just _ -> failTc (classAsTyConErr name)
+ Nothing -> pprPanic "tcLookupTyCon:" (ppr PprDebug name)
+ } }
tcLookupTyConByKey uniq
= tcGetEnv `thenNF_Tc` \ (TcEnv tve tce ce gve lve gtvs) ->
let
(kind, arity, tycon) = lookupWithDefaultUFM_Directly tce
- (pprPanic "tcLookupTyCon:" (pprUnique10 uniq))
+ (pprPanic "tcLookupTyConByKey:" (pprUnique10 uniq))
uniq
in
returnNF_Tc tycon
tcLookupClass name
= tcGetEnv `thenNF_Tc` \ (TcEnv tve tce ce gve lve gtvs) ->
--- pprTrace "tcLookupClass:" (hsep [text "Uniq:", pprUnique10 (uniqueOf name), text "; avail:", hsep (map (pprUnique10 . fst) (ufmToList ce))]) $
--- pprTrace "tcLookupClass:" (hsep [text "Uniq:", pprUnique (uniqueOf name), text "; avail:", hsep (map (pprUnique . fst) (ufmToList ce))]) $
case lookupUFM ce name of
- Just stuff -> returnTc stuff
- Nothing -> -- Could be that he's using a type constructor as a class
- case lookupUFM tce name of
- Just _ -> failTc (tyConAsClassErr name)
- Nothing -> pprPanic "tcLookupClass:" (ppr PprShowAll name)
+ Just stuff -- Common case: it's ok
+ -> returnTc stuff
+
+ Nothing -- Could be that he's using a type constructor as a class
+ | maybeToBool (maybeWiredInTyConName name)
+ || maybeToBool (lookupUFM tce name)
+ -> failTc (tyConAsClassErr name)
+
+ | otherwise -- Wierd! Renamer shouldn't let this happen
+ -> pprPanic "tcLookupClass:" (ppr PprShowAll name)
tcLookupClassByKey uniq
= tcGetEnv `thenNF_Tc` \ (TcEnv tve tce ce gve lve gtvs) ->
tcLookupGlobalValue :: Name -> NF_TcM s Id
-
tcLookupGlobalValue name
= case maybeWiredInIdName name of
Just id -> returnNF_Tc id
def = pprPanic "tcLookupGlobalValue:" (ppr PprDebug name)
tcLookupGlobalValueMaybe :: Name -> NF_TcM s (Maybe Id)
-
tcLookupGlobalValueMaybe name
= case maybeWiredInIdName name of
Just id -> returnNF_Tc (Just id)
= tcGetEnv `thenNF_Tc` \ (TcEnv tve tce ce gve lve gtvs) ->
returnNF_Tc (lookupUFM_Directly gve uniq)
+
+-- Non-monadic version, environment given explicitly
+tcExplicitLookupGlobal :: TcEnv s -> Name -> Maybe Id
+tcExplicitLookupGlobal (TcEnv tve tce ce gve lve gtvs) name
+ = case maybeWiredInIdName name of
+ Just id -> Just id
+ Nothing -> lookupUFM gve name
+
-- Extract the IdInfo from an IfaceSig imported from an interface file
-tcAddImportedIdInfo :: Id -> NF_TcM s Id
-tcAddImportedIdInfo id
- = tcLookupGlobalValueMaybe (getName id) `thenNF_Tc` \ maybe_id ->
- let
- new_info = case maybe_id of
+tcAddImportedIdInfo :: TcEnv s -> 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 `replaceIdInfo` new_info
+ -- The Id must be returned without a data dependency on maybe_id
+ where
+ new_info = -- pprTrace "tcAdd" (ppr PprDebug id) $
+ case tcExplicitLookupGlobal unf_env (getName id) of
Nothing -> noIdInfo
Just imported_id -> getIdInfo imported_id
-- ToDo: could check that types are the same
- in
- returnNF_Tc (id `replaceIdInfo` new_info)
- -- The Id must be returned without a data dependency on maybe_id
\end{code}