2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[PrelVals]{Prelude values the compiler ``knows about''}
7 #include "HsVersions.h"
12 IMPORT_DELOOPER(IdLoop) ( UnfoldingGuidance(..) )
13 import Id ( SYN_IE(Id), GenId, mkImported, mkUserId, mkTemplateLocals )
14 IMPORT_DELOOPER(PrelLoop)
22 import CmdLineOpts ( maybe_CompilingGhcInternals )
23 import CoreSyn -- quite a bit
24 import IdInfo -- quite a bit
25 import Literal ( mkMachInt )
26 import Name ( ExportFlag(..) )
28 import PrimOp ( PrimOp(..) )
29 import SpecEnv ( SYN_IE(SpecEnv), nullSpecEnv )
30 import Type ( mkTyVarTy )
31 import TyVar ( openAlphaTyVar, alphaTyVar, betaTyVar, gammaTyVar )
32 import Unique -- lots of *Keys
38 pcMiscPrelId :: Unique{-IdKey-} -> FAST_STRING -> FAST_STRING -> Type -> IdInfo -> Id
40 pcMiscPrelId key m n ty info
42 name = mkWiredInName key (OrigName m n) ExportAll
43 imp = mkImported name ty info -- the usual case...
46 -- We lie and say the thing is imported; otherwise, we get into
47 -- a mess with dependency analysis; e.g., core2stg may heave in
48 -- random calls to GHCbase.unpackPS__. If GHCbase is the module
49 -- being compiled, then it's just a matter of luck if the definition
50 -- will be in "the right place" to be in scope.
53 %************************************************************************
55 \subsection[PrelVals-error-related]{@error@ and friends; @trace@}
57 %************************************************************************
59 GHC randomly injects these into the code.
61 @patError@ is just a version of @error@ for pattern-matching
62 failures. It knows various ``codes'' which expand to longer
63 strings---this saves space!
65 @absentErr@ is a thing we put in for ``absent'' arguments. They jolly
66 well shouldn't be yanked on, but if one is, then you will get a
67 friendly message from @absentErr@ (rather a totally random crash).
69 @parError@ is a special version of @error@ which the compiler does
70 not know to be a bottoming Id. It is used in the @_par_@ and @_seq_@
71 templates, but we don't ever expect to generate code for it.
74 pc_bottoming_Id key mod name ty
75 = pcMiscPrelId key mod name ty bottoming_info
77 bottoming_info = noIdInfo `addInfo` mkBottomStrictnessInfo
78 -- these "bottom" out, no matter what their arguments
81 = pc_bottoming_Id errorIdKey pRELUDE SLIT("error") errorTy
84 = pc_bottoming_Id u gHC__ n errorTy
87 = generic_ERROR_ID patErrorIdKey SLIT("patError")
89 = generic_ERROR_ID recConErrorIdKey SLIT("recConError")
91 = generic_ERROR_ID recUpdErrorIdKey SLIT("recUpdError")
93 = generic_ERROR_ID irrefutPatErrorIdKey SLIT("irrefutPatError")
94 nON_EXHAUSTIVE_GUARDS_ERROR_ID
95 = generic_ERROR_ID nonExhaustiveGuardsErrorIdKey SLIT("nonExhaustiveGuardsError")
96 nO_DEFAULT_METHOD_ERROR_ID
97 = generic_ERROR_ID noDefaultMethodErrorIdKey SLIT("noDefaultMethodError")
98 nO_EXPLICIT_METHOD_ERROR_ID
99 = generic_ERROR_ID nonExplicitMethodErrorIdKey SLIT("noExplicitMethodError")
102 = pc_bottoming_Id absentErrorIdKey gHC__ SLIT("absentErr")
103 (mkSigmaTy [alphaTyVar] [] alphaTy)
106 = pcMiscPrelId parErrorIdKey gHC__ SLIT("parError")
107 (mkSigmaTy [alphaTyVar] [] alphaTy) noIdInfo
110 errorTy = mkSigmaTy [openAlphaTyVar] [] (mkFunTys [mkListTy charTy] (mkTyVarTy openAlphaTyVar))
113 We want \tr{GHCbase.trace} to be wired in
114 because we don't want the strictness analyser to get ahold of it,
115 decide that the second argument is strict, evaluate that first (!!),
116 and make a jolly old mess.
119 = pcMiscPrelId traceIdKey gHC__ SLIT("trace") traceTy
120 (noIdInfo `addInfo` pcGenerateSpecs traceIdKey tRACE_ID noIdInfo traceTy)
122 traceTy = mkSigmaTy [alphaTyVar] [] (mkFunTys [mkListTy charTy, alphaTy] alphaTy)
125 %************************************************************************
127 \subsection[PrelVals-Integer-support]{To support @Integer@ and @String@ literals}
129 %************************************************************************
133 = pcMiscPrelId packCStringIdKey{-ToDo:rename-} gHC__ SLIT("packStringForC__")
134 (mkFunTys [stringTy] byteArrayPrimTy) noIdInfo
136 --------------------------------------------------------------------
139 = pcMiscPrelId unpackCStringIdKey gHC__ SLIT("unpackPS__")
140 (mkFunTys [addrPrimTy{-a char *-}] stringTy) noIdInfo
142 -- (FunTy addrPrimTy{-a char *-} stringTy) (noIdInfo `addInfo` mkArityInfo 1)
143 -- but I don't like wired-in IdInfos (WDP)
145 unpackCString2Id -- for cases when a string has a NUL in it
146 = pcMiscPrelId unpackCString2IdKey gHC__ SLIT("unpackPS2__")
147 (mkFunTys [addrPrimTy{-a char *-}, intPrimTy{-length-}] stringTy)
150 --------------------------------------------------------------------
151 unpackCStringAppendId
152 = pcMiscPrelId unpackCStringAppendIdKey gHC__ SLIT("unpackAppendPS__")
153 (mkFunTys [addrPrimTy{-a "char *" pointer-},stringTy] stringTy)
155 {-LATER:`addInfo_UF` mkMagicUnfolding unpackCStringAppendIdKey-})
156 `addInfo` mkArityInfo 2)
159 = pcMiscPrelId unpackCStringFoldrIdKey gHC__ SLIT("unpackFoldrPS__")
160 (mkSigmaTy [alphaTyVar] []
161 (mkFunTys [addrPrimTy{-a "char *" pointer-},
162 mkFunTys [charTy, alphaTy] alphaTy,
166 {-LATER:`addInfo_UF` mkMagicUnfolding unpackCStringFoldrIdKey-})
167 `addInfo` mkArityInfo 3)
170 OK, this is Will's idea: we should have magic values for Integers 0,
171 +1, +2, and -1 (go ahead, fire me):
174 = pcMiscPrelId integerZeroIdKey gHC__ SLIT("integer_0") integerTy noIdInfo
176 = pcMiscPrelId integerPlusOneIdKey gHC__ SLIT("integer_1") integerTy noIdInfo
178 = pcMiscPrelId integerPlusTwoIdKey gHC__ SLIT("integer_2") integerTy noIdInfo
180 = pcMiscPrelId integerMinusOneIdKey gHC__ SLIT("integer_m1") integerTy noIdInfo
183 %************************************************************************
185 \subsection[PrelVals-parallel]{@seq@ and @par@: for parallel operation (only)}
187 %************************************************************************
191 --------------------------------------------------------------------
192 -- seqId :: "seq", used w/ GRIP, etc., is really quite similar to
196 seq = /\ a b -> \ x y -> case x of { _ -> y }
199 seq = /\ a b -> \ x y -> case seq# x y of { _Lift y' -> y' }
202 seq = /\ a b -> \ x::a y::b -> case seq# x of { 0# -> parError#; _ -> y; }
206 seqId = pcMiscPrelId seqIdKey gHC__ SLIT("seq")
207 (mkSigmaTy [alphaTyVar, betaTyVar] []
208 (mkFunTys [alphaTy, betaTy] betaTy))
209 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding seq_template))
219 = mkLam [alphaTyVar, betaTyVar] [x, y] (
220 Case (Prim SeqOp [TyArg alphaTy, VarArg x]) (
222 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
223 (BindDefault z (Var y))))
225 --------------------------------------------------------------------
226 -- parId :: "par", also used w/ GRIP, etc.
230 par = /\ a b -> \ x y -> case (par# (case x of { _ -> () })) of { _ -> y }
234 par = /\ a b -> \ x y -> case par# x y of { _Lift y' -> y' }
238 par = /\ a b -> \ x::a y::b -> case par# x of { 0# -> parError#; _ -> y; }
241 parId = pcMiscPrelId parIdKey gHC__ SLIT("par")
242 (mkSigmaTy [alphaTyVar, betaTyVar] []
243 (mkFunTys [alphaTy, betaTy] betaTy))
244 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding par_template))
254 = mkLam [alphaTyVar, betaTyVar] [x, y] (
255 Case (Prim ParOp [TyArg alphaTy, VarArg x]) (
257 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
258 (BindDefault z (Var y))))
260 -- forkId :: "fork", for *required* concurrent threads
262 _fork_ = /\ a b -> \ x::a y::b -> case fork# x of { 0# -> parError#; _ -> y; }
264 forkId = pcMiscPrelId forkIdKey gHC__ SLIT("fork")
265 (mkSigmaTy [alphaTyVar, betaTyVar] []
266 (mkFunTys [alphaTy, betaTy] betaTy))
267 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding fork_template))
277 = mkLam [alphaTyVar, betaTyVar] [x, y] (
278 Case (Prim ForkOp [TyArg alphaTy, VarArg x]) (
280 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
281 (BindDefault z (Var y))))
288 parLocalId = pcMiscPrelId parLocalIdKey gHC__ SLIT("parLocal")
289 (mkSigmaTy [alphaTyVar, betaTyVar] []
290 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy, alphaTy, betaTy] betaTy))
291 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parLocal_template))
293 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
294 [w, g, s, p, x, y, z]
306 = mkLam [alphaTyVar, betaTyVar] [w, g, s, p, x, y] (
307 Case (Prim ParLocalOp [TyArg alphaTy, TyArg betaTy, VarArg x, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
309 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
310 (BindDefault z (Var y))))
312 parGlobalId = pcMiscPrelId parGlobalIdKey gHC__ SLIT("parGlobal")
313 (mkSigmaTy [alphaTyVar, betaTyVar] []
314 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy, alphaTy, betaTy] betaTy))
315 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parGlobal_template))
317 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
318 [w, g, s, p, x, y, z]
330 = mkLam [alphaTyVar, betaTyVar] [w, g, s, p, x, y] (
331 Case (Prim ParGlobalOp [TyArg alphaTy, TyArg betaTy, VarArg x, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
333 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
334 (BindDefault z (Var y))))
337 parAtId = pcMiscPrelId parAtIdKey gHC__ SLIT("parAt")
338 (mkSigmaTy [alphaTyVar, betaTyVar] []
339 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy,
340 alphaTy, betaTy, gammaTy] gammaTy))
341 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parAt_template))
343 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
344 [w, g, s, p, v, x, y, z]
357 = mkLam [alphaTyVar, betaTyVar, gammaTyVar] [w, g, s, p, v, x, y] (
358 Case (Prim ParAtOp [TyArg alphaTy, TyArg betaTy, TyArg gammaTy, VarArg x, VarArg v, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
360 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [gammaTy])]
361 (BindDefault z (Var y))))
363 parAtAbsId = pcMiscPrelId parAtAbsIdKey gHC__ SLIT("parAtAbs")
364 (mkSigmaTy [alphaTyVar, betaTyVar] []
365 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy, intPrimTy, alphaTy, betaTy] betaTy))
366 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parAtAbs_template))
368 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
369 [w, g, s, p, v, x, y, z]
382 = mkLam [alphaTyVar, betaTyVar] [w, g, s, p, v, x, y] (
383 Case (Prim ParAtAbsOp [TyArg alphaTy, TyArg betaTy, VarArg x, VarArg v, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
385 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
386 (BindDefault z (Var y))))
388 parAtRelId = pcMiscPrelId parAtRelIdKey gHC__ SLIT("parAtRel")
389 (mkSigmaTy [alphaTyVar, betaTyVar] []
390 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy, intPrimTy, alphaTy, betaTy] betaTy))
391 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parAtRel_template))
393 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
394 [w, g, s, p, v, x, y, z]
407 = mkLam [alphaTyVar, betaTyVar] [w, g, s, p, v, x, y] (
408 Case (Prim ParAtRelOp [TyArg alphaTy, TyArg betaTy, VarArg x, VarArg v, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
410 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [betaTy])]
411 (BindDefault z (Var y))))
413 parAtForNowId = pcMiscPrelId parAtForNowIdKey gHC__ SLIT("parAtForNow")
414 (mkSigmaTy [alphaTyVar, betaTyVar] []
415 (mkFunTys [intPrimTy, intPrimTy, intPrimTy, intPrimTy,
416 alphaTy, betaTy, gammaTy] gammaTy))
417 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding parAtForNow_template))
419 -- Annotations: w: name, g: gran. info, s: size info, p: par info -- HWL
420 [w, g, s, p, v, x, y, z]
433 = mkLam [alphaTyVar, betaTyVar, gammaTyVar] [w, g, s, p, v, x, y] (
434 Case (Prim ParAtForNowOp [TyArg alphaTy, TyArg betaTy, TyArg gammaTy, VarArg x, VarArg v, VarArg w, VarArg g, VarArg s, VarArg p, VarArg y]) (
436 [(mkMachInt 0, mkTyApp (Var pAR_ERROR_ID) [gammaTy])]
437 (BindDefault z (Var y))))
439 -- copyable and noFollow are currently merely hooks: they are translated into
440 -- calls to the macros COPYABLE and NOFOLLOW -- HWL
442 copyableId = pcMiscPrelId copyableIdKey gHC__ SLIT("copyable")
443 (mkSigmaTy [alphaTyVar] []
445 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding copyable_template))
447 -- Annotations: x: closure that's tagged to by copyable
455 = mkLam [alphaTyVar] [x] ( Prim CopyableOp [TyArg alphaTy, VarArg x] )
457 noFollowId = pcMiscPrelId noFollowIdKey gHC__ SLIT("noFollow")
458 (mkSigmaTy [alphaTyVar] []
460 (noIdInfo `addInfo_UF` (mkUnfolding EssentialUnfolding noFollow_template))
462 -- Annotations: x: closure that's tagged to not follow
470 = mkLam [alphaTyVar] [x] ( Prim NoFollowOp [TyArg alphaTy, VarArg x] )
474 %************************************************************************
476 \subsection[PrelVals-runST]{@runST@: Magic start-state-transformer function}
478 %************************************************************************
480 @runST@ has a non-Haskell-able type:
482 -- runST :: forall a. (forall s. _ST s a) -> a
483 -- which is to say ::
484 -- forall a. (forall s. (_State s -> (a, _State s))) -> a
486 runST a m = case m _RealWorld (S# _RealWorld realWorld#) of
487 (r :: a, wild :: _State _RealWorld) -> r
490 We unfold always, just for simplicity:
493 = pcMiscPrelId runSTIdKey gHC__ SLIT("runST") run_ST_ty id_info
498 st_ty a = mkSigmaTy [s_tv] [] (mkStateTransformerTy s a)
501 = mkSigmaTy [alphaTyVar] [] (mkFunTys [st_ty alphaTy] alphaTy)
502 -- NB: rank-2 polymorphism! (forall inside the st_ty...)
506 `addInfo` mkArityInfo 1
507 `addInfo` mkStrictnessInfo [WwStrict] Nothing
508 `addInfo` mkArgUsageInfo [ArgUsage 1]
509 -- ABSOLUTELY NO UNFOLDING, e.g.: (mkUnfolding EssentialUnfolding run_ST_template)
515 {-t-} realWorldStateTy,
517 {-_-} realWorldStateTy
521 = mkLam [alphaTyVar] [m] (
522 Let (NonRec t (Con stateDataCon [TyArg realWorldTy, VarArg realWorldPrimId])) (
523 Case (App (mkTyApp (Var m) [realWorldTy]) (VarArg t)) (
525 [(mkTupleCon 2, [r, wild], Var r)]
530 SLPJ 95/04: Why @runST@ must not have an unfolding; consider:
534 (a, s') = newArray# 100 [] s
535 (_, s'') = fill_in_array_or_something a x s'
539 If we inline @runST@, we'll get:
542 (a, s') = newArray# 100 [] realWorld#{-NB-}
543 (_, s'') = fill_in_array_or_something a x s'
547 And now the @newArray#@ binding can be floated to become a CAF, which
548 is totally and utterly wrong:
551 (a, s') = newArray# 100 [] realWorld#{-NB-} -- YIKES!!!
554 let (_, s'') = fill_in_array_or_something a x s' in
557 All calls to @f@ will share a {\em single} array! End SLPJ 95/04.
559 @realWorld#@ used to be a magic literal, \tr{void#}. If things get
560 nasty as-is, change it back to a literal (@Literal@).
563 = pcMiscPrelId realWorldPrimIdKey gHC_BUILTINS SLIT("realWorld#")
569 voidId = pcMiscPrelId voidIdKey gHC_BUILTINS SLIT("void") voidTy noIdInfo
572 %************************************************************************
574 \subsection[PrelVals-foldr-build]{Values known about for ``foldr/build''}
576 %************************************************************************
580 = pcMiscPrelId buildIdKey gHC__ SLIT("build") buildTy
582 {-LATER:`addInfo_UF` mkMagicUnfolding buildIdKey-})
583 `addInfo` mkStrictnessInfo [WwStrict] Nothing)
584 `addInfo` mkArgUsageInfo [ArgUsage 2])
585 `addInfo` pcGenerateSpecs buildIdKey buildId noIdInfo{-ToDo-} buildTy)
586 -- cheating, but since _build never actually exists ...
588 -- The type of this strange object is:
589 -- \/ a . (\/ b . (a -> b -> b) -> b -> b) -> [a]
591 buildTy = mkSigmaTy [alphaTyVar] [] (mkFunTys [build_ty] (mkListTy alphaTy))
593 build_ty = mkSigmaTy [betaTyVar] []
594 (mkFunTys [mkFunTys [alphaTy, betaTy] betaTy, betaTy] betaTy)
597 @mkBuild@ is sugar for building a build!
599 @mkbuild ty tv c n e@ $Rightarrow$ @build ty (/\ tv -> \ c n -> e)@
600 @ty@ is the type of the list.
601 @tv@ is always a new type variable.
602 @c,n@ are Id's for the abstract cons and nil, @g@ for let binding the argument argument.
605 v :: (\/ b . (a -> b -> b) -> b -> b) -> [a]
606 -- \/ a . (\/ b . (a -> b -> b) -> b -> b) -> [a]
607 @e@ is the object right inside the @build@
615 -> CoreExpr -- template
616 -> CoreExpr -- template
618 mkBuild ty tv c n g expr
619 = Let (NonRec g (mkLam [tv] [c,n] expr))
620 (App (mkTyApp (Var buildId) [ty]) (VarArg g))
625 = pcMiscPrelId augmentIdKey gHC__ SLIT("augment") augmentTy
627 {-LATER:`addInfo_UF` mkMagicUnfolding augmentIdKey-})
628 `addInfo` mkStrictnessInfo [WwStrict,WwLazy False] Nothing)
629 `addInfo` mkArgUsageInfo [ArgUsage 2,UnknownArgUsage])
630 -- cheating, but since _augment never actually exists ...
632 -- The type of this strange object is:
633 -- \/ a . (\/ b . (a -> b -> b) -> b -> b) -> [a] -> [a]
635 augmentTy = mkSigmaTy [alphaTyVar] [] (mkFunTys [aug_ty, mkListTy alphaTy] (mkListTy alphaTy))
637 aug_ty = mkSigmaTy [betaTyVar] []
638 (mkFunTys [mkFunTys [alphaTy, betaTy] betaTy, betaTy] betaTy)
642 foldrId = pcMiscPrelId foldrIdKey pRELUDE SLIT("foldr")
646 mkSigmaTy [alphaTyVar, betaTyVar] []
647 (mkFunTys [mkFunTys [alphaTy, betaTy] betaTy, betaTy, mkListTy alphaTy] betaTy)
649 idInfo = (((((noIdInfo
650 {-LATER:`addInfo_UF` mkMagicUnfolding foldrIdKey-})
651 `addInfo` mkStrictnessInfo [WwLazy False,WwLazy False,WwStrict] Nothing)
652 `addInfo` mkArityInfo 3)
653 `addInfo` mkUpdateInfo [2,2,1])
654 `addInfo` pcGenerateSpecs foldrIdKey foldrId noIdInfo{-ToDo-} foldrTy)
656 foldlId = pcMiscPrelId foldlIdKey pRELUDE SLIT("foldl")
660 mkSigmaTy [alphaTyVar, betaTyVar] []
661 (mkFunTys [mkFunTys [alphaTy, betaTy] alphaTy, alphaTy, mkListTy betaTy] alphaTy)
663 idInfo = (((((noIdInfo
664 {-LATER:`addInfo_UF` mkMagicUnfolding foldlIdKey-})
665 `addInfo` mkStrictnessInfo [WwLazy False,WwLazy False,WwStrict] Nothing)
666 `addInfo` mkArityInfo 3)
667 `addInfo` mkUpdateInfo [2,2,1])
668 `addInfo` pcGenerateSpecs foldlIdKey foldlId noIdInfo{-ToDo-} foldlTy)
670 -- A bit of magic goes no here. We translate appendId into ++,
671 -- you have to be carefull when you actually compile append:
672 -- xs ++ ys = augment (\ c n -> foldr c n xs) ys
673 -- {- unfold augment -}
675 -- {- fold foldr to append -}
676 -- = ys `appendId` xs
677 -- = ys ++ xs -- ugg!
678 -- *BUT* you want (++) and not _append in your interfaces.
680 -- So you have to turn *off* unfolding of foldr inside FoldrBuild.hs inside
683 {- OLD: doesn't apply with 1.3
685 = pcMiscPrelId appendIdKey pRELUDE_LIST SLIT("++") appendTy idInfo
688 (mkSigmaTy [alphaTyVar] []
689 (mkFunTys [mkListTy alphaTy, mkListTy alphaTy] (mkListTy alphaTy)))
691 `addInfo` mkStrictnessInfo [WwStrict,WwLazy False] Nothing)
692 `addInfo` mkArityInfo 2)
693 `addInfo` mkUpdateInfo [1,2])
697 %************************************************************************
699 \subsection[PrelUtils-specialisations]{Specialisations for builtin values}
701 %************************************************************************
703 The specialisations which exist for the builtin values must be recorded in
706 NOTE: THE USES OF THE pcGenerate... FUNCTIONS MUST CORRESPOND
707 TO THE SPECIALISATIONS DECLARED IN THE PRELUDE !!!
709 HACK: We currently use the same unique for the specialised Ids.
711 The list @specing_types@ determines the types for which specialised
712 versions are created. Note: This should correspond with the
713 types passed to the pre-processor with the -genSPECS arg (see ghc.lprl).
715 ToDo: Create single mkworld definition which is grabbed here and in ghc.lprl
718 pcGenerateSpecs :: Unique -> Id -> IdInfo -> Type -> SpecEnv
719 pcGenerateSpecs key id info ty
724 pc_gen_specs True key id info ty
726 pc_gen_specs is_id key id info ty
727 = mkSpecEnv spec_infos
729 spec_infos = [ let spec_ty = specialiseTy ty spec_tys 0
731 then mkSpecId key {- HACK WARNING: same unique! -}
732 id spec_tys spec_ty info
733 else panic "SpecData:SpecInfo:SpecId"
735 SpecInfo spec_tys (length ctxts) spec_id
736 | spec_tys <- specialisations ]
738 (tyvars, ctxts, _) = splitSigmaTy ty
739 no_tyvars = length tyvars
741 specialisations = if no_tyvars == 0
743 else tail (cross_product no_tyvars specing_types)
745 -- N.B. tail removes fully polymorphic specialisation
747 cross_product 0 tys = []
748 cross_product 1 tys = map (:[]) tys
749 cross_product n tys = concat [map (:cp) tys | cp <- cross_product (n-1) tys]
752 specing_types = [Nothing,