X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FbasicTypes%2FVar.lhs;h=dae237db0eea8ac2453d976d1785490eb3889793;hb=ac704fcac946590eef0ec91ae19f3b47d779a75f;hp=e4aa8c23d65ae5c46a08433c3c9340ee246108c9;hpb=6fcf90065dc4e75b7dc6bbf238a9891a71ae5a86;p=ghc-hetmet.git diff --git a/compiler/basicTypes/Var.lhs b/compiler/basicTypes/Var.lhs index e4aa8c2..dae237d 100644 --- a/compiler/basicTypes/Var.lhs +++ b/compiler/basicTypes/Var.lhs @@ -1,4 +1,5 @@ % +% (c) The University of Glasgow 2006 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % \section{@Vars@: Variables} @@ -10,7 +11,7 @@ module Var ( setVarName, setVarUnique, -- TyVars - TyVar, mkTyVar, mkTcTyVar, mkWildTyVar, + TyVar, mkTyVar, mkTcTyVar, mkWildCoVar, tyVarName, tyVarKind, setTyVarName, setTyVarUnique, setTyVarKind, tcTyVarDetails, @@ -22,7 +23,7 @@ module Var ( Id, DictId, idName, idType, idUnique, idInfo, modifyIdInfo, maybeModifyIdInfo, setIdName, setIdUnique, setIdType, setIdInfo, lazySetIdInfo, - setIdExported, setIdNotExported, + setIdExported, setIdNotExported, globalIdDetails, globaliseId, @@ -35,17 +36,19 @@ module Var ( #include "HsVersions.h" -import {-# SOURCE #-} TypeRep( Type, Kind, isCoSuperKind ) +import {-# SOURCE #-} TypeRep( Type, Kind ) import {-# SOURCE #-} TcType( TcTyVarDetails, pprTcTyVarDetails ) -import {-# SOURCE #-} IdInfo( GlobalIdDetails, notGlobalId, IdInfo, seqIdInfo ) - -import Name ( Name, NamedThing(..), - setNameUnique, nameUnique, mkSysTvName - ) -import Unique ( Unique, Uniquable(..), mkUniqueGrimily, getKey#, - mkBuiltinUnique ) +import {-# SOURCE #-} IdInfo( GlobalIdDetails, notGlobalId, + IdInfo, seqIdInfo ) +#ifdef DEBUG +import {-# SOURCE #-} TypeRep( isCoercionKind ) +#endif + +import Name hiding (varName) +import Unique import FastTypes -import Outputable +import FastString +import Outputable \end{code} @@ -68,7 +71,9 @@ data Var realUnique :: FastInt, -- Key for fast comparison -- Identical to the Unique in the name, -- cached here for speed - tyVarKind :: Kind } + tyVarKind :: Kind, + isCoercionVar :: Bool + } | TcTyVar { -- Used only during type inference -- Used for kind variables during @@ -186,26 +191,21 @@ setTyVarKind tv k = tv {tyVarKind = k} \begin{code} mkTyVar :: Name -> Kind -> TyVar -mkTyVar name kind = TyVar { varName = name +mkTyVar name kind = ASSERT( not (isCoercionKind kind ) ) + TyVar { varName = name , realUnique = getKey# (nameUnique name) , tyVarKind = kind + , isCoercionVar = False } mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> TyVar mkTcTyVar name kind details - = TcTyVar { varName = name, + = ASSERT( not (isCoercionKind kind) ) + TcTyVar { varName = name, realUnique = getKey# (nameUnique name), tyVarKind = kind, tcTyVarDetails = details } - -mkWildTyVar :: Kind -> TyVar -mkWildTyVar kind - = TyVar { varName = mkSysTvName wild_uniq FSLIT("co_wild"), - realUnique = _ILIT(1), - tyVarKind = kind } - where - wild_uniq = (mkBuiltinUnique 1) \end{code} %************************************************************************ @@ -223,10 +223,24 @@ setCoVarUnique = setVarUnique setCoVarName = setVarName mkCoVar :: Name -> Kind -> CoVar -mkCoVar name kind = mkTyVar name kind +mkCoVar name kind = ASSERT( isCoercionKind kind ) + TyVar { varName = name + , realUnique = getKey# (nameUnique name) + , tyVarKind = kind + , isCoercionVar = True + } -isCoVar :: TyVar -> Bool -isCoVar ty = isCoSuperKind (tyVarKind ty) +mkWildCoVar :: Kind -> TyVar +-- A type variable that is never referred to, +-- so its unique doesn't matter +mkWildCoVar kind + = ASSERT( isCoercionKind kind ) + TyVar { varName = mkSysTvName wild_uniq FSLIT("co_wild"), + realUnique = _ILIT(1), + tyVarKind = kind, + isCoercionVar = True } + where + wild_uniq = mkBuiltinUnique 1 \end{code} %************************************************************************ @@ -342,6 +356,9 @@ isId other = False isLocalId (LocalId {}) = True isLocalId other = False +isCoVar (v@(TyVar {})) = isCoercionVar v +isCoVar other = False + -- isLocalVar returns True for type variables as well as local Ids -- These are the variables that we need to pay attention to when finding free -- variables, or doing dependency analysis.