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