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