Add missing type representations
[ghc.git] / compiler / prelude / TysWiredIn.hs
1 {-
2 (c) The GRASP Project, Glasgow University, 1994-1998
3
4 \section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types}
5 -}
6
7 {-# LANGUAGE CPP #-}
8
9 -- | This module is about types that can be defined in Haskell, but which
10 -- must be wired into the compiler nonetheless. C.f module TysPrim
11 module TysWiredIn (
12 -- * All wired in things
13 wiredInTyCons, isBuiltInOcc_maybe,
14
15 -- * Bool
16 boolTy, boolTyCon, boolTyCon_RDR, boolTyConName,
17 trueDataCon, trueDataConId, true_RDR,
18 falseDataCon, falseDataConId, false_RDR,
19 promotedFalseDataCon, promotedTrueDataCon,
20
21 -- * Ordering
22 orderingTyCon,
23 ltDataCon, ltDataConId,
24 eqDataCon, eqDataConId,
25 gtDataCon, gtDataConId,
26 promotedLTDataCon, promotedEQDataCon, promotedGTDataCon,
27
28 -- * Char
29 charTyCon, charDataCon, charTyCon_RDR,
30 charTy, stringTy, charTyConName,
31
32 -- * Double
33 doubleTyCon, doubleDataCon, doubleTy, doubleTyConName,
34
35 -- * Float
36 floatTyCon, floatDataCon, floatTy, floatTyConName,
37
38 -- * Int
39 intTyCon, intDataCon, intTyCon_RDR, intDataCon_RDR, intTyConName,
40 intTy,
41
42 -- * Word
43 wordTyCon, wordDataCon, wordTyConName, wordTy,
44
45 -- * Word8
46 word8TyCon, word8DataCon, word8TyConName, word8Ty,
47
48 -- * List
49 listTyCon, listTyCon_RDR, listTyConName, listTyConKey,
50 nilDataCon, nilDataConName, nilDataConKey,
51 consDataCon_RDR, consDataCon, consDataConName,
52 promotedNilDataCon, promotedConsDataCon,
53
54 mkListTy,
55
56 -- * Maybe
57 maybeTyCon, maybeTyConName,
58 nothingDataCon, nothingDataConName, promotedNothingDataCon,
59 justDataCon, justDataConName, promotedJustDataCon,
60
61 -- * Tuples
62 mkTupleTy, mkBoxedTupleTy,
63 tupleTyCon, tupleDataCon, tupleTyConName,
64 promotedTupleDataCon,
65 unitTyCon, unitDataCon, unitDataConId, unitTy, unitTyConKey,
66 pairTyCon,
67 unboxedUnitTyCon, unboxedUnitDataCon,
68 cTupleTyConName, cTupleTyConNames, isCTupleTyConName,
69
70 -- * Kinds
71 typeNatKindCon, typeNatKind, typeSymbolKindCon, typeSymbolKind,
72 isLiftedTypeKindTyConName, liftedTypeKind, constraintKind,
73 starKindTyCon, starKindTyConName,
74 unicodeStarKindTyCon, unicodeStarKindTyConName,
75 liftedTypeKindTyCon, constraintKindTyCon,
76
77 -- * Parallel arrays
78 mkPArrTy,
79 parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon,
80 parrTyCon_RDR, parrTyConName,
81
82 -- * Equality predicates
83 heqTyCon, heqClass, heqDataCon,
84 coercibleTyCon, coercibleDataCon, coercibleClass,
85
86 -- * Implicit Parameters
87 ipTyCon, ipDataCon, ipClass,
88
89 callStackTyCon,
90
91 mkWiredInTyConName, -- This is used in TcTypeNats to define the
92 -- built-in functions for evaluation.
93
94 mkWiredInIdName, -- used in MkId
95
96 -- * Levity
97 levityTy, levityTyCon, liftedDataCon, unliftedDataCon,
98 liftedPromDataCon, unliftedPromDataCon,
99 liftedDataConTy, unliftedDataConTy,
100 liftedDataConName, unliftedDataConName,
101
102 -- * Helpers for building type representations
103 tyConRepModOcc
104 ) where
105
106 #include "HsVersions.h"
107
108 import {-# SOURCE #-} MkId( mkDataConWorkId, mkDictSelId )
109
110 -- friends:
111 import PrelNames
112 import TysPrim
113
114 -- others:
115 import FamInstEnv( mkNewTypeCoAxiom )
116 import CoAxiom
117 import Id
118 import Constants ( mAX_TUPLE_SIZE, mAX_CTUPLE_SIZE )
119 import Module ( Module )
120 import Type
121 import DataCon
122 import {-# SOURCE #-} ConLike
123 import TyCon
124 import Class ( Class, mkClass )
125 import RdrName
126 import Name
127 import NameSet ( NameSet, mkNameSet, elemNameSet )
128 import BasicTypes ( Arity, RecFlag(..), Boxity(..),
129 TupleSort(..) )
130 import ForeignCall
131 import SrcLoc ( noSrcSpan )
132 import Unique
133 import Data.Array
134 import FastString
135 import Outputable
136 import Util
137 import BooleanFormula ( mkAnd )
138
139 alpha_tyvar :: [TyVar]
140 alpha_tyvar = [alphaTyVar]
141
142 alpha_ty :: [Type]
143 alpha_ty = [alphaTy]
144
145 -- * Some helpers for generating type representations
146
147 -- | Make a 'Name' for the 'Typeable' representation of the given wired-in type
148 mkPrelTyConRepName :: Name -> Name
149 -- See Note [Grand plan for Typeable] in 'TcTypeable' in TcTypeable.
150 -- This doesn't really belong here but a refactoring of this code eliminating
151 -- these manually-defined representations is imminent
152 mkPrelTyConRepName tc_name -- Prelude tc_name is always External,
153 -- so nameModule will work
154 = mkExternalName rep_uniq rep_mod rep_occ (nameSrcSpan tc_name)
155 where
156 name_occ = nameOccName tc_name
157 name_mod = nameModule tc_name
158 name_uniq = nameUnique tc_name
159 rep_uniq | isTcOcc name_occ = tyConRepNameUnique name_uniq
160 | otherwise = dataConRepNameUnique name_uniq
161 (rep_mod, rep_occ) = tyConRepModOcc name_mod name_occ
162
163 -- | The name (and defining module) for the Typeable representation (TyCon) of a
164 -- type constructor.
165 --
166 -- See Note [Grand plan for Typeable] in 'TcTypeable' in TcTypeable.
167 tyConRepModOcc :: Module -> OccName -> (Module, OccName)
168 tyConRepModOcc tc_module tc_occ
169 -- The list type is defined in GHC.Types and therefore must have its
170 -- representations defined manually in Data.Typeable.Internal.
171 -- However, $tc': isn't a valid Haskell identifier, so we override the derived
172 -- name here.
173 | is_wired_in promotedConsDataCon
174 = (tYPEABLE_INTERNAL, mkOccName varName "tc'Cons")
175 | is_wired_in promotedNilDataCon
176 = (tYPEABLE_INTERNAL, mkOccName varName "tc'Nil")
177
178 | tc_module == gHC_TYPES
179 = (tYPEABLE_INTERNAL, mkTyConRepUserOcc tc_occ)
180 | otherwise
181 = (tc_module, mkTyConRepSysOcc tc_occ)
182 where
183 is_wired_in :: TyCon -> Bool
184 is_wired_in tc =
185 tc_module == gHC_TYPES && tc_occ == nameOccName (tyConName tc)
186
187 {-
188 ************************************************************************
189 * *
190 \subsection{Wired in type constructors}
191 * *
192 ************************************************************************
193
194 If you change which things are wired in, make sure you change their
195 names in PrelNames, so they use wTcQual, wDataQual, etc
196 -}
197
198 -- This list is used only to define PrelInfo.wiredInThings. That in turn
199 -- is used to initialise the name environment carried around by the renamer.
200 -- This means that if we look up the name of a TyCon (or its implicit binders)
201 -- that occurs in this list that name will be assigned the wired-in key we
202 -- define here.
203 --
204 -- Because of their infinite nature, this list excludes tuples, Any and implicit
205 -- parameter TyCons. Instead, we have a hack in lookupOrigNameCache to deal with
206 -- these names.
207 --
208 -- See also Note [Known-key names]
209 wiredInTyCons :: [TyCon]
210
211 wiredInTyCons = [ unitTyCon -- Not treated like other tuples, because
212 -- it's defined in GHC.Base, and there's only
213 -- one of it. We put it in wiredInTyCons so
214 -- that it'll pre-populate the name cache, so
215 -- the special case in lookupOrigNameCache
216 -- doesn't need to look out for it
217 , boolTyCon
218 , charTyCon
219 , doubleTyCon
220 , floatTyCon
221 , intTyCon
222 , wordTyCon
223 , word8TyCon
224 , listTyCon
225 , maybeTyCon
226 , parrTyCon
227 , heqTyCon
228 , coercibleTyCon
229 , typeNatKindCon
230 , typeSymbolKindCon
231 , levityTyCon
232 , constraintKindTyCon
233 , liftedTypeKindTyCon
234 , starKindTyCon
235 , unicodeStarKindTyCon
236 , ipTyCon
237 ]
238
239 mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name
240 mkWiredInTyConName built_in modu fs unique tycon
241 = mkWiredInName modu (mkTcOccFS fs) unique
242 (ATyCon tycon) -- Relevant TyCon
243 built_in
244
245 mkWiredInDataConName :: BuiltInSyntax -> Module -> FastString -> Unique -> DataCon -> Name
246 mkWiredInDataConName built_in modu fs unique datacon
247 = mkWiredInName modu (mkDataOccFS fs) unique
248 (AConLike (RealDataCon datacon)) -- Relevant DataCon
249 built_in
250
251 mkWiredInCoAxiomName :: BuiltInSyntax -> Module -> FastString -> Unique
252 -> CoAxiom Branched -> Name
253 mkWiredInCoAxiomName built_in modu fs unique ax
254 = mkWiredInName modu (mkTcOccFS fs) unique
255 (ACoAxiom ax) -- Relevant CoAxiom
256 built_in
257
258 mkWiredInIdName :: Module -> FastString -> Unique -> Id -> Name
259 mkWiredInIdName mod fs uniq id
260 = mkWiredInName mod (mkOccNameFS Name.varName fs) uniq (AnId id) UserSyntax
261
262 -- See Note [Kind-changing of (~) and Coercible]
263 -- in libraries/ghc-prim/GHC/Types.hs
264 heqTyConName, heqDataConName, heqSCSelIdName :: Name
265 heqTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "~~") heqTyConKey heqTyCon
266 heqDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "Eq#") heqDataConKey heqDataCon
267 heqSCSelIdName = mkWiredInIdName gHC_TYPES (fsLit "HEq_sc") heqSCSelIdKey heqSCSelId
268
269 -- See Note [Kind-changing of (~) and Coercible] in libraries/ghc-prim/GHC/Types.hs
270 coercibleTyConName, coercibleDataConName, coercibleSCSelIdName :: Name
271 coercibleTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Coercible") coercibleTyConKey coercibleTyCon
272 coercibleDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "MkCoercible") coercibleDataConKey coercibleDataCon
273 coercibleSCSelIdName = mkWiredInIdName gHC_TYPES (fsLit "Coercible_sc") coercibleSCSelIdKey coercibleSCSelId
274
275 charTyConName, charDataConName, intTyConName, intDataConName :: Name
276 charTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Char") charTyConKey charTyCon
277 charDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "C#") charDataConKey charDataCon
278 intTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Int") intTyConKey intTyCon
279 intDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "I#") intDataConKey intDataCon
280
281 boolTyConName, falseDataConName, trueDataConName :: Name
282 boolTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Bool") boolTyConKey boolTyCon
283 falseDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "False") falseDataConKey falseDataCon
284 trueDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "True") trueDataConKey trueDataCon
285
286 listTyConName, nilDataConName, consDataConName :: Name
287 listTyConName = mkWiredInTyConName BuiltInSyntax gHC_TYPES (fsLit "[]") listTyConKey listTyCon
288 nilDataConName = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit "[]") nilDataConKey nilDataCon
289 consDataConName = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit ":") consDataConKey consDataCon
290
291 maybeTyConName, nothingDataConName, justDataConName :: Name
292 maybeTyConName = mkWiredInTyConName UserSyntax gHC_BASE (fsLit "Maybe")
293 maybeTyConKey maybeTyCon
294 nothingDataConName = mkWiredInDataConName UserSyntax gHC_BASE (fsLit "Nothing")
295 nothingDataConKey nothingDataCon
296 justDataConName = mkWiredInDataConName UserSyntax gHC_BASE (fsLit "Just")
297 justDataConKey justDataCon
298
299 wordTyConName, wordDataConName, word8TyConName, word8DataConName :: Name
300 wordTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Word") wordTyConKey wordTyCon
301 wordDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "W#") wordDataConKey wordDataCon
302 word8TyConName = mkWiredInTyConName UserSyntax gHC_WORD (fsLit "Word8") word8TyConKey word8TyCon
303 word8DataConName = mkWiredInDataConName UserSyntax gHC_WORD (fsLit "W8#") word8DataConKey word8DataCon
304
305 floatTyConName, floatDataConName, doubleTyConName, doubleDataConName :: Name
306 floatTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Float") floatTyConKey floatTyCon
307 floatDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "F#") floatDataConKey floatDataCon
308 doubleTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Double") doubleTyConKey doubleTyCon
309 doubleDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "D#") doubleDataConKey doubleDataCon
310
311 -- Kinds
312 typeNatKindConName, typeSymbolKindConName :: Name
313 typeNatKindConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Nat") typeNatKindConNameKey typeNatKindCon
314 typeSymbolKindConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Symbol") typeSymbolKindConNameKey typeSymbolKindCon
315
316 constraintKindTyConName :: Name
317 constraintKindTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Constraint") constraintKindTyConKey constraintKindTyCon
318
319 liftedTypeKindTyConName, starKindTyConName, unicodeStarKindTyConName
320 :: Name
321 liftedTypeKindTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Type") liftedTypeKindTyConKey liftedTypeKindTyCon
322 starKindTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "*") starKindTyConKey starKindTyCon
323 unicodeStarKindTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "★") unicodeStarKindTyConKey unicodeStarKindTyCon
324
325 levityTyConName, liftedDataConName, unliftedDataConName :: Name
326 levityTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Levity") levityTyConKey levityTyCon
327 liftedDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "Lifted") liftedDataConKey liftedDataCon
328 unliftedDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "Unlifted") unliftedDataConKey unliftedDataCon
329
330 parrTyConName, parrDataConName :: Name
331 parrTyConName = mkWiredInTyConName BuiltInSyntax
332 gHC_PARR' (fsLit "[::]") parrTyConKey parrTyCon
333 parrDataConName = mkWiredInDataConName UserSyntax
334 gHC_PARR' (fsLit "PArr") parrDataConKey parrDataCon
335
336 boolTyCon_RDR, false_RDR, true_RDR, intTyCon_RDR, charTyCon_RDR,
337 intDataCon_RDR, listTyCon_RDR, consDataCon_RDR, parrTyCon_RDR :: RdrName
338 boolTyCon_RDR = nameRdrName boolTyConName
339 false_RDR = nameRdrName falseDataConName
340 true_RDR = nameRdrName trueDataConName
341 intTyCon_RDR = nameRdrName intTyConName
342 charTyCon_RDR = nameRdrName charTyConName
343 intDataCon_RDR = nameRdrName intDataConName
344 listTyCon_RDR = nameRdrName listTyConName
345 consDataCon_RDR = nameRdrName consDataConName
346 parrTyCon_RDR = nameRdrName parrTyConName
347
348 {-
349 ************************************************************************
350 * *
351 \subsection{mkWiredInTyCon}
352 * *
353 ************************************************************************
354 -}
355
356 pcNonRecDataTyCon :: Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
357 -- Not an enumeration
358 pcNonRecDataTyCon = pcTyCon False NonRecursive
359
360 -- This function assumes that the types it creates have all parameters at
361 -- Representational role, and that there is no kind polymorphism.
362 pcTyCon :: Bool -> RecFlag -> Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
363 pcTyCon is_enum is_rec name cType tyvars cons
364 = mkAlgTyCon name
365 (mkFunTys (map tyVarKind tyvars) liftedTypeKind)
366 tyvars
367 (map (const Representational) tyvars)
368 cType
369 [] -- No stupid theta
370 (DataTyCon cons is_enum)
371 (VanillaAlgTyCon (mkPrelTyConRepName name))
372 is_rec
373 False -- Not in GADT syntax
374
375 pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon
376 pcDataCon n univs = pcDataConWithFixity False n univs [] -- no ex_tvs
377
378 pcDataConWithFixity :: Bool -- ^ declared infix?
379 -> Name -- ^ datacon name
380 -> [TyVar] -- ^ univ tyvars
381 -> [TyVar] -- ^ ex tyvars
382 -> [Type] -- ^ args
383 -> TyCon
384 -> DataCon
385 pcDataConWithFixity infx n = pcDataConWithFixity' infx n (incrUnique (nameUnique n))
386 -- The Name's unique is the first of two free uniques;
387 -- the first is used for the datacon itself,
388 -- the second is used for the "worker name"
389 --
390 -- To support this the mkPreludeDataConUnique function "allocates"
391 -- one DataCon unique per pair of Ints.
392
393 pcDataConWithFixity' :: Bool -> Name -> Unique -> [TyVar] -> [TyVar]
394 -> [Type] -> TyCon -> DataCon
395 -- The Name should be in the DataName name space; it's the name
396 -- of the DataCon itself.
397
398 pcDataConWithFixity' declared_infix dc_name wrk_key tyvars ex_tyvars arg_tys tycon
399 = data_con
400 where
401 data_con = mkDataCon dc_name declared_infix prom_info
402 (map (const no_bang) arg_tys)
403 [] -- No labelled fields
404 tyvars
405 ex_tyvars
406 [] -- No equality spec
407 [] -- No theta
408 arg_tys (mkTyConApp tycon (mkTyVarTys tyvars))
409 tycon
410 [] -- No stupid theta
411 (mkDataConWorkId wrk_name data_con)
412 NoDataConRep -- Wired-in types are too simple to need wrappers
413
414 no_bang = HsSrcBang Nothing NoSrcUnpack NoSrcStrict
415
416 modu = ASSERT( isExternalName dc_name )
417 nameModule dc_name
418 dc_occ = nameOccName dc_name
419 wrk_occ = mkDataConWorkerOcc dc_occ
420 wrk_name = mkWiredInName modu wrk_occ wrk_key
421 (AnId (dataConWorkId data_con)) UserSyntax
422
423 prom_info = mkPrelTyConRepName dc_name
424
425 {-
426 ************************************************************************
427 * *
428 Kinds
429 * *
430 ************************************************************************
431 -}
432
433 typeNatKindCon, typeSymbolKindCon :: TyCon
434 -- data Nat
435 -- data Symbol
436 typeNatKindCon = pcTyCon False NonRecursive typeNatKindConName Nothing [] []
437 typeSymbolKindCon = pcTyCon False NonRecursive typeSymbolKindConName Nothing [] []
438
439 typeNatKind, typeSymbolKind :: Kind
440 typeNatKind = mkTyConTy typeNatKindCon
441 typeSymbolKind = mkTyConTy typeSymbolKindCon
442
443 constraintKindTyCon :: TyCon
444 constraintKindTyCon = pcTyCon False NonRecursive constraintKindTyConName
445 Nothing [] []
446
447 liftedTypeKind, constraintKind :: Kind
448 liftedTypeKind = tYPE liftedDataConTy
449 constraintKind = mkTyConApp constraintKindTyCon []
450
451
452 {-
453 ************************************************************************
454 * *
455 Stuff for dealing with tuples
456 * *
457 ************************************************************************
458
459 Note [How tuples work] See also Note [Known-key names] in PrelNames
460 ~~~~~~~~~~~~~~~~~~~~~~
461 * There are three families of tuple TyCons and corresponding
462 DataCons, expressed by the type BasicTypes.TupleSort:
463 data TupleSort = BoxedTuple | UnboxedTuple | ConstraintTuple
464
465 * All three families are AlgTyCons, whose AlgTyConRhs is TupleTyCon
466
467 * BoxedTuples
468 - A wired-in type
469 - Data type declarations in GHC.Tuple
470 - The data constructors really have an info table
471
472 * UnboxedTuples
473 - A wired-in type
474 - Have a pretend DataCon, defined in GHC.Prim,
475 but no actual declaration and no info table
476
477 * ConstraintTuples
478 - Are known-key rather than wired-in. Reason: it's awkward to
479 have all the superclass selectors wired-in.
480 - Declared as classes in GHC.Classes, e.g.
481 class (c1,c2) => (c1,c2)
482 - Given constraints: the superclasses automatically become available
483 - Wanted constraints: there is a built-in instance
484 instance (c1,c2) => (c1,c2)
485 - Currently just go up to 16; beyond that
486 you have to use manual nesting
487 - Their OccNames look like (%,,,%), so they can easily be
488 distinguished from term tuples. But (following Haskell) we
489 pretty-print saturated constraint tuples with round parens; see
490 BasicTypes.tupleParens.
491
492 * In quite a lot of places things are restrcted just to
493 BoxedTuple/UnboxedTuple, and then we used BasicTypes.Boxity to distinguish
494 E.g. tupleTyCon has a Boxity argument
495
496 * When looking up an OccName in the original-name cache
497 (IfaceEnv.lookupOrigNameCache), we spot the tuple OccName to make sure
498 we get the right wired-in name. This guy can't tell the difference
499 betweeen BoxedTuple and ConstraintTuple (same OccName!), so tuples
500 are not serialised into interface files using OccNames at all.
501 -}
502
503 isBuiltInOcc_maybe :: OccName -> Maybe Name
504 -- Built in syntax isn't "in scope" so these OccNames
505 -- map to wired-in Names with BuiltInSyntax
506 isBuiltInOcc_maybe occ
507 = case occNameString occ of
508 "[]" -> choose_ns listTyConName nilDataConName
509 ":" -> Just consDataConName
510 "[::]" -> Just parrTyConName
511 "()" -> tup_name Boxed 0
512 "(##)" -> tup_name Unboxed 0
513 '(':',':rest -> parse_tuple Boxed 2 rest
514 '(':'#':',':rest -> parse_tuple Unboxed 2 rest
515 _other -> Nothing
516 where
517 ns = occNameSpace occ
518
519 parse_tuple sort n rest
520 | (',' : rest2) <- rest = parse_tuple sort (n+1) rest2
521 | tail_matches sort rest = tup_name sort n
522 | otherwise = Nothing
523
524 tail_matches Boxed ")" = True
525 tail_matches Unboxed "#)" = True
526 tail_matches _ _ = False
527
528 tup_name boxity arity
529 = choose_ns (getName (tupleTyCon boxity arity))
530 (getName (tupleDataCon boxity arity))
531
532 choose_ns tc dc
533 | isTcClsNameSpace ns = Just tc
534 | isDataConNameSpace ns = Just dc
535 | otherwise = pprPanic "tup_name" (ppr occ)
536
537 mkTupleOcc :: NameSpace -> Boxity -> Arity -> OccName
538 mkTupleOcc ns sort ar = mkOccName ns str
539 where
540 -- No need to cache these, the caching is done in mk_tuple
541 str = case sort of
542 Unboxed -> '(' : '#' : commas ++ "#)"
543 Boxed -> '(' : commas ++ ")"
544
545 commas = take (ar-1) (repeat ',')
546
547 mkCTupleOcc :: NameSpace -> Arity -> OccName
548 mkCTupleOcc ns ar = mkOccName ns str
549 where
550 str = "(%" ++ commas ++ "%)"
551 commas = take (ar-1) (repeat ',')
552
553 cTupleTyConName :: Arity -> Name
554 cTupleTyConName arity
555 = mkExternalName (mkCTupleTyConUnique arity) gHC_CLASSES
556 (mkCTupleOcc tcName arity) noSrcSpan
557 -- The corresponding DataCon does not have a known-key name
558
559 cTupleTyConNames :: [Name]
560 cTupleTyConNames = map cTupleTyConName (0 : [2..mAX_CTUPLE_SIZE])
561
562 cTupleTyConNameSet :: NameSet
563 cTupleTyConNameSet = mkNameSet cTupleTyConNames
564
565 isCTupleTyConName :: Name -> Bool
566 -- Use Type.isCTupleClass where possible
567 isCTupleTyConName n
568 = ASSERT2( isExternalName n, ppr n )
569 nameModule n == gHC_CLASSES
570 && n `elemNameSet` cTupleTyConNameSet
571
572 tupleTyCon :: Boxity -> Arity -> TyCon
573 tupleTyCon sort i | i > mAX_TUPLE_SIZE = fst (mk_tuple sort i) -- Build one specially
574 tupleTyCon Boxed i = fst (boxedTupleArr ! i)
575 tupleTyCon Unboxed i = fst (unboxedTupleArr ! i)
576
577 tupleTyConName :: TupleSort -> Arity -> Name
578 tupleTyConName ConstraintTuple a = cTupleTyConName a
579 tupleTyConName BoxedTuple a = tyConName (tupleTyCon Boxed a)
580 tupleTyConName UnboxedTuple a = tyConName (tupleTyCon Unboxed a)
581
582 promotedTupleDataCon :: Boxity -> Arity -> TyCon
583 promotedTupleDataCon boxity i = promoteDataCon (tupleDataCon boxity i)
584
585 tupleDataCon :: Boxity -> Arity -> DataCon
586 tupleDataCon sort i | i > mAX_TUPLE_SIZE = snd (mk_tuple sort i) -- Build one specially
587 tupleDataCon Boxed i = snd (boxedTupleArr ! i)
588 tupleDataCon Unboxed i = snd (unboxedTupleArr ! i)
589
590 boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon)
591 boxedTupleArr = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Boxed i | i <- [0..mAX_TUPLE_SIZE]]
592 unboxedTupleArr = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Unboxed i | i <- [0..mAX_TUPLE_SIZE]]
593
594 mk_tuple :: Boxity -> Int -> (TyCon,DataCon)
595 mk_tuple boxity arity = (tycon, tuple_con)
596 where
597 tycon = mkTupleTyCon tc_name tc_kind tc_arity tyvars tuple_con
598 tup_sort flavour
599
600 (tup_sort, modu, tc_kind, tc_arity, tyvars, tyvar_tys, flavour)
601 = case boxity of
602 Boxed ->
603 let boxed_tyvars = take arity alphaTyVars in
604 ( BoxedTuple
605 , gHC_TUPLE
606 , mkFunTys (nOfThem arity liftedTypeKind) liftedTypeKind
607 , arity
608 , boxed_tyvars
609 , mkTyVarTys boxed_tyvars
610 , VanillaAlgTyCon (mkPrelTyConRepName tc_name)
611 )
612 -- See Note [Unboxed tuple levity vars] in TyCon
613 Unboxed ->
614 let all_tvs = mkTemplateTyVars (replicate arity levityTy ++
615 map (tYPE . mkTyVarTy) (take arity all_tvs))
616 -- NB: This must be one call to mkTemplateTyVars, to make
617 -- sure that all the uniques are different
618 (lev_tvs, open_tvs) = splitAt arity all_tvs
619 in
620 ( UnboxedTuple
621 , gHC_PRIM
622 , mkSpecForAllTys lev_tvs $
623 mkFunTys (map tyVarKind open_tvs) $
624 unliftedTypeKind
625 , arity * 2
626 , all_tvs
627 , mkTyVarTys open_tvs
628 , UnboxedAlgTyCon
629 )
630
631 tc_name = mkWiredInName modu (mkTupleOcc tcName boxity arity) tc_uniq
632 (ATyCon tycon) BuiltInSyntax
633 tuple_con = pcDataCon dc_name tyvars tyvar_tys tycon
634 dc_name = mkWiredInName modu (mkTupleOcc dataName boxity arity) dc_uniq
635 (AConLike (RealDataCon tuple_con)) BuiltInSyntax
636 tc_uniq = mkTupleTyConUnique boxity arity
637 dc_uniq = mkTupleDataConUnique boxity arity
638
639 unitTyCon :: TyCon
640 unitTyCon = tupleTyCon Boxed 0
641
642 unitTyConKey :: Unique
643 unitTyConKey = getUnique unitTyCon
644
645 unitDataCon :: DataCon
646 unitDataCon = head (tyConDataCons unitTyCon)
647
648 unitDataConId :: Id
649 unitDataConId = dataConWorkId unitDataCon
650
651 pairTyCon :: TyCon
652 pairTyCon = tupleTyCon Boxed 2
653
654 unboxedUnitTyCon :: TyCon
655 unboxedUnitTyCon = tupleTyCon Unboxed 0
656
657 unboxedUnitDataCon :: DataCon
658 unboxedUnitDataCon = tupleDataCon Unboxed 0
659
660
661 {- *********************************************************************
662 * *
663 Equality types and classes
664 * *
665 ********************************************************************* -}
666
667 -- See Note [The equality types story] in TysPrim
668 heqTyCon, coercibleTyCon :: TyCon
669 heqClass, coercibleClass :: Class
670 heqDataCon, coercibleDataCon :: DataCon
671 heqSCSelId, coercibleSCSelId :: Id
672
673 (heqTyCon, heqClass, heqDataCon, heqSCSelId)
674 = (tycon, klass, datacon, sc_sel_id)
675 where
676 tycon = mkClassTyCon heqTyConName kind tvs roles
677 rhs klass NonRecursive
678 (mkSpecialTyConRepName (fsLit "tcHEq") heqTyConName)
679 klass = mkClass tvs [] [sc_pred] [sc_sel_id] [] [] (mkAnd []) tycon
680 datacon = pcDataCon heqDataConName tvs [sc_pred] tycon
681
682 kind = mkSpecForAllTys [kv1, kv2] $ mkFunTys [k1, k2] constraintKind
683 kv1:kv2:_ = drop 9 alphaTyVars -- gets "j" and "k"
684 k1 = mkTyVarTy kv1
685 k2 = mkTyVarTy kv2
686 [av,bv] = mkTemplateTyVars [k1, k2]
687 tvs = [kv1, kv2, av, bv]
688 roles = [Nominal, Nominal, Nominal, Nominal]
689 rhs = DataTyCon { data_cons = [datacon], is_enum = False }
690
691 sc_pred = mkTyConApp eqPrimTyCon (mkTyVarTys tvs)
692 sc_sel_id = mkDictSelId heqSCSelIdName klass
693
694 (coercibleTyCon, coercibleClass, coercibleDataCon, coercibleSCSelId)
695 = (tycon, klass, datacon, sc_sel_id)
696 where
697 tycon = mkClassTyCon coercibleTyConName kind tvs roles
698 rhs klass NonRecursive
699 (mkPrelTyConRepName coercibleTyConName)
700 klass = mkClass tvs [] [sc_pred] [sc_sel_id] [] [] (mkAnd []) tycon
701 datacon = pcDataCon coercibleDataConName tvs [sc_pred] tycon
702
703 kind = mkSpecForAllTys [kKiVar] $ mkFunTys [k, k] constraintKind
704 k = mkTyVarTy kKiVar
705 [av,bv] = mkTemplateTyVars [k, k]
706 tvs = [kKiVar, av, bv]
707 roles = [Nominal, Representational, Representational]
708 rhs = DataTyCon { data_cons = [datacon], is_enum = False }
709
710 sc_pred = mkTyConApp eqReprPrimTyCon [k, k, mkTyVarTy av, mkTyVarTy bv]
711 sc_sel_id = mkDictSelId coercibleSCSelIdName klass
712
713
714 {- *********************************************************************
715 * *
716 Kinds and levity
717 * *
718 ********************************************************************* -}
719
720 -- For information about the usage of the following type, see Note [TYPE]
721 -- in module TysPrim
722 levityTy :: Type
723 levityTy = mkTyConTy levityTyCon
724
725 levityTyCon :: TyCon
726 levityTyCon = pcTyCon True NonRecursive levityTyConName
727 Nothing [] [liftedDataCon, unliftedDataCon]
728
729 liftedDataCon, unliftedDataCon :: DataCon
730 liftedDataCon = pcDataCon liftedDataConName [] [] levityTyCon
731 unliftedDataCon = pcDataCon unliftedDataConName [] [] levityTyCon
732
733 liftedPromDataCon, unliftedPromDataCon :: TyCon
734 liftedPromDataCon = promoteDataCon liftedDataCon
735 unliftedPromDataCon = promoteDataCon unliftedDataCon
736
737 liftedDataConTy, unliftedDataConTy :: Type
738 liftedDataConTy = mkTyConTy liftedPromDataCon
739 unliftedDataConTy = mkTyConTy unliftedPromDataCon
740
741 liftedTypeKindTyCon, starKindTyCon, unicodeStarKindTyCon :: TyCon
742
743 -- See Note [TYPE] in TysPrim
744 liftedTypeKindTyCon = mkSynonymTyCon liftedTypeKindTyConName
745 liftedTypeKind
746 [] []
747 (tYPE liftedDataConTy)
748
749 starKindTyCon = mkSynonymTyCon starKindTyConName
750 liftedTypeKind
751 [] []
752 (tYPE liftedDataConTy)
753
754 unicodeStarKindTyCon = mkSynonymTyCon unicodeStarKindTyConName
755 liftedTypeKind
756 [] []
757 (tYPE liftedDataConTy)
758
759 {- *********************************************************************
760 * *
761 The boxed primitive types: Char, Int, etc
762 * *
763 ********************************************************************* -}
764
765 charTy :: Type
766 charTy = mkTyConTy charTyCon
767
768 charTyCon :: TyCon
769 charTyCon = pcNonRecDataTyCon charTyConName
770 (Just (CType "" Nothing ("HsChar",fsLit "HsChar")))
771 [] [charDataCon]
772 charDataCon :: DataCon
773 charDataCon = pcDataCon charDataConName [] [charPrimTy] charTyCon
774
775 stringTy :: Type
776 stringTy = mkListTy charTy -- convenience only
777
778 intTy :: Type
779 intTy = mkTyConTy intTyCon
780
781 intTyCon :: TyCon
782 intTyCon = pcNonRecDataTyCon intTyConName
783 (Just (CType "" Nothing ("HsInt",fsLit "HsInt"))) []
784 [intDataCon]
785 intDataCon :: DataCon
786 intDataCon = pcDataCon intDataConName [] [intPrimTy] intTyCon
787
788 wordTy :: Type
789 wordTy = mkTyConTy wordTyCon
790
791 wordTyCon :: TyCon
792 wordTyCon = pcNonRecDataTyCon wordTyConName
793 (Just (CType "" Nothing ("HsWord", fsLit "HsWord"))) []
794 [wordDataCon]
795 wordDataCon :: DataCon
796 wordDataCon = pcDataCon wordDataConName [] [wordPrimTy] wordTyCon
797
798 word8Ty :: Type
799 word8Ty = mkTyConTy word8TyCon
800
801 word8TyCon :: TyCon
802 word8TyCon = pcNonRecDataTyCon word8TyConName
803 (Just (CType "" Nothing ("HsWord8", fsLit "HsWord8"))) []
804 [word8DataCon]
805 word8DataCon :: DataCon
806 word8DataCon = pcDataCon word8DataConName [] [wordPrimTy] word8TyCon
807
808 floatTy :: Type
809 floatTy = mkTyConTy floatTyCon
810
811 floatTyCon :: TyCon
812 floatTyCon = pcNonRecDataTyCon floatTyConName
813 (Just (CType "" Nothing ("HsFloat", fsLit "HsFloat"))) []
814 [floatDataCon]
815 floatDataCon :: DataCon
816 floatDataCon = pcDataCon floatDataConName [] [floatPrimTy] floatTyCon
817
818 doubleTy :: Type
819 doubleTy = mkTyConTy doubleTyCon
820
821 doubleTyCon :: TyCon
822 doubleTyCon = pcNonRecDataTyCon doubleTyConName
823 (Just (CType "" Nothing ("HsDouble",fsLit "HsDouble"))) []
824 [doubleDataCon]
825
826 doubleDataCon :: DataCon
827 doubleDataCon = pcDataCon doubleDataConName [] [doublePrimTy] doubleTyCon
828
829 {-
830 ************************************************************************
831 * *
832 The Bool type
833 * *
834 ************************************************************************
835
836 An ordinary enumeration type, but deeply wired in. There are no
837 magical operations on @Bool@ (just the regular Prelude code).
838
839 {\em BEGIN IDLE SPECULATION BY SIMON}
840
841 This is not the only way to encode @Bool@. A more obvious coding makes
842 @Bool@ just a boxed up version of @Bool#@, like this:
843 \begin{verbatim}
844 type Bool# = Int#
845 data Bool = MkBool Bool#
846 \end{verbatim}
847
848 Unfortunately, this doesn't correspond to what the Report says @Bool@
849 looks like! Furthermore, we get slightly less efficient code (I
850 think) with this coding. @gtInt@ would look like this:
851
852 \begin{verbatim}
853 gtInt :: Int -> Int -> Bool
854 gtInt x y = case x of I# x# ->
855 case y of I# y# ->
856 case (gtIntPrim x# y#) of
857 b# -> MkBool b#
858 \end{verbatim}
859
860 Notice that the result of the @gtIntPrim@ comparison has to be turned
861 into an integer (here called @b#@), and returned in a @MkBool@ box.
862
863 The @if@ expression would compile to this:
864 \begin{verbatim}
865 case (gtInt x y) of
866 MkBool b# -> case b# of { 1# -> e1; 0# -> e2 }
867 \end{verbatim}
868
869 I think this code is a little less efficient than the previous code,
870 but I'm not certain. At all events, corresponding with the Report is
871 important. The interesting thing is that the language is expressive
872 enough to describe more than one alternative; and that a type doesn't
873 necessarily need to be a straightforwardly boxed version of its
874 primitive counterpart.
875
876 {\em END IDLE SPECULATION BY SIMON}
877 -}
878
879 boolTy :: Type
880 boolTy = mkTyConTy boolTyCon
881
882 boolTyCon :: TyCon
883 boolTyCon = pcTyCon True NonRecursive boolTyConName
884 (Just (CType "" Nothing ("HsBool", fsLit "HsBool")))
885 [] [falseDataCon, trueDataCon]
886
887 falseDataCon, trueDataCon :: DataCon
888 falseDataCon = pcDataCon falseDataConName [] [] boolTyCon
889 trueDataCon = pcDataCon trueDataConName [] [] boolTyCon
890
891 falseDataConId, trueDataConId :: Id
892 falseDataConId = dataConWorkId falseDataCon
893 trueDataConId = dataConWorkId trueDataCon
894
895 orderingTyCon :: TyCon
896 orderingTyCon = pcTyCon True NonRecursive orderingTyConName Nothing
897 [] [ltDataCon, eqDataCon, gtDataCon]
898
899 ltDataCon, eqDataCon, gtDataCon :: DataCon
900 ltDataCon = pcDataCon ltDataConName [] [] orderingTyCon
901 eqDataCon = pcDataCon eqDataConName [] [] orderingTyCon
902 gtDataCon = pcDataCon gtDataConName [] [] orderingTyCon
903
904 ltDataConId, eqDataConId, gtDataConId :: Id
905 ltDataConId = dataConWorkId ltDataCon
906 eqDataConId = dataConWorkId eqDataCon
907 gtDataConId = dataConWorkId gtDataCon
908
909 {-
910 ************************************************************************
911 * *
912 The List type
913 Special syntax, deeply wired in,
914 but otherwise an ordinary algebraic data type
915 * *
916 ************************************************************************
917
918 data [] a = [] | a : (List a)
919 -}
920
921 mkListTy :: Type -> Type
922 mkListTy ty = mkTyConApp listTyCon [ty]
923
924 listTyCon :: TyCon
925 listTyCon = buildAlgTyCon listTyConName alpha_tyvar [Representational]
926 Nothing []
927 (DataTyCon [nilDataCon, consDataCon] False )
928 Recursive False
929 (VanillaAlgTyCon (mkSpecialTyConRepName (fsLit "tcList") listTyConName))
930
931 nilDataCon :: DataCon
932 nilDataCon = pcDataCon nilDataConName alpha_tyvar [] listTyCon
933
934 consDataCon :: DataCon
935 consDataCon = pcDataConWithFixity True {- Declared infix -}
936 consDataConName
937 alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon
938 -- Interesting: polymorphic recursion would help here.
939 -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy
940 -- gets the over-specific type (Type -> Type)
941
942 -- Wired-in type Maybe
943
944 maybeTyCon :: TyCon
945 maybeTyCon = pcTyCon False NonRecursive maybeTyConName Nothing alpha_tyvar
946 [nothingDataCon, justDataCon]
947
948 nothingDataCon :: DataCon
949 nothingDataCon = pcDataCon nothingDataConName alpha_tyvar [] maybeTyCon
950
951 justDataCon :: DataCon
952 justDataCon = pcDataCon justDataConName alpha_tyvar [alphaTy] maybeTyCon
953
954 {-
955 ** *********************************************************************
956 * *
957 The tuple types
958 * *
959 ************************************************************************
960
961 The tuple types are definitely magic, because they form an infinite
962 family.
963
964 \begin{itemize}
965 \item
966 They have a special family of type constructors, of type @TyCon@
967 These contain the tycon arity, but don't require a Unique.
968
969 \item
970 They have a special family of constructors, of type
971 @Id@. Again these contain their arity but don't need a Unique.
972
973 \item
974 There should be a magic way of generating the info tables and
975 entry code for all tuples.
976
977 But at the moment we just compile a Haskell source
978 file\srcloc{lib/prelude/...} containing declarations like:
979 \begin{verbatim}
980 data Tuple0 = Tup0
981 data Tuple2 a b = Tup2 a b
982 data Tuple3 a b c = Tup3 a b c
983 data Tuple4 a b c d = Tup4 a b c d
984 ...
985 \end{verbatim}
986 The print-names associated with the magic @Id@s for tuple constructors
987 ``just happen'' to be the same as those generated by these
988 declarations.
989
990 \item
991 The instance environment should have a magic way to know
992 that each tuple type is an instances of classes @Eq@, @Ix@, @Ord@ and
993 so on. \ToDo{Not implemented yet.}
994
995 \item
996 There should also be a way to generate the appropriate code for each
997 of these instances, but (like the info tables and entry code) it is
998 done by enumeration\srcloc{lib/prelude/InTup?.hs}.
999 \end{itemize}
1000 -}
1001
1002 -- | Make a tuple type. The list of types should /not/ include any
1003 -- levity specifications.
1004 mkTupleTy :: Boxity -> [Type] -> Type
1005 -- Special case for *boxed* 1-tuples, which are represented by the type itself
1006 mkTupleTy Boxed [ty] = ty
1007 mkTupleTy Boxed tys = mkTyConApp (tupleTyCon Boxed (length tys)) tys
1008 mkTupleTy Unboxed tys = mkTyConApp (tupleTyCon Unboxed (length tys))
1009 (map (getLevity "mkTupleTy") tys ++ tys)
1010
1011 -- | Build the type of a small tuple that holds the specified type of thing
1012 mkBoxedTupleTy :: [Type] -> Type
1013 mkBoxedTupleTy tys = mkTupleTy Boxed tys
1014
1015 unitTy :: Type
1016 unitTy = mkTupleTy Boxed []
1017
1018
1019 {- *********************************************************************
1020 * *
1021 The parallel-array type, [::]
1022 * *
1023 ************************************************************************
1024
1025 Special syntax for parallel arrays needs some wired in definitions.
1026 -}
1027
1028 -- | Construct a type representing the application of the parallel array constructor
1029 mkPArrTy :: Type -> Type
1030 mkPArrTy ty = mkTyConApp parrTyCon [ty]
1031
1032 -- | Represents the type constructor of parallel arrays
1033 --
1034 -- * This must match the definition in @PrelPArr@
1035 --
1036 -- NB: Although the constructor is given here, it will not be accessible in
1037 -- user code as it is not in the environment of any compiled module except
1038 -- @PrelPArr@.
1039 --
1040 parrTyCon :: TyCon
1041 parrTyCon = pcNonRecDataTyCon parrTyConName Nothing alpha_tyvar [parrDataCon]
1042
1043 parrDataCon :: DataCon
1044 parrDataCon = pcDataCon
1045 parrDataConName
1046 alpha_tyvar -- forall'ed type variables
1047 [intTy, -- 1st argument: Int
1048 mkTyConApp -- 2nd argument: Array# a
1049 arrayPrimTyCon
1050 alpha_ty]
1051 parrTyCon
1052
1053 -- | Check whether a type constructor is the constructor for parallel arrays
1054 isPArrTyCon :: TyCon -> Bool
1055 isPArrTyCon tc = tyConName tc == parrTyConName
1056
1057 -- | Fake array constructors
1058 --
1059 -- * These constructors are never really used to represent array values;
1060 -- however, they are very convenient during desugaring (and, in particular,
1061 -- in the pattern matching compiler) to treat array pattern just like
1062 -- yet another constructor pattern
1063 --
1064 parrFakeCon :: Arity -> DataCon
1065 parrFakeCon i | i > mAX_TUPLE_SIZE = mkPArrFakeCon i -- build one specially
1066 parrFakeCon i = parrFakeConArr!i
1067
1068 -- pre-defined set of constructors
1069 --
1070 parrFakeConArr :: Array Int DataCon
1071 parrFakeConArr = array (0, mAX_TUPLE_SIZE) [(i, mkPArrFakeCon i)
1072 | i <- [0..mAX_TUPLE_SIZE]]
1073
1074 -- build a fake parallel array constructor for the given arity
1075 --
1076 mkPArrFakeCon :: Int -> DataCon
1077 mkPArrFakeCon arity = data_con
1078 where
1079 data_con = pcDataCon name [tyvar] tyvarTys parrTyCon
1080 tyvar = head alphaTyVars
1081 tyvarTys = replicate arity $ mkTyVarTy tyvar
1082 nameStr = mkFastString ("MkPArr" ++ show arity)
1083 name = mkWiredInName gHC_PARR' (mkDataOccFS nameStr) unique
1084 (AConLike (RealDataCon data_con)) UserSyntax
1085 unique = mkPArrDataConUnique arity
1086
1087 -- | Checks whether a data constructor is a fake constructor for parallel arrays
1088 isPArrFakeCon :: DataCon -> Bool
1089 isPArrFakeCon dcon = dcon == parrFakeCon (dataConSourceArity dcon)
1090
1091 -- Promoted Booleans
1092
1093 promotedFalseDataCon, promotedTrueDataCon :: TyCon
1094 promotedTrueDataCon = promoteDataCon trueDataCon
1095 promotedFalseDataCon = promoteDataCon falseDataCon
1096
1097 -- Promoted Maybe
1098 promotedNothingDataCon, promotedJustDataCon :: TyCon
1099 promotedNothingDataCon = promoteDataCon nothingDataCon
1100 promotedJustDataCon = promoteDataCon justDataCon
1101
1102 -- Promoted Ordering
1103
1104 promotedLTDataCon
1105 , promotedEQDataCon
1106 , promotedGTDataCon
1107 :: TyCon
1108 promotedLTDataCon = promoteDataCon ltDataCon
1109 promotedEQDataCon = promoteDataCon eqDataCon
1110 promotedGTDataCon = promoteDataCon gtDataCon
1111
1112 -- Promoted List
1113 promotedConsDataCon, promotedNilDataCon :: TyCon
1114 promotedConsDataCon = promoteDataCon consDataCon
1115 promotedNilDataCon = promoteDataCon nilDataCon
1116
1117 {-
1118 Note [The Implicit Parameter class]
1119
1120 Implicit parameters `?x :: a` are desugared into dictionaries for the
1121 class `IP "x" a`, which is defined (in GHC.Classes) as
1122
1123 class IP (x :: Symbol) a | x -> a
1124
1125 This class is wired-in so that `error` and `undefined`, which have
1126 wired-in types, can use the implicit-call-stack feature to provide
1127 a call-stack alongside the error message.
1128 -}
1129
1130 ipDataConName, ipTyConName, ipCoName :: Name
1131 ipDataConName = mkWiredInDataConName UserSyntax gHC_CLASSES (fsLit "IP")
1132 ipDataConKey ipDataCon
1133 ipTyConName = mkWiredInTyConName UserSyntax gHC_CLASSES (fsLit "IP")
1134 ipTyConKey ipTyCon
1135 ipCoName = mkWiredInCoAxiomName BuiltInSyntax gHC_CLASSES (fsLit "NTCo:IP")
1136 ipCoNameKey (toBranchedAxiom ipCoAxiom)
1137
1138 -- See Note [The Implicit Parameter class]
1139 ipTyCon :: TyCon
1140 ipTyCon = mkClassTyCon ipTyConName kind [ip,a] [] rhs ipClass NonRecursive
1141 (mkPrelTyConRepName ipTyConName)
1142 where
1143 kind = mkFunTys [typeSymbolKind, liftedTypeKind] constraintKind
1144 [ip,a] = mkTemplateTyVars [typeSymbolKind, liftedTypeKind]
1145 rhs = NewTyCon ipDataCon (mkTyVarTy a) ([], mkTyVarTy a) ipCoAxiom
1146
1147 ipCoAxiom :: CoAxiom Unbranched
1148 ipCoAxiom = mkNewTypeCoAxiom ipCoName ipTyCon [ip,a] [Nominal, Nominal] (mkTyVarTy a)
1149 where
1150 [ip,a] = mkTemplateTyVars [typeSymbolKind, liftedTypeKind]
1151
1152 ipDataCon :: DataCon
1153 ipDataCon = pcDataCon ipDataConName [ip,a] ts ipTyCon
1154 where
1155 [ip,a] = mkTemplateTyVars [typeSymbolKind, liftedTypeKind]
1156 ts = [mkTyVarTy a]
1157
1158 ipClass :: Class
1159 ipClass = mkClass (tyConTyVars ipTyCon) [([ip], [a])] [] [] [] [] (mkAnd [])
1160 ipTyCon
1161 where
1162 [ip, a] = tyConTyVars ipTyCon
1163
1164 -- this is a fake version of the CallStack TyCon so we can refer to it
1165 -- in MkCore.errorTy
1166 callStackTyCon :: TyCon
1167 callStackTyCon = pcNonRecDataTyCon callStackTyConName Nothing [] []