[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / compiler / uniType / TyCon.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
3 %
4 \section[TyCon]{Type constructors}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module TyCon (
10         TyCon(..),      -- not abstract; usually grabbed via AbsUniType
11         Arity(..),      -- synonym for Int
12         mkSynonymTyCon, mkDataTyCon, mkTupleTyCon,
13         mkPrimTyCon, mkSpecTyCon,
14 #ifdef DPH
15         mkProcessorTyCon,
16         mkPodizedPodTyCon,
17         isProcessorTyCon,
18         isPodizedPodTyCon,
19         getPodizedPodDimension,
20 #endif {- Data Parallel Haskell -}
21
22         isSynTyCon, isVisibleSynTyCon, isDataTyCon,
23         isPrimTyCon, isBoxedTyCon,
24         maybeCharLikeTyCon, maybeIntLikeTyCon,
25         maybeFloatLikeTyCon, maybeDoubleLikeTyCon,
26         isEnumerationTyCon, --UNUSED: isEnumerationTyConMostly,
27         isTupleTyCon,
28         isLocalSpecTyCon, isLocalGenTyCon, isBigTupleTyCon,
29         maybeSingleConstructorTyCon,
30         derivedFor, --UNUSED: preludeClassDerivedFor,
31         cmpTyCon, eqTyCon,
32
33         getTyConArity, getTyConDataCons,
34         getTyConTyVarTemplates,
35         getTyConKind,
36         getTyConDerivings,
37         getTyConFamilySize,
38
39         -- to make the interface self-sufficient...
40         Class, Id, FullName, PrimKind, TyVarTemplate, UniType,
41         Unique, Maybe, DataCon(..)
42     ) where
43
44 IMPORT_Trace            -- ToDo: rm (debugging)
45
46 import AbsPrel          ( charPrimTy, intPrimTy, floatPrimTy,
47                           doublePrimTy, pRELUDE_BUILTIN
48                         )
49
50 import Class            ( getClassKey, Class
51                           IF_ATTACK_PRAGMAS(COMMA cmpClass)
52                         )
53 import Id               -- DPH wants to export various things as well
54 import IdInfo
55 import Maybes           ( Maybe(..) )
56 import NameTypes        -- various types to do with names
57 import Outputable       -- class for printing, forcing
58 import Pretty           -- pretty-printing utilities
59 import PrimKind         ( PrimKind(..) )
60 import SrcLoc
61 import TyVar            ( TyVarTemplate, alphaTyVars )
62 import Unique           ( cmpUnique, Unique )
63 import UniTyFuns        ( getTauType, getUniDataTyCon, pprTyCon,
64                           cmpUniTypeMaybeList, specMaybeTysSuffix
65                           IF_ATTACK_PRAGMAS(COMMA pprUniType COMMA splitType)
66                         )
67 import UniType          ( UniType
68                           IF_ATTACK_PRAGMAS(COMMA cmpUniType)
69                         )
70 import Util
71 \end{code}
72
73 %************************************************************************
74 %*                                                                      *
75 \subsection[TyCon-basics]{@TyCon@ type and basic operations}
76 %*                                                                      *
77 %************************************************************************
78
79 \begin{code}
80 data TyCon
81   = SynonymTyCon Unique{-TyConKey-} -- for fast comparison
82                  FullName
83                  Arity
84                  [TyVarTemplate]-- Argument type variables
85                  UniType        -- Right-hand side, mentioning these type vars
86                                 -- Acts as a template for the expansion when
87                                 -- the tycon is applied to some types.
88                  Bool           -- True <=> expansion is visible to user;
89                                 -- i.e., *not* abstract
90
91   | DataTyCon   Unique{-TyConKey-}
92                 FullName
93                 Arity
94                 [TyVarTemplate] -- see note below
95                 [Id]            -- its data constructors
96                 [Class]         -- classes which have derived instances
97                 Bool            -- True <=> data constructors are visible
98                                 -- to user; i.e., *not* abstract
99
100   | TupleTyCon  Arity           -- just a special case of DataTyCon
101
102   | PrimTyCon                   -- Primitive types; cannot be defined in Haskell
103                                 -- Always unboxed; hence never represented by a closure
104                                 -- Often represented by a bit-pattern for the thing
105                                 -- itself (eg Int#), but sometimes by a pointer to
106                                 -- a heap-allocated object (eg ArrInt#).
107                                 -- The primitive types Arr# and StablePtr# have
108                                 -- parameters (hence arity /= 0); but the rest don't.
109                 Unique{-TyConKey-}
110                 FullName
111                 Arity           -- Arity is *usually* 0.
112                 ([PrimKind] -> PrimKind)
113                                 -- Only arrays use the list in a non-trivial way.
114                                 -- Length of that list must == arity.
115
116                                 -- Used only for naming purposes in CLabels
117   | SpecTyCon   TyCon           -- original data (or tuple) tycon
118                 [Maybe UniType] -- specialising types
119
120 #ifdef DPH
121   | ProcessorTyCon Arity        -- special cased in same way as tuples
122
123   | PodizedPodTyCon Int         -- podized dimension
124                     TyCon       -- Thing the pod contains
125 #endif
126
127 type Arity = Int
128 \end{code}
129
130 {\em Note about the the @[TyVarTemplates]@ in @DataTyCon@ (and
131 @SynonymTyCon@, too?  ToDo):} they should be the type variables which
132 appeared in the original @data@ declaration.  They are there {\em for
133 documentation purposes only}.  In particular, when printing out
134 interface files, we want to use the same type-variable names as
135 appeared in the @data@ declaration for that type constructor.
136 However, they have no semantic significance.
137
138 We could also ensure that the data constructors in the @[Id]@ had the
139 {\em same} type vars in their @[TyVarTemplate]@ lists, so that we
140 don't have to do a translation on printout.
141 {\em End of note.}
142
143 Constructor functions, and simple access functions:
144 \begin{code}
145 mkSynonymTyCon  = SynonymTyCon
146 mkDataTyCon     = DataTyCon
147 mkTupleTyCon    = TupleTyCon
148 mkPrimTyCon     = PrimTyCon
149 mkSpecTyCon     = SpecTyCon
150
151 #ifdef DPH
152 mkProcessorTyCon= ProcessorTyCon
153 mkPodizedPodTyCon = PodizedPodTyCon
154 #endif {- Data Parallell Haskell -}
155 \end{code}
156
157 %************************************************************************
158 %*                                                                      *
159 \subsection[TyCon-extractors]{Extractors for @TyCon@}
160 %*                                                                      *
161 %************************************************************************
162
163 \begin{code}
164 getTyConArity (PrimTyCon    _ _ a _)        = a
165 getTyConArity (SynonymTyCon _ _ a _ _ _)    = a
166 getTyConArity (DataTyCon    _ _ a _ _ _ _)  = a
167 getTyConArity (SpecTyCon    tc tys)         = getTyConArity tc - length tys
168 getTyConArity (TupleTyCon   a)              = a
169 #ifdef DPH
170 getTyConArity (ProcessorTyCon a)            = a
171 getTyConArity (PodizedPodTyCon _ _)         = panic "getTyConArity: pod"
172 #endif {- Data Parallel Haskell -}
173
174 getTyConKind (PrimTyCon _ _ _ kind_fn) kinds = kind_fn kinds
175 #ifdef DPH
176 getTyConKind (PodizedPodTyCon _ tc) kinds    = getTyConKind tc kinds
177 #endif {- Data Parallel Haskell -}
178 getTyConKind other kinds                     = PtrKind -- the "default"
179
180 getTyConDerivings (DataTyCon _ _ _ _ _ derivings _) = derivings
181 getTyConDerivings (SpecTyCon tc tys)                = panic "getTyConDerivings:SpecTyCon"
182 #ifdef DPH
183 getTyConDerivings (PodizedPodTyCon _ _) = panic "getTyConDerivings:pod"
184 #endif {- Data Parallel Haskell -}
185 getTyConDerivings other                           = []
186     -- NB: we do *not* report the PreludeCore types "derivings"...
187
188 getTyConDataCons (DataTyCon  _ _ _ _ data_cons _ _) = data_cons
189 getTyConDataCons (SpecTyCon  tc tys)                = panic "getTyConDataCons:SpecTyCon"
190 getTyConDataCons (TupleTyCon a)                     = [mkTupleCon a]
191 #ifdef DPH
192 getTyConDataCons (ProcessorTyCon a)             = [mkProcessorCon a]
193 getTyConDataCons (PodizedPodTyCon _ _)          = panic "getTyConDataCons: pod"
194 #endif {- Data Parallel Haskell -}
195 getTyConDataCons other_tycon                    = []
196 \end{code}
197 For the use of @getTyConDataCons@ in @MkUnfoldings@, the behaviour
198 above is right: return @[]@ if not an algebraic data type.  I am not
199 certain if that's right for all uses (perhaps should @panic@?) [WDP]
200
201 The following function returns (free) type-variables associated with a
202 given @TyCon@. As the information about these variables is distributed
203 over the @TyCon@'s constructors we take them from the type of any
204 of the constructors assuming that the variables in the remaining
205 type constructors are the same (responsible for keeping this assumption
206 valid is the typechecker).  ToDo: rm this old comment?
207 \begin{code}
208 getTyConTyVarTemplates (SynonymTyCon _ _ _ tvs _ _)   = tvs
209 getTyConTyVarTemplates (DataTyCon    _ _ _ tvs _ _ _) = tvs
210 getTyConTyVarTemplates (SpecTyCon    tc tys)          = panic "getTyConTyVarTemplates:SpecTyCon"
211 getTyConTyVarTemplates (TupleTyCon a)                 = take a alphaTyVars
212 getTyConTyVarTemplates (PrimTyCon _ _ _ _)            = [] -- ToDo: ???
213 #ifdef DPH
214 getTyConTyVarTemplates (ProcessorTyCon a)           = take a alphaTyVars
215 getTyConTyVarTemplates (PodizedPodTyCon _ _)        = panic "getTyConTyVarTem"
216 #endif {- Data Parallel Haskell -}
217 \end{code}
218
219 \begin{code}
220 getTyConFamilySize :: TyCon -> Maybe Int -- return Nothing if we don't know
221
222 getTyConFamilySize (TupleTyCon   _)             = Just 1
223 getTyConFamilySize (SpecTyCon tc tys)           = getTyConFamilySize tc
224 getTyConFamilySize (DataTyCon  _ _ _ _ dcs _ _)
225   = let
226         no_data_cons = length dcs
227     in
228     if no_data_cons == 0 then Nothing else Just no_data_cons
229
230 #ifdef DEBUG
231   -- ToDo: if 0 then the answer is really "I don't know"; what then?
232 getTyConFamilySize tc@(PrimTyCon _ _ _ _)
233   = pprPanic "getTyConFamilySize:prim:" (ppr PprDebug tc)
234 getTyConFamilySize (SynonymTyCon _ _ _ _ expand _)
235   = pprTrace "getTyConFamilySize:Syn:" (ppr PprDebug expand) (
236     let
237         (tycon,_,data_cons) = getUniDataTyCon (getTauType expand)
238         no_data_cons = length data_cons
239     in
240     if no_data_cons == 0 then Nothing else Just no_data_cons
241     )
242 #endif
243 #ifdef DPH
244 getTyConFamilySize (ProcessorTyCon   _)   = Just 1
245 getTyConFamilySize (PodizedPodTyCon _ _)  = panic "getTyConFamilySize: Pod"
246 #endif {- Data Parallel Haskell -}
247 \end{code}
248
249 %************************************************************************
250 %*                                                                      *
251 \subsection[TyCon-predicates]{Predicates on @TyCon@s}
252 %*                                                                      *
253 %************************************************************************
254
255 \begin{code}
256 -- True <=> Algebraic data type
257 isDataTyCon (DataTyCon _ _ _ _ _ _ _) = True
258 isDataTyCon (SpecTyCon tc tys)        = isDataTyCon tc
259 isDataTyCon (TupleTyCon _)            = True
260 #ifdef DPH
261 isDataTyCon (ProcessorTyCon _)        = True
262 isDataTyCon (PodizedPodTyCon _ tc)    = isDataTyCon tc
263 #endif {- Data Parallel Haskell -}
264 isDataTyCon other                     = False
265
266 -- True <=> Synonym
267 isSynTyCon (SynonymTyCon _ _ _ _ _ _) = True
268 isSynTyCon (SpecTyCon tc tys)         = panic "isSynTyCon: SpecTyCon"
269 #ifdef DPH
270 isSynTyCon (PodizedPodTyCon _ _)      = panic "isSynTyCon: Pod"
271 #endif {- Data Parallel Haskell -}
272 isSynTyCon other                      = False
273
274 isVisibleSynTyCon (SynonymTyCon _ _ _ _ _ visible) = visible
275 isVisibleSynTyCon other_tycon                      = panic "isVisibleSynTyCon"
276
277 isPrimTyCon (PrimTyCon _ _ _ _) = True
278 isPrimTyCon (SpecTyCon tc tys)  = isPrimTyCon tc
279 #ifdef DPH
280 isPrimTyCon (PodizedPodTyCon _ tc) = isPrimTyCon tc
281 #endif {- Data Parallel Haskell -}
282 isPrimTyCon other               = False
283
284 -- At present there are no unboxed non-primitive types, so isBoxedTyCon is
285 -- just the negation of isPrimTyCon.
286 isBoxedTyCon (PrimTyCon _ _ _ _) = False
287 isBoxedTyCon (SpecTyCon tc tys)  = isBoxedTyCon tc
288 #ifdef DPH
289 isBoxedTyCon (PodizedPodTyCon _ tc) = isBoxedTyCon tc
290 #endif {- Data Parallel Haskell -}
291 isBoxedTyCon other              = True
292
293 \end{code}
294
295 The @maybeCharLikeTyCon@ predicate tests for a tycon with no type
296 variables, and one constructor which has one argument of type
297 @CharPrim@.  Similarly @maybeIntLikeTyCon@, etc.
298
299 ToDo:SpecTyCon Do we want to CharLike etc for SpecTyCons ???
300
301 \begin{code}
302 maybeCharLikeTyCon (DataTyCon _ _ _ [] [con] [] _) = maybe_foo_like con charPrimTy
303 #ifdef DPH
304 maybeCharLikeTyCon (PodizedPodTyCon _ _) = panic "maybeCharLikeTyCon: Pod"
305 #endif {- Data Parallel Haskell -}
306 maybeCharLikeTyCon other = Nothing
307
308 maybeIntLikeTyCon (DataTyCon _ _ _ [] [con] [] _) = maybe_foo_like con intPrimTy
309 #ifdef DPH
310 maybeIntLikeTyCon (PodizedPodTyCon _ _) = panic "maybeIntLikeTyCon: Pod"
311 #endif {- Data Parallel Haskell -}
312 maybeIntLikeTyCon other = Nothing
313
314 maybeFloatLikeTyCon (DataTyCon _ _ _ [] [con] [] _) = maybe_foo_like con floatPrimTy
315 #ifdef DPH
316 maybeFloatLikeTyCon (PodizedPodTyCon _ _) = panic "maybeFloatLikeTyCon: Pod"
317 #endif {- Data Parallel Haskell -}
318 maybeFloatLikeTyCon other = Nothing
319
320 maybeDoubleLikeTyCon (DataTyCon _ _ _ [] [con] [] _) = maybe_foo_like con doublePrimTy
321 #ifdef DPH
322 maybeDoubleLikeTyCon (PodizedPodTyCon _ _) = panic "maybeDoubleLikeTyCon: Pod"
323 #endif {- Data Parallel Haskell -}
324 maybeDoubleLikeTyCon other = Nothing
325
326 maybe_foo_like con prim_type_to_match
327   = case (getDataConSig con) of
328       ([], [], [should_be_prim], _)
329         | should_be_prim == prim_type_to_match  -> Just con
330       other                                     -> Nothing
331
332 #ifdef DPH
333 isProcessorTyCon :: TyCon -> Bool
334 isProcessorTyCon (ProcessorTyCon _)     = True
335 isProcessorTyCon other                  = False
336
337 isPodizedPodTyCon :: TyCon -> Bool
338 isPodizedPodTyCon (PodizedPodTyCon _ _) = True
339 isPodizedPodTyCon other                 = False
340
341 getPodizedPodDimension::TyCon -> Int
342 getPodizedPodDimension (PodizedPodTyCon d _) = d
343 #endif {- Data Parallel Haskell -}
344 \end{code}
345
346 \begin{code}
347 isEnumerationTyCon :: TyCon -> Bool
348
349 isEnumerationTyCon (TupleTyCon arity)
350   = arity == 0
351 isEnumerationTyCon (DataTyCon _ _ _ _ data_cons _ _)
352   = not (null data_cons) && all is_nullary data_cons
353   where
354     is_nullary con = case (getDataConSig con) of { (_,_, arg_tys, _) ->
355                      null arg_tys }
356 #ifdef DEBUG
357 -- isEnumerationTyCon (SpecTyCon tc tys) -- ToDo:SpecTyCon
358 isEnumerationTyCon other = pprPanic "isEnumerationTyCon: " (ppr PprShowAll other)
359 #endif
360
361 -- this one is more of a *heuristic*
362 {- UNUSED:
363 isEnumerationTyConMostly :: TyCon -> Bool
364
365 isEnumerationTyConMostly (TupleTyCon arity) = arity == 0
366
367 isEnumerationTyConMostly tycon@(DataTyCon _ _ _ _ data_cons _ _)
368   =  isEnumerationTyCon tycon
369   || four_or_more data_cons 0
370   where
371     four_or_more :: [Id] -> Int -> Bool
372
373     four_or_more []     acc = if acc >= 4 then True else False
374     four_or_more (c:cs) acc
375       = case (getDataConSig c) of { (_,_, arg_tys, _) ->
376         four_or_more cs (if (null arg_tys) then acc+1 else acc)
377         }
378 -- isEnumerationTyConMostly (SpecTyCon tc tys) -- ToDo:SpecTyCon
379 -}
380
381
382 maybeSingleConstructorTyCon :: TyCon -> Maybe Id
383 maybeSingleConstructorTyCon (TupleTyCon arity)           = Just (mkTupleCon arity)
384 maybeSingleConstructorTyCon (DataTyCon _ _ _ _ [c] _ _)  = Just c
385 maybeSingleConstructorTyCon (DataTyCon _ _ _ _ _   _ _)  = Nothing
386 maybeSingleConstructorTyCon (PrimTyCon _ _ _ _)          = Nothing
387 maybeSingleConstructorTyCon (SpecTyCon tc tys)           = panic "maybeSingleConstructorTyCon:SpecTyCon"
388                                                            -- requires DataCons of TyCon
389 \end{code}
390
391 @derivedFor@ reports if we have an {\em obviously}-derived instance
392 for the given class/tycon.  Of course, you might be deriving something
393 because it a superclass of some other obviously-derived class---this
394 function doesn't deal with that.
395
396 ToDo:SpecTyCon Do we want derivedFor etc for SpecTyCons ???
397
398 \begin{code}
399 derivedFor              :: Class    -> TyCon -> Bool
400
401 clas `derivedFor` (DataTyCon _ _ _ _ _ derivs _) = clas `is_elem` derivs
402 clas `derivedFor` something_weird                = False
403
404 x `is_elem` y = isIn "X_derivedFor" x y
405
406 {- UNUSED:
407 preludeClassDerivedFor  :: Unique{-ClassKey-} -> TyCon -> Bool
408
409 preludeClassDerivedFor key (DataTyCon _ _ _ _ _ derivs _)
410   = key `is_elem` (map getClassKey derivs)
411 preludeClassDerivedFor key something_weird = False
412 -}
413 \end{code}
414
415 \begin{code}
416 isTupleTyCon (TupleTyCon arity) = arity >= 2    -- treat "0-tuple" specially
417 isTupleTyCon (SpecTyCon tc tys) = isTupleTyCon tc
418 isTupleTyCon other              = False
419 \end{code}
420
421 @isLocalSpecTyCon@ determines if a tycon has specialisations created
422 locally: locally defined tycons and any tycons from the prelude.
423 But *not* if we're compiling the prelude itself...
424
425 @isLocalGenTyCon@ determines if constructor code for a tycon is
426 generated locally: locally defined tycons and big tuple tycons.
427
428 \begin{code}
429 isLocalSpecTyCon :: Bool -> TyCon -> Bool
430
431 isLocalSpecTyCon compiling_prelude tc
432   = isLocallyDefined tc || (fromPreludeCore tc && not compiling_prelude)
433
434 isLocalGenTyCon (SpecTyCon tc tys) = isLocalGenTyCon tc
435 isLocalGenTyCon tc                 = isBigTupleTyCon tc || isLocallyDefined tc
436
437 isBigTupleTyCon (TupleTyCon arity) = arity > 32
438                                         -- Tuple0 to Tuple32 declared in prelude
439                                         -- HEY!  Nice magic constant! WDP 95/06
440 isBigTupleTyCon (SpecTyCon tc _)   = isBigTupleTyCon tc
441 isBigTupleTyCon _                  = False
442 \end{code}
443
444 %************************************************************************
445 %*                                                                      *
446 \subsection[TyCon-instances]{Instance declarations for @TyCon@}
447 %*                                                                      *
448 %************************************************************************
449
450 @TyCon@s are compared by comparing their @Unique@s.
451
452 The strictness analyser needs @Ord@. It is a lexicographic order with
453 the property @(a<=b) || (b<=a)@.
454
455 \begin{code}
456 cmpTyCon (SynonymTyCon k1 _ _ _ _ _) (SynonymTyCon k2 _ _ _ _ _)= cmpUnique k1 k2
457 cmpTyCon (DataTyCon  k1 _ _ _ _ _ _) (DataTyCon k2 _ _ _ _ _ _) = cmpUnique k1 k2
458 cmpTyCon (TupleTyCon   a1)           (TupleTyCon        a2)     = cmp_i a1 a2
459 cmpTyCon (PrimTyCon k1 _ _ _)        (PrimTyCon k2 _ _ _)       = cmpUnique k1 k2
460 cmpTyCon (SpecTyCon tc1 mtys1)       (SpecTyCon tc2 mtys2)
461   = case cmpTyCon tc1 tc2 of { EQ_ -> cmpUniTypeMaybeList mtys1 mtys2; other -> other }
462 #ifdef DPH
463 cmpTyCon (ProcessorTyCon  a1)        (ProcessorTyCon  a2)       = cmp_i a1 a2
464 cmpTyCon (PodizedPodTyCon d1 tc1)    (PodizedPodTyCon d2 tc2)
465   = case cmp_i d1 d2 of { EQ_ -> cmpTyCon tc1 tc2; other -> other }
466 #endif {- Data Parallel Haskell -}
467
468     -- now we *know* the tags are different, so...
469 cmpTyCon other_1                          other_2
470   = let
471         tag1 = tag_TyCon other_1
472         tag2 = tag_TyCon other_2
473     in
474     if tag1 _LT_ tag2 then LT_ else GT_
475   where
476     tag_TyCon (SynonymTyCon _ _ _ _ _ _)  = (ILIT(1) :: FAST_INT)
477     tag_TyCon (DataTyCon    _ _ _ _ _ _ _)= ILIT(2)
478     tag_TyCon (TupleTyCon   _)            = ILIT(3)
479     tag_TyCon (PrimTyCon    _ _ _ _)      = ILIT(4)
480     tag_TyCon (SpecTyCon    _ _)          = ILIT(5)
481 #ifdef DPH
482     tag_TyCon (ProcessorTyCon   _)        = ILIT(6)
483     tag_TyCon (PodizedPodTyCon _ _)       = ILIT(7)
484 #endif {- Data Parallel Haskell -}
485
486 cmp_i :: Int -> Int -> TAG_
487 cmp_i a1 a2
488   = if a1 == a2 then EQ_ else if a1 < a2 then LT_ else GT_
489 \end{code}
490
491 \begin{code}
492 eqTyCon :: TyCon -> TyCon -> Bool
493
494 eqTyCon a b = case cmpTyCon a b of { EQ_ -> True;  _   -> False }
495
496 instance Eq TyCon where
497     a == b = case cmpTyCon a b of { EQ_ -> True;   _ -> False }
498     a /= b = case cmpTyCon a b of { EQ_ -> False;  _ -> True  }
499
500 instance Ord TyCon where
501     a <= b = case cmpTyCon a b of { LT_ -> True;  EQ_ -> True;  GT__ -> False }
502     a <  b = case cmpTyCon a b of { LT_ -> True;  EQ_ -> False; GT__ -> False }
503     a >= b = case cmpTyCon a b of { LT_ -> False; EQ_ -> True;  GT__ -> True  }
504     a >  b = case cmpTyCon a b of { LT_ -> False; EQ_ -> False; GT__ -> True  }
505 #ifdef __GLASGOW_HASKELL__
506     _tagCmp a b = case cmpTyCon a b of { LT_ -> _LT; EQ_ -> _EQ; GT__ -> _GT }
507 #endif
508 \end{code}
509
510 \begin{code}
511 instance NamedThing TyCon where
512     getExportFlag       (TupleTyCon _)  = NotExported
513 #ifdef DPH
514     getExportFlag    (ProcessorTyCon _)     = NotExported
515     getExportFlag    (PodizedPodTyCon _ tc) = getExportFlag tc
516 #endif {- Data Parallel Haskell -}
517     getExportFlag       other           = getExportFlag (get_name other)
518
519     isLocallyDefined    (TupleTyCon _)  = False
520 #ifdef DPH
521     isLocallyDefined (ProcessorTyCon _)     = False
522     isLocallyDefined (PodizedPodTyCon _ tc) = isLocallyDefined tc
523 #endif {- Data Parallel Haskell -}
524     isLocallyDefined    other           = isLocallyDefined (get_name other)
525
526     getOrigName (TupleTyCon a)          = (pRELUDE_BUILTIN, _PK_ ("Tuple" ++ (show a)))
527     getOrigName (SpecTyCon tc tys)      = let (m,n) = getOrigName tc in
528                                           (m, n _APPEND_ specMaybeTysSuffix tys)
529 #ifdef DPH
530     getOrigName     (ProcessorTyCon a)     = ("PreludeBuiltin", "Processor" ++ (show a))
531     getOrigName     (PodizedPodTyCon d tc) = let (m,n) = getOrigName tc in
532                                              (m,n++"Pod"++show d)
533 #endif {- Data Parallel Haskell -}
534     getOrigName         other           = getOrigName (get_name other)
535
536     getOccurrenceName   (TupleTyCon a)       = _PK_ ("Tuple" ++ (show a))
537     getOccurrenceName (SpecTyCon tc tys)     = getOccurrenceName tc _APPEND_ specMaybeTysSuffix tys
538 #ifdef DPH
539     getOccurrenceName (ProcessorTyCon a)     = "Processor" ++ (show a)
540     getOccurrenceName (PodizedPodTyCon d tc) = getOccurrenceName tc ++
541                                                "Pod" ++ show d
542 #endif {- Data Parallel Haskell -}
543     getOccurrenceName   other           = getOccurrenceName (get_name other)
544
545     getInformingModules (TupleTyCon a)  = panic "getInformingModule:TupleTyCon"
546 #ifdef DPH
547     getInformingModules (ProcessorTyCon a)     = "Processor" ++ (show a)
548     getInformingModules (PodizedPodTyCon d tc) = getInformingModule tc ++
549                                                "Pod" ++ show d
550 #endif {- Data Parallel Haskell -}
551     getInformingModules other           = getInformingModules (get_name other)
552
553     getSrcLoc           (TupleTyCon _)  = mkBuiltinSrcLoc
554 #ifdef DPH
555     getSrcLoc       (ProcessorTyCon _)     = mkBuiltinSrcLoc
556     getSrcLoc       (PodizedPodTyCon _ tc) = getSrcLoc tc
557 #endif {- Data Parallel Haskell -}
558     getSrcLoc           other           = getSrcLoc (get_name other)
559
560     getTheUnique        other           = panic "NamedThing.TyCon.getTheUnique"
561
562     fromPreludeCore     (TupleTyCon a)  = True
563 #ifdef DPH
564     fromPreludeCore (ProcessorTyCon a)     = True
565     fromPreludeCore (PodizedPodTyCon _ tc) = fromPreludeCore tc
566 #endif {- Data Parallel Haskell -}
567     fromPreludeCore     other           = fromPreludeCore (get_name other)
568
569     hasType                             = panic "NamedThing.TyCon.hasType"
570     getType                             = panic "NamedThing.TyCon.getType"
571 \end{code}
572
573 Emphatically un-exported:
574 \begin{code}
575 get_name (SynonymTyCon _ n _ _ _ _)     = n
576 get_name (DataTyCon    _ n _ _ _ _ _)   = n
577 get_name (PrimTyCon    _ n _ _)         = n
578 get_name (SpecTyCon    tc _)            = get_name tc
579 \end{code}
580
581 And the usual output stuff:
582 \begin{code}
583 instance Outputable TyCon where
584     ppr sty tycon = pprTyCon sty tycon [{-No Specialisations-}]
585 \end{code}