X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FbasicTypes%2FVar.lhs;h=66876c6415deb6c03dd4c782953e7b6eb34d0625;hb=fc6b00498e653d6260e062bdfccbeede0a20fadd;hp=47d84a394886044d00ccc6de934f3fde0c6982ce;hpb=991a868b891c98cd58baf59cab423355a6b7025e;p=ghc-hetmet.git diff --git a/ghc/compiler/basicTypes/Var.lhs b/ghc/compiler/basicTypes/Var.lhs index 47d84a3..66876c6 100644 --- a/ghc/compiler/basicTypes/Var.lhs +++ b/ghc/compiler/basicTypes/Var.lhs @@ -14,8 +14,7 @@ module Var ( tyVarName, tyVarKind, setTyVarName, setTyVarUnique, mkTyVar, mkSysTyVar, - newMutTyVar, newSigTyVar, - readMutTyVar, writeMutTyVar, makeTyVarImmutable, + mkMutTyVar, mutTyVarRef, makeTyVarImmutable, -- Ids Id, DictId, @@ -27,7 +26,7 @@ module Var ( mkLocalId, mkGlobalId, mkSpecPragmaId, - isTyVar, isMutTyVar, isSigTyVar, + isTyVar, isMutTyVar, mutTyVarDetails, isId, isLocalVar, isLocalId, isGlobalId, isExportedId, isSpecPragmaId, mustHaveLocalBinding @@ -36,18 +35,19 @@ module Var ( #include "HsVersions.h" import {-# SOURCE #-} TypeRep( Type, Kind ) +import {-# SOURCE #-} TcType( TyVarDetails ) import {-# SOURCE #-} IdInfo( GlobalIdDetails, notGlobalId, IdInfo, seqIdInfo ) import Name ( Name, OccName, NamedThing(..), setNameUnique, setNameOcc, nameUnique, - mkSysLocalName + mkSystemTvNameEncoded, ) import Unique ( Unique, Uniquable(..), mkUniqueGrimily, getKey ) import FastTypes import Outputable -import IOExts ( IORef, newIORef, readIORef, writeIORef ) +import DATA_IOREF ( IORef ) \end{code} @@ -66,7 +66,7 @@ in its @VarDetails@. \begin{code} data Var = Var { - varName :: Name, + varName :: !Name, realUnique :: FastInt, -- Key for fast comparison -- Identical to the Unique in the name, -- cached here for speed @@ -84,13 +84,15 @@ data VarDetails | TyVar | MutTyVar (IORef (Maybe Type)) -- Used during unification; - Bool -- True <=> this is a type signature variable, which - -- should not be unified with a non-tyvar type + TyVarDetails + -- TODO: the IORef should be unboxed here, but we don't want to unbox + -- the Name above. - -- For a long time I tried to keep mutable Vars statically type-distinct - -- from immutable Vars, but I've finally given up. It's just too painful. - -- After type checking there are no MutTyVars left, but there's no static check - -- of that fact. + -- For a long time I tried to keep mutable Vars statically + -- type-distinct from immutable Vars, but I've finally given + -- up. It's just too painful. After type checking there are + -- no MutTyVars left, but there's no static check of that + -- fact. data LocalIdDetails = NotExported -- Not exported @@ -196,35 +198,25 @@ mkSysTyVar uniq kind = Var { varName = name , varInfo = pprPanic "mkSysTyVar" (ppr name) } where - name = mkSysLocalName uniq SLIT("t") + name = mkSystemTvNameEncoded uniq FSLIT("t") -newMutTyVar :: Name -> Kind -> IO TyVar -newMutTyVar name kind = newTyVar name kind False +mkMutTyVar :: Name -> Kind -> TyVarDetails -> IORef (Maybe Type) -> TyVar +mkMutTyVar name kind details ref + = Var { varName = name + , realUnique = getKey (nameUnique name) + , varType = kind + , varDetails = MutTyVar ref details + , varInfo = pprPanic "newMutTyVar" (ppr name) + } -newSigTyVar :: Name -> Kind -> IO TyVar --- Type variables from type signatures are still mutable, because --- they may get unified with type variables from other signatures --- But they do contain a flag to distinguish them, so we can tell if --- we unify them with a non-type-variable. -newSigTyVar name kind = newTyVar name kind True - -newTyVar name kind is_sig - = do loc <- newIORef Nothing - return (Var { varName = name - , realUnique = getKey (nameUnique name) - , varType = kind - , varDetails = MutTyVar loc is_sig - , varInfo = pprPanic "newMutTyVar" (ppr name) - }) - -readMutTyVar :: TyVar -> IO (Maybe Type) -readMutTyVar (Var {varDetails = MutTyVar loc _}) = readIORef loc - -writeMutTyVar :: TyVar -> Maybe Type -> IO () -writeMutTyVar (Var {varDetails = MutTyVar loc _}) val = writeIORef loc val +mutTyVarRef :: TyVar -> IORef (Maybe Type) +mutTyVarRef (Var {varDetails = MutTyVar loc _}) = loc makeTyVarImmutable :: TyVar -> TyVar makeTyVarImmutable tyvar = tyvar { varDetails = TyVar} + +mutTyVarDetails :: TyVar -> TyVarDetails +mutTyVarDetails (Var {varDetails = MutTyVar _ details}) = details \end{code} @@ -308,7 +300,7 @@ mkGlobalId details name ty info = mkId name ty (GlobalId details) info \end{code} \begin{code} -isTyVar, isMutTyVar, isSigTyVar :: Var -> Bool +isTyVar, isMutTyVar :: Var -> Bool isId, isLocalVar, isLocalId :: Var -> Bool isGlobalId, isExportedId, isSpecPragmaId :: Var -> Bool mustHaveLocalBinding :: Var -> Bool @@ -321,8 +313,6 @@ isTyVar var = case varDetails var of isMutTyVar (Var {varDetails = MutTyVar _ _}) = True isMutTyVar other = False -isSigTyVar (Var {varDetails = MutTyVar _ is_sig}) = is_sig -isSigTyVar other = False isId var = case varDetails var of LocalId _ -> True