--
-- * 'Id.Id': see "Id#name_types"
--
--- * 'Var.Var' is a synonym for the 'Id.Id' type but it may additionally potentially contain type variables,
--- which have a 'TypeRep.Kind' rather than a 'TypeRep.Type' and only contain some extra details during typechecking.
+-- * 'Var.Var' is a synonym for the 'Id.Id' type but it may additionally
+-- potentially contain type variables, which have a 'TypeRep.Kind'
+-- rather than a 'TypeRep.Type' and only contain some extra
+-- details during typechecking.
+--
-- These 'Var.Var' names may either be global or local, see "Var#globalvslocal"
--
-- #globalvslocal#
--- Global 'Id's and 'Var's are those that are imported or correspond to a data constructor, primitive operation, or record selectors.
--- Local 'Id's and 'Var's are those bound within an expression (e.g. by a lambda) or at the top level of the module being compiled.
+-- Global 'Id's and 'Var's are those that are imported or correspond
+-- to a data constructor, primitive operation, or record selectors.
+-- Local 'Id's and 'Var's are those bound within an expression
+-- (e.g. by a lambda) or at the top level of the module being compiled.
+
module Var (
- -- * The main data type
- Var,
+ -- * The main data type and synonyms
+ Var, TyVar, CoVar, Id, DictId, DFunId, EvVar, EvId, IpId,
-- ** Taking 'Var's apart
varName, varUnique, varType,
setIdExported, setIdNotExported,
-- ** Predicates
- isCoVar, isId, isTyVar, isTcTyVar,
+ isCoVar, isId, isTyCoVar, isTyVar, isTcTyVar,
isLocalVar, isLocalId,
isGlobalId, isExportedId,
mustHaveLocalBinding,
- -- * Type variable data type
- TyVar,
-
-- ** Constructing 'TyVar's
mkTyVar, mkTcTyVar, mkWildCoVar,
-- ** Taking 'TyVar's apart
- tyVarName, tyVarKind, tcTyVarDetails,
+ tyVarName, tyVarKind, tcTyVarDetails, setTcTyVarDetails,
-- ** Modifying 'TyVar's
setTyVarName, setTyVarUnique, setTyVarKind,
- -- * Coercion variable data type
- CoVar,
-
-- ** Constructing 'CoVar's
mkCoVar,
coVarName,
-- ** Modifying 'CoVar's
- setCoVarUnique, setCoVarName,
+ setCoVarUnique, setCoVarName
- -- * 'Var' type synonyms
- Id, DictId
) where
#include "HsVersions.h"
%************************************************************************
%* *
+ Synonyms
+%* *
+%************************************************************************
+-- These synonyms are here and not in Id because otherwise we need a very
+-- large number of SOURCE imports of Id.hs :-(
+
+\begin{code}
+type EvVar = Var -- An evidence variable: dictionary or equality constraint
+ -- Could be an DictId or a CoVar
+
+type Id = Var -- A term-level identifier
+type DFunId = Id -- A dictionary function
+type EvId = Id -- Term-level evidence: DictId or IpId
+type DictId = EvId -- A dictionary variable
+type IpId = EvId -- A term-level implicit parameter
+
+type TyVar = Var
+type CoVar = TyVar -- A coercion variable is simply a type
+ -- variable of kind @ty1 ~ ty2@. Hence its
+ -- 'varType' is always @PredTy (EqPred t1 t2)@
+\end{code}
+
+%************************************************************************
+%* *
\subsection{The main data type declarations}
%* *
%************************************************************************
varName :: !Name,
realUnique :: FastInt,
varType :: Kind,
- tcTyVarDetails :: TcTyVarDetails }
+ tc_tv_details :: TcTyVarDetails }
| Id {
varName :: !Name,
ppr var = ppr (varName var) <+> ifPprDebug (brackets (ppr_debug var))
ppr_debug :: Var -> SDoc
-ppr_debug (TyVar {}) = ptext (sLit "tv")
-ppr_debug (TcTyVar {tcTyVarDetails = d}) = pprTcTyVarDetails d
+ppr_debug (TyVar { isCoercionVar = False }) = ptext (sLit "tv")
+ppr_debug (TyVar { isCoercionVar = True }) = ptext (sLit "co")
+ppr_debug (TcTyVar {tc_tv_details = d}) = pprTcTyVarDetails d
ppr_debug (Id { idScope = s, id_details = d }) = ppr_id_scope s <> pprIdDetails d
ppr_id_scope :: IdScope -> SDoc
%************************************************************************
\begin{code}
-type TyVar = Var
-
tyVarName :: TyVar -> Name
tyVarName = varName
TcTyVar { varName = name,
realUnique = getKeyFastInt (nameUnique name),
varType = kind,
- tcTyVarDetails = details
+ tc_tv_details = details
}
+
+tcTyVarDetails :: TyVar -> TcTyVarDetails
+tcTyVarDetails (TcTyVar { tc_tv_details = details }) = details
+tcTyVarDetails var = pprPanic "tcTyVarDetails" (ppr var)
+
+setTcTyVarDetails :: TyVar -> TcTyVarDetails -> TyVar
+setTcTyVarDetails tv details = tv { tc_tv_details = details }
\end{code}
%************************************************************************
%************************************************************************
\begin{code}
-type CoVar = TyVar -- A coercion variable is simply a type
- -- variable of kind @ty1 ~ ty2@. Hence its
- -- 'varType' is always @PredTy (EqPred t1 t2)@
-
coVarName :: CoVar -> Name
coVarName = varName
%************************************************************************
\begin{code}
--- These synonyms are here and not in Id because otherwise we need a very
--- large number of SOURCE imports of Id.hs :-(
-type Id = Var
-type DictId = Var
-
idInfo :: Id -> IdInfo
idInfo (Id { id_info = info }) = info
idInfo other = pprPanic "idInfo" (ppr other)
%************************************************************************
\begin{code}
-isTyVar :: Var -> Bool -- True of both type and coercion variables
-isTyVar (TyVar {}) = True
+isTyCoVar :: Var -> Bool -- True of both type and coercion variables
+isTyCoVar (TyVar {}) = True
+isTyCoVar (TcTyVar {}) = True
+isTyCoVar _ = False
+
+isTyVar :: Var -> Bool -- True of both type variables only
+isTyVar v@(TyVar {}) = not (isCoercionVar v)
isTyVar (TcTyVar {}) = True
isTyVar _ = False
+isCoVar :: Var -> Bool -- Only works after type checking (sigh)
+isCoVar v@(TyVar {}) = isCoercionVar v
+isCoVar _ = False
+
isTcTyVar :: Var -> Bool
isTcTyVar (TcTyVar {}) = True
isTcTyVar _ = False
isLocalId (Id { idScope = LocalId _ }) = True
isLocalId _ = False
-isCoVar :: Var -> Bool
-isCoVar (v@(TyVar {})) = isCoercionVar v
-isCoVar (TcTyVar {varType = kind}) = isCoercionKind kind -- used during solving
-isCoVar _ = False
-
-- | 'isLocalVar' returns @True@ for type variables as well as local 'Id's
-- These are the variables that we need to pay attention to when finding free
-- variables, or doing dependency analysis.