valueEnvIds,
newLocalId, newSpecPragmaId,
+ newDefaultMethodName, newDFunName,
tcGetGlobalTyVars, tcExtendGlobalTyVars,
InstEnv, emptyInstEnv, addToInstEnv,
import Type ( Kind, Type, superKind,
tyVarsOfType, tyVarsOfTypes,
splitForAllTys, splitRhoTy, splitFunTys,
- splitAlgTyConApp_maybe, getTyVar
+ splitAlgTyConApp_maybe, getTyVar, getDFunTyKey
)
import Subst ( substTy )
import UsageSPUtils ( unannotTy )
import TcMonad
-import BasicTypes ( Arity )
import IdInfo ( vanillaIdInfo )
-import Name ( Name, OccName, nameOccName, getSrcLoc,
+import Name ( Name, OccName, Provenance(..), ExportFlag(..), NamedThing(..),
+ nameOccName, nameModule, getSrcLoc, mkGlobalName,
maybeWiredInTyConName, maybeWiredInIdName, isLocallyDefined,
- NamedThing(..),
NameEnv, emptyNameEnv, lookupNameEnv, nameEnvElts,
extendNameEnv, extendNameEnvList
)
+import OccName ( mkDFunOcc, mkDefaultMethodOcc, occNameString )
+import Module ( Module )
import Unify ( unifyTyListsX, matchTys )
import Unique ( pprUnique10, Unique, Uniquable(..) )
import UniqFM
~~~~~~~~~~~~~~~~~~~~~
\begin{code}
-data TcEnv = TcEnv
- UsageEnv
- TypeEnv
- ValueEnv
- InstEnv
- (TcTyVarSet, -- The in-scope TyVars
- TcRef TcTyVarSet) -- Free type variables of the value env
- -- ...why mutable? see notes with tcGetGlobalTyVars
- -- Includes the in-scope tyvars
+data TcEnv
+ = TcEnv {
+ tcGST :: GlobalSymbolTable, -- The symbol table at the moment we began this compilation
+
+ tcGEnv :: NameEnv TyThing -- The global type environment we've accumulated while
+ -- compiling this module:
+ -- types and classes (both imported and local)
+ -- imported Ids
+ -- (Ids defined in this module are in the local envt)
+ -- When type checking is over we'll augment the
+ -- global symbol table with everything in tcGEnv
+
+ tcInst :: InstEnv, -- All instances (both imported and in this module)
+
+ tcLEnv :: NameEnv TcTyThing, -- The local type environment: Ids and TyVars
+ -- defined in this module
+
+ tcTyVars :: FreeTyVars -- Type variables free in tcLST
+ }
-type UsageEnv = NameEnv UVar
-type TypeEnv = NameEnv TyThing
-type ValueEnv = NameEnv Id
+
+type InScopeTyVars = (TcTyVarSet, -- The in-scope TyVars
+ TcRef TcTyVarSet) -- Free type variables of the value env
+ -- ...why mutable? see notes with tcGetGlobalTyVars
valueEnvIds :: ValueEnv -> [Id]
valueEnvIds ve = nameEnvElts ve
-data TyThing = ATyVar TyVar
- | ATyCon TyCon
- | AClass Class
- | AThing TcKind -- Used temporarily, during kind checking
+data TcTyThing = ATyVar TyVar
+ | ATcId TcId
+ | AThing TcKind -- Used temporarily, during kind checking
-- For example, when 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.
Nothing -> tcGetEnv `thenNF_Tc` \ (TcEnv ue te ve ie gtvs) ->
returnNF_Tc (lookupWithDefaultUFM ve def name)
where
- def = pprPanic "tcLookupValue:" (ppr name)
+ 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
identical = ins_item_more_specific && cur_item_more_specific
\end{code}
+Make a name for the dict fun for an instance decl
+
+\begin{code}
+newDFunName :: Module -> Class -> [Type] -> SrcLoc -> NF_TcM s Name
+newDFunName mod clas (ty:_) loc
+ = tcGetDFunUniq dfun_string `thenNF_Tc` \ inst_uniq ->
+ tcGetUnique `thenNF_Tc` \ uniq ->
+ returnNF_Tc (mkGlobalName uniq mod
+ (mkDFunOcc dfun_string inst_uniq)
+ (LocalDef loc Exported))
+ where
+ -- Any string that is somewhat unique will do
+ dfun_string = occNameString (getOccName clas) ++ occNameString (getDFunTyKey ty)
+
+newDefaultMethodName :: Name -> SrcLoc -> NF_TcM s Name
+newDefaultMethodName op_name loc
+ = tcGetUnique `thenNF_Tc` \ uniq ->
+ returnNF_Tc (mkGlobalName uniq (nameModule op_name)
+ (mkDefaultMethodOcc (getOccName op_name))
+ (LocalDef loc Exported))
+\end{code}
%************************************************************************