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