afefa6eb7dd0ae73407b15e3d30b5128f1c156d2
[ghc.git] / compiler / basicTypes / Var.hs
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
8 {-# LANGUAGE CPP, FlexibleContexts, MultiWayIf, FlexibleInstances, DeriveDataTypeable #-}
9
10 -- |
11 -- #name_types#
12 -- GHC uses several kinds of name internally:
13 --
14 -- * 'OccName.OccName': see "OccName#name_types"
15 --
16 -- * 'RdrName.RdrName': see "RdrName#name_types"
17 --
18 -- * 'Name.Name': see "Name#name_types"
19 --
20 -- * 'Id.Id': see "Id#name_types"
21 --
22 -- * 'Var.Var' is a synonym for the 'Id.Id' type but it may additionally
23 -- potentially contain type variables, which have a 'TyCoRep.Kind'
24 -- rather than a 'TyCoRep.Type' and only contain some extra
25 -- details during typechecking.
26 --
27 -- These 'Var.Var' names may either be global or local, see "Var#globalvslocal"
28 --
29 -- #globalvslocal#
30 -- Global 'Id's and 'Var's are those that are imported or correspond
31 -- to a data constructor, primitive operation, or record selectors.
32 -- Local 'Id's and 'Var's are those bound within an expression
33 -- (e.g. by a lambda) or at the top level of the module being compiled.
34
35 module Var (
36 -- * The main data type and synonyms
37 Var, CoVar, Id, NcId, DictId, DFunId, EvVar, EqVar, EvId, IpId, JoinId,
38 TyVar, TcTyVar, TypeVar, KindVar, TKVar, TyCoVar,
39
40 -- * In and Out variants
41 InVar, InCoVar, InId, InTyVar,
42 OutVar, OutCoVar, OutId, OutTyVar,
43
44 -- ** Taking 'Var's apart
45 varName, varUnique, varType,
46
47 -- ** Modifying 'Var's
48 setVarName, setVarUnique, setVarType, updateVarType,
49 updateVarTypeM,
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, isTyVar, isTcTyVar,
59 isLocalVar, isLocalId, isCoVar, isNonCoVarId, isTyCoVar,
60 isGlobalId, isExportedId,
61 mustHaveLocalBinding,
62
63 -- * TyVar's
64 TyVarBndr(..), ArgFlag(..), TyVarBinder,
65 binderVar, binderVars, binderArgFlag, binderKind,
66 isVisibleArgFlag, isInvisibleArgFlag, sameVis,
67 mkTyVarBinder, mkTyVarBinders,
68
69 -- ** Constructing TyVar's
70 mkTyVar, mkTcTyVar,
71
72 -- ** Taking 'TyVar's apart
73 tyVarName, tyVarKind, tcTyVarDetails, setTcTyVarDetails,
74
75 -- ** Modifying 'TyVar's
76 setTyVarName, setTyVarUnique, setTyVarKind, updateTyVarKind,
77 updateTyVarKindM,
78
79 nonDetCmpVar
80
81 ) where
82
83 #include "HsVersions.h"
84
85 import GhcPrelude
86
87 import {-# SOURCE #-} TyCoRep( Type, Kind, pprKind )
88 import {-# SOURCE #-} TcType( TcTyVarDetails, pprTcTyVarDetails, vanillaSkolemTv )
89 import {-# SOURCE #-} IdInfo( IdDetails, IdInfo, coVarDetails, isCoVarDetails,
90 vanillaIdInfo, pprIdDetails )
91
92 import Name hiding (varName)
93 import Unique ( Uniquable, Unique, getKey, getUnique
94 , mkUniqueGrimily, nonDetCmpUnique )
95 import Util
96 import Binary
97 import DynFlags
98 import Outputable
99
100 import Data.Data
101
102 {-
103 ************************************************************************
104 * *
105 Synonyms
106 * *
107 ************************************************************************
108 -- These synonyms are here and not in Id because otherwise we need a very
109 -- large number of SOURCE imports of Id.hs :-(
110 -}
111
112 -- | Identifier
113 type Id = Var -- A term-level identifier
114 -- predicate: isId
115
116 -- | Coercion Variable
117 type CoVar = Id -- See Note [Evidence: EvIds and CoVars]
118 -- predicate: isCoVar
119
120 -- |
121 type NcId = Id -- A term-level (value) variable that is
122 -- /not/ an (unlifted) coercion
123 -- predicate: isNonCoVarId
124
125 -- | Type or kind Variable
126 type TyVar = Var -- Type *or* kind variable (historical)
127
128 -- | Type or Kind Variable
129 type TKVar = Var -- Type *or* kind variable (historical)
130
131 -- | Type variable that might be a metavariable
132 type TcTyVar = Var
133
134 -- | Type Variable
135 type TypeVar = Var -- Definitely a type variable
136
137 -- | Kind Variable
138 type KindVar = Var -- Definitely a kind variable
139 -- See Note [Kind and type variables]
140
141 -- See Note [Evidence: EvIds and CoVars]
142 -- | Evidence Identifier
143 type EvId = Id -- Term-level evidence: DictId, IpId, or EqVar
144
145 -- | Evidence Variable
146 type EvVar = EvId -- ...historical name for EvId
147
148 -- | Dictionary Function Identifier
149 type DFunId = Id -- A dictionary function
150
151 -- | Dictionary Identifier
152 type DictId = EvId -- A dictionary variable
153
154 -- | Implicit parameter Identifier
155 type IpId = EvId -- A term-level implicit parameter
156
157 -- | Equality Variable
158 type EqVar = EvId -- Boxed equality evidence
159 type JoinId = Id -- A join variable
160
161 -- | Type or Coercion Variable
162 type TyCoVar = Id -- Type, *or* coercion variable
163 -- predicate: isTyCoVar
164
165
166 {- Many passes apply a substitution, and it's very handy to have type
167 synonyms to remind us whether or not the substitution has been applied -}
168
169 type InVar = Var
170 type InTyVar = TyVar
171 type InCoVar = CoVar
172 type InId = Id
173 type OutVar = Var
174 type OutTyVar = TyVar
175 type OutCoVar = CoVar
176 type OutId = Id
177
178
179
180 {- Note [Evidence: EvIds and CoVars]
181 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
182 * An EvId (evidence Id) is a term-level evidence variable
183 (dictionary, implicit parameter, or equality). Could be boxed or unboxed.
184
185 * DictId, IpId, and EqVar are synonyms when we know what kind of
186 evidence we are talking about. For example, an EqVar has type (t1 ~ t2).
187
188 * A CoVar is always an un-lifted coercion, of type (t1 ~# t2) or (t1 ~R# t2)
189
190 Note [Kind and type variables]
191 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
192 Before kind polymorphism, TyVar were used to mean type variables. Now
193 they are use to mean kind *or* type variables. KindVar is used when we
194 know for sure that it is a kind variable. In future, we might want to
195 go over the whole compiler code to use:
196 - TKVar to mean kind or type variables
197 - TypeVar to mean type variables only
198 - KindVar to mean kind variables
199
200
201 ************************************************************************
202 * *
203 \subsection{The main data type declarations}
204 * *
205 ************************************************************************
206
207
208 Every @Var@ has a @Unique@, to uniquify it and for fast comparison, a
209 @Type@, and an @IdInfo@ (non-essential info about it, e.g.,
210 strictness). The essential info about different kinds of @Vars@ is
211 in its @VarDetails@.
212 -}
213
214 -- | Variable
215 --
216 -- Essentially a typed 'Name', that may also contain some additional information
217 -- about the 'Var' and it's use sites.
218 data Var
219 = TyVar { -- Type and kind variables
220 -- see Note [Kind and type variables]
221 varName :: !Name,
222 realUnique :: {-# UNPACK #-} !Int,
223 -- ^ Key for fast comparison
224 -- Identical to the Unique in the name,
225 -- cached here for speed
226 varType :: Kind -- ^ The type or kind of the 'Var' in question
227 }
228
229 | TcTyVar { -- Used only during type inference
230 -- Used for kind variables during
231 -- inference, as well
232 varName :: !Name,
233 realUnique :: {-# UNPACK #-} !Int,
234 varType :: Kind,
235 tc_tv_details :: TcTyVarDetails
236 }
237
238 | Id {
239 varName :: !Name,
240 realUnique :: {-# UNPACK #-} !Int,
241 varType :: Type,
242 idScope :: IdScope,
243 id_details :: IdDetails, -- Stable, doesn't change
244 id_info :: IdInfo } -- Unstable, updated by simplifier
245
246 -- | Identifier Scope
247 data IdScope -- See Note [GlobalId/LocalId]
248 = GlobalId
249 | LocalId ExportFlag
250
251 data ExportFlag -- See Note [ExportFlag on binders]
252 = NotExported -- ^ Not exported: may be discarded as dead code.
253 | Exported -- ^ Exported: kept alive
254
255 {- Note [ExportFlag on binders]
256 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257 An ExportFlag of "Exported" on a top-level binder says "keep this
258 binding alive; do not drop it as dead code". This transitively
259 keeps alive all the other top-level bindings that this binding refers
260 to. This property is persisted all the way down the pipeline, so that
261 the binding will be compiled all the way to object code, and its
262 symbols will appear in the linker symbol table.
263
264 However, note that this use of "exported" is quite different to the
265 export list on a Haskell module. Setting the ExportFlag on an Id does
266 /not/ mean that if you import the module (in Haskell source code) you
267 will see this Id. Of course, things that appear in the export list
268 of the source Haskell module do indeed have their ExportFlag set.
269 But many other things, such as dictionary functions, are kept alive
270 by having their ExportFlag set, even though they are not exported
271 in the source-code sense.
272
273 We should probably use a different term for ExportFlag, like
274 KeepAlive.
275
276 Note [GlobalId/LocalId]
277 ~~~~~~~~~~~~~~~~~~~~~~~
278 A GlobalId is
279 * always a constant (top-level)
280 * imported, or data constructor, or primop, or record selector
281 * has a Unique that is globally unique across the whole
282 GHC invocation (a single invocation may compile multiple modules)
283 * never treated as a candidate by the free-variable finder;
284 it's a constant!
285
286 A LocalId is
287 * bound within an expression (lambda, case, local let(rec))
288 * or defined at top level in the module being compiled
289 * always treated as a candidate by the free-variable finder
290
291 After CoreTidy, top-level LocalIds are turned into GlobalIds
292 -}
293
294 instance Outputable Var where
295 ppr var = sdocWithDynFlags $ \dflags ->
296 getPprStyle $ \ppr_style ->
297 if | debugStyle ppr_style && (not (gopt Opt_SuppressVarKinds dflags))
298 -> parens (ppr (varName var) <+> ppr_debug var ppr_style <+>
299 dcolon <+> pprKind (tyVarKind var))
300 | otherwise
301 -> ppr (varName var) <> ppr_debug var ppr_style
302
303 ppr_debug :: Var -> PprStyle -> SDoc
304 ppr_debug (TyVar {}) sty
305 | debugStyle sty = brackets (text "tv")
306 ppr_debug (TcTyVar {tc_tv_details = d}) sty
307 | dumpStyle sty || debugStyle sty = brackets (pprTcTyVarDetails d)
308 ppr_debug (Id { idScope = s, id_details = d }) sty
309 | debugStyle sty = brackets (ppr_id_scope s <> pprIdDetails d)
310 ppr_debug _ _ = empty
311
312 ppr_id_scope :: IdScope -> SDoc
313 ppr_id_scope GlobalId = text "gid"
314 ppr_id_scope (LocalId Exported) = text "lidx"
315 ppr_id_scope (LocalId NotExported) = text "lid"
316
317 instance NamedThing Var where
318 getName = varName
319
320 instance Uniquable Var where
321 getUnique = varUnique
322
323 instance Eq Var where
324 a == b = realUnique a == realUnique b
325
326 instance Ord Var where
327 a <= b = realUnique a <= realUnique b
328 a < b = realUnique a < realUnique b
329 a >= b = realUnique a >= realUnique b
330 a > b = realUnique a > realUnique b
331 a `compare` b = a `nonDetCmpVar` b
332
333 -- | Compare Vars by their Uniques.
334 -- This is what Ord Var does, provided here to make it explicit at the
335 -- call-site that it can introduce non-determinism.
336 -- See Note [Unique Determinism]
337 nonDetCmpVar :: Var -> Var -> Ordering
338 nonDetCmpVar a b = varUnique a `nonDetCmpUnique` varUnique b
339
340 instance Data Var where
341 -- don't traverse?
342 toConstr _ = abstractConstr "Var"
343 gunfold _ _ = error "gunfold"
344 dataTypeOf _ = mkNoRepType "Var"
345
346 instance HasOccName Var where
347 occName = nameOccName . varName
348
349 varUnique :: Var -> Unique
350 varUnique var = mkUniqueGrimily (realUnique var)
351
352 setVarUnique :: Var -> Unique -> Var
353 setVarUnique var uniq
354 = var { realUnique = getKey uniq,
355 varName = setNameUnique (varName var) uniq }
356
357 setVarName :: Var -> Name -> Var
358 setVarName var new_name
359 = var { realUnique = getKey (getUnique new_name),
360 varName = new_name }
361
362 setVarType :: Id -> Type -> Id
363 setVarType id ty = id { varType = ty }
364
365 updateVarType :: (Type -> Type) -> Id -> Id
366 updateVarType f id = id { varType = f (varType id) }
367
368 updateVarTypeM :: Monad m => (Type -> m Type) -> Id -> m Id
369 updateVarTypeM f id = do { ty' <- f (varType id)
370 ; return (id { varType = ty' }) }
371
372 {- *********************************************************************
373 * *
374 * ArgFlag
375 * *
376 ********************************************************************* -}
377
378 -- | Argument Flag
379 --
380 -- Is something required to appear in source Haskell ('Required'),
381 -- permitted by request ('Specified') (visible type application), or
382 -- prohibited entirely from appearing in source Haskell ('Inferred')?
383 -- See Note [TyVarBndrs, TyVarBinders, TyConBinders, and visibility] in TyCoRep
384 data ArgFlag = Inferred | Specified | Required
385 deriving (Eq, Ord, Data)
386 -- (<) on ArgFlag meant "is less visible than"
387
388 -- | Does this 'ArgFlag' classify an argument that is written in Haskell?
389 isVisibleArgFlag :: ArgFlag -> Bool
390 isVisibleArgFlag Required = True
391 isVisibleArgFlag _ = False
392
393 -- | Does this 'ArgFlag' classify an argument that is not written in Haskell?
394 isInvisibleArgFlag :: ArgFlag -> Bool
395 isInvisibleArgFlag = not . isVisibleArgFlag
396
397 -- | Do these denote the same level of visibility? 'Required'
398 -- arguments are visible, others are not. So this function
399 -- equates 'Specified' and 'Inferred'. Used for printing.
400 sameVis :: ArgFlag -> ArgFlag -> Bool
401 sameVis Required Required = True
402 sameVis Required _ = False
403 sameVis _ Required = False
404 sameVis _ _ = True
405
406 {- *********************************************************************
407 * *
408 * TyVarBndr, TyVarBinder
409 * *
410 ********************************************************************* -}
411
412 -- Type Variable Binder
413 --
414 -- TyVarBndr is polymorphic in both tyvar and visibility fields:
415 -- * tyvar can be TyVar or IfaceTv
416 -- * argf can be ArgFlag or TyConBndrVis
417 data TyVarBndr tyvar argf = TvBndr tyvar argf
418 deriving( Data )
419
420 -- | Type Variable Binder
421 --
422 -- A 'TyVarBinder' is the binder of a ForAllTy
423 -- It's convenient to define this synonym here rather its natural
424 -- home in TyCoRep, because it's used in DataCon.hs-boot
425 type TyVarBinder = TyVarBndr TyVar ArgFlag
426
427 binderVar :: TyVarBndr tv argf -> tv
428 binderVar (TvBndr v _) = v
429
430 binderVars :: [TyVarBndr tv argf] -> [tv]
431 binderVars tvbs = map binderVar tvbs
432
433 binderArgFlag :: TyVarBndr tv argf -> argf
434 binderArgFlag (TvBndr _ argf) = argf
435
436 binderKind :: TyVarBndr TyVar argf -> Kind
437 binderKind (TvBndr tv _) = tyVarKind tv
438
439 -- | Make a named binder
440 mkTyVarBinder :: ArgFlag -> Var -> TyVarBinder
441 mkTyVarBinder vis var = TvBndr var vis
442
443 -- | Make many named binders
444 mkTyVarBinders :: ArgFlag -> [TyVar] -> [TyVarBinder]
445 mkTyVarBinders vis = map (mkTyVarBinder vis)
446
447 {-
448 ************************************************************************
449 * *
450 * Type and kind variables *
451 * *
452 ************************************************************************
453 -}
454
455 tyVarName :: TyVar -> Name
456 tyVarName = varName
457
458 tyVarKind :: TyVar -> Kind
459 tyVarKind = varType
460
461 setTyVarUnique :: TyVar -> Unique -> TyVar
462 setTyVarUnique = setVarUnique
463
464 setTyVarName :: TyVar -> Name -> TyVar
465 setTyVarName = setVarName
466
467 setTyVarKind :: TyVar -> Kind -> TyVar
468 setTyVarKind tv k = tv {varType = k}
469
470 updateTyVarKind :: (Kind -> Kind) -> TyVar -> TyVar
471 updateTyVarKind update tv = tv {varType = update (tyVarKind tv)}
472
473 updateTyVarKindM :: (Monad m) => (Kind -> m Kind) -> TyVar -> m TyVar
474 updateTyVarKindM update tv
475 = do { k' <- update (tyVarKind tv)
476 ; return $ tv {varType = k'} }
477
478 mkTyVar :: Name -> Kind -> TyVar
479 mkTyVar name kind = TyVar { varName = name
480 , realUnique = getKey (nameUnique name)
481 , varType = kind
482 }
483
484 mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> TyVar
485 mkTcTyVar name kind details
486 = -- NB: 'kind' may be a coercion kind; cf, 'TcMType.newMetaCoVar'
487 TcTyVar { varName = name,
488 realUnique = getKey (nameUnique name),
489 varType = kind,
490 tc_tv_details = details
491 }
492
493 tcTyVarDetails :: TyVar -> TcTyVarDetails
494 -- See Note [TcTyVars in the typechecker] in TcType
495 tcTyVarDetails (TcTyVar { tc_tv_details = details }) = details
496 tcTyVarDetails (TyVar {}) = vanillaSkolemTv
497 tcTyVarDetails var = pprPanic "tcTyVarDetails" (ppr var <+> dcolon <+> pprKind (tyVarKind var))
498
499 setTcTyVarDetails :: TyVar -> TcTyVarDetails -> TyVar
500 setTcTyVarDetails tv details = tv { tc_tv_details = details }
501
502 -------------------------------------
503 instance Outputable tv => Outputable (TyVarBndr tv ArgFlag) where
504 ppr (TvBndr v Required) = ppr v
505 ppr (TvBndr v Specified) = char '@' <> ppr v
506 ppr (TvBndr v Inferred) = braces (ppr v)
507
508 instance Outputable ArgFlag where
509 ppr Required = text "[req]"
510 ppr Specified = text "[spec]"
511 ppr Inferred = text "[infrd]"
512
513 instance (Binary tv, Binary vis) => Binary (TyVarBndr tv vis) where
514 put_ bh (TvBndr tv vis) = do { put_ bh tv; put_ bh vis }
515
516 get bh = do { tv <- get bh; vis <- get bh; return (TvBndr tv vis) }
517
518
519 instance Binary ArgFlag where
520 put_ bh Required = putByte bh 0
521 put_ bh Specified = putByte bh 1
522 put_ bh Inferred = putByte bh 2
523
524 get bh = do
525 h <- getByte bh
526 case h of
527 0 -> return Required
528 1 -> return Specified
529 _ -> return Inferred
530
531 {-
532 %************************************************************************
533 %* *
534 \subsection{Ids}
535 * *
536 ************************************************************************
537 -}
538
539 idInfo :: HasDebugCallStack => Id -> IdInfo
540 idInfo (Id { id_info = info }) = info
541 idInfo other = pprPanic "idInfo" (ppr other)
542
543 idDetails :: Id -> IdDetails
544 idDetails (Id { id_details = details }) = details
545 idDetails other = pprPanic "idDetails" (ppr other)
546
547 -- The next three have a 'Var' suffix even though they always build
548 -- Ids, because Id.hs uses 'mkGlobalId' etc with different types
549 mkGlobalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
550 mkGlobalVar details name ty info
551 = mk_id name ty GlobalId details info
552
553 mkLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
554 mkLocalVar details name ty info
555 = mk_id name ty (LocalId NotExported) details info
556
557 mkCoVar :: Name -> Type -> CoVar
558 -- Coercion variables have no IdInfo
559 mkCoVar name ty = mk_id name ty (LocalId NotExported) coVarDetails vanillaIdInfo
560
561 -- | Exported 'Var's will not be removed as dead code
562 mkExportedLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
563 mkExportedLocalVar details name ty info
564 = mk_id name ty (LocalId Exported) details info
565
566 mk_id :: Name -> Type -> IdScope -> IdDetails -> IdInfo -> Id
567 mk_id name ty scope details info
568 = Id { varName = name,
569 realUnique = getKey (nameUnique name),
570 varType = ty,
571 idScope = scope,
572 id_details = details,
573 id_info = info }
574
575 -------------------
576 lazySetIdInfo :: Id -> IdInfo -> Var
577 lazySetIdInfo id info = id { id_info = info }
578
579 setIdDetails :: Id -> IdDetails -> Id
580 setIdDetails id details = id { id_details = details }
581
582 globaliseId :: Id -> Id
583 -- ^ If it's a local, make it global
584 globaliseId id = id { idScope = GlobalId }
585
586 setIdExported :: Id -> Id
587 -- ^ Exports the given local 'Id'. Can also be called on global 'Id's, such as data constructors
588 -- and class operations, which are born as global 'Id's and automatically exported
589 setIdExported id@(Id { idScope = LocalId {} }) = id { idScope = LocalId Exported }
590 setIdExported id@(Id { idScope = GlobalId }) = id
591 setIdExported tv = pprPanic "setIdExported" (ppr tv)
592
593 setIdNotExported :: Id -> Id
594 -- ^ We can only do this to LocalIds
595 setIdNotExported id = ASSERT( isLocalId id )
596 id { idScope = LocalId NotExported }
597
598 {-
599 ************************************************************************
600 * *
601 \subsection{Predicates over variables}
602 * *
603 ************************************************************************
604 -}
605
606 isTyVar :: Var -> Bool -- True of both TyVar and TcTyVar
607 isTyVar (TyVar {}) = True
608 isTyVar (TcTyVar {}) = True
609 isTyVar _ = False
610
611 isTcTyVar :: Var -> Bool -- True of TcTyVar only
612 isTcTyVar (TcTyVar {}) = True
613 isTcTyVar _ = False
614
615 isTyCoVar :: Var -> Bool
616 isTyCoVar v = isTyVar v || isCoVar v
617
618 isId :: Var -> Bool
619 isId (Id {}) = True
620 isId _ = False
621
622 isCoVar :: Var -> Bool
623 -- A coercion variable
624 isCoVar (Id { id_details = details }) = isCoVarDetails details
625 isCoVar _ = False
626
627 isNonCoVarId :: Var -> Bool
628 -- A term variable (Id) that is /not/ a coercion variable
629 isNonCoVarId (Id { id_details = details }) = not (isCoVarDetails details)
630 isNonCoVarId _ = False
631
632 isLocalId :: Var -> Bool
633 isLocalId (Id { idScope = LocalId _ }) = True
634 isLocalId _ = False
635
636 -- | 'isLocalVar' returns @True@ for type variables as well as local 'Id's
637 -- These are the variables that we need to pay attention to when finding free
638 -- variables, or doing dependency analysis.
639 isLocalVar :: Var -> Bool
640 isLocalVar v = not (isGlobalId v)
641
642 isGlobalId :: Var -> Bool
643 isGlobalId (Id { idScope = GlobalId }) = True
644 isGlobalId _ = False
645
646 -- | 'mustHaveLocalBinding' returns @True@ of 'Id's and 'TyVar's
647 -- that must have a binding in this module. The converse
648 -- is not quite right: there are some global 'Id's that must have
649 -- bindings, such as record selectors. But that doesn't matter,
650 -- because it's only used for assertions
651 mustHaveLocalBinding :: Var -> Bool
652 mustHaveLocalBinding var = isLocalVar var
653
654 -- | 'isExportedIdVar' means \"don't throw this away\"
655 isExportedId :: Var -> Bool
656 isExportedId (Id { idScope = GlobalId }) = True
657 isExportedId (Id { idScope = LocalId Exported}) = True
658 isExportedId _ = False