[project @ 2000-10-23 09:03:26 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / IdInfo.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
3 %
4 \section[IdInfo]{@IdInfos@: Non-essential information about @Ids@}
5
6 (And a pretty good illustration of quite a few things wrong with
7 Haskell. [WDP 94/11])
8
9 \begin{code}
10 module IdInfo (
11         IdInfo,         -- Abstract
12
13         vanillaIdInfo, mkIdInfo, seqIdInfo, megaSeqIdInfo,
14
15         -- Zapping
16         zapFragileInfo, zapLamInfo, zapSpecPragInfo, shortableIdInfo, copyIdInfo,
17
18         -- Flavour
19         IdFlavour(..), flavourInfo, 
20         setNoDiscardInfo,
21         ppFlavourInfo,
22
23         -- Arity
24         ArityInfo(..),
25         exactArity, atLeastArity, unknownArity, hasArity,
26         arityInfo, setArityInfo, ppArityInfo, arityLowerBound,
27
28         -- Strictness; imported from Demand
29         StrictnessInfo(..),
30         mkStrictnessInfo, noStrictnessInfo,
31         ppStrictnessInfo,isBottomingStrictness, 
32
33         strictnessInfo, setStrictnessInfo,      
34
35         -- Worker
36         WorkerInfo(..), workerExists, wrapperArity, workerId,
37         workerInfo, setWorkerInfo, ppWorkerInfo,
38
39         -- Unfolding
40         unfoldingInfo, setUnfoldingInfo, 
41
42         -- DemandInfo
43         demandInfo, setDemandInfo, 
44
45         -- Inline prags
46         InlinePragInfo(..), 
47         inlinePragInfo, setInlinePragInfo, pprInlinePragInfo,
48         isNeverInlinePrag, neverInlinePrag,
49
50         -- Occurrence info
51         OccInfo(..), isFragileOcc, isDeadOcc, isLoopBreaker,
52         InsideLam, OneBranch, insideLam, notInsideLam, oneBranch, notOneBranch,
53         occInfo, setOccInfo, 
54
55         -- Specialisation
56         specInfo, setSpecInfo,
57
58         -- CAF info
59         CafInfo(..), cafInfo, setCafInfo, ppCafInfo,
60
61         -- Constructed Product Result Info
62         CprInfo(..), cprInfo, setCprInfo, ppCprInfo, noCprInfo,
63
64         -- Lambda-bound variable info
65         LBVarInfo(..), lbvarInfo, setLBVarInfo, noLBVarInfo
66     ) where
67
68 #include "HsVersions.h"
69
70
71 import CoreSyn
72 import PrimOp           ( PrimOp )
73 import Var              ( Id )
74 import BasicTypes       ( OccInfo(..), isFragileOcc, isDeadOcc, seqOccInfo, isLoopBreaker,
75                           InsideLam, insideLam, notInsideLam, 
76                           OneBranch, oneBranch, notOneBranch,
77                           Arity
78                         )
79 import DataCon          ( DataCon )
80 import FieldLabel       ( FieldLabel )
81 import Demand           -- Lots of stuff
82 import Outputable       
83
84 infixl  1 `setDemandInfo`,
85           `setStrictnessInfo`,
86           `setSpecInfo`,
87           `setArityInfo`,
88           `setInlinePragInfo`,
89           `setUnfoldingInfo`,
90           `setCprInfo`,
91           `setWorkerInfo`,
92           `setCafInfo`,
93           `setOccInfo`
94         -- infixl so you can say (id `set` a `set` b)
95 \end{code}
96
97 An @IdInfo@ gives {\em optional} information about an @Id@.  If
98 present it never lies, but it may not be present, in which case there
99 is always a conservative assumption which can be made.
100
101         There is one exception: the 'flavour' is *not* optional.
102         You must not discard it.
103         It used to be in Var.lhs, but that seems unclean.
104
105 Two @Id@s may have different info even though they have the same
106 @Unique@ (and are hence the same @Id@); for example, one might lack
107 the properties attached to the other.
108
109 The @IdInfo@ gives information about the value, or definition, of the
110 @Id@.  It does {\em not} contain information about the @Id@'s usage
111 (except for @DemandInfo@? ToDo). (@lbvarInfo@ is also a marginal
112 case.  KSW 1999-04).
113
114 \begin{code}
115 data IdInfo
116   = IdInfo {
117         flavourInfo     :: IdFlavour,           -- NOT OPTIONAL
118         arityInfo       :: ArityInfo,           -- Its arity
119         demandInfo      :: Demand,              -- Whether or not it is definitely demanded
120         specInfo        :: CoreRules,           -- Specialisations of this function which exist
121         strictnessInfo  :: StrictnessInfo,      -- Strictness properties
122         workerInfo      :: WorkerInfo,          -- Pointer to Worker Function
123         unfoldingInfo   :: Unfolding,           -- Its unfolding
124         cafInfo         :: CafInfo,
125         cprInfo         :: CprInfo,             -- Function always constructs a product result
126         lbvarInfo       :: LBVarInfo,           -- Info about a lambda-bound variable
127         inlinePragInfo  :: InlinePragInfo,      -- Inline pragma
128         occInfo         :: OccInfo              -- How it occurs
129     }
130
131 seqIdInfo :: IdInfo -> ()
132 seqIdInfo (IdInfo {}) = ()
133
134 megaSeqIdInfo :: IdInfo -> ()
135 megaSeqIdInfo info
136   = seqFlavour (flavourInfo info)               `seq`
137     seqArity (arityInfo info)                   `seq`
138     seqDemand (demandInfo info)                 `seq`
139     seqRules (specInfo info)                    `seq`
140     seqStrictnessInfo (strictnessInfo info)     `seq`
141     seqWorker (workerInfo info)                 `seq`
142
143 --    seqUnfolding (unfoldingInfo info) `seq`
144 -- Omitting this improves runtimes a little, presumably because
145 -- some unfoldings are not calculated at all
146
147     seqCaf (cafInfo info)               `seq`
148     seqCpr (cprInfo info)               `seq`
149     seqLBVar (lbvarInfo info)           `seq`
150     seqOccInfo (occInfo info) 
151 \end{code}
152
153 Setters
154
155 \begin{code}
156 setWorkerInfo     info wk = wk `seq` info { workerInfo = wk }
157 setSpecInfo       info sp = PSEQ sp (info { specInfo = sp })
158 setInlinePragInfo info pr = pr `seq` info { inlinePragInfo = pr }
159 setOccInfo        info oc = oc `seq` info { occInfo = oc }
160 setStrictnessInfo info st = st `seq` info { strictnessInfo = st }
161         -- Try to avoid spack leaks by seq'ing
162
163 setUnfoldingInfo  info uf 
164   | isEvaldUnfolding uf && isStrict (demandInfo info)
165         -- If the unfolding is a value, the demand info may
166         -- go pear-shaped, so we nuke it.  Example:
167         --      let x = (a,b) in
168         --      case x of (p,q) -> h p q x
169         -- Here x is certainly demanded. But after we've nuked
170         -- the case, we'll get just
171         --      let x = (a,b) in h a b x
172         -- and now x is not demanded (I'm assuming h is lazy)
173         -- This really happens.  The solution here is a bit ad hoc...
174   = info { unfoldingInfo = uf, demandInfo = wwLazy }
175
176   | otherwise
177         -- We do *not* seq on the unfolding info, For some reason, doing so 
178         -- actually increases residency significantly. 
179   = info { unfoldingInfo = uf }
180
181 setDemandInfo     info dd = info { demandInfo = dd }
182 setArityInfo      info ar = info { arityInfo = ar  }
183 setCafInfo        info cf = info { cafInfo = cf }
184 setCprInfo        info cp = info { cprInfo = cp }
185 setLBVarInfo      info lb = info { lbvarInfo = lb }
186
187 setNoDiscardInfo  info = case flavourInfo info of
188                                 VanillaId -> info { flavourInfo = NoDiscardId }
189                                 other     -> info
190 zapSpecPragInfo   info = case flavourInfo info of
191                                 SpecPragmaId -> info { flavourInfo = VanillaId }
192                                 other        -> info
193 \end{code}
194
195
196 \begin{code}
197 vanillaIdInfo :: IdInfo
198 vanillaIdInfo = mkIdInfo VanillaId
199
200 mkIdInfo :: IdFlavour -> IdInfo
201 mkIdInfo flv = IdInfo {
202                     flavourInfo         = flv,
203                     arityInfo           = UnknownArity,
204                     demandInfo          = wwLazy,
205                     specInfo            = emptyCoreRules,
206                     workerInfo          = NoWorker,
207                     strictnessInfo      = NoStrictnessInfo,
208                     unfoldingInfo       = noUnfolding,
209                     cafInfo             = MayHaveCafRefs,
210                     cprInfo             = NoCPRInfo,
211                     lbvarInfo           = NoLBVarInfo,
212                     inlinePragInfo      = NoInlinePragInfo,
213                     occInfo             = NoOccInfo
214            }
215 \end{code}
216
217
218 %************************************************************************
219 %*                                                                      *
220 \subsection{Flavour}
221 %*                                                                      *
222 %************************************************************************
223
224 \begin{code}
225 data IdFlavour
226   = VanillaId                   -- Most Ids are like this
227   | DataConId DataCon           -- The Id for a data constructor *worker*
228   | DataConWrapId DataCon       -- The Id for a data constructor *wrapper*
229                                 -- [the only reasons we need to know is so that
230                                 --  a) we can  suppress printing a definition in the interface file
231                                 --  b) when typechecking a pattern we can get from the
232                                 --     Id back to the data con]
233   | PrimOpId PrimOp             -- The Id for a primitive operator
234   | RecordSelId FieldLabel      -- The Id for a record selector
235   | SpecPragmaId                -- Don't discard these
236   | NoDiscardId                 -- Don't discard these either
237
238 ppFlavourInfo :: IdFlavour -> SDoc
239 ppFlavourInfo VanillaId         = empty
240 ppFlavourInfo (DataConId _)     = ptext SLIT("[DataCon]")
241 ppFlavourInfo (DataConWrapId _) = ptext SLIT("[DataConWrapper]")
242 ppFlavourInfo (PrimOpId _)      = ptext SLIT("[PrimOp]")
243 ppFlavourInfo (RecordSelId _)   = ptext SLIT("[RecSel]")
244 ppFlavourInfo SpecPragmaId      = ptext SLIT("[SpecPrag]")
245 ppFlavourInfo NoDiscardId       = ptext SLIT("[NoDiscard]")
246
247 seqFlavour :: IdFlavour -> ()
248 seqFlavour f = f `seq` ()
249 \end{code}
250
251 The @SpecPragmaId@ exists only to make Ids that are
252 on the *LHS* of bindings created by SPECIALISE pragmas; 
253 eg:             s = f Int d
254 The SpecPragmaId is never itself mentioned; it
255 exists solely so that the specialiser will find
256 the call to f, and make specialised version of it.
257 The SpecPragmaId binding is discarded by the specialiser
258 when it gathers up overloaded calls.
259 Meanwhile, it is not discarded as dead code.
260
261
262 %************************************************************************
263 %*                                                                      *
264 \subsection[arity-IdInfo]{Arity info about an @Id@}
265 %*                                                                      *
266 %************************************************************************
267
268 For locally-defined Ids, the code generator maintains its own notion
269 of their arities; so it should not be asking...  (but other things
270 besides the code-generator need arity info!)
271
272 \begin{code}
273 data ArityInfo
274   = UnknownArity        -- No idea
275
276   | ArityExactly Arity  -- Arity is exactly this.  We use this when importing a
277                         -- function; it's already been compiled and we know its
278                         -- arity for sure.
279
280   | ArityAtLeast Arity  -- A partial application of this Id to up to n-1 value arguments
281                         -- does essentially no work.  That is not necessarily the
282                         -- same as saying that it has n leading lambdas, because coerces
283                         -- may get in the way.
284
285                         -- functions in the module being compiled.  Their arity
286                         -- might increase later in the compilation process, if
287                         -- an extra lambda floats up to the binding site.
288   deriving( Eq )
289
290 seqArity :: ArityInfo -> ()
291 seqArity a = arityLowerBound a `seq` ()
292
293 exactArity   = ArityExactly
294 atLeastArity = ArityAtLeast
295 unknownArity = UnknownArity
296
297 arityLowerBound :: ArityInfo -> Arity
298 arityLowerBound UnknownArity     = 0
299 arityLowerBound (ArityAtLeast n) = n
300 arityLowerBound (ArityExactly n) = n
301
302 hasArity :: ArityInfo -> Bool
303 hasArity UnknownArity = False
304 hasArity other        = True
305
306 ppArityInfo UnknownArity         = empty
307 ppArityInfo (ArityExactly arity) = hsep [ptext SLIT("__A"), int arity]
308 ppArityInfo (ArityAtLeast arity) = hsep [ptext SLIT("__AL"), int arity]
309 \end{code}
310
311 %************************************************************************
312 %*                                                                      *
313 \subsection{Inline-pragma information}
314 %*                                                                      *
315 %************************************************************************
316
317 \begin{code}
318 data InlinePragInfo
319   = NoInlinePragInfo
320   | IMustNotBeINLINEd Bool              -- True <=> came from an INLINE prag, False <=> came from a NOINLINE prag
321                       (Maybe Int)       -- Phase number from pragma, if any
322   deriving( Eq )
323         -- The True, Nothing case doesn't need to be recorded
324
325         -- SEE COMMENTS WITH CoreUnfold.blackListed on the
326         -- exact significance of the IMustNotBeINLINEd pragma
327
328 isNeverInlinePrag :: InlinePragInfo -> Bool
329 isNeverInlinePrag (IMustNotBeINLINEd _ Nothing) = True
330 isNeverInlinePrag other                         = False
331
332 neverInlinePrag :: InlinePragInfo
333 neverInlinePrag = IMustNotBeINLINEd True{-should be False? --SDM -} Nothing
334
335 instance Outputable InlinePragInfo where
336   -- This is now parsed in interface files
337   ppr NoInlinePragInfo = empty
338   ppr other_prag       = ptext SLIT("__U") <> pprInlinePragInfo other_prag
339
340 pprInlinePragInfo NoInlinePragInfo                   = empty
341 pprInlinePragInfo (IMustNotBeINLINEd True Nothing)   = empty
342 pprInlinePragInfo (IMustNotBeINLINEd True (Just n))  = brackets (int n)
343 pprInlinePragInfo (IMustNotBeINLINEd False Nothing)  = brackets (char '!')
344 pprInlinePragInfo (IMustNotBeINLINEd False (Just n)) = brackets (char '!' <> int n)
345                                                         
346 instance Show InlinePragInfo where
347   showsPrec p prag = showsPrecSDoc p (ppr prag)
348 \end{code}
349
350
351 %************************************************************************
352 %*                                                                      *
353 \subsection[worker-IdInfo]{Worker info about an @Id@}
354 %*                                                                      *
355 %************************************************************************
356
357 If this Id has a worker then we store a reference to it. Worker
358 functions are generated by the worker/wrapper pass.  This uses
359 information from the strictness and CPR analyses.
360
361 There might not be a worker, even for a strict function, because:
362 (a) the function might be small enough to inline, so no need 
363     for w/w split
364 (b) the strictness info might be "SSS" or something, so no w/w split.
365
366 \begin{code}
367
368 data WorkerInfo = NoWorker
369                 | HasWorker Id Arity
370         -- The Arity is the arity of the *wrapper* at the moment of the
371         -- w/w split. See comments in MkIface.ifaceId, with the 'Worker' code.
372
373 seqWorker :: WorkerInfo -> ()
374 seqWorker (HasWorker id _) = id `seq` ()
375 seqWorker NoWorker         = ()
376
377 ppWorkerInfo NoWorker            = empty
378 ppWorkerInfo (HasWorker wk_id _) = ptext SLIT("__P") <+> ppr wk_id
379
380 noWorkerInfo = NoWorker
381
382 workerExists :: WorkerInfo -> Bool
383 workerExists NoWorker        = False
384 workerExists (HasWorker _ _) = True
385
386 workerId :: WorkerInfo -> Id
387 workerId (HasWorker id _) = id
388
389 wrapperArity :: WorkerInfo -> Arity
390 wrapperArity (HasWorker _ a) = a
391 \end{code}
392
393
394 %************************************************************************
395 %*                                                                      *
396 \subsection[CAF-IdInfo]{CAF-related information}
397 %*                                                                      *
398 %************************************************************************
399
400 This information is used to build Static Reference Tables (see
401 simplStg/ComputeSRT.lhs).
402
403 \begin{code}
404 data CafInfo 
405         = MayHaveCafRefs                -- either:
406                                         -- (1) A function or static constructor
407                                         --     that refers to one or more CAFs,
408                                         -- (2) A real live CAF
409
410         | NoCafRefs                     -- A function or static constructor
411                                         -- that refers to no CAFs.
412
413 -- LATER: not sure how easy this is...
414 --      | OneCafRef Id
415
416
417 seqCaf c = c `seq` ()
418
419 ppCafInfo NoCafRefs = ptext SLIT("__C")
420 ppCafInfo MayHaveCafRefs = empty
421 \end{code}
422
423
424 %************************************************************************
425 %*                                                                      *
426 \subsection[cpr-IdInfo]{Constructed Product Result info about an @Id@}
427 %*                                                                      *
428 %************************************************************************
429
430 If the @Id@ is a function then it may have CPR info. A CPR analysis
431 phase detects whether:
432
433 \begin{enumerate}
434 \item
435 The function's return value has a product type, i.e. an algebraic  type 
436 with a single constructor. Examples of such types are tuples and boxed
437 primitive values.
438 \item
439 The function always 'constructs' the value that it is returning.  It
440 must do this on every path through,  and it's OK if it calls another
441 function which constructs the result.
442 \end{enumerate}
443
444 If this is the case then we store a template which tells us the
445 function has the CPR property and which components of the result are
446 also CPRs.   
447
448 \begin{code}
449 data CprInfo
450   = NoCPRInfo
451   | ReturnsCPR  -- Yes, this function returns a constructed product
452                 -- Implicitly, this means "after the function has been applied
453                 -- to all its arguments", so the worker/wrapper builder in 
454                 -- WwLib.mkWWcpr checks that that it is indeed saturated before
455                 -- making use of the CPR info
456
457         -- We used to keep nested info about sub-components, but
458         -- we never used it so I threw it away
459 \end{code}
460
461 \begin{code}
462 seqCpr :: CprInfo -> ()
463 seqCpr ReturnsCPR = ()
464 seqCpr NoCPRInfo  = ()
465
466 noCprInfo       = NoCPRInfo
467
468 ppCprInfo NoCPRInfo  = empty
469 ppCprInfo ReturnsCPR = ptext SLIT("__M")
470
471 instance Outputable CprInfo where
472     ppr = ppCprInfo
473
474 instance Show CprInfo where
475     showsPrec p c = showsPrecSDoc p (ppr c)
476 \end{code}
477
478
479 %************************************************************************
480 %*                                                                      *
481 \subsection[lbvar-IdInfo]{Lambda-bound var info about an @Id@}
482 %*                                                                      *
483 %************************************************************************
484
485 If the @Id@ is a lambda-bound variable then it may have lambda-bound
486 var info.  The usage analysis (UsageSP) detects whether the lambda
487 binding this var is a ``one-shot'' lambda; that is, whether it is
488 applied at most once.
489
490 This information may be useful in optimisation, as computations may
491 safely be floated inside such a lambda without risk of duplicating
492 work.
493
494 \begin{code}
495 data LBVarInfo
496   = NoLBVarInfo
497
498   | IsOneShotLambda             -- The lambda that binds this Id is applied
499                                 --   at most once
500                                 -- HACK ALERT! placing this info here is a short-term hack,
501                                 --   but it minimises changes to the rest of the compiler.
502                                 --   Hack agreed by SLPJ/KSW 1999-04.
503
504 seqLBVar l = l `seq` ()
505 \end{code}
506
507 \begin{code}
508 noLBVarInfo = NoLBVarInfo
509
510 -- not safe to print or parse LBVarInfo because it is not really a
511 -- property of the definition, but a property of the context.
512 pprLBVarInfo NoLBVarInfo     = empty
513 pprLBVarInfo IsOneShotLambda = getPprStyle $ \ sty ->
514                                if ifaceStyle sty then empty
515                                                  else ptext SLIT("OneShot")
516
517 instance Outputable LBVarInfo where
518     ppr = pprLBVarInfo
519
520 instance Show LBVarInfo where
521     showsPrec p c = showsPrecSDoc p (ppr c)
522 \end{code}
523
524
525 %************************************************************************
526 %*                                                                      *
527 \subsection{Bulk operations on IdInfo}
528 %*                                                                      *
529 %************************************************************************
530
531 zapFragileInfo is used when cloning binders, mainly in the
532 simplifier.  We must forget about used-once information because that
533 isn't necessarily correct in the transformed program.
534 Also forget specialisations and unfoldings because they would need
535 substitution to be correct.  (They get pinned back on separately.)
536
537 \begin{code}
538 zapFragileInfo :: IdInfo -> Maybe IdInfo
539 zapFragileInfo info@(IdInfo {occInfo            = occ, 
540                              workerInfo         = wrkr,
541                              specInfo           = rules, 
542                              unfoldingInfo      = unfolding})
543   |  not (isFragileOcc occ)
544         -- We must forget about whether it was marked safe-to-inline,
545         -- because that isn't necessarily true in the simplified expression.
546         -- This is important because expressions may  be re-simplified
547         -- We don't zap deadness or loop-breaker-ness.
548         -- The latter is important because it tells MkIface not to 
549         -- spit out an inlining for the thing.  The former doesn't
550         -- seem so important, but there's no harm.
551
552   && isEmptyCoreRules rules
553         -- Specialisations would need substituting.  They get pinned
554         -- back on separately.
555
556   && not (workerExists wrkr)
557
558   && not (hasUnfolding unfolding)
559         -- This is very important; occasionally a let-bound binder is used
560         -- as a binder in some lambda, in which case its unfolding is utterly
561         -- bogus.  Also the unfolding uses old binders so if we left it we'd
562         -- have to substitute it. Much better simply to give the Id a new
563         -- unfolding each time, which is what the simplifier does.
564   = Nothing
565
566   | otherwise
567   = Just (info {occInfo         = robust_occ_info,
568                 workerInfo      = noWorkerInfo,
569                 specInfo        = emptyCoreRules,
570                 unfoldingInfo   = noUnfolding})
571   where
572         -- It's important to keep the loop-breaker info,
573         -- because the substitution doesn't remember it.
574     robust_occ_info = case occ of
575                         OneOcc _ _ -> NoOccInfo
576                         other      -> occ
577 \end{code}
578
579 @zapLamInfo@ is used for lambda binders that turn out to to be
580 part of an unsaturated lambda
581
582 \begin{code}
583 zapLamInfo :: IdInfo -> Maybe IdInfo
584 zapLamInfo info@(IdInfo {occInfo = occ, demandInfo = demand})
585   | is_safe_occ && not (isStrict demand)
586   = Nothing
587   | otherwise
588   = Just (info {occInfo = safe_occ,
589                 demandInfo = wwLazy})
590   where
591         -- The "unsafe" occ info is the ones that say I'm not in a lambda
592         -- because that might not be true for an unsaturated lambda
593     is_safe_occ = case occ of
594                         OneOcc in_lam once -> in_lam
595                         other              -> True
596
597     safe_occ = case occ of
598                  OneOcc _ once -> OneOcc insideLam once
599                  other         -> occ
600 \end{code}
601
602
603 copyIdInfo is used when shorting out a top-level binding
604         f_local = BIG
605         f = f_local
606 where f is exported.  We are going to swizzle it around to
607         f = BIG
608         f_local = f
609
610 BUT (a) we must be careful about messing up rules
611     (b) we must ensure f's IdInfo ends up right
612
613 (a) Messing up the rules
614 ~~~~~~~~~~~~~~~~~~~~
615 The example that went bad on me was this one:
616         
617     iterate :: (a -> a) -> a -> [a]
618     iterate = iterateList
619     
620     iterateFB c f x = x `c` iterateFB c f (f x)
621     iterateList f x =  x : iterateList f (f x)
622     
623     {-# RULES
624     "iterate"   forall f x.     iterate f x = build (\c _n -> iterateFB c f x)
625     "iterateFB"                 iterateFB (:) = iterateList
626      #-}
627
628 This got shorted out to:
629
630     iterateList :: (a -> a) -> a -> [a]
631     iterateList = iterate
632     
633     iterateFB c f x = x `c` iterateFB c f (f x)
634     iterate f x =  x : iterate f (f x)
635     
636     {-# RULES
637     "iterate"   forall f x.     iterate f x = build (\c _n -> iterateFB c f x)
638     "iterateFB"                 iterateFB (:) = iterate
639      #-}
640
641 And now we get an infinite loop in the rule system 
642         iterate f x -> build (\cn -> iterateFB c f x
643                     -> iterateFB (:) f x
644                     -> iterate f x
645
646 Tiresome solution: don't do shorting out if f has rewrite rules.
647 Hence shortableIdInfo.
648
649 (b) Keeping the IdInfo right
650 ~~~~~~~~~~~~~~~~~~~~~~~~
651 We want to move strictness/worker info from f_local to f, but keep the rest.
652 Hence copyIdInfo.
653
654 \begin{code}
655 shortableIdInfo :: IdInfo -> Bool
656 shortableIdInfo info = isEmptyCoreRules (specInfo info)
657
658 copyIdInfo :: IdInfo    -- f_local
659            -> IdInfo    -- f (the exported one)
660            -> IdInfo    -- New info for f
661 copyIdInfo f_local f = f { strictnessInfo = strictnessInfo f_local,
662                            workerInfo     = workerInfo     f_local,
663                            cprInfo        = cprInfo        f_local
664                           }
665 \end{code}