2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
5 \section[IdInfo]{@IdInfos@: Non-essential information about @Ids@}
7 (And a pretty good illustration of quite a few things wrong with
12 -- * The IdDetails type
13 IdDetails(..), pprIdDetails,
17 vanillaIdInfo, noCafIdInfo,
18 seqIdInfo, megaSeqIdInfo,
20 -- ** Zapping various forms of Info
21 zapLamInfo, zapDemandInfo, zapFragileInfo,
23 -- ** The ArityInfo type
26 arityInfo, setArityInfo, ppArityInfo,
28 -- ** Demand and strictness Info
29 newStrictnessInfo, setNewStrictnessInfo,
30 newDemandInfo, setNewDemandInfo, pprNewStrictness,
34 -- ** Old strictness Info
36 mkStrictnessInfo, noStrictnessInfo,
37 ppStrictnessInfo, isBottomingStrictness,
38 strictnessInfo, setStrictnessInfo,
40 oldStrictnessFromNew, newStrictnessFromOld,
43 demandInfo, setDemandInfo,
46 -- ** Old Constructed Product Result Info
48 cprInfo, setCprInfo, ppCprInfo, noCprInfo,
49 cprInfoFromNewStrictness,
52 -- ** The WorkerInfo type
54 workerExists, wrapperArity, workerId,
55 workerInfo, setWorkerInfo, ppWorkerInfo,
58 unfoldingInfo, setUnfoldingInfo, setUnfoldingInfoLazily,
60 -- ** The InlinePragInfo type
62 inlinePragInfo, setInlinePragInfo,
64 -- ** The OccInfo type
66 isFragileOcc, isDeadOcc, isLoopBreaker,
70 insideLam, notInsideLam, oneBranch, notOneBranch,
72 -- ** The SpecInfo type
74 isEmptySpecInfo, specInfoFreeVars,
75 specInfoRules, seqSpecInfo, setSpecInfoHead,
76 specInfo, setSpecInfo,
78 -- ** The CAFInfo type
80 ppCafInfo, mayHaveCafRefs,
83 -- ** The LBVarInfo type
85 noLBVarInfo, hasNoLBVarInfo,
86 lbvarInfo, setLBVarInfo,
89 TickBoxOp(..), TickBoxId,
92 import CoreSyn ( CoreRule, setRuleIdName, seqRules, Unfolding, noUnfolding )
110 #ifdef OLD_STRICTNESS
112 import qualified Demand
117 -- infixl so you can say (id `set` a `set` b)
118 infixl 1 `setSpecInfo`,
126 `setNewStrictnessInfo`,
127 `setAllStrictnessInfo`,
129 #ifdef OLD_STRICTNESS
132 , `setStrictnessInfo`
136 %************************************************************************
138 \subsection{New strictness info}
140 %************************************************************************
145 -- | Set old and new strictness information together
146 setAllStrictnessInfo :: IdInfo -> Maybe StrictSig -> IdInfo
147 setAllStrictnessInfo info Nothing
148 = info { newStrictnessInfo = Nothing
149 #ifdef OLD_STRICTNESS
150 , strictnessInfo = NoStrictnessInfo
151 , cprInfo = NoCPRInfo
155 setAllStrictnessInfo info (Just sig)
156 = info { newStrictnessInfo = Just sig
157 #ifdef OLD_STRICTNESS
158 , strictnessInfo = oldStrictnessFromNew sig
159 , cprInfo = cprInfoFromNewStrictness sig
163 seqNewStrictnessInfo :: Maybe StrictSig -> ()
164 seqNewStrictnessInfo Nothing = ()
165 seqNewStrictnessInfo (Just ty) = seqStrictSig ty
167 pprNewStrictness :: Maybe StrictSig -> SDoc
168 pprNewStrictness Nothing = empty
169 pprNewStrictness (Just sig) = ftext (fsLit "Str:") <+> ppr sig
171 #ifdef OLD_STRICTNESS
172 oldStrictnessFromNew :: StrictSig -> Demand.StrictnessInfo
173 oldStrictnessFromNew sig = mkStrictnessInfo (map oldDemand dmds, isBotRes res_info)
175 (dmds, res_info) = splitStrictSig sig
177 cprInfoFromNewStrictness :: StrictSig -> CprInfo
178 cprInfoFromNewStrictness sig = case strictSigResInfo sig of
182 newStrictnessFromOld :: Name -> Arity -> Demand.StrictnessInfo -> CprInfo -> StrictSig
183 newStrictnessFromOld name arity (Demand.StrictnessInfo ds res) cpr
184 | listLengthCmp ds arity /= GT -- length ds <= arity
185 -- Sometimes the old strictness analyser has more
186 -- demands than the arity justifies
187 = mk_strict_sig name arity $
188 mkTopDmdType (map newDemand ds) (newRes res cpr)
190 newStrictnessFromOld name arity other cpr
191 = -- Either no strictness info, or arity is too small
192 -- In either case we can't say anything useful
193 mk_strict_sig name arity $
194 mkTopDmdType (replicate arity lazyDmd) (newRes False cpr)
196 mk_strict_sig name arity dmd_ty
197 = WARN( arity /= dmdTypeDepth dmd_ty, ppr name <+> (ppr arity $$ ppr dmd_ty) )
200 newRes True _ = BotRes
201 newRes False ReturnsCPR = retCPR
202 newRes False NoCPRInfo = TopRes
204 newDemand :: Demand.Demand -> NewDemand.Demand
205 newDemand (WwLazy True) = Abs
206 newDemand (WwLazy False) = lazyDmd
207 newDemand WwStrict = evalDmd
208 newDemand (WwUnpack unpk ds) = Eval (Prod (map newDemand ds))
209 newDemand WwPrim = lazyDmd
210 newDemand WwEnum = evalDmd
212 oldDemand :: NewDemand.Demand -> Demand.Demand
213 oldDemand Abs = WwLazy True
214 oldDemand Top = WwLazy False
215 oldDemand Bot = WwStrict
216 oldDemand (Box Bot) = WwStrict
217 oldDemand (Box Abs) = WwLazy False
218 oldDemand (Box (Eval _)) = WwStrict -- Pass box only
219 oldDemand (Defer d) = WwLazy False
220 oldDemand (Eval (Prod ds)) = WwUnpack True (map oldDemand ds)
221 oldDemand (Eval (Poly _)) = WwStrict
222 oldDemand (Call _) = WwStrict
224 #endif /* OLD_STRICTNESS */
229 seqNewDemandInfo :: Maybe Demand -> ()
230 seqNewDemandInfo Nothing = ()
231 seqNewDemandInfo (Just dmd) = seqDemand dmd
235 %************************************************************************
239 %************************************************************************
242 -- | The 'IdDetails' of an 'Id' give stable, and necessary,
243 -- information about the Id.
247 -- | The 'Id' for a record selector
249 { sel_tycon :: TyCon -- ^ For a data type family, this is the /instance/ 'TyCon'
250 -- not the family 'TyCon'
251 , sel_naughty :: Bool -- True <=> a "naughty" selector which can't actually exist, for example @x@ in:
252 -- data T = forall a. MkT { x :: a }
253 } -- See Note [Naughty record selectors] in TcTyClsDecls
255 | DataConWorkId DataCon -- ^ The 'Id' is for a data constructor /worker/
256 | DataConWrapId DataCon -- ^ The 'Id' is for a data constructor /wrapper/
258 -- [the only reasons we need to know is so that
259 -- a) to support isImplicitId
260 -- b) when desugaring a RecordCon we can get
261 -- from the Id back to the data con]
263 | ClassOpId Class -- ^ The 'Id' is an operation of a class
265 | PrimOpId PrimOp -- ^ The 'Id' is for a primitive operator
266 | FCallId ForeignCall -- ^ The 'Id' is for a foreign call
268 | TickBoxOpId TickBoxOp -- ^ The 'Id' is for a HPC tick box (both traditional and binary)
270 | DFunId -- ^ A dictionary function. We don't use this in an essential way,
271 -- currently, but it's kind of nice that we can keep track of
272 -- which Ids are DFuns, across module boundaries too
275 instance Outputable IdDetails where
278 pprIdDetails :: IdDetails -> SDoc
279 pprIdDetails VanillaId = empty
280 pprIdDetails (RecSelId {}) = ptext (sLit "[RecSel]")
281 pprIdDetails (DataConWorkId _) = ptext (sLit "[DataCon]")
282 pprIdDetails (DataConWrapId _) = ptext (sLit "[DataConWrapper]")
283 pprIdDetails (ClassOpId _) = ptext (sLit "[ClassOp]")
284 pprIdDetails (PrimOpId _) = ptext (sLit "[PrimOp]")
285 pprIdDetails (FCallId _) = ptext (sLit "[ForeignCall]")
286 pprIdDetails (TickBoxOpId _) = ptext (sLit "[TickBoxOp]")
287 pprIdDetails DFunId = ptext (sLit "[DFunId]")
293 %************************************************************************
295 \subsection{The main IdInfo type}
297 %************************************************************************
300 -- | An 'IdInfo' gives /optional/ information about an 'Id'. If
301 -- present it never lies, but it may not be present, in which case there
302 -- is always a conservative assumption which can be made.
304 -- Two 'Id's may have different info even though they have the same
305 -- 'Unique' (and are hence the same 'Id'); for example, one might lack
306 -- the properties attached to the other.
308 -- The 'IdInfo' gives information about the value, or definition, of the
309 -- 'Id'. It does not contain information about the 'Id''s usage,
310 -- except for 'demandInfo' and 'lbvarInfo'.
313 arityInfo :: !ArityInfo, -- ^ 'Id' arity
314 specInfo :: SpecInfo, -- ^ Specialisations of the 'Id's function which exist
315 #ifdef OLD_STRICTNESS
316 cprInfo :: CprInfo, -- ^ If the 'Id's function always constructs a product result
317 demandInfo :: Demand.Demand, -- ^ Whether or not the 'Id' is definitely demanded
318 strictnessInfo :: StrictnessInfo, -- ^ 'Id' strictness properties
320 workerInfo :: WorkerInfo, -- ^ Pointer to worker function.
321 -- Within one module this is irrelevant; the
322 -- inlining of a worker is handled via the 'Unfolding'.
323 -- However, when the module is imported by others, the
324 -- 'WorkerInfo' is used /only/ to indicate the form of
325 -- the RHS, so that interface files don't actually
326 -- need to contain the RHS; it can be derived from
327 -- the strictness info
329 unfoldingInfo :: Unfolding, -- ^ The 'Id's unfolding
330 cafInfo :: CafInfo, -- ^ 'Id' CAF info
331 lbvarInfo :: LBVarInfo, -- ^ Info about a lambda-bound variable, if the 'Id' is one
332 inlinePragInfo :: InlinePragInfo, -- ^ Any inline pragma atached to the 'Id'
333 occInfo :: OccInfo, -- ^ How the 'Id' occurs in the program
335 newStrictnessInfo :: Maybe StrictSig, -- ^ Id strictness information. Reason for Maybe:
336 -- the DmdAnal phase needs to know whether
337 -- this is the first visit, so it can assign botSig.
338 -- Other customers want topSig. So @Nothing@ is good.
340 newDemandInfo :: Maybe Demand -- ^ Id demand information. Similarly we want to know
341 -- if there's no known demand yet, for when we are looking
345 -- | Just evaluate the 'IdInfo' to WHNF
346 seqIdInfo :: IdInfo -> ()
347 seqIdInfo (IdInfo {}) = ()
349 -- | Evaluate all the fields of the 'IdInfo' that are generally demanded by the
351 megaSeqIdInfo :: IdInfo -> ()
353 = seqSpecInfo (specInfo info) `seq`
354 seqWorker (workerInfo info) `seq`
356 -- Omitting this improves runtimes a little, presumably because
357 -- some unfoldings are not calculated at all
358 -- seqUnfolding (unfoldingInfo info) `seq`
360 seqNewDemandInfo (newDemandInfo info) `seq`
361 seqNewStrictnessInfo (newStrictnessInfo info) `seq`
363 #ifdef OLD_STRICTNESS
364 Demand.seqDemand (demandInfo info) `seq`
365 seqStrictnessInfo (strictnessInfo info) `seq`
366 seqCpr (cprInfo info) `seq`
369 seqCaf (cafInfo info) `seq`
370 seqLBVar (lbvarInfo info) `seq`
371 seqOccInfo (occInfo info)
377 setWorkerInfo :: IdInfo -> WorkerInfo -> IdInfo
378 setWorkerInfo info wk = wk `seq` info { workerInfo = wk }
379 setSpecInfo :: IdInfo -> SpecInfo -> IdInfo
380 setSpecInfo info sp = sp `seq` info { specInfo = sp }
381 setInlinePragInfo :: IdInfo -> InlinePragInfo -> IdInfo
382 setInlinePragInfo info pr = pr `seq` info { inlinePragInfo = pr }
383 setOccInfo :: IdInfo -> OccInfo -> IdInfo
384 setOccInfo info oc = oc `seq` info { occInfo = oc }
385 #ifdef OLD_STRICTNESS
386 setStrictnessInfo info st = st `seq` info { strictnessInfo = st }
388 -- Try to avoid spack leaks by seq'ing
390 setUnfoldingInfoLazily :: IdInfo -> Unfolding -> IdInfo
391 setUnfoldingInfoLazily info uf -- Lazy variant to avoid looking at the
392 = -- unfolding of an imported Id unless necessary
393 info { unfoldingInfo = uf } -- (In this case the demand-zapping is redundant.)
395 setUnfoldingInfo :: IdInfo -> Unfolding -> IdInfo
396 setUnfoldingInfo info uf
397 -- We do *not* seq on the unfolding info, For some reason, doing so
398 -- actually increases residency significantly.
399 = info { unfoldingInfo = uf }
401 #ifdef OLD_STRICTNESS
402 setDemandInfo info dd = info { demandInfo = dd }
403 setCprInfo info cp = info { cprInfo = cp }
406 setArityInfo :: IdInfo -> ArityInfo -> IdInfo
407 setArityInfo info ar = info { arityInfo = ar }
408 setCafInfo :: IdInfo -> CafInfo -> IdInfo
409 setCafInfo info caf = info { cafInfo = caf }
411 setLBVarInfo :: IdInfo -> LBVarInfo -> IdInfo
412 setLBVarInfo info lb = {-lb `seq`-} info { lbvarInfo = lb }
414 setNewDemandInfo :: IdInfo -> Maybe Demand -> IdInfo
415 setNewDemandInfo info dd = dd `seq` info { newDemandInfo = dd }
416 setNewStrictnessInfo :: IdInfo -> Maybe StrictSig -> IdInfo
417 setNewStrictnessInfo info dd = dd `seq` info { newStrictnessInfo = dd }
422 -- | Basic 'IdInfo' that carries no useful information whatsoever
423 vanillaIdInfo :: IdInfo
426 cafInfo = vanillaCafInfo,
427 arityInfo = unknownArity,
428 #ifdef OLD_STRICTNESS
431 strictnessInfo = NoStrictnessInfo,
433 specInfo = emptySpecInfo,
434 workerInfo = NoWorker,
435 unfoldingInfo = noUnfolding,
436 lbvarInfo = NoLBVarInfo,
437 inlinePragInfo = AlwaysActive,
439 newDemandInfo = Nothing,
440 newStrictnessInfo = Nothing
443 -- | More informative 'IdInfo' we can use when we know the 'Id' has no CAF references
444 noCafIdInfo :: IdInfo
445 noCafIdInfo = vanillaIdInfo `setCafInfo` NoCafRefs
446 -- Used for built-in type Ids in MkId.
450 %************************************************************************
452 \subsection[arity-IdInfo]{Arity info about an @Id@}
454 %************************************************************************
456 For locally-defined Ids, the code generator maintains its own notion
457 of their arities; so it should not be asking... (but other things
458 besides the code-generator need arity info!)
461 -- | An 'ArityInfo' of @n@ tells us that partial application of this
462 -- 'Id' to up to @n-1@ value arguments does essentially no work.
464 -- That is not necessarily the same as saying that it has @n@ leading
465 -- lambdas, because coerces may get in the way.
467 -- The arity might increase later in the compilation process, if
468 -- an extra lambda floats up to the binding site.
469 type ArityInfo = Arity
471 -- | It is always safe to assume that an 'Id' has an arity of 0
472 unknownArity :: Arity
473 unknownArity = 0 :: Arity
475 ppArityInfo :: Int -> SDoc
476 ppArityInfo 0 = empty
477 ppArityInfo n = hsep [ptext (sLit "Arity"), int n]
480 %************************************************************************
482 \subsection{Inline-pragma information}
484 %************************************************************************
487 -- | Tells when the inlining is active.
488 -- When it is active the thing may be inlined, depending on how
491 -- If there was an @INLINE@ pragma, then as a separate matter, the
492 -- RHS will have been made to look small with a Core inline 'Note'
494 -- The default 'InlinePragInfo' is 'AlwaysActive', so the info serves
495 -- entirely as a way to inhibit inlining until we want it
496 type InlinePragInfo = Activation
500 %************************************************************************
504 %************************************************************************
507 -- | Records the specializations of this 'Id' that we know about
508 -- in the form of rewrite 'CoreRule's that target them
512 VarSet -- Locally-defined free vars of *both* LHS and RHS
513 -- of rules. I don't think it needs to include the
515 -- Note [Rule dependency info] in OccurAnal
517 -- | Assume that no specilizations exist: always safe
518 emptySpecInfo :: SpecInfo
519 emptySpecInfo = SpecInfo [] emptyVarSet
521 isEmptySpecInfo :: SpecInfo -> Bool
522 isEmptySpecInfo (SpecInfo rs _) = null rs
524 -- | Retrieve the locally-defined free variables of both the left and
525 -- right hand sides of the specialization rules
526 specInfoFreeVars :: SpecInfo -> VarSet
527 specInfoFreeVars (SpecInfo _ fvs) = fvs
529 specInfoRules :: SpecInfo -> [CoreRule]
530 specInfoRules (SpecInfo rules _) = rules
532 -- | Change the name of the function the rule is keyed on on all of the 'CoreRule's
533 setSpecInfoHead :: Name -> SpecInfo -> SpecInfo
534 setSpecInfoHead fn (SpecInfo rules fvs)
535 = SpecInfo (map (setRuleIdName fn) rules) fvs
537 seqSpecInfo :: SpecInfo -> ()
538 seqSpecInfo (SpecInfo rules fvs) = seqRules rules `seq` seqVarSet fvs
541 %************************************************************************
543 \subsection[worker-IdInfo]{Worker info about an @Id@}
545 %************************************************************************
547 There might not be a worker, even for a strict function, because:
548 (a) the function might be small enough to inline, so no need
550 (b) the strictness info might be "SSS" or something, so no w/w split.
552 Sometimes the arity of a wrapper changes from the original arity from
553 which it was generated, so we always emit the "original" arity into
554 the interface file, as part of the worker info.
556 How can this happen? Sometimes we get
557 f = coerce t (\x y -> $wf x y)
558 at the moment of w/w split; but the eta reducer turns it into
560 which is perfectly fine except that the exposed arity so far as
561 the code generator is concerned (zero) differs from the arity
562 when we did the split (2).
564 All this arises because we use 'arity' to mean "exactly how many
565 top level lambdas are there" in interface files; but during the
566 compilation of this module it means "how many things can I apply
571 -- | If this Id has a worker then we store a reference to it. Worker
572 -- functions are generated by the worker\/wrapper pass, using information
573 -- information from strictness analysis.
574 data WorkerInfo = NoWorker -- ^ No known worker function
575 | HasWorker Id Arity -- ^ The 'Arity' is the arity of the /wrapper/ at the moment of the
576 -- worker\/wrapper split, which may be different from the current 'Id' 'Aritiy'
578 seqWorker :: WorkerInfo -> ()
579 seqWorker (HasWorker id a) = id `seq` a `seq` ()
580 seqWorker NoWorker = ()
582 ppWorkerInfo :: WorkerInfo -> SDoc
583 ppWorkerInfo NoWorker = empty
584 ppWorkerInfo (HasWorker wk_id _) = ptext (sLit "Worker") <+> ppr wk_id
586 workerExists :: WorkerInfo -> Bool
587 workerExists NoWorker = False
588 workerExists (HasWorker _ _) = True
590 -- | The 'Id' of the worker function if it exists, or a panic otherwise
591 workerId :: WorkerInfo -> Id
592 workerId (HasWorker id _) = id
593 workerId NoWorker = panic "workerId: NoWorker"
595 -- | The 'Arity' of the worker function at the time of the split if it exists, or a panic otherwise
596 wrapperArity :: WorkerInfo -> Arity
597 wrapperArity (HasWorker _ a) = a
598 wrapperArity NoWorker = panic "wrapperArity: NoWorker"
602 %************************************************************************
604 \subsection[CG-IdInfo]{Code generator-related information}
606 %************************************************************************
609 -- CafInfo is used to build Static Reference Tables (see simplStg/SRT.lhs).
611 -- | Records whether an 'Id' makes Constant Applicative Form references
613 = MayHaveCafRefs -- ^ Indicates that the 'Id' is for either:
615 -- 1. A function or static constructor
616 -- that refers to one or more CAFs, or
618 -- 2. A real live CAF
620 | NoCafRefs -- ^ A function or static constructor
621 -- that refers to no CAFs.
624 -- | Assumes that the 'Id' has CAF references: definitely safe
625 vanillaCafInfo :: CafInfo
626 vanillaCafInfo = MayHaveCafRefs
628 mayHaveCafRefs :: CafInfo -> Bool
629 mayHaveCafRefs MayHaveCafRefs = True
630 mayHaveCafRefs _ = False
632 seqCaf :: CafInfo -> ()
633 seqCaf c = c `seq` ()
635 ppCafInfo :: CafInfo -> SDoc
636 ppCafInfo NoCafRefs = ptext (sLit "NoCafRefs")
637 ppCafInfo MayHaveCafRefs = empty
640 %************************************************************************
642 \subsection[cpr-IdInfo]{Constructed Product Result info about an @Id@}
644 %************************************************************************
647 #ifdef OLD_STRICTNESS
648 -- | If the @Id@ is a function then it may have Constructed Product Result
649 -- (CPR) info. A CPR analysis phase detects whether:
651 -- 1. The function's return value has a product type, i.e. an algebraic type
652 -- with a single constructor. Examples of such types are tuples and boxed
655 -- 2. The function always 'constructs' the value that it is returning. It
656 -- must do this on every path through, and it's OK if it calls another
657 -- function which constructs the result.
659 -- If this is the case then we store a template which tells us the
660 -- function has the CPR property and which components of the result are
663 = NoCPRInfo -- ^ No, this function does not return a constructed product
664 | ReturnsCPR -- ^ Yes, this function returns a constructed product
666 -- Implicitly, this means "after the function has been applied
667 -- to all its arguments", so the worker\/wrapper builder in
668 -- WwLib.mkWWcpr checks that that it is indeed saturated before
669 -- making use of the CPR info
671 -- We used to keep nested info about sub-components, but
672 -- we never used it so I threw it away
674 -- | It's always safe to assume that an 'Id' does not have the CPR property
676 noCprInfo = NoCPRInfo
678 seqCpr :: CprInfo -> ()
679 seqCpr ReturnsCPR = ()
680 seqCpr NoCPRInfo = ()
682 ppCprInfo NoCPRInfo = empty
683 ppCprInfo ReturnsCPR = ptext (sLit "__M")
685 instance Outputable CprInfo where
688 instance Show CprInfo where
689 showsPrec p c = showsPrecSDoc p (ppr c)
693 %************************************************************************
695 \subsection[lbvar-IdInfo]{Lambda-bound var info about an @Id@}
697 %************************************************************************
700 -- | If the 'Id' is a lambda-bound variable then it may have lambda-bound
701 -- variable info. Sometimes we know whether the lambda binding this variable
702 -- is a \"one-shot\" lambda; that is, whether it is applied at most once.
704 -- This information may be useful in optimisation, as computations may
705 -- safely be floated inside such a lambda without risk of duplicating
707 data LBVarInfo = NoLBVarInfo -- ^ No information
708 | IsOneShotLambda -- ^ The lambda is applied at most once).
710 -- | It is always safe to assume that an 'Id' has no lambda-bound variable information
711 noLBVarInfo :: LBVarInfo
712 noLBVarInfo = NoLBVarInfo
714 hasNoLBVarInfo :: LBVarInfo -> Bool
715 hasNoLBVarInfo NoLBVarInfo = True
716 hasNoLBVarInfo IsOneShotLambda = False
718 seqLBVar :: LBVarInfo -> ()
719 seqLBVar l = l `seq` ()
721 pprLBVarInfo :: LBVarInfo -> SDoc
722 pprLBVarInfo NoLBVarInfo = empty
723 pprLBVarInfo IsOneShotLambda = ptext (sLit "OneShot")
725 instance Outputable LBVarInfo where
728 instance Show LBVarInfo where
729 showsPrec p c = showsPrecSDoc p (ppr c)
733 %************************************************************************
735 \subsection{Bulk operations on IdInfo}
737 %************************************************************************
740 -- | This is used to remove information on lambda binders that we have
741 -- setup as part of a lambda group, assuming they will be applied all at once,
742 -- but turn out to be part of an unsaturated lambda as in e.g:
744 -- > (\x1. \x2. e) arg1
745 zapLamInfo :: IdInfo -> Maybe IdInfo
746 zapLamInfo info@(IdInfo {occInfo = occ, newDemandInfo = demand})
747 | is_safe_occ occ && is_safe_dmd demand
750 = Just (info {occInfo = safe_occ, newDemandInfo = Nothing})
752 -- The "unsafe" occ info is the ones that say I'm not in a lambda
753 -- because that might not be true for an unsaturated lambda
754 is_safe_occ (OneOcc in_lam _ _) = in_lam
755 is_safe_occ _other = True
757 safe_occ = case occ of
758 OneOcc _ once int_cxt -> OneOcc insideLam once int_cxt
761 is_safe_dmd Nothing = True
762 is_safe_dmd (Just dmd) = not (isStrictDmd dmd)
766 -- | Remove demand info on the 'IdInfo' if it is present, otherwise return @Nothing@
767 zapDemandInfo :: IdInfo -> Maybe IdInfo
768 zapDemandInfo info@(IdInfo {newDemandInfo = dmd})
769 | isJust dmd = Just (info {newDemandInfo = Nothing})
770 | otherwise = Nothing
774 zapFragileInfo :: IdInfo -> Maybe IdInfo
775 -- ^ Zap info that depends on free variables
777 = Just (info `setSpecInfo` emptySpecInfo
778 `setWorkerInfo` NoWorker
779 `setUnfoldingInfo` noUnfolding
780 `setOccInfo` if isFragileOcc occ then NoOccInfo else occ)
785 %************************************************************************
787 \subsection{TickBoxOp}
789 %************************************************************************
794 -- | Tick box for Hpc-style coverage
796 = TickBox Module {-# UNPACK #-} !TickBoxId
798 instance Outputable TickBoxOp where
799 ppr (TickBox mod n) = ptext (sLit "tick") <+> ppr (mod,n)