| 1 | % |
|---|
| 2 | % (c) The University of Glasgow 2006 |
|---|
| 3 | % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 |
|---|
| 4 | % |
|---|
| 5 | \section{@Vars@: Variables} |
|---|
| 6 | |
|---|
| 7 | \begin{code} |
|---|
| 8 | {-# OPTIONS -fno-warn-tabs #-} |
|---|
| 9 | -- The above warning supression flag is a temporary kludge. |
|---|
| 10 | -- While working on this module you are encouraged to remove it and |
|---|
| 11 | -- detab the module (please do the detabbing in a separate patch). See |
|---|
| 12 | -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces |
|---|
| 13 | -- for details |
|---|
| 14 | |
|---|
| 15 | -- | |
|---|
| 16 | -- #name_types# |
|---|
| 17 | -- GHC uses several kinds of name internally: |
|---|
| 18 | -- |
|---|
| 19 | -- * 'OccName.OccName': see "OccName#name_types" |
|---|
| 20 | -- |
|---|
| 21 | -- * 'RdrName.RdrName': see "RdrName#name_types" |
|---|
| 22 | -- |
|---|
| 23 | -- * 'Name.Name': see "Name#name_types" |
|---|
| 24 | -- |
|---|
| 25 | -- * 'Id.Id': see "Id#name_types" |
|---|
| 26 | -- |
|---|
| 27 | -- * 'Var.Var' is a synonym for the 'Id.Id' type but it may additionally |
|---|
| 28 | -- potentially contain type variables, which have a 'TypeRep.Kind' |
|---|
| 29 | -- rather than a 'TypeRep.Type' and only contain some extra |
|---|
| 30 | -- details during typechecking. |
|---|
| 31 | -- |
|---|
| 32 | -- These 'Var.Var' names may either be global or local, see "Var#globalvslocal" |
|---|
| 33 | -- |
|---|
| 34 | -- #globalvslocal# |
|---|
| 35 | -- Global 'Id's and 'Var's are those that are imported or correspond |
|---|
| 36 | -- to a data constructor, primitive operation, or record selectors. |
|---|
| 37 | -- Local 'Id's and 'Var's are those bound within an expression |
|---|
| 38 | -- (e.g. by a lambda) or at the top level of the module being compiled. |
|---|
| 39 | |
|---|
| 40 | module Var ( |
|---|
| 41 | -- * The main data type and synonyms |
|---|
| 42 | Var, CoVar, Id, DictId, DFunId, EvVar, EqVar, EvId, IpId, |
|---|
| 43 | TyVar, TypeVar, KindVar, TKVar, |
|---|
| 44 | |
|---|
| 45 | -- ** Taking 'Var's apart |
|---|
| 46 | varName, varUnique, varType, |
|---|
| 47 | |
|---|
| 48 | -- ** Modifying 'Var's |
|---|
| 49 | setVarName, setVarUnique, setVarType, |
|---|
| 50 | |
|---|
| 51 | -- ** Constructing, taking apart, modifying 'Id's |
|---|
| 52 | mkGlobalVar, mkLocalVar, mkExportedLocalVar, mkCoVar, |
|---|
| 53 | idInfo, idDetails, |
|---|
| 54 | lazySetIdInfo, setIdDetails, globaliseId, |
|---|
| 55 | setIdExported, setIdNotExported, |
|---|
| 56 | |
|---|
| 57 | -- ** Predicates |
|---|
| 58 | isId, isTKVar, isTyVar, isTcTyVar, |
|---|
| 59 | isLocalVar, isLocalId, |
|---|
| 60 | isGlobalId, isExportedId, |
|---|
| 61 | mustHaveLocalBinding, |
|---|
| 62 | |
|---|
| 63 | -- ** Constructing 'TyVar's |
|---|
| 64 | mkTyVar, mkTcTyVar, mkKindVar, |
|---|
| 65 | |
|---|
| 66 | -- ** Taking 'TyVar's apart |
|---|
| 67 | tyVarName, tyVarKind, tcTyVarDetails, setTcTyVarDetails, |
|---|
| 68 | |
|---|
| 69 | -- ** Modifying 'TyVar's |
|---|
| 70 | setTyVarName, setTyVarUnique, setTyVarKind, updateTyVarKind, |
|---|
| 71 | updateTyVarKindM |
|---|
| 72 | |
|---|
| 73 | ) where |
|---|
| 74 | |
|---|
| 75 | #include "HsVersions.h" |
|---|
| 76 | #include "Typeable.h" |
|---|
| 77 | |
|---|
| 78 | import {-# SOURCE #-} TypeRep( Type, Kind, SuperKind ) |
|---|
| 79 | import {-# SOURCE #-} TcType( TcTyVarDetails, pprTcTyVarDetails ) |
|---|
| 80 | import {-# SOURCE #-} IdInfo( IdDetails, IdInfo, coVarDetails, vanillaIdInfo, pprIdDetails ) |
|---|
| 81 | |
|---|
| 82 | import Name hiding (varName) |
|---|
| 83 | import Unique |
|---|
| 84 | import Util |
|---|
| 85 | import FastTypes |
|---|
| 86 | import FastString |
|---|
| 87 | import Outputable |
|---|
| 88 | |
|---|
| 89 | -- import StaticFlags ( opt_SuppressVarKinds ) |
|---|
| 90 | |
|---|
| 91 | import Data.Data |
|---|
| 92 | \end{code} |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | %************************************************************************ |
|---|
| 96 | %* * |
|---|
| 97 | Synonyms |
|---|
| 98 | %* * |
|---|
| 99 | %************************************************************************ |
|---|
| 100 | -- These synonyms are here and not in Id because otherwise we need a very |
|---|
| 101 | -- large number of SOURCE imports of Id.hs :-( |
|---|
| 102 | |
|---|
| 103 | \begin{code} |
|---|
| 104 | type Id = Var -- A term-level identifier |
|---|
| 105 | |
|---|
| 106 | type TyVar = Var -- Type *or* kind variable (historical) |
|---|
| 107 | |
|---|
| 108 | type TKVar = Var -- Type *or* kind variable (historical) |
|---|
| 109 | type TypeVar = Var -- Definitely a type variable |
|---|
| 110 | type KindVar = Var -- Definitely a kind variable |
|---|
| 111 | -- See Note [Kind and type variables] |
|---|
| 112 | |
|---|
| 113 | -- See Note [Evidence: EvIds and CoVars] |
|---|
| 114 | type EvId = Id -- Term-level evidence: DictId, IpId, or EqVar |
|---|
| 115 | type EvVar = EvId -- ...historical name for EvId |
|---|
| 116 | type DFunId = Id -- A dictionary function |
|---|
| 117 | type DictId = EvId -- A dictionary variable |
|---|
| 118 | type IpId = EvId -- A term-level implicit parameter |
|---|
| 119 | type EqVar = EvId -- Boxed equality evidence |
|---|
| 120 | |
|---|
| 121 | type CoVar = Id -- See Note [Evidence: EvIds and CoVars] |
|---|
| 122 | \end{code} |
|---|
| 123 | |
|---|
| 124 | Note [Evidence: EvIds and CoVars] |
|---|
| 125 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 126 | * An EvId (evidence Id) is a *boxed*, term-level evidence variable |
|---|
| 127 | (dictionary, implicit parameter, or equality). |
|---|
| 128 | |
|---|
| 129 | * A CoVar (coercion variable) is an *unboxed* term-level evidence variable |
|---|
| 130 | of type (t1 ~# t2). So it's the unboxed version of an EqVar. |
|---|
| 131 | |
|---|
| 132 | * Only CoVars can occur in Coercions, EqVars appear in TcCoercions. |
|---|
| 133 | |
|---|
| 134 | * DictId, IpId, and EqVar are synonyms when we know what kind of |
|---|
| 135 | evidence we are talking about. For example, an EqVar has type (t1 ~ t2). |
|---|
| 136 | |
|---|
| 137 | Note [Kind and type variables] |
|---|
| 138 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 139 | Before kind polymorphism, TyVar were used to mean type variables. Now |
|---|
| 140 | they are use to mean kind *or* type variables. KindVar is used when we |
|---|
| 141 | know for sure that it is a kind variable. In future, we might want to |
|---|
| 142 | go over the whole compiler code to use: |
|---|
| 143 | - TKVar to mean kind or type variables |
|---|
| 144 | - TypeVar to mean type variables only |
|---|
| 145 | - KindVar to mean kind variables |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | %************************************************************************ |
|---|
| 149 | %* * |
|---|
| 150 | \subsection{The main data type declarations} |
|---|
| 151 | %* * |
|---|
| 152 | %************************************************************************ |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | Every @Var@ has a @Unique@, to uniquify it and for fast comparison, a |
|---|
| 156 | @Type@, and an @IdInfo@ (non-essential info about it, e.g., |
|---|
| 157 | strictness). The essential info about different kinds of @Vars@ is |
|---|
| 158 | in its @VarDetails@. |
|---|
| 159 | |
|---|
| 160 | \begin{code} |
|---|
| 161 | -- | Essentially a typed 'Name', that may also contain some additional information |
|---|
| 162 | -- about the 'Var' and it's use sites. |
|---|
| 163 | data Var |
|---|
| 164 | = TyVar { -- Type and kind variables |
|---|
| 165 | -- see Note [Kind and type variables] |
|---|
| 166 | varName :: !Name, |
|---|
| 167 | realUnique :: FastInt, -- Key for fast comparison |
|---|
| 168 | -- Identical to the Unique in the name, |
|---|
| 169 | -- cached here for speed |
|---|
| 170 | varType :: Kind -- ^ The type or kind of the 'Var' in question |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | | TcTyVar { -- Used only during type inference |
|---|
| 174 | -- Used for kind variables during |
|---|
| 175 | -- inference, as well |
|---|
| 176 | varName :: !Name, |
|---|
| 177 | realUnique :: FastInt, |
|---|
| 178 | varType :: Kind, |
|---|
| 179 | tc_tv_details :: TcTyVarDetails } |
|---|
| 180 | |
|---|
| 181 | | Id { |
|---|
| 182 | varName :: !Name, |
|---|
| 183 | realUnique :: FastInt, |
|---|
| 184 | varType :: Type, |
|---|
| 185 | idScope :: IdScope, |
|---|
| 186 | id_details :: IdDetails, -- Stable, doesn't change |
|---|
| 187 | id_info :: IdInfo } -- Unstable, updated by simplifier |
|---|
| 188 | deriving Typeable |
|---|
| 189 | |
|---|
| 190 | data IdScope -- See Note [GlobalId/LocalId] |
|---|
| 191 | = GlobalId |
|---|
| 192 | | LocalId ExportFlag |
|---|
| 193 | |
|---|
| 194 | data ExportFlag |
|---|
| 195 | = NotExported -- ^ Not exported: may be discarded as dead code. |
|---|
| 196 | | Exported -- ^ Exported: kept alive |
|---|
| 197 | \end{code} |
|---|
| 198 | |
|---|
| 199 | Note [GlobalId/LocalId] |
|---|
| 200 | ~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 201 | A GlobalId is |
|---|
| 202 | * always a constant (top-level) |
|---|
| 203 | * imported, or data constructor, or primop, or record selector |
|---|
| 204 | * has a Unique that is globally unique across the whole |
|---|
| 205 | GHC invocation (a single invocation may compile multiple modules) |
|---|
| 206 | * never treated as a candidate by the free-variable finder; |
|---|
| 207 | it's a constant! |
|---|
| 208 | |
|---|
| 209 | A LocalId is |
|---|
| 210 | * bound within an expression (lambda, case, local let(rec)) |
|---|
| 211 | * or defined at top level in the module being compiled |
|---|
| 212 | * always treated as a candidate by the free-variable finder |
|---|
| 213 | |
|---|
| 214 | After CoreTidy, top-level LocalIds are turned into GlobalIds |
|---|
| 215 | |
|---|
| 216 | \begin{code} |
|---|
| 217 | instance Outputable Var where |
|---|
| 218 | ppr var = ppr (varName var) <+> ifPprDebug (brackets (ppr_debug var)) |
|---|
| 219 | -- Printing the type on every occurrence is too much! |
|---|
| 220 | -- <+> if (not opt_SuppressVarKinds) |
|---|
| 221 | -- then ifPprDebug (text "::" <+> ppr (tyVarKind var) <+> text ")") |
|---|
| 222 | -- else empty |
|---|
| 223 | |
|---|
| 224 | ppr_debug :: Var -> SDoc |
|---|
| 225 | ppr_debug (TyVar {}) = ptext (sLit "tv") |
|---|
| 226 | ppr_debug (TcTyVar {tc_tv_details = d}) = pprTcTyVarDetails d |
|---|
| 227 | ppr_debug (Id { idScope = s, id_details = d }) = ppr_id_scope s <> pprIdDetails d |
|---|
| 228 | |
|---|
| 229 | ppr_id_scope :: IdScope -> SDoc |
|---|
| 230 | ppr_id_scope GlobalId = ptext (sLit "gid") |
|---|
| 231 | ppr_id_scope (LocalId Exported) = ptext (sLit "lidx") |
|---|
| 232 | ppr_id_scope (LocalId NotExported) = ptext (sLit "lid") |
|---|
| 233 | |
|---|
| 234 | instance Show Var where |
|---|
| 235 | showsPrec p var = showsPrecSDoc p (ppr var) |
|---|
| 236 | |
|---|
| 237 | instance NamedThing Var where |
|---|
| 238 | getName = varName |
|---|
| 239 | |
|---|
| 240 | instance Uniquable Var where |
|---|
| 241 | getUnique = varUnique |
|---|
| 242 | |
|---|
| 243 | instance Eq Var where |
|---|
| 244 | a == b = realUnique a ==# realUnique b |
|---|
| 245 | |
|---|
| 246 | instance Ord Var where |
|---|
| 247 | a <= b = realUnique a <=# realUnique b |
|---|
| 248 | a < b = realUnique a <# realUnique b |
|---|
| 249 | a >= b = realUnique a >=# realUnique b |
|---|
| 250 | a > b = realUnique a ># realUnique b |
|---|
| 251 | a `compare` b = varUnique a `compare` varUnique b |
|---|
| 252 | |
|---|
| 253 | instance Data Var where |
|---|
| 254 | -- don't traverse? |
|---|
| 255 | toConstr _ = abstractConstr "Var" |
|---|
| 256 | gunfold _ _ = error "gunfold" |
|---|
| 257 | dataTypeOf _ = mkNoRepType "Var" |
|---|
| 258 | \end{code} |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | \begin{code} |
|---|
| 262 | varUnique :: Var -> Unique |
|---|
| 263 | varUnique var = mkUniqueGrimily (iBox (realUnique var)) |
|---|
| 264 | |
|---|
| 265 | setVarUnique :: Var -> Unique -> Var |
|---|
| 266 | setVarUnique var uniq |
|---|
| 267 | = var { realUnique = getKeyFastInt uniq, |
|---|
| 268 | varName = setNameUnique (varName var) uniq } |
|---|
| 269 | |
|---|
| 270 | setVarName :: Var -> Name -> Var |
|---|
| 271 | setVarName var new_name |
|---|
| 272 | = var { realUnique = getKeyFastInt (getUnique new_name), |
|---|
| 273 | varName = new_name } |
|---|
| 274 | |
|---|
| 275 | setVarType :: Id -> Type -> Id |
|---|
| 276 | setVarType id ty = id { varType = ty } |
|---|
| 277 | \end{code} |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | %************************************************************************ |
|---|
| 281 | %* * |
|---|
| 282 | \subsection{Type and kind variables} |
|---|
| 283 | %* * |
|---|
| 284 | %************************************************************************ |
|---|
| 285 | |
|---|
| 286 | \begin{code} |
|---|
| 287 | tyVarName :: TyVar -> Name |
|---|
| 288 | tyVarName = varName |
|---|
| 289 | |
|---|
| 290 | tyVarKind :: TyVar -> Kind |
|---|
| 291 | tyVarKind = varType |
|---|
| 292 | |
|---|
| 293 | setTyVarUnique :: TyVar -> Unique -> TyVar |
|---|
| 294 | setTyVarUnique = setVarUnique |
|---|
| 295 | |
|---|
| 296 | setTyVarName :: TyVar -> Name -> TyVar |
|---|
| 297 | setTyVarName = setVarName |
|---|
| 298 | |
|---|
| 299 | setTyVarKind :: TyVar -> Kind -> TyVar |
|---|
| 300 | setTyVarKind tv k = tv {varType = k} |
|---|
| 301 | |
|---|
| 302 | updateTyVarKind :: (Kind -> Kind) -> TyVar -> TyVar |
|---|
| 303 | updateTyVarKind update tv = tv {varType = update (tyVarKind tv)} |
|---|
| 304 | |
|---|
| 305 | updateTyVarKindM :: (Monad m) => (Kind -> m Kind) -> TyVar -> m TyVar |
|---|
| 306 | updateTyVarKindM update tv |
|---|
| 307 | = do { k' <- update (tyVarKind tv) |
|---|
| 308 | ; return $ tv {varType = k'} } |
|---|
| 309 | \end{code} |
|---|
| 310 | |
|---|
| 311 | \begin{code} |
|---|
| 312 | mkTyVar :: Name -> Kind -> TyVar |
|---|
| 313 | mkTyVar name kind = TyVar { varName = name |
|---|
| 314 | , realUnique = getKeyFastInt (nameUnique name) |
|---|
| 315 | , varType = kind |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> TyVar |
|---|
| 319 | mkTcTyVar name kind details |
|---|
| 320 | = -- NB: 'kind' may be a coercion kind; cf, 'TcMType.newMetaCoVar' |
|---|
| 321 | TcTyVar { varName = name, |
|---|
| 322 | realUnique = getKeyFastInt (nameUnique name), |
|---|
| 323 | varType = kind, |
|---|
| 324 | tc_tv_details = details |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | tcTyVarDetails :: TyVar -> TcTyVarDetails |
|---|
| 328 | tcTyVarDetails (TcTyVar { tc_tv_details = details }) = details |
|---|
| 329 | tcTyVarDetails var = pprPanic "tcTyVarDetails" (ppr var) |
|---|
| 330 | |
|---|
| 331 | setTcTyVarDetails :: TyVar -> TcTyVarDetails -> TyVar |
|---|
| 332 | setTcTyVarDetails tv details = tv { tc_tv_details = details } |
|---|
| 333 | |
|---|
| 334 | mkKindVar :: Name -> SuperKind -> KindVar |
|---|
| 335 | -- mkKindVar take a SuperKind as argument because we don't have access |
|---|
| 336 | -- to superKind here. |
|---|
| 337 | mkKindVar name kind = TyVar |
|---|
| 338 | { varName = name |
|---|
| 339 | , realUnique = getKeyFastInt (nameUnique name) |
|---|
| 340 | , varType = kind } |
|---|
| 341 | |
|---|
| 342 | \end{code} |
|---|
| 343 | |
|---|
| 344 | %************************************************************************ |
|---|
| 345 | %* * |
|---|
| 346 | \subsection{Ids} |
|---|
| 347 | %* * |
|---|
| 348 | %************************************************************************ |
|---|
| 349 | |
|---|
| 350 | \begin{code} |
|---|
| 351 | idInfo :: Id -> IdInfo |
|---|
| 352 | idInfo (Id { id_info = info }) = info |
|---|
| 353 | idInfo other = pprPanic "idInfo" (ppr other) |
|---|
| 354 | |
|---|
| 355 | idDetails :: Id -> IdDetails |
|---|
| 356 | idDetails (Id { id_details = details }) = details |
|---|
| 357 | idDetails other = pprPanic "idDetails" (ppr other) |
|---|
| 358 | |
|---|
| 359 | -- The next three have a 'Var' suffix even though they always build |
|---|
| 360 | -- Ids, becuase Id.lhs uses 'mkGlobalId' etc with different types |
|---|
| 361 | mkGlobalVar :: IdDetails -> Name -> Type -> IdInfo -> Id |
|---|
| 362 | mkGlobalVar details name ty info |
|---|
| 363 | = mk_id name ty GlobalId details info |
|---|
| 364 | |
|---|
| 365 | mkLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id |
|---|
| 366 | mkLocalVar details name ty info |
|---|
| 367 | = mk_id name ty (LocalId NotExported) details info |
|---|
| 368 | |
|---|
| 369 | mkCoVar :: Name -> Type -> CoVar |
|---|
| 370 | -- Coercion variables have no IdInfo |
|---|
| 371 | mkCoVar name ty = mk_id name ty (LocalId NotExported) coVarDetails vanillaIdInfo |
|---|
| 372 | |
|---|
| 373 | -- | Exported 'Var's will not be removed as dead code |
|---|
| 374 | mkExportedLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id |
|---|
| 375 | mkExportedLocalVar details name ty info |
|---|
| 376 | = mk_id name ty (LocalId Exported) details info |
|---|
| 377 | |
|---|
| 378 | mk_id :: Name -> Type -> IdScope -> IdDetails -> IdInfo -> Id |
|---|
| 379 | mk_id name ty scope details info |
|---|
| 380 | = Id { varName = name, |
|---|
| 381 | realUnique = getKeyFastInt (nameUnique name), |
|---|
| 382 | varType = ty, |
|---|
| 383 | idScope = scope, |
|---|
| 384 | id_details = details, |
|---|
| 385 | id_info = info } |
|---|
| 386 | |
|---|
| 387 | ------------------- |
|---|
| 388 | lazySetIdInfo :: Id -> IdInfo -> Var |
|---|
| 389 | lazySetIdInfo id info = id { id_info = info } |
|---|
| 390 | |
|---|
| 391 | setIdDetails :: Id -> IdDetails -> Id |
|---|
| 392 | setIdDetails id details = id { id_details = details } |
|---|
| 393 | |
|---|
| 394 | globaliseId :: Id -> Id |
|---|
| 395 | -- ^ If it's a local, make it global |
|---|
| 396 | globaliseId id = id { idScope = GlobalId } |
|---|
| 397 | |
|---|
| 398 | setIdExported :: Id -> Id |
|---|
| 399 | -- ^ Exports the given local 'Id'. Can also be called on global 'Id's, such as data constructors |
|---|
| 400 | -- and class operations, which are born as global 'Id's and automatically exported |
|---|
| 401 | setIdExported id@(Id { idScope = LocalId {} }) = id { idScope = LocalId Exported } |
|---|
| 402 | setIdExported id@(Id { idScope = GlobalId }) = id |
|---|
| 403 | setIdExported tv = pprPanic "setIdExported" (ppr tv) |
|---|
| 404 | |
|---|
| 405 | setIdNotExported :: Id -> Id |
|---|
| 406 | -- ^ We can only do this to LocalIds |
|---|
| 407 | setIdNotExported id = ASSERT( isLocalId id ) |
|---|
| 408 | id { idScope = LocalId NotExported } |
|---|
| 409 | \end{code} |
|---|
| 410 | |
|---|
| 411 | %************************************************************************ |
|---|
| 412 | %* * |
|---|
| 413 | \subsection{Predicates over variables} |
|---|
| 414 | %* * |
|---|
| 415 | %************************************************************************ |
|---|
| 416 | |
|---|
| 417 | \begin{code} |
|---|
| 418 | isTyVar :: Var -> Bool |
|---|
| 419 | isTyVar = isTKVar -- Historical |
|---|
| 420 | |
|---|
| 421 | isTKVar :: Var -> Bool -- True of both type and kind variables |
|---|
| 422 | isTKVar (TyVar {}) = True |
|---|
| 423 | isTKVar (TcTyVar {}) = True |
|---|
| 424 | isTKVar _ = False |
|---|
| 425 | |
|---|
| 426 | isTcTyVar :: Var -> Bool |
|---|
| 427 | isTcTyVar (TcTyVar {}) = True |
|---|
| 428 | isTcTyVar _ = False |
|---|
| 429 | |
|---|
| 430 | isId :: Var -> Bool |
|---|
| 431 | isId (Id {}) = True |
|---|
| 432 | isId _ = False |
|---|
| 433 | |
|---|
| 434 | isLocalId :: Var -> Bool |
|---|
| 435 | isLocalId (Id { idScope = LocalId _ }) = True |
|---|
| 436 | isLocalId _ = False |
|---|
| 437 | |
|---|
| 438 | -- | 'isLocalVar' returns @True@ for type variables as well as local 'Id's |
|---|
| 439 | -- These are the variables that we need to pay attention to when finding free |
|---|
| 440 | -- variables, or doing dependency analysis. |
|---|
| 441 | isLocalVar :: Var -> Bool |
|---|
| 442 | isLocalVar v = not (isGlobalId v) |
|---|
| 443 | |
|---|
| 444 | isGlobalId :: Var -> Bool |
|---|
| 445 | isGlobalId (Id { idScope = GlobalId }) = True |
|---|
| 446 | isGlobalId _ = False |
|---|
| 447 | |
|---|
| 448 | -- | 'mustHaveLocalBinding' returns @True@ of 'Id's and 'TyVar's |
|---|
| 449 | -- that must have a binding in this module. The converse |
|---|
| 450 | -- is not quite right: there are some global 'Id's that must have |
|---|
| 451 | -- bindings, such as record selectors. But that doesn't matter, |
|---|
| 452 | -- because it's only used for assertions |
|---|
| 453 | mustHaveLocalBinding :: Var -> Bool |
|---|
| 454 | mustHaveLocalBinding var = isLocalVar var |
|---|
| 455 | |
|---|
| 456 | -- | 'isExportedIdVar' means \"don't throw this away\" |
|---|
| 457 | isExportedId :: Var -> Bool |
|---|
| 458 | isExportedId (Id { idScope = GlobalId }) = True |
|---|
| 459 | isExportedId (Id { idScope = LocalId Exported}) = True |
|---|
| 460 | isExportedId _ = False |
|---|
| 461 | \end{code} |
|---|