Fix #16293 by cleaning up Proxy# infelicities
[ghc.git] / compiler / prelude / TysPrim.hs
1 {-
2 (c) The AQUA Project, Glasgow University, 1994-1998
3
4
5 \section[TysPrim]{Wired-in knowledge about primitive types}
6 -}
7
8 {-# LANGUAGE CPP #-}
9
10 -- | This module defines TyCons that can't be expressed in Haskell.
11 -- They are all, therefore, wired-in TyCons. C.f module TysWiredIn
12 module TysPrim(
13 mkPrimTyConName, -- For implicit parameters in TysWiredIn only
14
15 mkTemplateKindVars, mkTemplateTyVars, mkTemplateTyVarsFrom,
16 mkTemplateKiTyVars,
17
18 mkTemplateTyConBinders, mkTemplateKindTyConBinders,
19 mkTemplateAnonTyConBinders,
20
21 alphaTyVars, alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar,
22 alphaTys, alphaTy, betaTy, gammaTy, deltaTy,
23 alphaTyVarsUnliftedRep, alphaTyVarUnliftedRep,
24 alphaTysUnliftedRep, alphaTyUnliftedRep,
25 runtimeRep1TyVar, runtimeRep2TyVar, runtimeRep1Ty, runtimeRep2Ty,
26 openAlphaTy, openBetaTy, openAlphaTyVar, openBetaTyVar,
27
28 -- Kind constructors...
29 tYPETyCon, tYPETyConName,
30
31 -- Kinds
32 tYPE, primRepToRuntimeRep,
33
34 funTyCon, funTyConName,
35 unexposedPrimTyCons, exposedPrimTyCons, primTyCons,
36
37 charPrimTyCon, charPrimTy, charPrimTyConName,
38 intPrimTyCon, intPrimTy, intPrimTyConName,
39 wordPrimTyCon, wordPrimTy, wordPrimTyConName,
40 addrPrimTyCon, addrPrimTy, addrPrimTyConName,
41 floatPrimTyCon, floatPrimTy, floatPrimTyConName,
42 doublePrimTyCon, doublePrimTy, doublePrimTyConName,
43
44 voidPrimTyCon, voidPrimTy,
45 statePrimTyCon, mkStatePrimTy,
46 realWorldTyCon, realWorldTy, realWorldStatePrimTy,
47
48 proxyPrimTyCon, mkProxyPrimTy,
49
50 arrayPrimTyCon, mkArrayPrimTy,
51 byteArrayPrimTyCon, byteArrayPrimTy,
52 arrayArrayPrimTyCon, mkArrayArrayPrimTy,
53 smallArrayPrimTyCon, mkSmallArrayPrimTy,
54 mutableArrayPrimTyCon, mkMutableArrayPrimTy,
55 mutableByteArrayPrimTyCon, mkMutableByteArrayPrimTy,
56 mutableArrayArrayPrimTyCon, mkMutableArrayArrayPrimTy,
57 smallMutableArrayPrimTyCon, mkSmallMutableArrayPrimTy,
58 mutVarPrimTyCon, mkMutVarPrimTy,
59
60 mVarPrimTyCon, mkMVarPrimTy,
61 tVarPrimTyCon, mkTVarPrimTy,
62 stablePtrPrimTyCon, mkStablePtrPrimTy,
63 stableNamePrimTyCon, mkStableNamePrimTy,
64 compactPrimTyCon, compactPrimTy,
65 bcoPrimTyCon, bcoPrimTy,
66 weakPrimTyCon, mkWeakPrimTy,
67 threadIdPrimTyCon, threadIdPrimTy,
68
69 int8PrimTyCon, int8PrimTy, int8PrimTyConName,
70 word8PrimTyCon, word8PrimTy, word8PrimTyConName,
71
72 int16PrimTyCon, int16PrimTy, int16PrimTyConName,
73 word16PrimTyCon, word16PrimTy, word16PrimTyConName,
74
75 int32PrimTyCon, int32PrimTy, int32PrimTyConName,
76 word32PrimTyCon, word32PrimTy, word32PrimTyConName,
77
78 int64PrimTyCon, int64PrimTy, int64PrimTyConName,
79 word64PrimTyCon, word64PrimTy, word64PrimTyConName,
80
81 eqPrimTyCon, -- ty1 ~# ty2
82 eqReprPrimTyCon, -- ty1 ~R# ty2 (at role Representational)
83 eqPhantPrimTyCon, -- ty1 ~P# ty2 (at role Phantom)
84
85 -- * SIMD
86 #include "primop-vector-tys-exports.hs-incl"
87 ) where
88
89 #include "HsVersions.h"
90
91 import GhcPrelude
92
93 import {-# SOURCE #-} TysWiredIn
94 ( runtimeRepTy, unboxedTupleKind, liftedTypeKind
95 , vecRepDataConTyCon, tupleRepDataConTyCon
96 , liftedRepDataConTy, unliftedRepDataConTy, intRepDataConTy, int8RepDataConTy
97 , int16RepDataConTy, word16RepDataConTy
98 , wordRepDataConTy, int64RepDataConTy, word8RepDataConTy, word64RepDataConTy
99 , addrRepDataConTy
100 , floatRepDataConTy, doubleRepDataConTy
101 , vec2DataConTy, vec4DataConTy, vec8DataConTy, vec16DataConTy, vec32DataConTy
102 , vec64DataConTy
103 , int8ElemRepDataConTy, int16ElemRepDataConTy, int32ElemRepDataConTy
104 , int64ElemRepDataConTy, word8ElemRepDataConTy, word16ElemRepDataConTy
105 , word32ElemRepDataConTy, word64ElemRepDataConTy, floatElemRepDataConTy
106 , doubleElemRepDataConTy
107 , mkPromotedListTy )
108
109 import Var ( TyVar, VarBndr(Bndr), mkTyVar )
110 import Name
111 import TyCon
112 import SrcLoc
113 import Unique
114 import PrelNames
115 import FastString
116 import Outputable
117 import TyCoRep -- Doesn't need special access, but this is easier to avoid
118 -- import loops which show up if you import Type instead
119
120 import Data.Char
121
122 {-
123 ************************************************************************
124 * *
125 \subsection{Primitive type constructors}
126 * *
127 ************************************************************************
128 -}
129
130 primTyCons :: [TyCon]
131 primTyCons = unexposedPrimTyCons ++ exposedPrimTyCons
132
133 -- | Primitive 'TyCon's that are defined in "GHC.Prim" but not exposed.
134 -- It's important to keep these separate as we don't want users to be able to
135 -- write them (see Trac #15209) or see them in GHCi's @:browse@ output
136 -- (see Trac #12023).
137 unexposedPrimTyCons :: [TyCon]
138 unexposedPrimTyCons
139 = [ eqPrimTyCon
140 , eqReprPrimTyCon
141 , eqPhantPrimTyCon
142 ]
143
144 -- | Primitive 'TyCon's that are defined in, and exported from, "GHC.Prim".
145 exposedPrimTyCons :: [TyCon]
146 exposedPrimTyCons
147 = [ addrPrimTyCon
148 , arrayPrimTyCon
149 , byteArrayPrimTyCon
150 , arrayArrayPrimTyCon
151 , smallArrayPrimTyCon
152 , charPrimTyCon
153 , doublePrimTyCon
154 , floatPrimTyCon
155 , intPrimTyCon
156 , int8PrimTyCon
157 , int16PrimTyCon
158 , int32PrimTyCon
159 , int64PrimTyCon
160 , bcoPrimTyCon
161 , weakPrimTyCon
162 , mutableArrayPrimTyCon
163 , mutableByteArrayPrimTyCon
164 , mutableArrayArrayPrimTyCon
165 , smallMutableArrayPrimTyCon
166 , mVarPrimTyCon
167 , tVarPrimTyCon
168 , mutVarPrimTyCon
169 , realWorldTyCon
170 , stablePtrPrimTyCon
171 , stableNamePrimTyCon
172 , compactPrimTyCon
173 , statePrimTyCon
174 , voidPrimTyCon
175 , proxyPrimTyCon
176 , threadIdPrimTyCon
177 , wordPrimTyCon
178 , word8PrimTyCon
179 , word16PrimTyCon
180 , word32PrimTyCon
181 , word64PrimTyCon
182
183 , tYPETyCon
184
185 #include "primop-vector-tycons.hs-incl"
186 ]
187
188 mkPrimTc :: FastString -> Unique -> TyCon -> Name
189 mkPrimTc fs unique tycon
190 = mkWiredInName gHC_PRIM (mkTcOccFS fs)
191 unique
192 (ATyCon tycon) -- Relevant TyCon
193 UserSyntax
194
195 mkBuiltInPrimTc :: FastString -> Unique -> TyCon -> Name
196 mkBuiltInPrimTc fs unique tycon
197 = mkWiredInName gHC_PRIM (mkTcOccFS fs)
198 unique
199 (ATyCon tycon) -- Relevant TyCon
200 BuiltInSyntax
201
202
203 charPrimTyConName, intPrimTyConName, int8PrimTyConName, int16PrimTyConName, int32PrimTyConName, int64PrimTyConName, wordPrimTyConName, word32PrimTyConName, word8PrimTyConName, word16PrimTyConName, word64PrimTyConName, addrPrimTyConName, floatPrimTyConName, doublePrimTyConName, statePrimTyConName, proxyPrimTyConName, realWorldTyConName, arrayPrimTyConName, arrayArrayPrimTyConName, smallArrayPrimTyConName, byteArrayPrimTyConName, mutableArrayPrimTyConName, mutableByteArrayPrimTyConName, mutableArrayArrayPrimTyConName, smallMutableArrayPrimTyConName, mutVarPrimTyConName, mVarPrimTyConName, tVarPrimTyConName, stablePtrPrimTyConName, stableNamePrimTyConName, compactPrimTyConName, bcoPrimTyConName, weakPrimTyConName, threadIdPrimTyConName, eqPrimTyConName, eqReprPrimTyConName, eqPhantPrimTyConName, voidPrimTyConName :: Name
204 charPrimTyConName = mkPrimTc (fsLit "Char#") charPrimTyConKey charPrimTyCon
205 intPrimTyConName = mkPrimTc (fsLit "Int#") intPrimTyConKey intPrimTyCon
206 int8PrimTyConName = mkPrimTc (fsLit "Int8#") int8PrimTyConKey int8PrimTyCon
207 int16PrimTyConName = mkPrimTc (fsLit "Int16#") int16PrimTyConKey int16PrimTyCon
208 int32PrimTyConName = mkPrimTc (fsLit "Int32#") int32PrimTyConKey int32PrimTyCon
209 int64PrimTyConName = mkPrimTc (fsLit "Int64#") int64PrimTyConKey int64PrimTyCon
210 wordPrimTyConName = mkPrimTc (fsLit "Word#") wordPrimTyConKey wordPrimTyCon
211 word8PrimTyConName = mkPrimTc (fsLit "Word8#") word8PrimTyConKey word8PrimTyCon
212 word16PrimTyConName = mkPrimTc (fsLit "Word16#") word16PrimTyConKey word16PrimTyCon
213 word32PrimTyConName = mkPrimTc (fsLit "Word32#") word32PrimTyConKey word32PrimTyCon
214 word64PrimTyConName = mkPrimTc (fsLit "Word64#") word64PrimTyConKey word64PrimTyCon
215 addrPrimTyConName = mkPrimTc (fsLit "Addr#") addrPrimTyConKey addrPrimTyCon
216 floatPrimTyConName = mkPrimTc (fsLit "Float#") floatPrimTyConKey floatPrimTyCon
217 doublePrimTyConName = mkPrimTc (fsLit "Double#") doublePrimTyConKey doublePrimTyCon
218 statePrimTyConName = mkPrimTc (fsLit "State#") statePrimTyConKey statePrimTyCon
219 voidPrimTyConName = mkPrimTc (fsLit "Void#") voidPrimTyConKey voidPrimTyCon
220 proxyPrimTyConName = mkPrimTc (fsLit "Proxy#") proxyPrimTyConKey proxyPrimTyCon
221 eqPrimTyConName = mkPrimTc (fsLit "~#") eqPrimTyConKey eqPrimTyCon
222 eqReprPrimTyConName = mkBuiltInPrimTc (fsLit "~R#") eqReprPrimTyConKey eqReprPrimTyCon
223 eqPhantPrimTyConName = mkBuiltInPrimTc (fsLit "~P#") eqPhantPrimTyConKey eqPhantPrimTyCon
224 realWorldTyConName = mkPrimTc (fsLit "RealWorld") realWorldTyConKey realWorldTyCon
225 arrayPrimTyConName = mkPrimTc (fsLit "Array#") arrayPrimTyConKey arrayPrimTyCon
226 byteArrayPrimTyConName = mkPrimTc (fsLit "ByteArray#") byteArrayPrimTyConKey byteArrayPrimTyCon
227 arrayArrayPrimTyConName = mkPrimTc (fsLit "ArrayArray#") arrayArrayPrimTyConKey arrayArrayPrimTyCon
228 smallArrayPrimTyConName = mkPrimTc (fsLit "SmallArray#") smallArrayPrimTyConKey smallArrayPrimTyCon
229 mutableArrayPrimTyConName = mkPrimTc (fsLit "MutableArray#") mutableArrayPrimTyConKey mutableArrayPrimTyCon
230 mutableByteArrayPrimTyConName = mkPrimTc (fsLit "MutableByteArray#") mutableByteArrayPrimTyConKey mutableByteArrayPrimTyCon
231 mutableArrayArrayPrimTyConName= mkPrimTc (fsLit "MutableArrayArray#") mutableArrayArrayPrimTyConKey mutableArrayArrayPrimTyCon
232 smallMutableArrayPrimTyConName= mkPrimTc (fsLit "SmallMutableArray#") smallMutableArrayPrimTyConKey smallMutableArrayPrimTyCon
233 mutVarPrimTyConName = mkPrimTc (fsLit "MutVar#") mutVarPrimTyConKey mutVarPrimTyCon
234 mVarPrimTyConName = mkPrimTc (fsLit "MVar#") mVarPrimTyConKey mVarPrimTyCon
235 tVarPrimTyConName = mkPrimTc (fsLit "TVar#") tVarPrimTyConKey tVarPrimTyCon
236 stablePtrPrimTyConName = mkPrimTc (fsLit "StablePtr#") stablePtrPrimTyConKey stablePtrPrimTyCon
237 stableNamePrimTyConName = mkPrimTc (fsLit "StableName#") stableNamePrimTyConKey stableNamePrimTyCon
238 compactPrimTyConName = mkPrimTc (fsLit "Compact#") compactPrimTyConKey compactPrimTyCon
239 bcoPrimTyConName = mkPrimTc (fsLit "BCO#") bcoPrimTyConKey bcoPrimTyCon
240 weakPrimTyConName = mkPrimTc (fsLit "Weak#") weakPrimTyConKey weakPrimTyCon
241 threadIdPrimTyConName = mkPrimTc (fsLit "ThreadId#") threadIdPrimTyConKey threadIdPrimTyCon
242
243 {-
244 ************************************************************************
245 * *
246 \subsection{Support code}
247 * *
248 ************************************************************************
249
250 alphaTyVars is a list of type variables for use in templates:
251 ["a", "b", ..., "z", "t1", "t2", ... ]
252 -}
253
254 mkTemplateKindVars :: [Kind] -> [TyVar]
255 -- k0 with unique (mkAlphaTyVarUnique 0)
256 -- k1 with unique (mkAlphaTyVarUnique 1)
257 -- ... etc
258 mkTemplateKindVars [kind]
259 = [mkTyVar (mk_tv_name 0 "k") kind]
260 -- Special case for one kind: just "k"
261
262 mkTemplateKindVars kinds
263 = [ mkTyVar (mk_tv_name u ('k' : show u)) kind
264 | (kind, u) <- kinds `zip` [0..] ]
265 mk_tv_name :: Int -> String -> Name
266 mk_tv_name u s = mkInternalName (mkAlphaTyVarUnique u)
267 (mkTyVarOccFS (mkFastString s))
268 noSrcSpan
269
270 mkTemplateTyVarsFrom :: Int -> [Kind] -> [TyVar]
271 -- a with unique (mkAlphaTyVarUnique n)
272 -- b with unique (mkAlphaTyVarUnique n+1)
273 -- ... etc
274 -- Typically called as
275 -- mkTemplateTyVarsFrom (length kv_bndrs) kinds
276 -- where kv_bndrs are the kind-level binders of a TyCon
277 mkTemplateTyVarsFrom n kinds
278 = [ mkTyVar name kind
279 | (kind, index) <- zip kinds [0..],
280 let ch_ord = index + ord 'a'
281 name_str | ch_ord <= ord 'z' = [chr ch_ord]
282 | otherwise = 't':show index
283 name = mk_tv_name (index + n) name_str
284 ]
285
286 mkTemplateTyVars :: [Kind] -> [TyVar]
287 mkTemplateTyVars = mkTemplateTyVarsFrom 1
288
289 mkTemplateTyConBinders
290 :: [Kind] -- [k1, .., kn] Kinds of kind-forall'd vars
291 -> ([Kind] -> [Kind]) -- Arg is [kv1:k1, ..., kvn:kn]
292 -- same length as first arg
293 -- Result is anon arg kinds
294 -> [TyConBinder]
295 mkTemplateTyConBinders kind_var_kinds mk_anon_arg_kinds
296 = kv_bndrs ++ tv_bndrs
297 where
298 kv_bndrs = mkTemplateKindTyConBinders kind_var_kinds
299 anon_kinds = mk_anon_arg_kinds (mkTyVarTys (binderVars kv_bndrs))
300 tv_bndrs = mkTemplateAnonTyConBindersFrom (length kv_bndrs) anon_kinds
301
302 mkTemplateKiTyVars
303 :: [Kind] -- [k1, .., kn] Kinds of kind-forall'd vars
304 -> ([Kind] -> [Kind]) -- Arg is [kv1:k1, ..., kvn:kn]
305 -- same length as first arg
306 -- Result is anon arg kinds [ak1, .., akm]
307 -> [TyVar] -- [kv1:k1, ..., kvn:kn, av1:ak1, ..., avm:akm]
308 -- Example: if you want the tyvars for
309 -- forall (r:RuntimeRep) (a:TYPE r) (b:*). blah
310 -- call mkTemplateKiTyVars [RuntimeRep] (\[r]. [TYPE r, *)
311 mkTemplateKiTyVars kind_var_kinds mk_arg_kinds
312 = kv_bndrs ++ tv_bndrs
313 where
314 kv_bndrs = mkTemplateKindVars kind_var_kinds
315 anon_kinds = mk_arg_kinds (mkTyVarTys kv_bndrs)
316 tv_bndrs = mkTemplateTyVarsFrom (length kv_bndrs) anon_kinds
317
318 mkTemplateKindTyConBinders :: [Kind] -> [TyConBinder]
319 -- Makes named, Specified binders
320 mkTemplateKindTyConBinders kinds = [mkNamedTyConBinder Specified tv | tv <- mkTemplateKindVars kinds]
321
322 mkTemplateAnonTyConBinders :: [Kind] -> [TyConBinder]
323 mkTemplateAnonTyConBinders kinds = map mkAnonTyConBinder (mkTemplateTyVars kinds)
324
325 mkTemplateAnonTyConBindersFrom :: Int -> [Kind] -> [TyConBinder]
326 mkTemplateAnonTyConBindersFrom n kinds = map mkAnonTyConBinder (mkTemplateTyVarsFrom n kinds)
327
328 alphaTyVars :: [TyVar]
329 alphaTyVars = mkTemplateTyVars $ repeat liftedTypeKind
330
331 alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar :: TyVar
332 (alphaTyVar:betaTyVar:gammaTyVar:deltaTyVar:_) = alphaTyVars
333
334 alphaTys :: [Type]
335 alphaTys = mkTyVarTys alphaTyVars
336 alphaTy, betaTy, gammaTy, deltaTy :: Type
337 (alphaTy:betaTy:gammaTy:deltaTy:_) = alphaTys
338
339 alphaTyVarsUnliftedRep :: [TyVar]
340 alphaTyVarsUnliftedRep = mkTemplateTyVars $ repeat (tYPE unliftedRepDataConTy)
341
342 alphaTyVarUnliftedRep :: TyVar
343 (alphaTyVarUnliftedRep:_) = alphaTyVarsUnliftedRep
344
345 alphaTysUnliftedRep :: [Type]
346 alphaTysUnliftedRep = mkTyVarTys alphaTyVarsUnliftedRep
347 alphaTyUnliftedRep :: Type
348 (alphaTyUnliftedRep:_) = alphaTysUnliftedRep
349
350 runtimeRep1TyVar, runtimeRep2TyVar :: TyVar
351 (runtimeRep1TyVar : runtimeRep2TyVar : _)
352 = drop 16 (mkTemplateTyVars (repeat runtimeRepTy)) -- selects 'q','r'
353
354 runtimeRep1Ty, runtimeRep2Ty :: Type
355 runtimeRep1Ty = mkTyVarTy runtimeRep1TyVar
356 runtimeRep2Ty = mkTyVarTy runtimeRep2TyVar
357
358 openAlphaTyVar, openBetaTyVar :: TyVar
359 [openAlphaTyVar,openBetaTyVar]
360 = mkTemplateTyVars [tYPE runtimeRep1Ty, tYPE runtimeRep2Ty]
361
362 openAlphaTy, openBetaTy :: Type
363 openAlphaTy = mkTyVarTy openAlphaTyVar
364 openBetaTy = mkTyVarTy openBetaTyVar
365
366 {-
367 ************************************************************************
368 * *
369 FunTyCon
370 * *
371 ************************************************************************
372 -}
373
374 funTyConName :: Name
375 funTyConName = mkPrimTyConName (fsLit "->") funTyConKey funTyCon
376
377 -- | The @(->)@ type constructor.
378 --
379 -- @
380 -- (->) :: forall (rep1 :: RuntimeRep) (rep2 :: RuntimeRep).
381 -- TYPE rep1 -> TYPE rep2 -> *
382 -- @
383 funTyCon :: TyCon
384 funTyCon = mkFunTyCon funTyConName tc_bndrs tc_rep_nm
385 where
386 tc_bndrs = [ Bndr runtimeRep1TyVar (NamedTCB Inferred)
387 , Bndr runtimeRep2TyVar (NamedTCB Inferred)
388 ]
389 ++ mkTemplateAnonTyConBinders [ tYPE runtimeRep1Ty
390 , tYPE runtimeRep2Ty
391 ]
392 tc_rep_nm = mkPrelTyConRepName funTyConName
393
394 {-
395 ************************************************************************
396 * *
397 Kinds
398 * *
399 ************************************************************************
400
401 Note [TYPE and RuntimeRep]
402 ~~~~~~~~~~~~~~~~~~~~~~~~~~
403 All types that classify values have a kind of the form (TYPE rr), where
404
405 data RuntimeRep -- Defined in ghc-prim:GHC.Types
406 = LiftedRep
407 | UnliftedRep
408 | IntRep
409 | FloatRep
410 .. etc ..
411
412 rr :: RuntimeRep
413
414 TYPE :: RuntimeRep -> TYPE 'LiftedRep -- Built in
415
416 So for example:
417 Int :: TYPE 'LiftedRep
418 Array# Int :: TYPE 'UnliftedRep
419 Int# :: TYPE 'IntRep
420 Float# :: TYPE 'FloatRep
421 Maybe :: TYPE 'LiftedRep -> TYPE 'LiftedRep
422 (# , #) :: TYPE r1 -> TYPE r2 -> TYPE (TupleRep [r1, r2])
423
424 We abbreviate '*' specially:
425 type * = TYPE 'LiftedRep
426
427 The 'rr' parameter tells us how the value is represented at runime.
428
429 Generally speaking, you can't be polymorphic in 'rr'. E.g
430 f :: forall (rr:RuntimeRep) (a:TYPE rr). a -> [a]
431 f = /\(rr:RuntimeRep) (a:rr) \(a:rr). ...
432 This is no good: we could not generate code code for 'f', because the
433 calling convention for 'f' varies depending on whether the argument is
434 a a Int, Int#, or Float#. (You could imagine generating specialised
435 code, one for each instantiation of 'rr', but we don't do that.)
436
437 Certain functions CAN be runtime-rep-polymorphic, because the code
438 generator never has to manipulate a value of type 'a :: TYPE rr'.
439
440 * error :: forall (rr:RuntimeRep) (a:TYPE rr). String -> a
441 Code generator never has to manipulate the return value.
442
443 * unsafeCoerce#, defined in MkId.unsafeCoerceId:
444 Always inlined to be a no-op
445 unsafeCoerce# :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)
446 (a :: TYPE r1) (b :: TYPE r2).
447 a -> b
448
449 * Unboxed tuples, and unboxed sums, defined in TysWiredIn
450 Always inlined, and hence specialised to the call site
451 (#,#) :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)
452 (a :: TYPE r1) (b :: TYPE r2).
453 a -> b -> TYPE ('TupleRep '[r1, r2])
454
455 Note [PrimRep and kindPrimRep]
456 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
457 As part of its source code, in TyCon, GHC has
458 data PrimRep = LiftedRep | UnliftedRep | IntRep | FloatRep | ...etc...
459
460 Notice that
461 * RuntimeRep is part of the syntax tree of the program being compiled
462 (defined in a library: ghc-prim:GHC.Types)
463 * PrimRep is part of GHC's source code.
464 (defined in TyCon)
465
466 We need to get from one to the other; that is what kindPrimRep does.
467 Suppose we have a value
468 (v :: t) where (t :: k)
469 Given this kind
470 k = TyConApp "TYPE" [rep]
471 GHC needs to be able to figure out how 'v' is represented at runtime.
472 It expects 'rep' to be form
473 TyConApp rr_dc args
474 where 'rr_dc' is a promoteed data constructor from RuntimeRep. So
475 now we need to go from 'dc' to the corresponding PrimRep. We store this
476 PrimRep in the promoted data constructor itself: see TyCon.promDcRepInfo.
477
478 -}
479
480 tYPETyCon :: TyCon
481 tYPETyConName :: Name
482
483 tYPETyCon = mkKindTyCon tYPETyConName
484 (mkTemplateAnonTyConBinders [runtimeRepTy])
485 liftedTypeKind
486 [Nominal]
487 (mkPrelTyConRepName tYPETyConName)
488
489 --------------------------
490 -- ... and now their names
491
492 -- If you edit these, you may need to update the GHC formalism
493 -- See Note [GHC Formalism] in coreSyn/CoreLint.hs
494 tYPETyConName = mkPrimTyConName (fsLit "TYPE") tYPETyConKey tYPETyCon
495
496 mkPrimTyConName :: FastString -> Unique -> TyCon -> Name
497 mkPrimTyConName = mkPrimTcName BuiltInSyntax
498 -- All of the super kinds and kinds are defined in Prim,
499 -- and use BuiltInSyntax, because they are never in scope in the source
500
501 mkPrimTcName :: BuiltInSyntax -> FastString -> Unique -> TyCon -> Name
502 mkPrimTcName built_in_syntax occ key tycon
503 = mkWiredInName gHC_PRIM (mkTcOccFS occ) key (ATyCon tycon) built_in_syntax
504
505 -----------------------------
506 -- | Given a RuntimeRep, applies TYPE to it.
507 -- see Note [TYPE and RuntimeRep]
508 tYPE :: Type -> Type
509 tYPE rr = TyConApp tYPETyCon [rr]
510
511 {-
512 ************************************************************************
513 * *
514 \subsection[TysPrim-basic]{Basic primitive types (@Char#@, @Int#@, etc.)}
515 * *
516 ************************************************************************
517 -}
518
519 -- only used herein
520 pcPrimTyCon :: Name -> [Role] -> PrimRep -> TyCon
521 pcPrimTyCon name roles rep
522 = mkPrimTyCon name binders result_kind roles
523 where
524 binders = mkTemplateAnonTyConBinders (map (const liftedTypeKind) roles)
525 result_kind = tYPE (primRepToRuntimeRep rep)
526
527 -- | Convert a 'PrimRep' to a 'Type' of kind RuntimeRep
528 -- Defined here to avoid (more) module loops
529 primRepToRuntimeRep :: PrimRep -> Type
530 primRepToRuntimeRep rep = case rep of
531 VoidRep -> TyConApp tupleRepDataConTyCon [mkPromotedListTy runtimeRepTy []]
532 LiftedRep -> liftedRepDataConTy
533 UnliftedRep -> unliftedRepDataConTy
534 IntRep -> intRepDataConTy
535 Int8Rep -> int8RepDataConTy
536 Int16Rep -> int16RepDataConTy
537 WordRep -> wordRepDataConTy
538 Int64Rep -> int64RepDataConTy
539 Word8Rep -> word8RepDataConTy
540 Word16Rep -> word16RepDataConTy
541 Word64Rep -> word64RepDataConTy
542 AddrRep -> addrRepDataConTy
543 FloatRep -> floatRepDataConTy
544 DoubleRep -> doubleRepDataConTy
545 VecRep n elem -> TyConApp vecRepDataConTyCon [n', elem']
546 where
547 n' = case n of
548 2 -> vec2DataConTy
549 4 -> vec4DataConTy
550 8 -> vec8DataConTy
551 16 -> vec16DataConTy
552 32 -> vec32DataConTy
553 64 -> vec64DataConTy
554 _ -> pprPanic "Disallowed VecCount" (ppr n)
555
556 elem' = case elem of
557 Int8ElemRep -> int8ElemRepDataConTy
558 Int16ElemRep -> int16ElemRepDataConTy
559 Int32ElemRep -> int32ElemRepDataConTy
560 Int64ElemRep -> int64ElemRepDataConTy
561 Word8ElemRep -> word8ElemRepDataConTy
562 Word16ElemRep -> word16ElemRepDataConTy
563 Word32ElemRep -> word32ElemRepDataConTy
564 Word64ElemRep -> word64ElemRepDataConTy
565 FloatElemRep -> floatElemRepDataConTy
566 DoubleElemRep -> doubleElemRepDataConTy
567
568 pcPrimTyCon0 :: Name -> PrimRep -> TyCon
569 pcPrimTyCon0 name rep
570 = pcPrimTyCon name [] rep
571
572 charPrimTy :: Type
573 charPrimTy = mkTyConTy charPrimTyCon
574 charPrimTyCon :: TyCon
575 charPrimTyCon = pcPrimTyCon0 charPrimTyConName WordRep
576
577 intPrimTy :: Type
578 intPrimTy = mkTyConTy intPrimTyCon
579 intPrimTyCon :: TyCon
580 intPrimTyCon = pcPrimTyCon0 intPrimTyConName IntRep
581
582 int8PrimTy :: Type
583 int8PrimTy = mkTyConTy int8PrimTyCon
584 int8PrimTyCon :: TyCon
585 int8PrimTyCon = pcPrimTyCon0 int8PrimTyConName Int8Rep
586
587 int16PrimTy :: Type
588 int16PrimTy = mkTyConTy int16PrimTyCon
589 int16PrimTyCon :: TyCon
590 int16PrimTyCon = pcPrimTyCon0 int16PrimTyConName Int16Rep
591
592 int32PrimTy :: Type
593 int32PrimTy = mkTyConTy int32PrimTyCon
594 int32PrimTyCon :: TyCon
595 int32PrimTyCon = pcPrimTyCon0 int32PrimTyConName IntRep
596
597 int64PrimTy :: Type
598 int64PrimTy = mkTyConTy int64PrimTyCon
599 int64PrimTyCon :: TyCon
600 int64PrimTyCon = pcPrimTyCon0 int64PrimTyConName Int64Rep
601
602 wordPrimTy :: Type
603 wordPrimTy = mkTyConTy wordPrimTyCon
604 wordPrimTyCon :: TyCon
605 wordPrimTyCon = pcPrimTyCon0 wordPrimTyConName WordRep
606
607 word8PrimTy :: Type
608 word8PrimTy = mkTyConTy word8PrimTyCon
609 word8PrimTyCon :: TyCon
610 word8PrimTyCon = pcPrimTyCon0 word8PrimTyConName Word8Rep
611
612 word16PrimTy :: Type
613 word16PrimTy = mkTyConTy word16PrimTyCon
614 word16PrimTyCon :: TyCon
615 word16PrimTyCon = pcPrimTyCon0 word16PrimTyConName Word16Rep
616
617 word32PrimTy :: Type
618 word32PrimTy = mkTyConTy word32PrimTyCon
619 word32PrimTyCon :: TyCon
620 word32PrimTyCon = pcPrimTyCon0 word32PrimTyConName WordRep
621
622 word64PrimTy :: Type
623 word64PrimTy = mkTyConTy word64PrimTyCon
624 word64PrimTyCon :: TyCon
625 word64PrimTyCon = pcPrimTyCon0 word64PrimTyConName Word64Rep
626
627 addrPrimTy :: Type
628 addrPrimTy = mkTyConTy addrPrimTyCon
629 addrPrimTyCon :: TyCon
630 addrPrimTyCon = pcPrimTyCon0 addrPrimTyConName AddrRep
631
632 floatPrimTy :: Type
633 floatPrimTy = mkTyConTy floatPrimTyCon
634 floatPrimTyCon :: TyCon
635 floatPrimTyCon = pcPrimTyCon0 floatPrimTyConName FloatRep
636
637 doublePrimTy :: Type
638 doublePrimTy = mkTyConTy doublePrimTyCon
639 doublePrimTyCon :: TyCon
640 doublePrimTyCon = pcPrimTyCon0 doublePrimTyConName DoubleRep
641
642 {-
643 ************************************************************************
644 * *
645 \subsection[TysPrim-state]{The @State#@ type (and @_RealWorld@ types)}
646 * *
647 ************************************************************************
648
649 Note [The equality types story]
650 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
651 GHC sports a veritable menagerie of equality types:
652
653 Type or Lifted? Hetero? Role Built in Defining module
654 class? L/U TyCon
655 -----------------------------------------------------------------------------------------
656 ~# T U hetero nominal eqPrimTyCon GHC.Prim
657 ~~ C L hetero nominal heqTyCon GHC.Types
658 ~ C L homo nominal eqTyCon GHC.Types
659 :~: T L homo nominal (not built-in) Data.Type.Equality
660 :~~: T L hetero nominal (not built-in) Data.Type.Equality
661
662 ~R# T U hetero repr eqReprPrimTy GHC.Prim
663 Coercible C L homo repr coercibleTyCon GHC.Types
664 Coercion T L homo repr (not built-in) Data.Type.Coercion
665 ~P# T U hetero phantom eqPhantPrimTyCon GHC.Prim
666
667 Recall that "hetero" means the equality can related types of different
668 kinds. Knowing that (t1 ~# t2) or (t1 ~R# t2) or even that (t1 ~P# t2)
669 also means that (k1 ~# k2), where (t1 :: k1) and (t2 :: k2).
670
671 To produce less confusion for end users, when not dumping and without
672 -fprint-equality-relations, each of these groups is printed as the bottommost
673 listed equality. That is, (~#) and (~~) are both rendered as (~) in
674 error messages, and (~R#) is rendered as Coercible.
675
676 Let's take these one at a time:
677
678 --------------------------
679 (~#) :: forall k1 k2. k1 -> k2 -> #
680 --------------------------
681 This is The Type Of Equality in GHC. It classifies nominal coercions.
682 This type is used in the solver for recording equality constraints.
683 It responds "yes" to Type.isEqPred and classifies as an EqPred in
684 Type.classifyPredType.
685
686 All wanted constraints of this type are built with coercion holes.
687 (See Note [Coercion holes] in TyCoRep.) But see also
688 Note [Deferred errors for coercion holes] in TcErrors to see how
689 equality constraints are deferred.
690
691 Within GHC, ~# is called eqPrimTyCon, and it is defined in TysPrim.
692
693
694 --------------------------
695 (~~) :: forall k1 k2. k1 -> k2 -> Constraint
696 --------------------------
697 This is (almost) an ordinary class, defined as if by
698 class a ~# b => a ~~ b
699 instance a ~# b => a ~~ b
700 Here's what's unusual about it:
701
702 * We can't actually declare it that way because we don't have syntax for ~#.
703 And ~# isn't a constraint, so even if we could write it, it wouldn't kind
704 check.
705
706 * Users cannot write instances of it.
707
708 * It is "naturally coherent". This means that the solver won't hesitate to
709 solve a goal of type (a ~~ b) even if there is, say (Int ~~ c) in the
710 context. (Normally, it waits to learn more, just in case the given
711 influences what happens next.) See Note [Naturally coherent classes]
712 in TcInteract.
713
714 * It always terminates. That is, in the UndecidableInstances checks, we
715 don't worry if a (~~) constraint is too big, as we know that solving
716 equality terminates.
717
718 On the other hand, this behaves just like any class w.r.t. eager superclass
719 unpacking in the solver. So a lifted equality given quickly becomes an unlifted
720 equality given. This is good, because the solver knows all about unlifted
721 equalities. There is some special-casing in TcInteract.matchClassInst to
722 pretend that there is an instance of this class, as we can't write the instance
723 in Haskell.
724
725 Within GHC, ~~ is called heqTyCon, and it is defined in TysWiredIn.
726
727
728 --------------------------
729 (~) :: forall k. k -> k -> Constraint
730 --------------------------
731 This is /exactly/ like (~~), except with a homogeneous kind.
732 It is an almost-ordinary class defined as if by
733 class a ~# b => (a :: k) ~ (b :: k)
734 instance a ~# b => a ~ b
735
736 * All the bullets for (~~) apply
737
738 * In addition (~) is magical syntax, as ~ is a reserved symbol.
739 It cannot be exported or imported.
740
741 Within GHC, ~ is called eqTyCon, and it is defined in TysWiredIn.
742
743 Historical note: prior to July 18 (~) was defined as a
744 more-ordinary class with (~~) as a superclass. But that made it
745 special in different ways; and the extra superclass selections to
746 get from (~) to (~#) via (~~) were tiresome. Now it's defined
747 uniformly with (~~) and Coercible; much nicer.)
748
749
750 --------------------------
751 (:~:) :: forall k. k -> k -> *
752 (:~~:) :: forall k1 k2. k1 -> k2 -> *
753 --------------------------
754 These are perfectly ordinary GADTs, wrapping (~) and (~~) resp.
755 They are not defined within GHC at all.
756
757
758 --------------------------
759 (~R#) :: forall k1 k2. k1 -> k2 -> #
760 --------------------------
761 The is the representational analogue of ~#. This is the type of representational
762 equalities that the solver works on. All wanted constraints of this type are
763 built with coercion holes.
764
765 Within GHC, ~R# is called eqReprPrimTyCon, and it is defined in TysPrim.
766
767
768 --------------------------
769 Coercible :: forall k. k -> k -> Constraint
770 --------------------------
771 This is quite like (~~) in the way it's defined and treated within GHC, but
772 it's homogeneous. Homogeneity helps with type inference (as GHC can solve one
773 kind from the other) and, in my (Richard's) estimation, will be more intuitive
774 for users.
775
776 An alternative design included HCoercible (like (~~)) and Coercible (like (~)).
777 One annoyance was that we want `coerce :: Coercible a b => a -> b`, and
778 we need the type of coerce to be fully wired-in. So the HCoercible/Coercible
779 split required that both types be fully wired-in. Instead of doing this,
780 I just got rid of HCoercible, as I'm not sure who would use it, anyway.
781
782 Within GHC, Coercible is called coercibleTyCon, and it is defined in
783 TysWiredIn.
784
785
786 --------------------------
787 Coercion :: forall k. k -> k -> *
788 --------------------------
789 This is a perfectly ordinary GADT, wrapping Coercible. It is not defined
790 within GHC at all.
791
792
793 --------------------------
794 (~P#) :: forall k1 k2. k1 -> k2 -> #
795 --------------------------
796 This is the phantom analogue of ~# and it is barely used at all.
797 (The solver has no idea about this one.) Here is the motivation:
798
799 data Phant a = MkPhant
800 type role Phant phantom
801
802 Phant <Int, Bool>_P :: Phant Int ~P# Phant Bool
803
804 We just need to have something to put on that last line. You probably
805 don't need to worry about it.
806
807
808
809 Note [The State# TyCon]
810 ~~~~~~~~~~~~~~~~~~~~~~~
811 State# is the primitive, unlifted type of states. It has one type parameter,
812 thus
813 State# RealWorld
814 or
815 State# s
816
817 where s is a type variable. The only purpose of the type parameter is to
818 keep different state threads separate. It is represented by nothing at all.
819
820 The type parameter to State# is intended to keep separate threads separate.
821 Even though this parameter is not used in the definition of State#, it is
822 given role Nominal to enforce its intended use.
823 -}
824
825 mkStatePrimTy :: Type -> Type
826 mkStatePrimTy ty = TyConApp statePrimTyCon [ty]
827
828 statePrimTyCon :: TyCon -- See Note [The State# TyCon]
829 statePrimTyCon = pcPrimTyCon statePrimTyConName [Nominal] VoidRep
830
831 {-
832 RealWorld is deeply magical. It is *primitive*, but it is not
833 *unlifted* (hence ptrArg). We never manipulate values of type
834 RealWorld; it's only used in the type system, to parameterise State#.
835 -}
836
837 realWorldTyCon :: TyCon
838 realWorldTyCon = mkLiftedPrimTyCon realWorldTyConName [] liftedTypeKind []
839 realWorldTy :: Type
840 realWorldTy = mkTyConTy realWorldTyCon
841 realWorldStatePrimTy :: Type
842 realWorldStatePrimTy = mkStatePrimTy realWorldTy -- State# RealWorld
843
844 -- Note: the ``state-pairing'' types are not truly primitive,
845 -- so they are defined in \tr{TysWiredIn.hs}, not here.
846
847
848 voidPrimTy :: Type
849 voidPrimTy = TyConApp voidPrimTyCon []
850
851 voidPrimTyCon :: TyCon
852 voidPrimTyCon = pcPrimTyCon voidPrimTyConName [] VoidRep
853
854 mkProxyPrimTy :: Type -> Type -> Type
855 mkProxyPrimTy k ty = TyConApp proxyPrimTyCon [k, ty]
856
857 proxyPrimTyCon :: TyCon
858 proxyPrimTyCon = mkPrimTyCon proxyPrimTyConName binders res_kind [Nominal,Phantom]
859 where
860 -- Kind: forall k. k -> TYPE (Tuple '[])
861 binders = mkTemplateTyConBinders [liftedTypeKind] id
862 res_kind = unboxedTupleKind []
863
864
865 {- *********************************************************************
866 * *
867 Primitive equality constraints
868 See Note [The equality types story]
869 * *
870 ********************************************************************* -}
871
872 eqPrimTyCon :: TyCon -- The representation type for equality predicates
873 -- See Note [The equality types story]
874 eqPrimTyCon = mkPrimTyCon eqPrimTyConName binders res_kind roles
875 where
876 -- Kind :: forall k1 k2. k1 -> k2 -> TYPE (Tuple '[])
877 binders = mkTemplateTyConBinders [liftedTypeKind, liftedTypeKind] id
878 res_kind = unboxedTupleKind []
879 roles = [Nominal, Nominal, Nominal, Nominal]
880
881 -- like eqPrimTyCon, but the type for *Representational* coercions
882 -- this should only ever appear as the type of a covar. Its role is
883 -- interpreted in coercionRole
884 eqReprPrimTyCon :: TyCon -- See Note [The equality types story]
885 eqReprPrimTyCon = mkPrimTyCon eqReprPrimTyConName binders res_kind roles
886 where
887 -- Kind :: forall k1 k2. k1 -> k2 -> TYPE (Tuple '[])
888 binders = mkTemplateTyConBinders [liftedTypeKind, liftedTypeKind] id
889 res_kind = unboxedTupleKind []
890 roles = [Nominal, Nominal, Representational, Representational]
891
892 -- like eqPrimTyCon, but the type for *Phantom* coercions.
893 -- This is only used to make higher-order equalities. Nothing
894 -- should ever actually have this type!
895 eqPhantPrimTyCon :: TyCon
896 eqPhantPrimTyCon = mkPrimTyCon eqPhantPrimTyConName binders res_kind roles
897 where
898 -- Kind :: forall k1 k2. k1 -> k2 -> TYPE (Tuple '[])
899 binders = mkTemplateTyConBinders [liftedTypeKind, liftedTypeKind] id
900 res_kind = unboxedTupleKind []
901 roles = [Nominal, Nominal, Phantom, Phantom]
902
903 {- *********************************************************************
904 * *
905 The primitive array types
906 * *
907 ********************************************************************* -}
908
909 arrayPrimTyCon, mutableArrayPrimTyCon, mutableByteArrayPrimTyCon,
910 byteArrayPrimTyCon, arrayArrayPrimTyCon, mutableArrayArrayPrimTyCon,
911 smallArrayPrimTyCon, smallMutableArrayPrimTyCon :: TyCon
912 arrayPrimTyCon = pcPrimTyCon arrayPrimTyConName [Representational] UnliftedRep
913 mutableArrayPrimTyCon = pcPrimTyCon mutableArrayPrimTyConName [Nominal, Representational] UnliftedRep
914 mutableByteArrayPrimTyCon = pcPrimTyCon mutableByteArrayPrimTyConName [Nominal] UnliftedRep
915 byteArrayPrimTyCon = pcPrimTyCon0 byteArrayPrimTyConName UnliftedRep
916 arrayArrayPrimTyCon = pcPrimTyCon0 arrayArrayPrimTyConName UnliftedRep
917 mutableArrayArrayPrimTyCon = pcPrimTyCon mutableArrayArrayPrimTyConName [Nominal] UnliftedRep
918 smallArrayPrimTyCon = pcPrimTyCon smallArrayPrimTyConName [Representational] UnliftedRep
919 smallMutableArrayPrimTyCon = pcPrimTyCon smallMutableArrayPrimTyConName [Nominal, Representational] UnliftedRep
920
921 mkArrayPrimTy :: Type -> Type
922 mkArrayPrimTy elt = TyConApp arrayPrimTyCon [elt]
923 byteArrayPrimTy :: Type
924 byteArrayPrimTy = mkTyConTy byteArrayPrimTyCon
925 mkArrayArrayPrimTy :: Type
926 mkArrayArrayPrimTy = mkTyConTy arrayArrayPrimTyCon
927 mkSmallArrayPrimTy :: Type -> Type
928 mkSmallArrayPrimTy elt = TyConApp smallArrayPrimTyCon [elt]
929 mkMutableArrayPrimTy :: Type -> Type -> Type
930 mkMutableArrayPrimTy s elt = TyConApp mutableArrayPrimTyCon [s, elt]
931 mkMutableByteArrayPrimTy :: Type -> Type
932 mkMutableByteArrayPrimTy s = TyConApp mutableByteArrayPrimTyCon [s]
933 mkMutableArrayArrayPrimTy :: Type -> Type
934 mkMutableArrayArrayPrimTy s = TyConApp mutableArrayArrayPrimTyCon [s]
935 mkSmallMutableArrayPrimTy :: Type -> Type -> Type
936 mkSmallMutableArrayPrimTy s elt = TyConApp smallMutableArrayPrimTyCon [s, elt]
937
938
939 {- *********************************************************************
940 * *
941 The mutable variable type
942 * *
943 ********************************************************************* -}
944
945 mutVarPrimTyCon :: TyCon
946 mutVarPrimTyCon = pcPrimTyCon mutVarPrimTyConName [Nominal, Representational] UnliftedRep
947
948 mkMutVarPrimTy :: Type -> Type -> Type
949 mkMutVarPrimTy s elt = TyConApp mutVarPrimTyCon [s, elt]
950
951 {-
952 ************************************************************************
953 * *
954 \subsection[TysPrim-synch-var]{The synchronizing variable type}
955 * *
956 ************************************************************************
957 -}
958
959 mVarPrimTyCon :: TyCon
960 mVarPrimTyCon = pcPrimTyCon mVarPrimTyConName [Nominal, Representational] UnliftedRep
961
962 mkMVarPrimTy :: Type -> Type -> Type
963 mkMVarPrimTy s elt = TyConApp mVarPrimTyCon [s, elt]
964
965 {-
966 ************************************************************************
967 * *
968 \subsection[TysPrim-stm-var]{The transactional variable type}
969 * *
970 ************************************************************************
971 -}
972
973 tVarPrimTyCon :: TyCon
974 tVarPrimTyCon = pcPrimTyCon tVarPrimTyConName [Nominal, Representational] UnliftedRep
975
976 mkTVarPrimTy :: Type -> Type -> Type
977 mkTVarPrimTy s elt = TyConApp tVarPrimTyCon [s, elt]
978
979 {-
980 ************************************************************************
981 * *
982 \subsection[TysPrim-stable-ptrs]{The stable-pointer type}
983 * *
984 ************************************************************************
985 -}
986
987 stablePtrPrimTyCon :: TyCon
988 stablePtrPrimTyCon = pcPrimTyCon stablePtrPrimTyConName [Representational] AddrRep
989
990 mkStablePtrPrimTy :: Type -> Type
991 mkStablePtrPrimTy ty = TyConApp stablePtrPrimTyCon [ty]
992
993 {-
994 ************************************************************************
995 * *
996 \subsection[TysPrim-stable-names]{The stable-name type}
997 * *
998 ************************************************************************
999 -}
1000
1001 stableNamePrimTyCon :: TyCon
1002 stableNamePrimTyCon = pcPrimTyCon stableNamePrimTyConName [Phantom] UnliftedRep
1003
1004 mkStableNamePrimTy :: Type -> Type
1005 mkStableNamePrimTy ty = TyConApp stableNamePrimTyCon [ty]
1006
1007 {-
1008 ************************************************************************
1009 * *
1010 \subsection[TysPrim-compact-nfdata]{The Compact NFData (CNF) type}
1011 * *
1012 ************************************************************************
1013 -}
1014
1015 compactPrimTyCon :: TyCon
1016 compactPrimTyCon = pcPrimTyCon0 compactPrimTyConName UnliftedRep
1017
1018 compactPrimTy :: Type
1019 compactPrimTy = mkTyConTy compactPrimTyCon
1020
1021 {-
1022 ************************************************************************
1023 * *
1024 \subsection[TysPrim-BCOs]{The ``bytecode object'' type}
1025 * *
1026 ************************************************************************
1027 -}
1028
1029 bcoPrimTy :: Type
1030 bcoPrimTy = mkTyConTy bcoPrimTyCon
1031 bcoPrimTyCon :: TyCon
1032 bcoPrimTyCon = pcPrimTyCon0 bcoPrimTyConName UnliftedRep
1033
1034 {-
1035 ************************************************************************
1036 * *
1037 \subsection[TysPrim-Weak]{The ``weak pointer'' type}
1038 * *
1039 ************************************************************************
1040 -}
1041
1042 weakPrimTyCon :: TyCon
1043 weakPrimTyCon = pcPrimTyCon weakPrimTyConName [Representational] UnliftedRep
1044
1045 mkWeakPrimTy :: Type -> Type
1046 mkWeakPrimTy v = TyConApp weakPrimTyCon [v]
1047
1048 {-
1049 ************************************************************************
1050 * *
1051 \subsection[TysPrim-thread-ids]{The ``thread id'' type}
1052 * *
1053 ************************************************************************
1054
1055 A thread id is represented by a pointer to the TSO itself, to ensure
1056 that they are always unique and we can always find the TSO for a given
1057 thread id. However, this has the unfortunate consequence that a
1058 ThreadId# for a given thread is treated as a root by the garbage
1059 collector and can keep TSOs around for too long.
1060
1061 Hence the programmer API for thread manipulation uses a weak pointer
1062 to the thread id internally.
1063 -}
1064
1065 threadIdPrimTy :: Type
1066 threadIdPrimTy = mkTyConTy threadIdPrimTyCon
1067 threadIdPrimTyCon :: TyCon
1068 threadIdPrimTyCon = pcPrimTyCon0 threadIdPrimTyConName UnliftedRep
1069
1070 {-
1071 ************************************************************************
1072 * *
1073 \subsection{SIMD vector types}
1074 * *
1075 ************************************************************************
1076 -}
1077
1078 #include "primop-vector-tys.hs-incl"