2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[Id]{@Ids@: Value and constructor identifiers}
7 #include "HsVersions.h"
11 IdInfo, -- re-exporting
12 ConTag(..), DictVar(..), DictFun(..), DataCon(..),
15 mkSysLocal, mkUserLocal,
17 mkSpecId, mkSameSpecCon,
19 mkImported, mkPreludeId,
20 mkDataCon, mkTupleCon,
22 mkClassOpId, mkSuperDictSelId, mkDefaultMethodId,
23 mkConstMethodId, mkInstId,
27 #endif {- Data Parallel Haskell -}
36 getInstNamePieces, getIdInfo, replaceIdInfo,
38 getMentionedTyConsAndClassesFromId,
40 getDataConSig, getInstantiatedDataConSig,
41 getDataConTyCon, -- UNUSED: getDataConFamily,
42 #ifdef USE_SEMANTIQUE_STRANAL
47 isDataCon, isTupleCon, isNullaryDataCon,
48 isSpecId_maybe, isSpecPragmaId_maybe,
49 toplevelishId, externallyVisibleId,
50 isTopLevId, isWorkerId, isWrapperId,
51 isImportedId, isSysLocalId,
53 isClassOpId, isConstMethodId, isDefaultMethodId,
54 isDictFunId, isInstId_maybe, isSuperDictSelId_maybe,
58 #endif {- Data Parallel Haskell -}
60 cmpId_withSpecDataCon,
63 unfoldingUnfriendlyId, -- ToDo: rm, eventually
65 -- dataConMentionsNonPreludeTyCon,
68 applySubstToId, applyTypeEnvToId,
69 -- not exported: apply_to_Id, -- please don't use this, generally
71 -- UNFOLDING, ARITY, UPDATE, AND STRICTNESS STUFF (etc)
72 getIdArity, getDataConArity, addIdArity,
73 getIdDemandInfo, addIdDemandInfo,
74 getIdSpecialisation, addIdSpecialisation,
75 getIdStrictness, addIdStrictness,
76 getIdUnfolding, addIdUnfolding, -- UNUSED? clearIdUnfolding,
77 getIdUpdateInfo, addIdUpdateInfo,
78 getIdArgUsageInfo, addIdArgUsageInfo,
79 getIdFBTypeInfo, addIdFBTypeInfo,
80 -- don't export the types, lest OptIdInfo be dragged in!
88 -- and to make the interface self-sufficient...
89 Class, ClassOp, GlobalSwitch, Inst, Maybe, Name,
90 FullName, PprStyle, PrettyRep,
91 PrimKind, SrcLoc, Pretty(..), Subst, UnfoldingDetails,
92 TyCon, TyVar, TyVarTemplate, TauType(..), UniType, Unique,
93 UniqueSupply, Arity(..), ThetaType(..),
94 TypeEnv(..), UniqFM, InstTemplate, Bag,
95 SpecEnv, nullSpecEnv, SpecInfo,
97 -- and to make sure pragmas work...
98 IdDetails -- from this module, abstract
99 IF_ATTACK_PRAGMAS(COMMA getMentionedTyConsAndClassesFromUniType)
100 IF_ATTACK_PRAGMAS(COMMA bottomIsGuaranteed)
101 IF_ATTACK_PRAGMAS(COMMA getInfo_UF)
103 #ifndef __GLASGOW_HASKELL__
108 IMPORT_Trace -- ToDo: rm (debugging only)
110 import AbsPrel ( PrimOp, PrimKind, mkFunTy, nilDataCon, pRELUDE_BUILTIN
111 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
112 IF_ATTACK_PRAGMAS(COMMA pprPrimOp)
114 , mkPodNTy, mkPodizedPodNTy
115 #endif {- Data Parallel Haskell -}
120 import CLabelInfo ( identToC, cSEP )
121 import CmdLineOpts ( GlobalSwitch(..) )
122 import IdEnv -- ( nullIdEnv, IdEnv )
123 import IdInfo -- piles of it
124 import Inst -- lots of things
125 import Maybes ( maybeToBool, Maybe(..) )
126 import Name ( Name(..) )
129 import Pretty -- for pretty-printing
131 import Subst ( applySubstToTy ) -- PRETTY GRIMY TO LOOK IN HERE
133 import PrelFuns ( pcGenerateDataSpecs ) -- PRETTY GRIMY TO LOOK IN HERE
140 import PodizeCore ( podizeTemplateExpr )
141 import PodInfoTree ( infoTypeNumToMask )
142 #endif {- Data Parallel Haskell -}
145 Here are the @Id@ and @IdDetails@ datatypes; also see the notes that
148 Every @Id@ has a @Unique@, to uniquify it and for fast comparison, a
149 @UniType@, and an @IdInfo@ (non-essential info about it, e.g.,
150 strictness). The essential info about different kinds of @Ids@ is
153 ToDo: possibly cache other stuff in the single-constructor @Id@ type.
156 data Id = Id Unique -- key for fast comparison
157 UniType -- Id's type; used all the time;
158 IdInfo -- non-essential info about this Id;
159 IdDetails -- stuff about individual kinds of Ids.
163 ---------------- Local values
165 = LocalId ShortName -- mentioned by the user
166 Bool -- True <=> no free type vars
168 | SysLocalId ShortName -- made up by the compiler
169 Bool -- as for LocalId
171 | SpecPragmaId ShortName -- introduced by the compiler
172 (Maybe SpecInfo)-- for explicit specid in pragma
173 Bool -- as for LocalId
175 ---------------- Global values
177 | ImportedId FullName -- Id imported from an interface
179 | PreludeId FullName -- things < Prelude that compiler "knows" about
181 | TopLevId FullName -- Top-level in the orig source pgm
182 -- (not moved there by transformations).
184 -- a TopLevId's type may contain free type variables, if
185 -- the monomorphism restriction applies.
187 ---------------- Data constructors
191 -- cached pieces of the type:
192 [TyVarTemplate] [(Class,UniType)] [UniType] TyCon
194 -- forall tyvars . theta_ty =>
195 -- unitype_1 -> ... -> unitype_n -> tycon tyvars
197 -- "type ThetaType = [(Class, UniType)]"
199 -- The [TyVarTemplate] is in the same order as the args of the
200 -- TyCon for the constructor
202 | TupleConId Int -- Its arity
205 | ProcessorCon Int -- Its arity
206 #endif {- Data Parallel Haskell -}
208 ---------------- Things to do with overloading
210 | SuperDictSelId -- Selector for superclass dictionary
211 Class -- The class (input dict)
212 Class -- The superclass (result dict)
214 | ClassOpId Class -- An overloaded class operation, with
215 -- a fully polymorphic type. Its code
216 -- just selects a method from the
217 -- dictionary. The class.
218 ClassOp -- The operation
220 -- NB: The IdInfo for a ClassOpId has all the info about its
221 -- related "constant method Ids", which are just
222 -- specialisations of this general one.
224 | DefaultMethodId -- Default method for a particular class op
225 Class -- same class, <blah-blah> info as ClassOpId
226 ClassOp -- (surprise, surprise)
227 Bool -- True <=> I *know* this default method Id
228 -- is a generated one that just says
229 -- `error "No default method for <op>"'.
232 DictFunIds are generated from instance decls.
237 instance Foo a => Foo [a] where
240 generates the dict fun id decl
242 dfun.Foo.[*] = \d -> ...
244 The dfun id is uniquely named by the (class, type) pair. Notice, it
245 isn't a (class,tycon) pair any more, because we may get manually or
246 automatically generated specialisations of the instance decl:
248 instance Foo [Int] where
255 The type variables in the name are irrelevant; we print them as stars.
258 | DictFunId Class -- A DictFun is uniquely identified
259 UniType -- by its class and type; this type has free type vars,
260 -- whose identity is irrelevant. Eg Class = Eq
262 -- The "a" is irrelevant. As it is too painful to
263 -- actually do comparisons that way, we kindly supply
264 -- a Unique for that purpose.
265 Bool -- True <=> from an instance decl in this mod
268 Constant method ids are generated from instance decls where
269 there is no context; that is, no dictionaries are needed to
270 construct the method. Example
272 instance Foo Int where
275 Then we get a constant method
280 It is possible, albeit unusual, to have a constant method
281 for an instance decl which has type vars:
283 instance Foo [a] where
287 We get the constant method
291 So a constant method is identified by a class/op/type triple.
292 The type variables in the type are irrelevant.
295 | ConstMethodId -- A method which depends only on the type of the
296 -- instance, and not on any further dictionaries etc.
297 Class -- Uniquely identified by:
298 UniType -- (class, type, classop) triple
300 Bool -- True <=> from an instance decl in this mod
302 | InstId Inst -- An instance of a dictionary, class operation,
303 -- or overloaded value
305 | SpecId -- A specialisation of another Id
306 Id -- Id of which this is a specialisation
307 [Maybe UniType] -- Types at which it is specialised;
308 -- A "Nothing" says this type ain't relevant.
309 Bool -- True <=> no free type vars; it's not enough
310 -- to know about the unspec version, because
311 -- we may specialise to a type w/ free tyvars
312 -- (i.e., in one of the "Maybe UniType" dudes).
314 | WorkerId -- A "worker" for some other Id
315 Id -- Id for which this is a worker
318 | PodId Int -- The dimension of the PODs context
319 Int -- Which specialisation of InfoType is
320 -- bind. ToDo(hilly): Int is a little messy
321 -- and has a restricted range---change.
322 Id -- One of the aboves Ids.
323 #endif {- Data Parallel Haskell -}
331 For Ids whose names must be known/deducible in other modules, we have
332 to conjure up their worker's names (and their worker's worker's
333 names... etc) in a known systematic way.
335 %************************************************************************
337 \subsection[Id-documentation]{Documentation}
339 %************************************************************************
343 The @Id@ datatype describes {\em values}. The basic things we want to
344 know: (1)~a value's {\em type} (@getIdUniType@ is a very common
345 operation in the compiler); and (2)~what ``flavour'' of value it might
346 be---for example, it can be terribly useful to know that a value is a
350 %----------------------------------------------------------------------
351 \item[@DataConId@:] For the data constructors declared by a @data@
352 declaration. Their type is kept in {\em two} forms---as a regular
353 @UniType@ (in the usual place), and also in its constituent pieces (in
354 the ``details''). We are frequently interested in those pieces.
356 %----------------------------------------------------------------------
357 \item[@TupleConId@:] This is just a special shorthand for @DataCons@ for
358 the infinite family of tuples.
360 %----------------------------------------------------------------------
361 \item[@ImportedId@:] These are values defined outside this module.
362 {\em Everything} we want to know about them must be stored here (or in
365 %----------------------------------------------------------------------
366 \item[@PreludeId@:] ToDo
368 %----------------------------------------------------------------------
369 \item[@TopLevId@:] These are values defined at the top-level in this
370 module; i.e., those which {\em might} be exported (hence, a
371 @FullName@). It does {\em not} include those which are moved to the
372 top-level through program transformations.
374 We also guarantee that @TopLevIds@ will {\em stay} at top-level.
375 Theoretically, they could be floated inwards, but there's no known
376 advantage in doing so. This way, we can keep them with the same
377 @Unique@ throughout (no cloning), and, in general, we don't have to be
378 so paranoid about them.
380 In particular, we had the following problem generating an interface:
381 We have to ``stitch together'' info (1)~from the typechecker-produced
382 global-values list (GVE) and (2)~from the STG code [which @Ids@ have
383 what arities]. If the @Uniques@ on the @TopLevIds@ can {\em change}
384 between (1) and (2), you're sunk!
386 %----------------------------------------------------------------------
387 \item[@ClassOpId@:] A selector from a dictionary; it may select either
388 a method or a dictionary for one of the class's superclasses.
390 %----------------------------------------------------------------------
393 @mkDictFunId [a,b..] theta C T@ is the function derived from the
396 instance theta => C (T a b ..) where
399 It builds function @Id@ which maps dictionaries for theta,
400 to a dictionary for C (T a b ..).
402 *Note* that with the ``Mark Jones optimisation'', the theta may
403 include dictionaries for the immediate superclasses of C at the type
406 %----------------------------------------------------------------------
409 %----------------------------------------------------------------------
412 %----------------------------------------------------------------------
415 %----------------------------------------------------------------------
416 \item[@LocalId@:] A purely-local value, e.g., a function argument,
417 something defined in a @where@ clauses, ... --- but which appears in
418 the original program text.
420 %----------------------------------------------------------------------
421 \item[@SysLocalId@:] Same as a @LocalId@, except does {\em not} appear in
422 the original program text; these are introduced by the compiler in
425 %----------------------------------------------------------------------
426 \item[@SpecPragmaId@:] Introduced by the compiler to record
427 Specialisation pragmas. It is dead code which MUST NOT be removed
428 before specialisation.
433 %----------------------------------------------------------------------
436 @DataCons@ @TupleCons@, @Importeds@, @TopLevIds@, @SuperDictSelIds@,
437 @ClassOpIds@, @DictFunIds@, and @DefaultMethodIds@ have the following
441 They have no free type variables, so if you are making a
442 type-variable substitution you don't need to look inside them.
444 They are constants, so they are not free variables. (When the STG
445 machine makes a closure, it puts all the free variables in the
446 closure; the above are not required.)
448 Note that @InstIds@, @Locals@ and @SysLocals@ {\em may} have the above
449 properties, but they may not.
453 %************************************************************************
455 \subsection[Id-general-funs]{General @Id@-related functions}
457 %************************************************************************
460 isDataCon (Id _ _ _ (DataConId _ _ _ _ _ _)) = True
461 isDataCon (Id _ _ _ (TupleConId _)) = True
462 isDataCon (Id _ _ _ (SpecId unspec _ _)) = isDataCon unspec
464 isDataCon (ProcessorCon _ _) = True
465 isDataCon (PodId _ _ id ) = isDataCon id
466 #endif {- Data Parallel Haskell -}
467 isDataCon other = False
469 isTupleCon (Id _ _ _ (TupleConId _)) = True
470 isTupleCon (Id _ _ _ (SpecId unspec _ _)) = isTupleCon unspec
472 isTupleCon (PodId _ _ id) = isTupleCon id
473 #endif {- Data Parallel Haskell -}
474 isTupleCon other = False
476 isNullaryDataCon data_con
478 && (case arityMaybe (getIdArity data_con) of
480 _ -> panic "isNullaryDataCon")
482 isSpecId_maybe (Id _ _ _ (SpecId unspec ty_maybes _))
483 = ASSERT(not (maybeToBool (isSpecId_maybe unspec)))
484 Just (unspec, ty_maybes)
485 isSpecId_maybe other_id
488 isSpecPragmaId_maybe (Id _ _ _ (SpecPragmaId _ specinfo _))
490 isSpecPragmaId_maybe other_id
494 isProcessorCon (ProcessorCon _ _) = True
495 isProcessorCon (PodId _ _ id) = isProcessorCon id
496 isProcessorCon other = False
497 #endif {- Data Parallel Haskell -}
500 @toplevelishId@ tells whether an @Id@ {\em may} be defined in a
501 nested @let(rec)@ (returns @False@), or whether it is {\em sure} to be
502 defined at top level (returns @True@). This is used to decide whether
503 the @Id@ is a candidate free variable. NB: you are only {\em sure}
504 about something if it returns @True@!
507 toplevelishId :: Id -> Bool
508 idHasNoFreeTyVars :: Id -> Bool
510 toplevelishId (Id _ _ _ details)
513 chk (DataConId _ _ _ _ _ _) = True
514 chk (TupleConId _) = True
515 chk (ImportedId _) = True
516 chk (PreludeId _) = True
517 chk (TopLevId _) = True -- NB: see notes
518 chk (SuperDictSelId _ _) = True
519 chk (ClassOpId _ _) = True
520 chk (DefaultMethodId _ _ _) = True
521 chk (DictFunId _ _ _) = True
522 chk (ConstMethodId _ _ _ _) = True
523 chk (SpecId unspec _ _) = toplevelishId unspec
524 -- depends what the unspecialised thing is
525 chk (WorkerId unwrkr) = toplevelishId unwrkr
526 chk (InstId _) = False -- these are local
527 chk (LocalId _ _) = False
528 chk (SysLocalId _ _) = False
529 chk (SpecPragmaId _ _ _) = False
531 chk (ProcessorCon _ _) = True
532 chk (PodId _ _ id) = toplevelishId id
533 #endif {- Data Parallel Haskell -}
535 idHasNoFreeTyVars (Id _ _ info details)
538 chk (DataConId _ _ _ _ _ _) = True
539 chk (TupleConId _) = True
540 chk (ImportedId _) = True
541 chk (PreludeId _) = True
542 chk (TopLevId _) = True
543 chk (SuperDictSelId _ _) = True
544 chk (ClassOpId _ _) = True
545 chk (DefaultMethodId _ _ _) = True
546 chk (DictFunId _ _ _) = True
547 chk (ConstMethodId _ _ _ _) = True
548 chk (WorkerId unwrkr) = idHasNoFreeTyVars unwrkr
549 chk (InstId _) = False -- these are local
550 chk (SpecId _ _ no_free_tvs) = no_free_tvs
551 chk (LocalId _ no_free_tvs) = no_free_tvs
552 chk (SysLocalId _ no_free_tvs) = no_free_tvs
553 chk (SpecPragmaId _ _ no_free_tvs) = no_free_tvs
555 chk (ProcessorCon _ _) = True
556 chk (PodId _ _ id) = idHasNoFreeTyVars id
557 #endif {- Data Parallel Haskell -}
561 isTopLevId (Id _ _ _ (TopLevId _)) = True
563 isTopLevId (PodId _ _ id) = isTopLevId id
564 #endif {- Data Parallel Haskell -}
565 isTopLevId other = False
567 -- an "invented" one is a top-level Id, must be globally visible, etc.,
568 -- but it's slightly different in that it was "conjured up".
569 -- This handles workers fine, but may need refinement for other
570 -- conjured-up things (e.g., specializations)
571 -- NB: Only used in DPH now (93/08/20)
575 isInventedTopLevId (TopLevId _ n _ _) = isInventedFullName n
576 isInventedTopLevId (SpecId _ _ _) = True
577 isInventedTopLevId (WorkerId _) = True
578 isInventedTopLevId (PodId _ _ id) = isInventedTopLevId id
579 isInventedTopLevId other = False
580 #endif {- Data Parallel Haskell -}
582 isImportedId (Id _ _ _ (ImportedId _)) = True
584 isImportedId (PodId _ _ id) = isImportedId id
585 #endif {- Data Parallel Haskell -}
586 isImportedId other = False
588 isBottomingId (Id _ _ info _) = bottomIsGuaranteed (getInfo info)
590 isBottomingId (PodId _ _ id) = isBottomingId id
591 #endif {- Data Parallel Haskell -}
592 --isBottomingId other = False
594 isSysLocalId (Id _ _ _ (SysLocalId _ _)) = True
596 isSysLocalId (PodId _ _ id) = isSysLocalId id
597 #endif {- Data Parallel Haskell -}
598 isSysLocalId other = False
600 isSpecPragmaId (Id _ _ _ (SpecPragmaId _ _ _)) = True
602 isSpecPragmaId (PodId _ _ id) = isSpecPragmaId id
603 #endif {- Data Parallel Haskell -}
604 isSpecPragmaId other = False
606 isClassOpId (Id _ _ _ (ClassOpId _ _)) = True
607 isClassOpId _ = False
609 isDefaultMethodId (Id _ _ _ (DefaultMethodId _ _ _)) = True
611 isDefaultMethodId (PodId _ _ id) = isDefaultMethodId id
612 #endif {- Data Parallel Haskell -}
613 isDefaultMethodId other = False
615 isDictFunId (Id _ _ _ (DictFunId _ _ _)) = True
617 isDictFunId (PodId _ _ id) = isDictFunId id
618 #endif {- Data Parallel Haskell -}
619 isDictFunId other = False
621 isConstMethodId (Id _ _ _ (ConstMethodId _ _ _ _)) = True
623 isConstMethodId (PodId _ _ id) = isConstMethodId id
624 #endif {- Data Parallel Haskell -}
625 isConstMethodId other = False
627 isInstId_maybe (Id _ _ _ (InstId inst)) = Just inst
629 isInstId_maybe (PodId _ _ id) = isInstId_maybe id
630 #endif {- Data Parallel Haskell -}
631 isInstId_maybe other_id = Nothing
633 isSuperDictSelId_maybe (Id _ _ _ (SuperDictSelId c sc)) = Just (c, sc)
635 isSuperDictSelId_maybe (PodId _ _ id) = isSuperDictSelId_maybe id
636 #endif {- Data Parallel Haskell -}
637 isSuperDictSelId_maybe other_id = Nothing
639 isWorkerId (Id _ _ _ (WorkerId _)) = True
641 isWorkerId (PodId _ _ id) = isWorkerId id
642 #endif {- Data Parallel Haskell -}
643 isWorkerId other = False
645 isWrapperId id = workerExists (getIdStrictness id)
649 pprIdInUnfolding :: IdSet -> Id -> Pretty
651 pprIdInUnfolding in_scopes v
653 v_ty = getIdUniType v
656 if v `elementOfUniqSet` in_scopes then
657 pprUnique (getTheUnique v)
659 -- ubiquitous Ids with special syntax:
660 else if v == nilDataCon then
662 else if isTupleCon v then
663 ppBeside (ppPStr SLIT("_TUP_")) (ppInt (getDataConArity v))
665 -- ones to think about:
668 (Id _ _ _ v_details) = v
671 -- these ones must have been exported by their original module
672 ImportedId _ -> pp_full_name
673 PreludeId _ -> pp_full_name
675 -- these ones' exportedness checked later...
676 TopLevId _ -> pp_full_name
677 DataConId _ _ _ _ _ _ -> pp_full_name
679 -- class-ish things: class already recorded as "mentioned"
681 -> ppCat [ppPStr SLIT("_SDSEL_"), pp_class c, pp_class sc]
683 -> ppCat [ppPStr SLIT("_METH_"), pp_class c, pp_class_op o]
684 DefaultMethodId c o _
685 -> ppCat [ppPStr SLIT("_DEFM_"), pp_class c, pp_class_op o]
687 -- instance-ish things: should we try to figure out
688 -- *exactly* which extra instances have to be exported? (ToDo)
690 -> ppCat [ppPStr SLIT("_DFUN_"), pp_class c, pp_type t]
691 ConstMethodId c t o _
692 -> ppCat [ppPStr SLIT("_CONSTM_"), pp_class c, pp_class_op o, pp_type t]
694 -- specialisations and workers
695 SpecId unspec ty_maybes _
697 pp = pprIdInUnfolding in_scopes unspec
699 ppCat [ppPStr SLIT("_SPEC_"), pp, ppLbrack,
700 ppIntersperse pp'SP{-'-} (map pp_ty_maybe ty_maybes),
705 pp = pprIdInUnfolding in_scopes unwrkr
707 ppBeside (ppPStr SLIT("_WRKR_ ")) pp
709 -- anything else? we're nae interested
710 other_id -> panic "pprIdInUnfolding:mystery Id"
712 ppr_Unfolding = PprUnfolding (panic "Id:ppr_Unfolding")
716 (m_str, n_str) = getOrigName v
719 if isAvarop n_str || isAconop n_str then
720 ppBesides [ppLparen, ppPStr n_str, ppRparen]
724 if fromPreludeCore v then
727 ppCat [ppPStr SLIT("_ORIG_"), ppPStr m_str, pp_n]
729 pp_class :: Class -> Pretty
730 pp_class_op :: ClassOp -> Pretty
731 pp_type :: UniType -> Pretty
732 pp_ty_maybe :: Maybe UniType -> Pretty
734 pp_class clas = ppr ppr_Unfolding clas
735 pp_class_op op = ppr ppr_Unfolding op
737 pp_type t = ppBesides [ppLparen, ppr ppr_Unfolding t, ppRparen]
739 pp_ty_maybe Nothing = ppPStr SLIT("_N_")
740 pp_ty_maybe (Just t) = pp_type t
743 @whatsMentionedInId@ ferrets out the types/classes/instances on which
744 this @Id@ depends. If this Id is to appear in an interface, then
745 those entities had Jolly Well be in scope. Someone else up the
746 call-tree decides that.
750 :: IdSet -- Ids known to be in scope
751 -> Id -- Id being processed
752 -> (Bag Id, Bag TyCon, Bag Class) -- mentioned Ids/TyCons/etc.
754 whatsMentionedInId in_scopes v
756 v_ty = getIdUniType v
759 = getMentionedTyConsAndClassesFromUniType v_ty
761 result0 id_bag = (id_bag, tycons, clss)
764 = (ids `unionBags` unitBag v, -- we add v to "mentioned"...
765 tcs `unionBags` tycons,
769 if v `elementOfUniqSet` in_scopes then
770 result0 emptyBag -- v not added to "mentioned"
772 -- ones to think about:
775 (Id _ _ _ v_details) = v
778 -- specialisations and workers
779 SpecId unspec ty_maybes _
781 (ids2, tcs2, cs2) = whatsMentionedInId in_scopes unspec
783 result1 ids2 tcs2 cs2
787 (ids2, tcs2, cs2) = whatsMentionedInId in_scopes unwrkr
789 result1 ids2 tcs2 cs2
791 anything_else -> result0 (unitBag v) -- v is added to "mentioned"
794 Tell them who my wrapper function is.
796 myWrapperMaybe :: Id -> Maybe Id
798 myWrapperMaybe (Id _ _ _ (WorkerId my_wrapper)) = Just my_wrapper
799 myWrapperMaybe other_id = Nothing
803 unfoldingUnfriendlyId -- return True iff it is definitely a bad
804 :: Id -- idea to export an unfolding that
805 -> Bool -- mentions this Id. Reason: it cannot
806 -- possibly be seen in another module.
808 unfoldingUnfriendlyId id
809 | not (externallyVisibleId id) -- that settles that...
812 unfoldingUnfriendlyId (Id _ _ _ (WorkerId wrapper))
813 = class_thing wrapper
815 -- "class thing": If we're going to use this worker Id in
816 -- an interface, we *have* to be able to untangle the wrapper's
817 -- strictness when reading it back in. At the moment, this
818 -- is not always possible: in precisely those cases where
819 -- we pass tcGenPragmas a "Nothing" for its "ty_maybe".
821 class_thing (Id _ _ _ (SuperDictSelId _ _)) = True
822 class_thing (Id _ _ _ (ClassOpId _ _)) = True
823 class_thing (Id _ _ _ (DefaultMethodId _ _ _)) = True
824 class_thing other = False
826 unfoldingUnfriendlyId (Id _ _ _ (SpecId d@(Id _ _ _ dfun@(DictFunId _ t _)) _ _))
827 -- a SPEC of a DictFunId can end up w/ gratuitous
828 -- TyVar(Templates) in the i/face; only a problem
829 -- if -fshow-pragma-name-errs; but we can do without the pain.
830 -- A HACK in any case (WDP 94/05/02)
831 = --pprTrace "unfriendly1:" (ppCat [ppr PprDebug d, ppr PprDebug t]) (
832 naughty_DictFunId dfun
835 unfoldingUnfriendlyId d@(Id _ _ _ dfun@(DictFunId _ t _))
836 = --pprTrace "unfriendly2:" (ppCat [ppr PprDebug d, ppr PprDebug t]) (
837 naughty_DictFunId dfun -- similar deal...
840 unfoldingUnfriendlyId other_id = False -- is friendly in all other cases
842 naughty_DictFunId :: IdDetails -> Bool
843 -- True <=> has a TyVar(Template) in the "type" part of its "name"
845 naughty_DictFunId (DictFunId _ _ False) = False -- came from outside; must be OK
846 naughty_DictFunId (DictFunId _ ty _)
847 = not (isGroundTy ty)
850 @externallyVisibleId@: is it true that another module might be
851 able to ``see'' this Id?
853 We need the @toplevelishId@ check as well as @isExported@ for when we
854 compile instance declarations in the prelude. @DictFunIds@ are
855 ``exported'' if either their class or tycon is exported, but, in
856 compiling the prelude, the compiler may not recognise that as true.
859 externallyVisibleId :: Id -> Bool
861 externallyVisibleId id@(Id _ _ _ details)
862 = if isLocallyDefined id then
863 toplevelishId id && isExported id && not (weird_datacon details)
865 not (weird_tuplecon details)
866 -- if visible here, it must be visible elsewhere, too.
868 -- If it's a DataCon, it's not enough to know it (meaning
869 -- its TyCon) is exported; we need to know that it might
870 -- be visible outside. Consider:
872 -- data Foo a = Mumble | BigFoo a WeirdLocalType
874 -- We can't tell the outside world *anything* about Foo, because
875 -- of WeirdLocalType; but we need to know this when asked if
876 -- "Mumble" is externally visible...
878 weird_datacon (DataConId _ _ _ _ _ tycon)
879 = maybeToBool (maybePurelyLocalTyCon tycon)
880 weird_datacon not_a_datacon_therefore_not_weird = False
882 weird_tuplecon (TupleConId arity)
883 = arity > 32 -- sigh || isBigTupleTyCon tycon -- generated *purely* for local use
884 weird_tuplecon _ = False
888 idWantsToBeINLINEd :: Id -> Bool
890 idWantsToBeINLINEd id
891 = case (getIdUnfolding id) of
892 IWantToBeINLINEd _ -> True
896 For @unlocaliseId@: See the brief commentary in
897 \tr{simplStg/SimplStg.lhs}.
900 unlocaliseId :: FAST_STRING{-modulename-} -> Id -> Maybe Id
902 unlocaliseId mod (Id u ty info (TopLevId fn))
903 = Just (Id u ty info (TopLevId (unlocaliseFullName fn)))
905 unlocaliseId mod (Id u ty info (LocalId sn no_ftvs))
906 = --false?: ASSERT(no_ftvs)
908 full_name = unlocaliseShortName mod u sn
910 Just (Id u ty info (TopLevId full_name))
912 unlocaliseId mod (Id u ty info (SysLocalId sn no_ftvs))
913 = --false?: on PreludeGlaST: ASSERT(no_ftvs)
915 full_name = unlocaliseShortName mod u sn
917 Just (Id u ty info (TopLevId full_name))
919 unlocaliseId mod (Id u ty info (SpecId unspec ty_maybes no_ftvs))
920 = case unlocalise_parent mod u unspec of
922 Just xx -> Just (Id u ty info (SpecId xx ty_maybes no_ftvs))
924 unlocaliseId mod (Id u ty info (WorkerId unwrkr))
925 = case unlocalise_parent mod u unwrkr of
927 Just xx -> Just (Id u ty info (WorkerId xx))
929 unlocaliseId mod (Id u ty info (InstId inst))
930 = Just (Id u ty info (TopLevId full_name))
931 -- type might be wrong, but it hardly matters
932 -- at this stage (just before printing C) ToDo
934 name = let (bit1:bits) = getInstNamePieces True inst in
935 _CONCAT_ (bit1 : [ _CONS_ '.' b | b <- bits ])
937 full_name = mkFullName mod (mod _APPEND_ name) InventedInThisModule ExportAll mkGeneratedSrcLoc
940 unlocaliseId mod (PodId dim ity id)
941 = case (unlocaliseId mod id) of
942 Just id' -> Just (PodId dim ity id')
944 #endif {- Data Parallel Haskell -}
946 unlocaliseId mod other_id = Nothing
949 -- we have to be Very Careful for workers/specs of
952 unlocalise_parent mod uniq (Id _ ty info (LocalId sn no_ftvs))
953 = --false?: ASSERT(no_ftvs)
955 full_name = unlocaliseShortName mod uniq sn
957 Just (Id uniq ty info (TopLevId full_name))
959 unlocalise_parent mod uniq (Id _ ty info (SysLocalId sn no_ftvs))
960 = --false?: ASSERT(no_ftvs)
962 full_name = unlocaliseShortName mod uniq sn
964 Just (Id uniq ty info (TopLevId full_name))
966 unlocalise_parent mod uniq other_id = unlocaliseId mod other_id
967 -- we're OK otherwise
970 CLAIM (not ASSERTed) for @applyTypeEnvToId@ and @applySubstToId@:
971 `Top-levelish Ids'' cannot have any free type variables, so applying
972 the type-env cannot have any effect. (NB: checked in CoreLint?)
974 The special casing is in @applyTypeEnvToId@, not @apply_to_Id@, as the
975 former ``should be'' the usual crunch point.
978 applyTypeEnvToId :: TypeEnv -> Id -> Id
980 applyTypeEnvToId type_env id@(Id u ty info details)
981 | idHasNoFreeTyVars id
984 = apply_to_Id ( \ ty ->
985 applyTypeEnvToTy type_env ty
990 apply_to_Id :: (UniType -> UniType)
994 apply_to_Id ty_fn (Id u ty info details)
995 = Id u (ty_fn ty) (apply_to_IdInfo ty_fn info) (apply_to_details details)
997 apply_to_details (InstId inst)
999 new_inst = apply_to_Inst ty_fn inst
1003 apply_to_details (SpecId unspec ty_maybes no_ftvs)
1005 new_unspec = apply_to_Id ty_fn unspec
1006 new_maybes = map apply_to_maybe ty_maybes
1008 SpecId new_unspec new_maybes no_ftvs
1009 -- ToDo: recalc no_ftvs????
1011 apply_to_maybe Nothing = Nothing
1012 apply_to_maybe (Just ty) = Just (ty_fn ty)
1014 apply_to_details (WorkerId unwrkr)
1016 new_unwrkr = apply_to_Id ty_fn unwrkr
1021 apply_to_details (PodId d ity id )
1022 = PodId d ity (apply_to_Id ty_fn id)
1023 #endif {- Data Parallel Haskell -}
1025 apply_to_details other = other
1028 Sadly, I don't think the one using the magic typechecker substitution
1029 can be done with @apply_to_Id@. Here we go....
1031 Strictness is very important here. We can't leave behind thunks
1032 with pointers to the substitution: it {\em must} be single-threaded.
1035 applySubstToId :: Subst -> Id -> (Subst, Id)
1037 applySubstToId subst id@(Id u ty info details)
1038 -- *cannot* have a "idHasNoFreeTyVars" get-out clause
1039 -- because, in the typechecker, we are still
1040 -- *concocting* the types.
1041 = case (applySubstToTy subst ty) of { (s2, new_ty) ->
1042 case (applySubstToIdInfo s2 info) of { (s3, new_info) ->
1043 case (apply_to_details s3 new_ty details) of { (s4, new_details) ->
1044 (s4, Id u new_ty new_info new_details) }}}
1046 apply_to_details subst _ (InstId inst)
1047 = case (applySubstToInst subst inst) of { (s2, new_inst) ->
1048 (s2, InstId new_inst) }
1050 apply_to_details subst new_ty (SpecId unspec ty_maybes _)
1051 = case (applySubstToId subst unspec) of { (s2, new_unspec) ->
1052 case (mapAccumL apply_to_maybe s2 ty_maybes) of { (s3, new_maybes) ->
1053 (s3, SpecId new_unspec new_maybes (no_free_tvs new_ty)) }}
1054 -- NB: recalc no_ftvs (I think it's necessary (?) WDP 95/04)
1056 apply_to_maybe subst Nothing = (subst, Nothing)
1057 apply_to_maybe subst (Just ty)
1058 = case (applySubstToTy subst ty) of { (s2, new_ty) ->
1061 apply_to_details subst _ (WorkerId unwrkr)
1062 = case (applySubstToId subst unwrkr) of { (s2, new_unwrkr) ->
1063 (s2, WorkerId new_unwrkr) }
1065 apply_to_details subst _ other = (subst, other)
1068 applySubstToId (PodId d ity id )
1069 = ???? ToDo:DPH; not sure what! returnLft (PodId d ity (applySubstToId id))
1070 #endif {- Data Parallel Haskell -}
1074 getIdNamePieces :: Bool {-show Uniques-} -> Id -> [FAST_STRING]
1076 getIdNamePieces show_uniqs (Id u ty info details)
1078 DataConId n _ _ _ _ _ ->
1079 case (getOrigName n) of { (mod, name) ->
1080 if fromPrelude mod then [name] else [mod, name] }
1082 TupleConId a -> [SLIT("Tup") _APPEND_ (_PK_ (show a))]
1084 ImportedId n -> get_fullname_pieces n
1085 PreludeId n -> get_fullname_pieces n
1086 TopLevId n -> get_fullname_pieces n
1088 SuperDictSelId c sc ->
1089 case (getOrigName c) of { (c_mod, c_name) ->
1090 case (getOrigName sc) of { (sc_mod, sc_name) ->
1092 c_bits = if fromPreludeCore c
1094 else [c_mod, c_name]
1096 sc_bits= if fromPreludeCore sc
1098 else [sc_mod, sc_name]
1100 [SLIT("sdsel")] ++ c_bits ++ sc_bits }}
1102 ClassOpId clas op ->
1103 case (getOrigName clas) of { (c_mod, c_name) ->
1104 case (getClassOpString op) of { op_name ->
1105 if fromPreludeCore clas then [op_name] else [c_mod, c_name, op_name]
1108 DefaultMethodId clas op _ ->
1109 case (getOrigName clas) of { (c_mod, c_name) ->
1110 case (getClassOpString op) of { op_name ->
1111 if fromPreludeCore clas
1112 then [SLIT("defm"), op_name]
1113 else [SLIT("defm"), c_mod, c_name, op_name] }}
1116 case (getOrigName c) of { (c_mod, c_name) ->
1118 c_bits = if fromPreludeCore c
1120 else [c_mod, c_name]
1122 ty_bits = getTypeString ty
1124 [SLIT("dfun")] ++ c_bits ++ ty_bits }
1127 ConstMethodId c ty o _ ->
1128 case (getOrigName c) of { (c_mod, c_name) ->
1129 case (getTypeString ty) of { ty_bits ->
1130 case (getClassOpString o) of { o_name ->
1131 case (if fromPreludeCore c
1133 else [c_mod, c_name]) of { c_bits ->
1134 [SLIT("const")] ++ c_bits ++ ty_bits ++ [o_name] }}}}
1136 -- if the unspecialised equiv is "top-level",
1137 -- the name must be concocted from its name and the
1138 -- names of the types to which specialised...
1140 SpecId unspec ty_maybes _ ->
1141 getIdNamePieces show_uniqs unspec ++ (
1142 if not (toplevelishId unspec)
1144 else concat (map typeMaybeString ty_maybes)
1148 getIdNamePieces show_uniqs unwrkr ++ (
1149 if not (toplevelishId unwrkr)
1151 else [SLIT("wrk")] -- show u
1154 InstId inst -> getInstNamePieces show_uniqs inst
1155 LocalId n _ -> let local = getLocalName n in
1156 if show_uniqs then [local, showUnique u] else [local]
1157 SysLocalId n _ -> [getLocalName n, showUnique u]
1158 SpecPragmaId n _ _ -> [getLocalName n, showUnique u]
1161 ProcessorCon a _ -> ["MkProcessor" ++ (show a)]
1162 PodId n ity id -> getIdNamePieces show_uniqs id ++
1163 ["mapped", "POD" ++ (show n), show ity]
1164 #endif {- Data Parallel Haskell -}
1166 get_fullname_pieces :: FullName -> [FAST_STRING]
1167 get_fullname_pieces n
1168 = BIND (getOrigName n) _TO_ (mod, name) ->
1175 Really Inst-ish, but only used in this module...
1177 getInstNamePieces :: Bool -> Inst -> [FAST_STRING]
1179 getInstNamePieces show_uniqs (Dict u clas ty _)
1180 = let (mod, nm) = getOrigName clas in
1181 if fromPreludeCore clas
1182 then [SLIT("d"), nm, showUnique u]
1183 else [SLIT("d"), mod, nm, showUnique u]
1185 getInstNamePieces show_uniqs (Method u id tys _)
1186 = let local = getIdNamePieces show_uniqs id in
1187 if show_uniqs then local ++ [showUnique u] else local
1189 getInstNamePieces show_uniqs (LitInst u _ _ _) = [SLIT("lit"), showUnique u]
1192 %************************************************************************
1194 \subsection[Id-type-funs]{Type-related @Id@ functions}
1196 %************************************************************************
1199 getIdUniType :: Id -> UniType
1201 getIdUniType (Id _ ty _ _) = ty
1205 getIdUniType (ProcessorCon _ ty) = ty
1206 getIdUniType (PodId d ity id)
1207 = let (foralls,rho) = splitForalls (getIdUniType id) in
1208 let tys = get_args rho in
1209 let itys_mask = infoTypeNumToMask ity in
1210 let tys' = zipWith convert tys itys_mask in
1211 mkForallTy foralls (foldr1 mkFunTy tys')
1212 where -- ToDo(hilly) change to use getSourceType etc...
1214 get_args ty = case (maybeUnpackFunTy ty) of
1216 Just (arg,res) -> arg:get_args res
1218 convert ty cond = if cond
1222 coerce ty = case (maybeUnpackFunTy ty) of
1223 Nothing ->mkPodizedPodNTy d ty
1224 Just (arg,res) ->mkFunTy (coerce arg) (coerce res)
1225 #endif {- Data Parallel Haskell -}
1229 getMentionedTyConsAndClassesFromId :: Id -> (Bag TyCon, Bag Class)
1231 getMentionedTyConsAndClassesFromId id
1232 = getMentionedTyConsAndClassesFromUniType (getIdUniType id)
1236 getIdKind i = kindFromType (getIdUniType i)
1241 getIdTauType :: Id -> TauType
1242 getIdTauType i = expandTySyn (getTauType (getIdUniType i))
1244 getIdSourceTypes :: Id -> [TauType]
1245 getIdSourceTypes i = map expandTySyn (sourceTypes (getTauType (getIdUniType i)))
1247 getIdTargetType :: Id -> TauType
1248 getIdTargetType i = expandTySyn (targetType (getTauType (getIdUniType i)))
1252 %************************************************************************
1254 \subsection[Id-overloading]{Functions related to overloading}
1256 %************************************************************************
1259 mkSuperDictSelId u c sc ty info = Id u ty info (SuperDictSelId c sc)
1260 mkClassOpId u c op ty info = Id u ty info (ClassOpId c op)
1261 mkDefaultMethodId u c op gen ty info = Id u ty info (DefaultMethodId c op gen)
1263 mkDictFunId u c ity full_ty from_here info
1264 = Id u full_ty info (DictFunId c ity from_here)
1266 mkConstMethodId u c op ity full_ty from_here info
1267 = Id u full_ty info (ConstMethodId c ity op from_here)
1269 mkWorkerId u unwrkr ty info = Id u ty info (WorkerId unwrkr)
1272 = Id u (getInstUniType inst) noIdInfo (InstId inst)
1276 Method u i ts o -> u
1277 LitInst u l ty o -> u
1280 getSuperDictSelIdSig (Id _ _ _ (SuperDictSelId input_class result_class))
1281 = (input_class, result_class)
1285 %************************************************************************
1287 \subsection[local-funs]{@LocalId@-related functions}
1289 %************************************************************************
1292 mkImported u n ty info = Id u ty info (ImportedId n)
1293 mkPreludeId u n ty info = Id u ty info (PreludeId n)
1296 mkPodId d i = PodId d i
1299 updateIdType :: Id -> UniType -> Id
1300 updateIdType (Id u _ info details) ty = Id u ty info details
1304 no_free_tvs ty = null (extractTyVarsFromTy ty)
1306 -- SysLocal: for an Id being created by the compiler out of thin air...
1307 -- UserLocal: an Id with a name the user might recognize...
1308 mkSysLocal, mkUserLocal :: FAST_STRING -> Unique -> UniType -> SrcLoc -> Id
1310 mkSysLocal str uniq ty loc
1311 = Id uniq ty noIdInfo (SysLocalId (mkShortName str loc) (no_free_tvs ty))
1313 mkUserLocal str uniq ty loc
1314 = Id uniq ty noIdInfo (LocalId (mkShortName str loc) (no_free_tvs ty))
1316 -- for an SpecPragmaId being created by the compiler out of thin air...
1317 mkSpecPragmaId :: FAST_STRING -> Unique -> UniType -> Maybe SpecInfo -> SrcLoc -> Id
1318 mkSpecPragmaId str uniq ty specinfo loc
1319 = Id uniq ty noIdInfo (SpecPragmaId (mkShortName str loc) specinfo (no_free_tvs ty))
1322 mkSpecId u unspec ty_maybes ty info
1323 = ASSERT(not (maybeToBool (isSpecId_maybe unspec)))
1324 Id u ty info (SpecId unspec ty_maybes (no_free_tvs ty))
1326 -- Specialised version of constructor: only used in STG and code generation
1327 -- Note: The specialsied Id has the same unique as the unspeced Id
1329 mkSameSpecCon ty_maybes unspec@(Id u ty info details)
1330 = ASSERT(isDataCon unspec)
1331 ASSERT(not (maybeToBool (isSpecId_maybe unspec)))
1332 Id u new_ty info (SpecId unspec ty_maybes (no_free_tvs new_ty))
1334 new_ty = specialiseTy ty ty_maybes 0
1336 -- pprTrace "SameSpecCon:Unique:"
1337 -- (ppSep (ppr PprDebug unspec: [pprMaybeTy PprDebug ty | ty <- ty_maybes]))
1339 -- mkId builds a local or top-level Id, depending on the name given
1340 mkId :: Name -> UniType -> IdInfo -> Id
1341 mkId (Short uniq short) ty info = Id uniq ty info (LocalId short (no_free_tvs ty))
1342 mkId (OtherTopId uniq full) ty info
1344 (if isLocallyDefined full then TopLevId full else ImportedId full)
1346 localiseId :: Id -> Id
1347 localiseId id@(Id u ty info details)
1348 = Id u ty info (LocalId (mkShortName name loc) (no_free_tvs ty))
1350 name = getOccurrenceName id
1353 -- this has to be one of the "local" flavours (LocalId, SysLocalId, InstId)
1354 -- ToDo: it does??? WDP
1355 mkIdWithNewUniq :: Id -> Unique -> Id
1357 mkIdWithNewUniq (Id _ ty info details) uniq
1361 InstId (Dict _ c t o) -> InstId (Dict uniq c t o)
1362 InstId (Method _ i ts o) -> InstId (Method uniq i ts o)
1363 InstId (LitInst _ l ty o) -> InstId (LitInst uniq l ty o)
1364 old_details -> old_details
1366 Id uniq ty info new_details
1369 mkIdWithNewUniq (PodId d t id) uniq = PodId d t (mkIdWithNewUniq id uniq)
1370 #endif {- Data Parallel Haskell -}
1373 Make some local @Ids@ for a template @CoreExpr@. These have bogus
1374 @Uniques@, but that's OK because the templates are supposed to be
1375 instantiated before use.
1377 mkTemplateLocals :: [UniType] -> [Id]
1378 mkTemplateLocals tys
1379 = zipWith (\ u -> \ ty -> mkSysLocal SLIT("tpl") u ty mkUnknownSrcLoc)
1380 (getBuiltinUniques (length tys))
1385 getIdInfo :: Id -> IdInfo
1387 getIdInfo (Id _ _ info _) = info
1390 getIdInfo (PodId _ _ id) = getIdInfo id
1391 #endif {- Data Parallel Haskell -}
1393 replaceIdInfo :: Id -> IdInfo -> Id
1395 replaceIdInfo (Id u ty _ details) info = Id u ty info details
1398 replaceIdInfo (PodId dim ity id) info = PodId dim ity (replaceIdInfo id info)
1399 #endif {- Data Parallel Haskell -}
1402 %************************************************************************
1404 \subsection[Id-arities]{Arity-related functions}
1406 %************************************************************************
1408 For locally-defined Ids, the code generator maintains its own notion
1409 of their arities; so it should not be asking... (but other things
1410 besides the code-generator need arity info!)
1413 getIdArity :: Id -> ArityInfo
1414 getDataConArity :: DataCon -> Int -- a simpler i/face; they always have arities
1417 getIdArity (ProcessorCon n _) = mkArityInfo n
1418 getIdArity (PodId _ _ id) = getIdArity id
1419 #endif {- Data Parallel Haskell -}
1421 getIdArity (Id _ _ id_info _) = getInfo id_info
1423 getDataConArity id@(Id _ _ id_info _)
1424 = ASSERT(isDataCon id)
1425 case (arityMaybe (getInfo id_info)) of
1426 Nothing -> pprPanic "getDataConArity:Nothing:" (ppr PprDebug id)
1429 addIdArity :: Id -> Int -> Id
1430 addIdArity (Id u ty info details) arity
1431 = Id u ty (info `addInfo` (mkArityInfo arity)) details
1434 %************************************************************************
1436 \subsection[constructor-funs]{@DataCon@-related functions (incl.~tuples)}
1438 %************************************************************************
1441 mkDataCon :: Unique{-DataConKey-} -> FullName -> [TyVarTemplate] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id
1442 -- can get the tag and all the pieces of the type from the UniType
1444 mkDataCon k n tyvar_tmpls context args_tys tycon specenv = data_con
1446 data_con = Id k type_of_constructor datacon_info
1448 (position_within fIRST_TAG data_con_family data_con)
1449 tyvar_tmpls context args_tys tycon)
1451 -- Note data_con self-recursion;
1452 -- should be OK as tags are not looked at until
1453 -- late in the game.
1455 data_con_family = getTyConDataCons tycon
1457 position_within :: Int -> [Id] -> Id -> Int
1458 position_within acc [] con
1459 = panic "mkDataCon: con not found in family"
1461 position_within acc (c:cs) con
1462 = if c `eqId` con then acc else position_within (acc+(1::Int)) cs con
1464 type_of_constructor = mkSigmaTy tyvar_tmpls context
1467 (applyTyCon tycon (map mkTyVarTemplateTy tyvar_tmpls)))
1469 datacon_info = noIdInfo `addInfo_UF` unfolding
1470 `addInfo` mkArityInfo arity
1473 arity = length args_tys
1478 -- else -- do some business...
1480 (tyvars, dict_vars, vars) = mk_uf_bits tyvar_tmpls context args_tys tycon
1481 tyvar_tys = map mkTyVarTy tyvars
1483 BIND (CoCon data_con tyvar_tys [CoVarAtom v | v <- vars]) _TO_ plain_CoCon ->
1485 BIND (mkCoLam (dict_vars ++ vars) plain_CoCon) _TO_ lambdized_CoCon ->
1487 mkUnfolding EssentialUnfolding -- for data constructors
1488 (foldr CoTyLam lambdized_CoCon tyvars)
1491 mk_uf_bits tyvar_tmpls context arg_tys tycon
1493 (inst_env, tyvars, tyvar_tys)
1494 = instantiateTyVarTemplates tyvar_tmpls
1495 (map getTheUnique tyvar_tmpls)
1497 -- the "context" and "arg_tys" have TyVarTemplates in them, so
1498 -- we instantiate those types to have the right TyVars in them
1500 BIND (map (instantiateTauTy inst_env) (map ctxt_ty context))
1501 _TO_ inst_dict_tys ->
1502 BIND (map (instantiateTauTy inst_env) arg_tys) _TO_ inst_arg_tys ->
1504 -- We can only have **ONE** call to mkTemplateLocals here;
1505 -- otherwise, we get two blobs of locals w/ mixed-up Uniques
1506 -- (Mega-Sigh) [ToDo]
1507 BIND (mkTemplateLocals (inst_dict_tys ++ inst_arg_tys)) _TO_ all_vars ->
1509 BIND (splitAt (length context) all_vars) _TO_ (dict_vars, vars) ->
1511 (tyvars, dict_vars, vars)
1514 -- these are really dubious UniTypes, but they are only to make the
1515 -- binders for the lambdas for tossed-away dicts.
1516 ctxt_ty (clas, ty) = mkDictTy clas ty
1520 mkTupleCon :: Arity -> Id
1522 mkTupleCon arity = data_con
1524 data_con = Id unique ty tuplecon_info (TupleConId arity)
1525 unique = mkTupleDataConUnique arity
1526 ty = mkSigmaTy tyvars [] (glueTyArgs tyvar_tys (applyTyCon tycon tyvar_tys))
1527 tycon = mkTupleTyCon arity
1528 tyvars = take arity alphaTyVars
1529 tyvar_tys = map mkTyVarTemplateTy tyvars
1532 = noIdInfo `addInfo_UF` unfolding
1533 `addInfo` mkArityInfo arity
1534 `addInfo` tuplecon_specenv
1537 = if arity == 2 then
1538 pcGenerateDataSpecs ty
1545 -- else -- do some business...
1547 (tyvars, dict_vars, vars) = mk_uf_bits arity
1548 tyvar_tys = map mkTyVarTy tyvars
1550 BIND (CoCon data_con tyvar_tys [CoVarAtom v | v <- vars]) _TO_ plain_CoCon ->
1552 BIND (mkCoLam (dict_vars ++ vars) plain_CoCon) _TO_ lambdized_CoCon ->
1555 EssentialUnfolding -- data constructors
1556 (foldr CoTyLam lambdized_CoCon tyvars)
1560 = BIND (mkTemplateLocals tyvar_tys) _TO_ vars ->
1564 tyvar_tmpls = take arity alphaTyVars
1565 (_, tyvars, tyvar_tys) = instantiateTyVarTemplates tyvar_tmpls (map getTheUnique tyvar_tmpls)
1569 mkProcessorCon :: Arity -> Id
1570 mkProcessorCon arity
1571 = ProcessorCon arity ty
1573 ty = mkSigmaTy tyvars [] (glueTyArgs tyvar_tys (applyTyCon tycon tyvar_tys))
1574 tycon = mkProcessorTyCon arity
1575 tyvars = take arity alphaTyVars
1576 tyvar_tys = map mkTyVarTemplateTy tyvars
1577 #endif {- Data Parallel Haskell -}
1580 fIRST_TAG = 1 -- Tags allocated from here for real constructors
1582 -- given one data constructor in a family, return a list
1583 -- of all the data constructors in that family.
1586 getDataConFamily :: DataCon -> [DataCon]
1588 getDataConFamily data_con
1589 = ASSERT(isDataCon data_con)
1590 getTyConDataCons (getDataConTyCon data_con)
1595 getDataConTag :: DataCon -> ConTag -- will panic if not a DataCon
1597 getDataConTag (Id _ _ _ (DataConId _ tag _ _ _ _)) = tag
1598 getDataConTag (Id _ _ _ (TupleConId _)) = fIRST_TAG
1599 getDataConTag (Id _ _ _ (SpecId unspec _ _)) = getDataConTag unspec
1601 getDataConTag (ProcessorCon _ _) = fIRST_TAG
1602 #endif {- Data Parallel Haskell -}
1604 getDataConTyCon :: DataCon -> TyCon -- will panic if not a DataCon
1606 getDataConTyCon (Id _ _ _ (DataConId _ _ _ _ _ tycon)) = tycon
1607 getDataConTyCon (Id _ _ _ (TupleConId a)) = mkTupleTyCon a
1608 getDataConTyCon (Id _ _ _ (SpecId unspec tys _)) = mkSpecTyCon (getDataConTyCon unspec) tys
1610 getDataConTyCon (ProcessorCon a _) = mkProcessorTyCon a
1611 #endif {- Data Parallel Haskell -}
1613 getDataConSig :: DataCon -> ([TyVarTemplate], ThetaType, [TauType], TyCon)
1614 -- will panic if not a DataCon
1616 getDataConSig (Id _ _ _ (DataConId _ _ tyvars theta_ty arg_tys tycon))
1617 = (tyvars, theta_ty, arg_tys, tycon)
1619 getDataConSig (Id _ _ _ (TupleConId arity))
1620 = (tyvars, [], tyvar_tys, mkTupleTyCon arity)
1622 tyvars = take arity alphaTyVars
1623 tyvar_tys = map mkTyVarTemplateTy tyvars
1625 getDataConSig (Id _ _ _ (SpecId unspec ty_maybes _))
1626 = (spec_tyvars, spec_theta_ty, spec_arg_tys, spec_tycon)
1628 (tyvars, theta_ty, arg_tys, tycon) = getDataConSig unspec
1630 ty_env = tyvars `zip` ty_maybes
1632 spec_tyvars = foldr nothing_tyvars [] ty_env
1633 nothing_tyvars (tyvar, Nothing) l = tyvar : l
1634 nothing_tyvars (tyvar, Just ty) l = l
1636 spec_env = foldr just_env [] ty_env
1637 just_env (tyvar, Nothing) l = l
1638 just_env (tyvar, Just ty) l = (tyvar, ty) : l
1639 spec_arg_tys = map (instantiateTauTy spec_env) arg_tys
1641 spec_theta_ty = if null theta_ty then []
1642 else panic "getDataConSig:ThetaTy:SpecDataCon"
1643 spec_tycon = mkSpecTyCon tycon ty_maybes
1646 getDataConSig (ProcessorCon arity _)
1647 = (tyvars, [], tyvar_tys, mkProcessorTyCon arity)
1649 tyvars = take arity alphaTyVars
1650 tyvar_tys = map mkTyVarTemplateTy tyvars
1651 #endif {- Data Parallel Haskell -}
1654 @getInstantiatedDataConSig@ takes a constructor and some types to which
1655 it is applied; it returns its signature instantiated to these types.
1658 getInstantiatedDataConSig ::
1659 DataCon -- The data constructor
1660 -- Not a specialised data constructor
1661 -> [TauType] -- Types to which applied
1662 -- Must be fully applied i.e. contain all types of tycon
1663 -> ([TauType], -- Types of dict args
1664 [TauType], -- Types of regular args
1665 TauType -- Type of result
1668 getInstantiatedDataConSig data_con tycon_arg_tys
1669 = ASSERT(isDataCon data_con)
1670 --false?? WDP 95/06: ASSERT(not (maybeToBool (isSpecId_maybe data_con)))
1672 (tv_tmpls, theta, cmpnt_ty_tmpls, tycon) = getDataConSig data_con
1674 inst_env = --ASSERT(length tv_tmpls == length tycon_arg_tys)
1675 {- if (length tv_tmpls /= length tycon_arg_tys) then
1676 pprPanic "Id:1666:" (ppCat [ppr PprShowAll data_con, ppr PprDebug tycon_arg_tys])
1678 -} tv_tmpls `zip` tycon_arg_tys
1680 theta_tys = [ instantiateTauTy inst_env (mkDictTy c t) | (c,t) <- theta ]
1681 cmpnt_tys = map (instantiateTauTy inst_env) cmpnt_ty_tmpls
1682 result_ty = instantiateTauTy inst_env (applyTyCon tycon tycon_arg_tys)
1684 -- Are the first/third results ever used?
1685 (theta_tys, cmpnt_tys, result_ty)
1687 {- UNUSED: allows a specilaised constructor to be instantiated
1688 (with all argument types of the unspecialsied tycon)
1690 getInstantiatedDataConSig data_con tycon_arg_tys
1691 = ASSERT(isDataCon data_con)
1692 if is_speccon && arg_tys_match_error then
1693 pprPanic "getInstantiatedDataConSig:SpecId:"
1694 (ppHang (ppr PprDebug data_con) 4 pp_match_error)
1696 (theta_tys, cmpnt_tys, result_ty) -- Are the first/third results ever used?
1698 is_speccon = maybeToBool is_speccon_maybe
1699 is_speccon_maybe = isSpecId_maybe data_con
1700 Just (unspec_con, spec_tys) = is_speccon_maybe
1702 arg_tys_match_error = maybeToBool match_error_maybe
1703 match_error_maybe = ASSERT(length spec_tys == length tycon_arg_tys)
1704 argTysMatchSpecTys spec_tys tycon_arg_tys
1705 (Just pp_match_error) = match_error_maybe
1707 (tv_tmpls, theta, cmpnt_ty_tmpls, tycon)
1709 then getDataConSig unspec_con
1710 else getDataConSig data_con
1712 inst_env = ASSERT(length tv_tmpls == length tycon_arg_tys)
1713 tv_tmpls `zip` tycon_arg_tys
1715 theta_tys = [ instantiateTauTy inst_env (mkDictTy c t) | (c,t) <- theta ]
1716 cmpnt_tys = map (instantiateTauTy inst_env) cmpnt_ty_tmpls
1717 result_ty = instantiateTauTy inst_env (applyTyCon tycon tycon_arg_tys)
1721 The function @getDataConDeps@ is passed an @Id@ representing a data
1722 constructor of some type. We look at the source types of the
1723 constructor and create the set of all @TyCons@ referred to directly
1724 from the source types.
1727 #ifdef USE_SEMANTIQUE_STRANAL
1728 getDataConDeps :: Id -> [TyCon]
1730 getDataConDeps (Id _ _ _ (DataConId _ _ _ _ arg_tys _))
1731 = concat (map getReferredToTyCons arg_tys)
1732 getDataConDeps (Id _ _ _ (TupleConId _)) = []
1733 getDataConDeps (Id _ _ _ (SpecId unspec ty_maybes _))
1734 = getDataConDeps unspec ++ concat (map getReferredToTyCons (catMaybes ty_maybes))
1736 getDataConDeps (ProcessorCon _ _) = []
1737 #endif {- Data Parallel Haskell -}
1738 #endif {- Semantique strictness analyser -}
1741 Data type declarations are of the form:
1743 data Foo a b = C1 ... | C2 ... | ... | Cn ...
1745 For each constructor @Ci@, we want to generate a curried function; so, e.g., for
1746 @C1 x y z@, we want a function binding:
1748 fun_C1 = /\ a -> /\ b -> \ [x, y, z] -> CoCon C1 [a, b] [x, y, z]
1750 Notice the ``big lambdas'' and type arguments to @CoCon@---we are producing
1751 2nd-order polymorphic lambda calculus with explicit types.
1753 %************************************************************************
1755 \subsection[unfolding-Ids]{Functions related to @Ids@' unfoldings}
1757 %************************************************************************
1759 @getIdUnfolding@ takes a @Id@ (we are discussing the @DataCon@ case)
1760 and generates an @UnfoldingDetails@ for its unfolding. The @Ids@ and
1761 @TyVars@ don't really have to be new, because we are only producing a
1764 ToDo: what if @DataConId@'s type has a context (haven't thought about it
1767 Note: @getDataConUnfolding@ is a ``poor man's'' version---it is NOT
1768 EXPORTED. It just returns the binders (@TyVars@ and @Ids@) [in the
1769 example above: a, b, and x, y, z], which is enough (in the important
1770 \tr{DsExpr} case). (The middle set of @Ids@ is binders for any
1771 dictionaries, in the even of an overloaded data-constructor---none at
1775 getIdUnfolding :: Id -> UnfoldingDetails
1778 getIdUnfolding dcon@(ProcessorCon arity _)
1780 (tyvars, dict_vars, vars) = getDataConUnfolding dcon
1781 tyvar_tys = map mkTyVarTy tyvars
1783 BIND (CoCon dcon tyvar_tys [CoVarAtom v | v <- vars]) _TO_ plain_CoCon ->
1784 BIND (mkCoLam vars plain_CoCon) _TO_ lambdized_CoCon ->
1785 mkUnfoldTemplate (\x->False){-ToDo-} EssentialUnfolding{-ToDo???DPH-} (foldr CoTyLam lambdized_CoCon tyvars)
1788 -- If we have a PodId whose ``id'' has an unfolding, then we need to
1789 -- parallelize the unfolded expression for the d^th dimension.
1791 getIdUnfolding (PodId d _ id)
1792 = case (unfoldingMaybe (getIdUnfolding id)) of
1794 Just expr -> trace ("getIdUnfolding ("++
1795 ppShow 80 (ppr PprDebug id) ++
1796 ") for " ++ show d ++ "D pod")
1797 (podizeTemplateExpr d expr)
1799 #endif {- Data Parallel Haskell -}
1801 getIdUnfolding (Id _ _ id_info _) = getInfo_UF id_info
1803 addIdUnfolding :: Id -> UnfoldingDetails -> Id
1804 addIdUnfolding id@(Id u ty info details) unfold_details
1806 case (isLocallyDefined id, unfold_details) of
1807 (_, NoUnfoldingDetails) -> True
1808 (True, IWantToBeINLINEd _) -> True
1809 (False, IWantToBeINLINEd _) -> False -- v bad
1813 Id u ty (info `addInfo_UF` unfold_details) details
1816 clearIdUnfolding :: Id -> Id
1817 clearIdUnfolding (Id u ty info details) = Id u ty (clearInfo_UF info) details
1821 In generating selector functions (take a dictionary, give back one
1822 component...), we need to what out for the nothing-to-select cases (in
1823 which case the ``selector'' is just an identity function):
1825 class Eq a => Foo a { } # the superdict selector for "Eq"
1827 class Foo a { op :: Complex b => c -> b -> a }
1828 # the method selector for "op";
1829 # note local polymorphism...
1832 For data constructors, we make an unfolding which has a bunch of
1833 lambdas to bind the arguments, with a (saturated) @CoCon@ inside. In
1834 the case of overloaded constructors, the dictionaries are just thrown
1835 away; they were only required in the first place to ensure that the
1836 type was indeed an instance of the required class.
1839 getDataConUnfolding :: Id -> ([TyVar], [Id], [Id])
1841 getDataConUnfolding dcon@(ProcessorCon arity _)
1842 = BIND (mkTemplateLocals tyvar_tys) _TO_ vars ->
1846 tyvar_tmpls = take arity alphaTyVars
1847 (_, tyvars, tyvar_tys) = instantiateTyVarTemplates tyvar_tmpls (map getTheUnique tyvar_tmpls)
1848 #endif {- Data Parallel Haskell -}
1851 %************************************************************************
1853 \subsection[IdInfo-funs]{Functions related to @Ids@' @IdInfos@}
1855 %************************************************************************
1858 getIdDemandInfo :: Id -> DemandInfo
1859 getIdDemandInfo (Id _ _ info _) = getInfo info
1861 addIdDemandInfo :: Id -> DemandInfo -> Id
1862 addIdDemandInfo (Id u ty info details) demand_info
1863 = Id u ty (info `addInfo` demand_info) details
1867 getIdUpdateInfo :: Id -> UpdateInfo
1868 getIdUpdateInfo (Id u ty info details) = getInfo info
1870 addIdUpdateInfo :: Id -> UpdateInfo -> Id
1871 addIdUpdateInfo (Id u ty info details) upd_info
1872 = Id u ty (info `addInfo` upd_info) details
1876 getIdArgUsageInfo :: Id -> ArgUsageInfo
1877 getIdArgUsageInfo (Id u ty info details) = getInfo info
1879 addIdArgUsageInfo :: Id -> ArgUsageInfo -> Id
1880 addIdArgUsageInfo (Id u ty info details) au_info
1881 = Id u ty (info `addInfo` au_info) details
1885 getIdFBTypeInfo :: Id -> FBTypeInfo
1886 getIdFBTypeInfo (Id u ty info details) = getInfo info
1888 addIdFBTypeInfo :: Id -> FBTypeInfo -> Id
1889 addIdFBTypeInfo (Id u ty info details) upd_info
1890 = Id u ty (info `addInfo` upd_info) details
1894 getIdSpecialisation :: Id -> SpecEnv
1895 getIdSpecialisation (Id _ _ info _) = getInfo info
1897 addIdSpecialisation :: Id -> SpecEnv -> Id
1898 addIdSpecialisation (Id u ty info details) spec_info
1899 = Id u ty (info `addInfo` spec_info) details
1902 Strictness: we snaffle the info out of the IdInfo.
1905 getIdStrictness :: Id -> StrictnessInfo
1907 getIdStrictness (Id _ _ id_info _) = getInfo id_info
1909 addIdStrictness :: Id -> StrictnessInfo -> Id
1911 addIdStrictness (Id u ty info details) strict_info
1912 = Id u ty (info `addInfo` strict_info) details
1915 %************************************************************************
1917 \subsection[Id-comparison]{Comparison functions for @Id@s}
1919 %************************************************************************
1921 Comparison: equality and ordering---this stuff gets {\em hammered}.
1924 cmpId (Id u1 _ _ _) (Id u2 _ _ _) = cmpUnique u1 u2
1925 -- short and very sweet
1929 eqId :: Id -> Id -> Bool
1931 eqId a b = case cmpId a b of { EQ_ -> True; _ -> False }
1933 instance Eq Id where
1934 a == b = case cmpId a b of { EQ_ -> True; _ -> False }
1935 a /= b = case cmpId a b of { EQ_ -> False; _ -> True }
1937 instance Ord Id where
1938 a <= b = case cmpId a b of { LT_ -> True; EQ_ -> True; GT__ -> False }
1939 a < b = case cmpId a b of { LT_ -> True; EQ_ -> False; GT__ -> False }
1940 a >= b = case cmpId a b of { LT_ -> False; EQ_ -> True; GT__ -> True }
1941 a > b = case cmpId a b of { LT_ -> False; EQ_ -> False; GT__ -> True }
1942 #ifdef __GLASGOW_HASKELL__
1943 _tagCmp a b = case cmpId a b of { LT_ -> _LT; EQ_ -> _EQ; GT__ -> _GT }
1947 @cmpId_withSpecDataCon@ ensures that any spectys are taken into
1948 account when comparing two data constructors. We need to do this
1949 because a specialsied data constructor has the same unique as its
1950 unspeciailsed counterpart.
1953 cmpId_withSpecDataCon :: Id -> Id -> TAG_
1955 cmpId_withSpecDataCon id1 id2
1956 | eq_ids && isDataCon id1 && isDataCon id2
1957 = cmpEqDataCon id1 id2
1962 cmp_ids = cmpId id1 id2
1963 eq_ids = case cmp_ids of { EQ_ -> True; other -> False }
1965 cmpEqDataCon (Id _ _ _ (SpecId _ mtys1 _)) (Id _ _ _ (SpecId _ mtys2 _))
1966 = cmpUniTypeMaybeList mtys1 mtys2
1968 cmpEqDataCon unspec1 (Id _ _ _ (SpecId _ _ _))
1971 cmpEqDataCon (Id _ _ _ (SpecId _ _ _)) unspec2
1974 cmpEqDataCon unspec1 unspec2
1979 %************************************************************************
1981 \subsection[Id-other-instances]{Other instance declarations for @Id@s}
1983 %************************************************************************
1986 instance Outputable Id where
1987 ppr sty id = pprId sty id
1989 showId :: PprStyle -> Id -> String
1990 showId sty id = ppShow 80 (pprId sty id)
1993 -- for DictFuns (instances) and const methods (instance code bits we
1994 -- can call directly): exported (a) if *either* the class or
1995 -- ***OUTERMOST*** tycon [arbitrary...] is exported; or (b) *both*
1996 -- class and tycon are from PreludeCore [non-std, but convenient]
1997 -- *and* the thing was defined in this module.
1999 instance_export_flag :: Class -> UniType -> Bool -> ExportFlag
2001 instance_export_flag clas inst_ty from_here
2002 = if instanceIsExported clas inst_ty from_here
2007 Do we consider an ``instance type'' (as on a @DictFunId@) to be ``from
2008 PreludeCore''? True if the outermost TyCon is fromPreludeCore.
2010 is_prelude_core_ty :: UniType -> Bool
2012 is_prelude_core_ty inst_ty
2013 = case getUniDataTyCon_maybe inst_ty of
2014 Just (tycon,_,_) -> fromPreludeCore tycon
2015 Nothing -> panic "Id: is_prelude_core_ty"
2018 Default printing code (not used for interfaces):
2020 pprId :: PprStyle -> Id -> Pretty
2024 pieces = getIdNamePieces (case other_sty of {PprForUser -> False; _ -> True}) id
2028 pieces_to_print -- maybe use Unique only
2029 = if isSysLocalId id then tail pieces else pieces
2031 ppIntersperse (ppPStr cSEP) (map identToC pieces_to_print)
2034 PprForC _ -> for_code
2035 PprForAsm _ _ _ -> for_code
2036 PprInterface _ -> ppPStr occur_name
2037 PprForUser -> ppPStr occur_name
2038 PprUnfolding _ -> qualified_name pieces
2039 PprDebug -> qualified_name pieces
2040 PprShowAll -> ppBesides [qualified_name pieces,
2043 ppr other_sty (getIdUniType id),
2044 ppIdInfo other_sty id True (\x->x) nullIdEnv (getIdInfo id),
2045 ppPStr SLIT("-}") ])]
2047 occur_name = getOccurrenceName id _APPEND_
2048 ( _PK_ (if not (isSysLocalId id)
2050 else "." ++ (_UNPK_ (showUnique (getTheUnique id)))))
2052 qualified_name pieces
2053 = ppBeside (pp_ubxd (ppIntersperse (ppChar '.') (map ppPStr pieces))) (pp_uniq id)
2055 pp_uniq (Id _ _ _ (PreludeId _)) = ppNil -- No uniq to add
2056 pp_uniq (Id _ _ _ (DataConId _ _ _ _ _ _)) = ppNil -- No uniq to add
2057 pp_uniq (Id _ _ _ (TupleConId _)) = ppNil -- No uniq to add
2058 pp_uniq (Id _ _ _ (LocalId _ _)) = ppNil -- uniq printed elsewhere
2059 pp_uniq (Id _ _ _ (SysLocalId _ _)) = ppNil -- ditto
2060 pp_uniq (Id _ _ _ (SpecPragmaId _ _ _)) = ppNil -- ditto
2061 pp_uniq (Id _ _ _ (InstId _)) = ppNil -- ditto
2062 pp_uniq other_id = ppBesides [ppPStr SLIT("{-"), pprUnique (getTheUnique other_id), ppPStr SLIT("-}")]
2064 -- For Robin Popplestone: print PprDebug Ids with # afterwards
2065 -- if they are of primitive type.
2066 pp_ubxd pretty = if isPrimType (getIdUniType id)
2067 then ppBeside pretty (ppChar '#')
2072 instance NamedThing Id where
2073 getExportFlag (Id _ _ _ details)
2076 get (DataConId _ _ _ _ _ tc)= getExportFlag tc -- NB: don't use the FullName
2077 get (TupleConId _) = NotExported
2078 get (ImportedId n) = getExportFlag n
2079 get (PreludeId n) = getExportFlag n
2080 get (TopLevId n) = getExportFlag n
2081 get (SuperDictSelId c _) = getExportFlag c
2082 get (ClassOpId c _) = getExportFlag c
2083 get (DefaultMethodId c _ _) = getExportFlag c
2084 get (DictFunId c ty from_here) = instance_export_flag c ty from_here
2085 get (ConstMethodId c ty _ from_here) = instance_export_flag c ty from_here
2086 get (SpecId unspec _ _) = getExportFlag unspec
2087 get (WorkerId unwrkr) = getExportFlag unwrkr
2088 get (InstId _) = NotExported
2089 get (LocalId _ _) = NotExported
2090 get (SysLocalId _ _) = NotExported
2091 get (SpecPragmaId _ _ _) = NotExported
2093 get (ProcessorCon _ _) = NotExported
2094 get (PodId _ _ i) = getExportFlag i
2095 #endif {- Data Parallel Haskell -}
2097 isLocallyDefined this_id@(Id _ _ _ details)
2100 get (DataConId _ _ _ _ _ tc)= isLocallyDefined tc -- NB: don't use the FullName
2101 get (TupleConId _) = False
2102 get (ImportedId _) = False
2103 get (PreludeId _) = False
2104 get (TopLevId n) = isLocallyDefined n
2105 get (SuperDictSelId c _) = isLocallyDefined c
2106 get (ClassOpId c _) = isLocallyDefined c
2107 get (DefaultMethodId c _ _) = isLocallyDefined c
2108 get (DictFunId c tyc from_here) = from_here
2109 -- For DictFunId and ConstMethodId things, you really have to
2110 -- know whether it came from an imported instance or one
2111 -- really here; no matter where the tycon and class came from.
2113 get (ConstMethodId c tyc _ from_here) = from_here
2114 get (SpecId unspec _ _) = isLocallyDefined unspec
2115 get (WorkerId unwrkr) = isLocallyDefined unwrkr
2116 get (InstId _) = True
2117 get (LocalId _ _) = True
2118 get (SysLocalId _ _) = True
2119 get (SpecPragmaId _ _ _) = True
2121 get (ProcessorCon _ _) = False
2122 get (PodId _ _ i) = isLocallyDefined i
2123 #endif {- Data Parallel Haskell -}
2125 getOrigName this_id@(Id u _ _ details)
2128 get (DataConId n _ _ _ _ _) = getOrigName n
2129 get (TupleConId a) = (pRELUDE_BUILTIN, SLIT("Tup") _APPEND_ _PK_ (show a))
2130 get (ImportedId n) = getOrigName n
2131 get (PreludeId n) = getOrigName n
2132 get (TopLevId n) = getOrigName n
2134 get (ClassOpId c op) = case (getOrigName c) of -- ToDo; better ???
2135 (mod, _) -> (mod, getClassOpString op)
2137 get (SpecId unspec ty_maybes _)
2138 = BIND getOrigName unspec _TO_ (mod, unspec_nm) ->
2139 BIND specMaybeTysSuffix ty_maybes _TO_ tys_suffix ->
2142 (if not (toplevelishId unspec)
2148 get (WorkerId unwrkr)
2149 = BIND getOrigName unwrkr _TO_ (mod, unwrkr_nm) ->
2152 (if not (toplevelishId unwrkr)
2159 = (panic "NamedThing.Id.getOrigName (InstId)",
2160 BIND (getInstNamePieces True inst) _TO_ (piece1:pieces) ->
2161 BIND [ _CONS_ '.' p | p <- pieces ] _TO_ dotted_pieces ->
2162 _CONCAT_ (piece1 : dotted_pieces)
2165 get (LocalId n _) = (panic "NamedThing.Id.getOrigName (LocalId)",
2167 get (SysLocalId n _) = (panic "NamedThing.Id.getOrigName (SysLocal)",
2169 get (SpecPragmaId n _ _)=(panic "NamedThing.Id.getOrigName (SpecPragmaId)",
2172 get (ProcessorCon a _) = ("PreludeBuiltin",
2173 "MkProcessor" ++ (show a))
2174 get (PodId d ity id)
2175 = BIND (getOrigName id) _TO_ (m,n) ->
2176 (m,n ++ ".mapped.POD"++ show d ++ "." ++ show ity)
2178 -- ToDo(hilly): should the above be using getIdNamePieces???
2179 #endif {- Data Parallel Haskell -}
2182 -- the remaining internally-generated flavours of
2183 -- Ids really do not have meaningful "original name" stuff,
2184 -- but we need to make up something (usually for debugging output)
2186 = BIND (getIdNamePieces True this_id) _TO_ (piece1:pieces) ->
2187 BIND [ _CONS_ '.' p | p <- pieces ] _TO_ dotted_pieces ->
2188 (_NIL_, _CONCAT_ (piece1 : dotted_pieces))
2191 getOccurrenceName this_id@(Id _ _ _ details)
2194 get (DataConId n _ _ _ _ _) = getOccurrenceName n
2195 get (TupleConId a) = SLIT("Tup") _APPEND_ (_PK_ (show a))
2196 get (ImportedId n) = getOccurrenceName n
2197 get (PreludeId n) = getOccurrenceName n
2198 get (TopLevId n) = getOccurrenceName n
2199 get (ClassOpId _ op) = getClassOpString op
2201 get (ProcessorCon a _) = "MkProcessor" ++ (show a)
2202 get (PodId _ _ id) = getOccurrenceName id
2203 #endif {- Data Parallel Haskell -}
2204 get _ = snd (getOrigName this_id)
2206 getInformingModules id = panic "getInformingModule:Id"
2208 getSrcLoc (Id _ _ id_info details)
2211 get (DataConId n _ _ _ _ _) = getSrcLoc n
2212 get (TupleConId _) = mkBuiltinSrcLoc
2213 get (ImportedId n) = getSrcLoc n
2214 get (PreludeId n) = getSrcLoc n
2215 get (TopLevId n) = getSrcLoc n
2216 get (SuperDictSelId c _)= getSrcLoc c
2217 get (ClassOpId c _) = getSrcLoc c
2218 get (SpecId unspec _ _) = getSrcLoc unspec
2219 get (WorkerId unwrkr) = getSrcLoc unwrkr
2220 get (InstId i) = let (loc,_) = getInstOrigin i
2222 get (LocalId n _) = getSrcLoc n
2223 get (SysLocalId n _) = getSrcLoc n
2224 get (SpecPragmaId n _ _)= getSrcLoc n
2226 get (ProcessorCon _ _) = mkBuiltinSrcLoc
2227 get (PodId _ _ n) = getSrcLoc n
2228 #endif {- Data Parallel Haskell -}
2229 -- well, try the IdInfo
2230 get something_else = getSrcLocIdInfo id_info
2232 getTheUnique (Id u _ _ _) = u
2234 fromPreludeCore (Id _ _ _ details)
2237 get (DataConId _ _ _ _ _ tc)= fromPreludeCore tc -- NB: not from the FullName
2238 get (TupleConId _) = True
2239 get (ImportedId n) = fromPreludeCore n
2240 get (PreludeId n) = fromPreludeCore n
2241 get (TopLevId n) = fromPreludeCore n
2242 get (SuperDictSelId c _) = fromPreludeCore c
2243 get (ClassOpId c _) = fromPreludeCore c
2244 get (DefaultMethodId c _ _) = fromPreludeCore c
2245 get (DictFunId c t _) = fromPreludeCore c && is_prelude_core_ty t
2246 get (ConstMethodId c t _ _) = fromPreludeCore c && is_prelude_core_ty t
2247 get (SpecId unspec _ _) = fromPreludeCore unspec
2248 get (WorkerId unwrkr) = fromPreludeCore unwrkr
2249 get (InstId _) = False
2250 get (LocalId _ _) = False
2251 get (SysLocalId _ _) = False
2252 get (SpecPragmaId _ _ _) = False
2254 get (ProcessorCon _ _) = True
2255 get (PodId _ _ id) = fromPreludeCore id
2256 #endif {- Data Parallel Haskell -}
2259 getType id = getIdUniType id
2262 Reason for @getTheUnique@: The code generator doesn't carry a
2263 @UniqueSupply@, so it wants to use the @Uniques@ out of local @Ids@