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