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